From 1efb72a332aa8629cd7f2cf2ec55d8db02e76009 Mon Sep 17 00:00:00 2001 From: Abdel Date: Tue, 22 Sep 2015 22:17:14 -0400 Subject: [PATCH] FixedList to maintain MRU. Added simple config dialog --- vCardEditor/App.config | 3 - vCardEditor/Model/Contact.cs | 6 +- vCardEditor/Model/FixedList.cs | 53 +++++++ vCardEditor/Model/ObjectCopier.cs | 40 ++++++ vCardEditor/Presenter/MainPresenter.cs | 17 ++- vCardEditor/Repository/ConfigRepository.cs | 26 +++- vCardEditor/Repository/ContactRepository.cs | 3 + vCardEditor/View/ConfigDialog.Designer.cs | 83 +++++++++++ vCardEditor/View/ConfigDialog.cs | 28 ++++ vCardEditor/View/ConfigDialog.resx | 120 ++++++++++++++++ vCardEditor/View/IMainView.cs | 3 +- vCardEditor/View/MainForm.Designer.cs | 150 +++++++++++--------- vCardEditor/View/MainForm.cs | 25 ++-- vCardEditor/View/StateTextBox.cs | 12 +- vCardEditor/vCardEditor.csproj | 12 +- vCardEditor_Test/FixedListTest.cs | 67 +++++++++ vCardEditor_Test/vCardEditor_Test.csproj | 8 ++ 17 files changed, 544 insertions(+), 112 deletions(-) delete mode 100644 vCardEditor/App.config create mode 100644 vCardEditor/Model/FixedList.cs create mode 100644 vCardEditor/Model/ObjectCopier.cs create mode 100644 vCardEditor/View/ConfigDialog.Designer.cs create mode 100644 vCardEditor/View/ConfigDialog.cs create mode 100644 vCardEditor/View/ConfigDialog.resx create mode 100644 vCardEditor_Test/FixedListTest.cs diff --git a/vCardEditor/App.config b/vCardEditor/App.config deleted file mode 100644 index 49cc43e..0000000 --- a/vCardEditor/App.config +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/vCardEditor/Model/Contact.cs b/vCardEditor/Model/Contact.cs index cfe79da..4ffedb3 100644 --- a/vCardEditor/Model/Contact.cs +++ b/vCardEditor/Model/Contact.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; +using System.ComponentModel; using Thought.vCards; namespace VCFEditor.Model diff --git a/vCardEditor/Model/FixedList.cs b/vCardEditor/Model/FixedList.cs new file mode 100644 index 0000000..f2bb7e4 --- /dev/null +++ b/vCardEditor/Model/FixedList.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace vCardEditor.Model +{ + [Serializable] + public class FixedList + { + public List _innerList { get; set; } + + private int _size; + public int Size + { + get { return _size; } + set { _size = value; } + } + public FixedList() : this(5) + { + + } + public FixedList(int size) + { + this._size = size; + this._innerList = new List(size); + } + + public void Enqueue(string elem) + { + _innerList.Insert(_innerList.Count, elem); + + if (_innerList.Count > _size) + _innerList.RemoveAt(0); + } + + public string this[int index] + { + get { return _innerList[index]; } + set { _innerList[index] = value; } + } + + public bool Contains(string elem) + { + return _innerList.Any(x => string.Compare(x, elem, StringComparison.OrdinalIgnoreCase) == 0); + } + + public bool IsEmpty() + { + return (this._innerList.Count == 0); + } + } +} diff --git a/vCardEditor/Model/ObjectCopier.cs b/vCardEditor/Model/ObjectCopier.cs new file mode 100644 index 0000000..e3e9645 --- /dev/null +++ b/vCardEditor/Model/ObjectCopier.cs @@ -0,0 +1,40 @@ +using System; +using System.IO; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Formatters.Binary; + + +namespace vCardEditor.Model +{ + public static class ObjectCopier + { + /// + /// Perform a deep Copy of the object. + /// + /// The type of object being copied. + /// The object instance to copy. + /// The copied object. + public static T Clone(this T source) + { + if (!typeof(T).IsSerializable) + { + throw new ArgumentException("The type must be serializable.", "source"); + } + + // Don't serialize a null object, simply return the default for that object + if (Object.ReferenceEquals(source, null)) + { + return default(T); + } + + IFormatter formatter = new BinaryFormatter(); + Stream stream = new MemoryStream(); + using (stream) + { + formatter.Serialize(stream, source); + stream.Seek(0, SeekOrigin.Begin); + return (T)formatter.Deserialize(stream); + } + } + } +} diff --git a/vCardEditor/Presenter/MainPresenter.cs b/vCardEditor/Presenter/MainPresenter.cs index 9a0578b..d1c40fe 100644 --- a/vCardEditor/Presenter/MainPresenter.cs +++ b/vCardEditor/Presenter/MainPresenter.cs @@ -7,6 +7,7 @@ using vCardEditor.View; using VCFEditor.Repository; using System.Windows.Forms; using vCardEditor.Repository; +using vCardEditor.Model; namespace VCFEditor.Presenter @@ -78,18 +79,17 @@ namespace VCFEditor.Presenter string path = e.Data; if (!string.IsNullOrEmpty(path)) { - _repository.LoadContacts(path); - _view.DisplayContacts(_repository.Contacts); + FixedList MRUList = ConfigRepository.Instance.Paths; - List MRUList = ConfigRepository.Instance.Paths; - - if (!MRUList.Any(x => string.Compare(x, path, StringComparison.OrdinalIgnoreCase) == 0)) + if (!MRUList.Contains(path)) { - MRUList.Add(path); + MRUList.Enqueue(path); // ConfigRepository.Instance.Paths.Clear(); _view.UpdateMRUMenu(MRUList); } - + + _repository.LoadContacts(path); + _view.DisplayContacts(_repository.Contacts); } @@ -103,7 +103,10 @@ namespace VCFEditor.Presenter vCard card = _repository.Contacts[index].card; if (card != null) + { + _repository.Contacts[index].isDirty = false; _view.DisplayContactDetail(card, _repository.fileName); + } } } diff --git a/vCardEditor/Repository/ConfigRepository.cs b/vCardEditor/Repository/ConfigRepository.cs index 4bbc480..ddb4f2e 100644 --- a/vCardEditor/Repository/ConfigRepository.cs +++ b/vCardEditor/Repository/ConfigRepository.cs @@ -1,14 +1,15 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Xml.Serialization; using System.IO; -using System.Xml; +using System.ComponentModel; +using vCardEditor.Model; +using System.Runtime.Serialization; namespace vCardEditor.Repository { [XmlRoot("Config")] + [Serializable] public class ConfigRepository { private static string ConfigFileName @@ -29,12 +30,18 @@ namespace vCardEditor.Repository } } - public bool OverWrite; - [XmlArrayItemAttribute("Folder")] - public List Paths; + [Description("Overwrite the file when saving")] + public bool OverWrite { get; set; } + [Description("Maximum entries for MRU ")] + public int Maximum { get; set; } + + [Browsable(false)] + public FixedList Paths { get; set;} private ConfigRepository() { } + + /// /// save config file /// @@ -66,17 +73,22 @@ namespace vCardEditor.Repository XmlSerializer deserializer = new XmlSerializer(typeof(ConfigRepository)); using (TextReader reader = new StreamReader(ConfigFileName)) + { obj = (ConfigRepository)deserializer.Deserialize(reader); + obj.Paths.Size = obj.Maximum; + } } catch (Exception) { obj = new ConfigRepository(); - obj.Paths = new List(); + obj.Paths = new FixedList(5); } return obj; } + + } } diff --git a/vCardEditor/Repository/ContactRepository.cs b/vCardEditor/Repository/ContactRepository.cs index 665b348..0aa90fc 100644 --- a/vCardEditor/Repository/ContactRepository.cs +++ b/vCardEditor/Repository/ContactRepository.cs @@ -90,6 +90,9 @@ namespace VCFEditor.Repository if (string.IsNullOrEmpty(fileName)) fileName = this.fileName; + //Take a copy... + if (!ConfigRepository.Instance.OverWrite) + File.Move(fileName, fileName + ".old"); StringBuilder sb = new StringBuilder(); foreach (var entry in Contacts) diff --git a/vCardEditor/View/ConfigDialog.Designer.cs b/vCardEditor/View/ConfigDialog.Designer.cs new file mode 100644 index 0000000..4e6dc4f --- /dev/null +++ b/vCardEditor/View/ConfigDialog.Designer.cs @@ -0,0 +1,83 @@ +namespace vCardEditor.View +{ + partial class ConfigDialog + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.btnClose = new System.Windows.Forms.Button(); + this.pgConfig = new System.Windows.Forms.PropertyGrid(); + this.btnCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // btnClose + // + this.btnClose.Location = new System.Drawing.Point(253, 347); + this.btnClose.Name = "btnClose"; + this.btnClose.Size = new System.Drawing.Size(75, 23); + this.btnClose.TabIndex = 0; + this.btnClose.Text = "Close"; + this.btnClose.UseVisualStyleBackColor = true; + this.btnClose.Click += new System.EventHandler(this.btnClose_Click); + // + // pgConfig + // + this.pgConfig.Location = new System.Drawing.Point(12, 12); + this.pgConfig.Name = "pgConfig"; + this.pgConfig.Size = new System.Drawing.Size(316, 329); + this.pgConfig.TabIndex = 1; + // + // btnCancel + // + this.btnCancel.Location = new System.Drawing.Point(172, 347); + this.btnCancel.Name = "btnCancel"; + this.btnCancel.Size = new System.Drawing.Size(75, 23); + this.btnCancel.TabIndex = 0; + this.btnCancel.Text = "Cancel"; + this.btnCancel.UseVisualStyleBackColor = true; + this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); + // + // ConfigDialog + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(337, 382); + this.Controls.Add(this.pgConfig); + this.Controls.Add(this.btnCancel); + this.Controls.Add(this.btnClose); + this.Name = "ConfigDialog"; + this.Text = "ConfigDialog"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button btnClose; + private System.Windows.Forms.PropertyGrid pgConfig; + private System.Windows.Forms.Button btnCancel; + } +} \ No newline at end of file diff --git a/vCardEditor/View/ConfigDialog.cs b/vCardEditor/View/ConfigDialog.cs new file mode 100644 index 0000000..e415a93 --- /dev/null +++ b/vCardEditor/View/ConfigDialog.cs @@ -0,0 +1,28 @@ +using System; +using System.Windows.Forms; +using vCardEditor.Repository; +using vCardEditor.Model; + +namespace vCardEditor.View +{ + public partial class ConfigDialog : Form + { + public ConfigDialog() + { + InitializeComponent(); + ConfigRepository conf = ConfigRepository.Instance;//.Clone(); + pgConfig.SelectedObject = conf; + } + + private void btnClose_Click(object sender, EventArgs e) + { + + this.Close(); + } + + private void btnCancel_Click(object sender, EventArgs e) + { + this.Close(); + } + } +} diff --git a/vCardEditor/View/ConfigDialog.resx b/vCardEditor/View/ConfigDialog.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/vCardEditor/View/ConfigDialog.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/vCardEditor/View/IMainView.cs b/vCardEditor/View/IMainView.cs index 774d997..8913fdf 100644 --- a/vCardEditor/View/IMainView.cs +++ b/vCardEditor/View/IMainView.cs @@ -4,6 +4,7 @@ using Thought.vCards; using VCFEditor.Model; using System.ComponentModel; using System.Windows.Forms; +using vCardEditor.Model; namespace VCFEditor.View { @@ -24,6 +25,6 @@ namespace VCFEditor.View void DisplayContacts(BindingList contacts); void DisplayContactDetail(vCard card, string FileName); bool AskMessage(string msg, string caption); - void UpdateMRUMenu(List MRUList); + void UpdateMRUMenu(FixedList MRUList); } } diff --git a/vCardEditor/View/MainForm.Designer.cs b/vCardEditor/View/MainForm.Designer.cs index eb92ea1..036b356 100644 --- a/vCardEditor/View/MainForm.Designer.cs +++ b/vCardEditor/View/MainForm.Designer.cs @@ -53,8 +53,14 @@ this.PersonalWebSiteLabel = new System.Windows.Forms.Label(); this.WorkPhoneLabel = new System.Windows.Forms.Label(); this.gbContactDetail = 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.FormattedNameValue = new vCardEditor.View.StateTextBox(); this.bsContacts = new System.Windows.Forms.BindingSource(this.components); this.gbNameList = new System.Windows.Forms.GroupBox(); this.btnClearFilter = new System.Windows.Forms.Button(); @@ -62,12 +68,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.FormattedNameValue = new vCardEditor.View.StateTextBox(); + this.miConfig = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); this.toolStrip1.SuspendLayout(); this.gbContactDetail.SuspendLayout(); @@ -93,6 +94,7 @@ this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.miOpen, this.toolStripMenuItem1, + this.miConfig, this.recentFilesMenuItem, this.miQuit}); this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; @@ -287,6 +289,17 @@ this.gbContactDetail.TabStop = false; this.gbContactDetail.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); @@ -296,6 +309,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))); @@ -307,6 +342,39 @@ 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); + // + // FormattedNameValue + // + this.FormattedNameValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.FormattedNameValue.Location = new System.Drawing.Point(123, 24); + this.FormattedNameValue.Name = "FormattedNameValue"; + this.FormattedNameValue.Size = new System.Drawing.Size(272, 20); + this.FormattedNameValue.TabIndex = 44; + this.FormattedNameValue.LostFocus += new System.EventHandler(this.Value_TextChanged); + this.FormattedNameValue.Validated += new System.EventHandler(this.Value_TextChanged); + // // gbNameList // this.gbNameList.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -382,71 +450,12 @@ this.Column2.Name = "Column2"; this.Column2.ReadOnly = true; // - // EmailAddressValue + // miConfig // - 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); - // - // FormattedNameValue - // - this.FormattedNameValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.FormattedNameValue.Location = new System.Drawing.Point(123, 24); - this.FormattedNameValue.Name = "FormattedNameValue"; - this.FormattedNameValue.Size = new System.Drawing.Size(272, 20); - this.FormattedNameValue.TabIndex = 44; - this.FormattedNameValue.LostFocus += new System.EventHandler(this.Value_TextChanged); - this.FormattedNameValue.Validated += new System.EventHandler(this.Value_TextChanged); + this.miConfig.Name = "miConfig"; + this.miConfig.Size = new System.Drawing.Size(152, 22); + this.miConfig.Text = "Preference"; + this.miConfig.Click += new System.EventHandler(this.miConfig_Click); // // MainForm // @@ -521,5 +530,6 @@ internal System.Windows.Forms.PictureBox PhotoBox; private System.Windows.Forms.ToolStripMenuItem recentFilesMenuItem; internal StateTextBox FormattedNameValue; + private System.Windows.Forms.ToolStripMenuItem miConfig; } } \ No newline at end of file diff --git a/vCardEditor/View/MainForm.cs b/vCardEditor/View/MainForm.cs index 51aabe4..3b65eb6 100644 --- a/vCardEditor/View/MainForm.cs +++ b/vCardEditor/View/MainForm.cs @@ -7,6 +7,7 @@ using VCFEditor.View; using VCFEditor.Model; using Thought.vCards; using vCardEditor.Repository; +using vCardEditor.Model; namespace vCardEditor.View { @@ -139,23 +140,24 @@ namespace vCardEditor.View } #region helper methods to populate textboxes. - private void SetSummaryValue(TextBox valueLabel, string value) + private void SetSummaryValue(StateTextBox valueLabel, string value) { if (valueLabel == null) throw new ArgumentNullException("valueLabel"); //Clear textbox if value is empty! valueLabel.Text = value; + valueLabel.oldText = value; } - private void SetSummaryValue(TextBox valueLabel, vCardEmailAddress email) + private void SetSummaryValue(StateTextBox valueLabel, vCardEmailAddress email) { valueLabel.Text = string.Empty; if (email != null) SetSummaryValue(valueLabel, email.Address); } - private void SetSummaryValue(TextBox valueLabel, vCardPhone phone) + private void SetSummaryValue(StateTextBox valueLabel, vCardPhone phone) { valueLabel.Text = string.Empty; if (phone != null) @@ -163,7 +165,7 @@ namespace vCardEditor.View } - private void SetSummaryValue(TextBox valueLabel, vCardWebsite webSite) + private void SetSummaryValue(StateTextBox valueLabel, vCardWebsite webSite) { valueLabel.Text = string.Empty; if (webSite != null) @@ -298,15 +300,16 @@ namespace vCardEditor.View } - public void UpdateMRUMenu(List MRUList) + public void UpdateMRUMenu(FixedList MRUList) { //No need to go further if no menu entry to load! - if (MRUList == null || MRUList.Count == 0) + if (MRUList == null || MRUList.IsEmpty()) return; recentFilesMenuItem.DropDownItems.Clear(); - foreach (string item in MRUList) - recentFilesMenuItem.DropDownItems.Add(item); + for (int i = 0; i < MRUList._innerList.Count; i++) + recentFilesMenuItem.DropDownItems.Add(MRUList[i]); + } private void MainForm_FormClosing(object sender, FormClosingEventArgs e) @@ -335,6 +338,12 @@ namespace vCardEditor.View return result; } + private void miConfig_Click(object sender, EventArgs e) + { + ConfigDialog dialog = new ConfigDialog(); + dialog.ShowDialog(); + } + } } diff --git a/vCardEditor/View/StateTextBox.cs b/vCardEditor/View/StateTextBox.cs index a771ae2..6bab21d 100644 --- a/vCardEditor/View/StateTextBox.cs +++ b/vCardEditor/View/StateTextBox.cs @@ -1,24 +1,16 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Windows.Forms; namespace vCardEditor.View { public class StateTextBox : TextBox { - private string _oldText; - public string oldText - { - get { return _oldText; } - } - + public string oldText { get; set; } protected override void OnLostFocus(EventArgs e) { base.OnLostFocus(e); - _oldText = this.Text; + oldText = this.Text; } } diff --git a/vCardEditor/vCardEditor.csproj b/vCardEditor/vCardEditor.csproj index ff9954e..2bfcdbb 100644 --- a/vCardEditor/vCardEditor.csproj +++ b/vCardEditor/vCardEditor.csproj @@ -49,6 +49,8 @@ + + @@ -104,6 +106,12 @@ AboutDialog.cs + + Form + + + ConfigDialog.cs + @@ -129,10 +137,12 @@ AboutDialog.cs + + ConfigDialog.cs + MainForm.cs - SettingsSingleFileGenerator Settings.Designer.cs diff --git a/vCardEditor_Test/FixedListTest.cs b/vCardEditor_Test/FixedListTest.cs new file mode 100644 index 0000000..5414355 --- /dev/null +++ b/vCardEditor_Test/FixedListTest.cs @@ -0,0 +1,67 @@ +using vCardEditor.Model; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; + +namespace vCardEditor_Test +{ + + + /// + ///Classe de test pour FixedListTest, destinée à contenir tous + ///les tests unitaires FixedListTest + /// + [TestClass()] + public class FixedListTest + { + /// + ///Test pour enqueue + /// + [TestMethod()] + public void enqueue_one_element_test() + { + int size = 1; + FixedList target = new FixedList(size); + string elem = "test"; + target.Enqueue(elem); + + Assert.IsTrue( target.Size == 1); + Assert.IsTrue(target[0] == "test"); + } + + /// + ///Test pour enqueue + /// + [TestMethod()] + public void enqueue_two_elements_test() + { + int size = 1; + FixedList target = new FixedList(size); + + target.Enqueue("elem1"); + target.Enqueue("elem2"); + + Assert.IsTrue(target.Size == 1); + Assert.IsTrue(target[0] == "elem2"); + + Assert.IsTrue(target.Size == 1); + } + + [TestMethod()] + public void enqueue_three_elements_test() + { + int size = 3; + FixedList target = new FixedList(size); + + target.Enqueue("elem1"); // this one should be remove ! + target.Enqueue("elem2"); + target.Enqueue("elem3"); + target.Enqueue("elem4"); + + Assert.IsTrue(target.Size == 3); + Assert.IsTrue(target[0] == "elem2"); + Assert.IsTrue(target[1] == "elem3"); + + Assert.IsTrue(target.Size == 3); + } + } +} diff --git a/vCardEditor_Test/vCardEditor_Test.csproj b/vCardEditor_Test/vCardEditor_Test.csproj index bc7643b..c685641 100644 --- a/vCardEditor_Test/vCardEditor_Test.csproj +++ b/vCardEditor_Test/vCardEditor_Test.csproj @@ -41,6 +41,13 @@ 3.5 + + + + + + + @@ -48,6 +55,7 @@ +