draft of config file and MRU menu

This commit is contained in:
Abdel
2015-09-19 22:59:26 -04:00
parent 005710d1de
commit 57e4ff9729
6 changed files with 196 additions and 65 deletions

3
vCardEditor/App.config Normal file
View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>

View File

@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.IO;
namespace vCardEditor.Repository
{
public class ConfigDao : IConfigDao
{
public string ConfigFileName { get; set; }
string minimalConfigFile = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + Environment.NewLine +
"<configuration>" + Environment.NewLine +
" <appSettings>" + Environment.NewLine +
"</appSettings>" + Environment.NewLine +
"</configuration>";
private static ConfigDao instance = null;
public static ConfigDao Instance
{
get
{
if (instance == null)
instance = new ConfigDao();
return instance;
}
}
private ConfigDao()
{
ConfigFileName = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath;
//if config not found, create one.
if (!File.Exists(ConfigFileName))
File.WriteAllText(ConfigFileName, minimalConfigFile);
}
public string GetConfigKey(string key)
{
string returnValue = null;
if (ConfigurationManager.AppSettings[key] != null)
returnValue = ConfigurationManager.AppSettings[key];
return returnValue;
}
public void SaveConfigFile(string Key, string value)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings.Remove(Key);
config.AppSettings.Settings.Add(Key, value);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
}
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace vCardEditor.Repository
{
public interface IConfigDao
{
string ConfigFileName { get; set; }
string GetConfigKey(string key);
void SaveConfigFile(string Key, string value);
}
}

View File

@@ -53,8 +53,13 @@
this.PersonalWebSiteLabel = new System.Windows.Forms.Label();
this.WorkPhoneLabel = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.EmailAddressValue = new vCardEditor.View.StateTextBox();
this.EmailAddressLabel = new System.Windows.Forms.Label();
this.WorkPhoneValue = new vCardEditor.View.StateTextBox();
this.PersonalWebSiteValue = new vCardEditor.View.StateTextBox();
this.PhotoBox = new System.Windows.Forms.PictureBox();
this.CellularPhoneValue = new vCardEditor.View.StateTextBox();
this.HomePhoneValue = new vCardEditor.View.StateTextBox();
this.bsContacts = new System.Windows.Forms.BindingSource(this.components);
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.btnClearFilter = new System.Windows.Forms.Button();
@@ -62,11 +67,7 @@
this.dgContacts = new System.Windows.Forms.DataGridView();
this.Column1 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.EmailAddressValue = new vCardEditor.View.StateTextBox();
this.WorkPhoneValue = new vCardEditor.View.StateTextBox();
this.PersonalWebSiteValue = new vCardEditor.View.StateTextBox();
this.CellularPhoneValue = new vCardEditor.View.StateTextBox();
this.HomePhoneValue = new vCardEditor.View.StateTextBox();
this.recentFilesMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1.SuspendLayout();
this.toolStrip1.SuspendLayout();
this.groupBox1.SuspendLayout();
@@ -92,6 +93,7 @@
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.miOpen,
this.toolStripMenuItem1,
this.recentFilesMenuItem,
this.miQuit});
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
@@ -100,19 +102,19 @@
// miOpen
//
this.miOpen.Name = "miOpen";
this.miOpen.Size = new System.Drawing.Size(103, 22);
this.miOpen.Size = new System.Drawing.Size(152, 22);
this.miOpen.Text = "&Open";
this.miOpen.Click += new System.EventHandler(this.tbsOpen_Click);
//
// toolStripMenuItem1
//
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(100, 6);
this.toolStripMenuItem1.Size = new System.Drawing.Size(149, 6);
//
// miQuit
//
this.miQuit.Name = "miQuit";
this.miQuit.Size = new System.Drawing.Size(103, 22);
this.miQuit.Size = new System.Drawing.Size(152, 22);
this.miQuit.Text = "&Quit";
this.miQuit.Click += new System.EventHandler(this.miQuit_Click);
//
@@ -284,6 +286,17 @@
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Contact Detail :";
//
// EmailAddressValue
//
this.EmailAddressValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.EmailAddressValue.Location = new System.Drawing.Point(123, 99);
this.EmailAddressValue.Name = "EmailAddressValue";
this.EmailAddressValue.Size = new System.Drawing.Size(272, 20);
this.EmailAddressValue.TabIndex = 59;
this.EmailAddressValue.LostFocus += new System.EventHandler(this.Value_TextChanged);
this.EmailAddressValue.Validated += new System.EventHandler(this.Value_TextChanged);
//
// EmailAddressLabel
//
this.EmailAddressLabel.Location = new System.Drawing.Point(-7, 100);
@@ -293,6 +306,28 @@
this.EmailAddressLabel.Text = "Email Address:";
this.EmailAddressLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// WorkPhoneValue
//
this.WorkPhoneValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.WorkPhoneValue.Location = new System.Drawing.Point(123, 124);
this.WorkPhoneValue.Name = "WorkPhoneValue";
this.WorkPhoneValue.Size = new System.Drawing.Size(272, 20);
this.WorkPhoneValue.TabIndex = 57;
this.WorkPhoneValue.LostFocus += new System.EventHandler(this.Value_TextChanged);
this.WorkPhoneValue.Validated += new System.EventHandler(this.Value_TextChanged);
//
// PersonalWebSiteValue
//
this.PersonalWebSiteValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.PersonalWebSiteValue.Location = new System.Drawing.Point(123, 149);
this.PersonalWebSiteValue.Name = "PersonalWebSiteValue";
this.PersonalWebSiteValue.Size = new System.Drawing.Size(272, 20);
this.PersonalWebSiteValue.TabIndex = 56;
this.PersonalWebSiteValue.LostFocus += new System.EventHandler(this.Value_TextChanged);
this.PersonalWebSiteValue.Validated += new System.EventHandler(this.Value_TextChanged);
//
// PhotoBox
//
this.PhotoBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
@@ -304,6 +339,28 @@
this.PhotoBox.TabIndex = 53;
this.PhotoBox.TabStop = false;
//
// CellularPhoneValue
//
this.CellularPhoneValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.CellularPhoneValue.Location = new System.Drawing.Point(123, 74);
this.CellularPhoneValue.Name = "CellularPhoneValue";
this.CellularPhoneValue.Size = new System.Drawing.Size(272, 20);
this.CellularPhoneValue.TabIndex = 47;
this.CellularPhoneValue.LostFocus += new System.EventHandler(this.Value_TextChanged);
this.CellularPhoneValue.Validated += new System.EventHandler(this.Value_TextChanged);
//
// HomePhoneValue
//
this.HomePhoneValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.HomePhoneValue.Location = new System.Drawing.Point(123, 49);
this.HomePhoneValue.Name = "HomePhoneValue";
this.HomePhoneValue.Size = new System.Drawing.Size(272, 20);
this.HomePhoneValue.TabIndex = 45;
this.HomePhoneValue.LostFocus += new System.EventHandler(this.Value_TextChanged);
this.HomePhoneValue.Validated += new System.EventHandler(this.Value_TextChanged);
//
// groupBox2
//
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
@@ -378,60 +435,11 @@
this.Column2.Name = "Column2";
this.Column2.ReadOnly = true;
//
// EmailAddressValue
// recentFilesMenuItem
//
this.EmailAddressValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.EmailAddressValue.Location = new System.Drawing.Point(123, 99);
this.EmailAddressValue.Name = "EmailAddressValue";
this.EmailAddressValue.Size = new System.Drawing.Size(272, 20);
this.EmailAddressValue.TabIndex = 59;
this.EmailAddressValue.LostFocus += new System.EventHandler(this.Value_TextChanged);
this.EmailAddressValue.Validated += new System.EventHandler(this.Value_TextChanged);
//
// WorkPhoneValue
//
this.WorkPhoneValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.WorkPhoneValue.Location = new System.Drawing.Point(123, 124);
this.WorkPhoneValue.Name = "WorkPhoneValue";
this.WorkPhoneValue.Size = new System.Drawing.Size(272, 20);
this.WorkPhoneValue.TabIndex = 57;
this.WorkPhoneValue.LostFocus += new System.EventHandler(this.Value_TextChanged);
this.WorkPhoneValue.Validated += new System.EventHandler(this.Value_TextChanged);
//
// PersonalWebSiteValue
//
this.PersonalWebSiteValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.PersonalWebSiteValue.Location = new System.Drawing.Point(123, 149);
this.PersonalWebSiteValue.Name = "PersonalWebSiteValue";
this.PersonalWebSiteValue.Size = new System.Drawing.Size(272, 20);
this.PersonalWebSiteValue.TabIndex = 56;
this.PersonalWebSiteValue.LostFocus += new System.EventHandler(this.Value_TextChanged);
this.PersonalWebSiteValue.Validated += new System.EventHandler(this.Value_TextChanged);
//
// CellularPhoneValue
//
this.CellularPhoneValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.CellularPhoneValue.Location = new System.Drawing.Point(123, 74);
this.CellularPhoneValue.Name = "CellularPhoneValue";
this.CellularPhoneValue.Size = new System.Drawing.Size(272, 20);
this.CellularPhoneValue.TabIndex = 47;
this.CellularPhoneValue.LostFocus += new System.EventHandler(this.Value_TextChanged);
this.CellularPhoneValue.Validated += new System.EventHandler(this.Value_TextChanged);
//
// HomePhoneValue
//
this.HomePhoneValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.HomePhoneValue.Location = new System.Drawing.Point(123, 49);
this.HomePhoneValue.Name = "HomePhoneValue";
this.HomePhoneValue.Size = new System.Drawing.Size(272, 20);
this.HomePhoneValue.TabIndex = 45;
this.HomePhoneValue.LostFocus += new System.EventHandler(this.Value_TextChanged);
this.HomePhoneValue.Validated += new System.EventHandler(this.Value_TextChanged);
this.recentFilesMenuItem.Name = "recentFilesMenuItem";
this.recentFilesMenuItem.Size = new System.Drawing.Size(152, 22);
this.recentFilesMenuItem.Text = "Recent";
//
// MainForm
//
@@ -486,7 +494,6 @@
private System.Windows.Forms.BindingSource bsContacts;
internal System.Windows.Forms.Label FormattedNameLabel;
internal System.Windows.Forms.Label HomePhoneLabel;
internal System.Windows.Forms.TextBox FormattedNameValue;
internal StateTextBox HomePhoneValue;
internal System.Windows.Forms.Label CellularPhoneLabel;
internal StateTextBox CellularPhoneValue;
@@ -504,5 +511,7 @@
private System.Windows.Forms.DataGridViewTextBoxColumn Column2;
private System.Windows.Forms.Button btnClearFilter;
internal System.Windows.Forms.PictureBox PhotoBox;
private System.Windows.Forms.ToolStripMenuItem recentFilesMenuItem;
internal StateTextBox FormattedNameValue;
}
}

View File

@@ -10,6 +10,8 @@ using VCFEditor.View;
using VCFEditor.Model;
using Thought.vCards;
using System.IO;
using vCardEditor.Repository;
using System.Configuration;
namespace vCardEditor.View
{
@@ -26,6 +28,7 @@ namespace vCardEditor.View
public event EventHandler<FormClosingEventArgs> CloseForm;
#endregion
ComponentResourceManager resources;
List<String> MRUList;
public int SelectedContactIndex
{
@@ -43,8 +46,32 @@ namespace vCardEditor.View
{
InitializeComponent();
resources = new ComponentResourceManager(typeof(MainForm));
recentFilesMenuItem.DropDownItemClicked += (s, e) => OpenNewFile(s, e.ClickedItem.Text);
//Read the MRU List from Config file.
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["paths"]))
{
MRUList = new List<string>(ConfigurationManager.AppSettings["paths"].Split(new char[] { ';' }));
//Update the MRU Menu entries..
UpdateMRUMenu();
}
}
private void UpdateMRUMenu()
{
recentFilesMenuItem.DropDownItems.Clear();
foreach (string item in MRUList)
recentFilesMenuItem.DropDownItems.Add(item);
}
private void tbsOpen_Click(object sender, EventArgs e)
{
DialogResult result = openFileDialog.ShowDialog();
@@ -280,6 +307,17 @@ namespace vCardEditor.View
return;
}
//add to the MRU.
if (MRUList == null)
MRUList = new List<string>();
if (!MRUList.Any(x => string.Compare(x, file, StringComparison.OrdinalIgnoreCase) == 0))
{
MRUList.Add(file);
ConfigDao.Instance.SaveConfigFile("path", string.Join(";", MRUList.ToArray()));
UpdateMRUMenu();
}
if (NewFileOpened != null)
NewFileOpened(sender, new EventArg<string>(file));
}
@@ -309,7 +347,6 @@ namespace vCardEditor.View
return result;
}
}
}

View File

@@ -39,10 +39,10 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
@@ -50,8 +50,10 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Repository\ConfigDao.cs" />
<Compile Include="Repository\ContactRepository.cs" />
<Compile Include="Repository\FileHandler.cs" />
<Compile Include="Repository\IConfigDao.cs" />
<Compile Include="Repository\IContactRepository.cs" />
<Compile Include="Model\Contact.cs" />
<Compile Include="Presenter\MainPresenter.cs" />
@@ -132,6 +134,7 @@
<EmbeddedResource Include="View\MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
<None Include="App.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>