fixed a filter issue, and added a closing message

This commit is contained in:
Abdel
2015-09-19 21:46:03 -04:00
parent 5b8627126f
commit 23f05e3431
7 changed files with 132 additions and 78 deletions

View File

@@ -9,6 +9,7 @@ using System.ComponentModel;
using System.IO;
using vCardEditor.View;
using VCFEditor.Repository;
using System.Windows.Forms;
namespace VCFEditor.Presenter
@@ -31,14 +32,22 @@ namespace VCFEditor.Presenter
_view.FilterTextChanged += FilterTextChanged;
_view.TextBoxValueChanged += TextBoxValueChanged;
_view.BeforeLeavingContact += BeforeLeavingContact;
_view.CloseForm += CloseForm;
}
void CloseForm(object sender, FormClosingEventArgs e)
{
if (_repository.isDirty() && _view.AskMessage("Exit before saving", "Exit"))
e.Cancel = true;
}
public void BeforeLeavingContact(object sender, EventArg<vCard> e)
{
if (_view.SelectedContactIndex > -1)
_repository.SaveDirtyVCard(_view.SelectedContactIndex, e.Data);
{
if (_repository.isDirty())
_repository.SaveDirtyVCard(_view.SelectedContactIndex, e.Data);
}
}
public void TextBoxValueChanged(object sender, EventArgs e)

View File

@@ -223,5 +223,13 @@ namespace VCFEditor.Repository
return tw.ToString();
}
/// <summary>
/// Check if some iem in the contact list is modified
/// </summary>
/// <returns>true for dirty</returns>
public bool isDirty()
{
return (_contacts != null && _contacts.Any(x => x.isDirty));
}
}
}

View File

@@ -19,5 +19,6 @@ namespace VCFEditor.Repository
BindingList<Contact> FilterContacts(string p);
void SaveDirtyFlag(int index);
void SaveDirtyVCard(int index, vCard card);
bool isDirty();
}
}

View File

@@ -5,6 +5,7 @@ using System.Text;
using Thought.vCards;
using VCFEditor.Model;
using System.ComponentModel;
using System.Windows.Forms;
namespace VCFEditor.View
{
@@ -18,11 +19,12 @@ namespace VCFEditor.View
event EventHandler<EventArg<vCard>> BeforeLeavingContact;
event EventHandler<EventArg<string>> FilterTextChanged;
event EventHandler TextBoxValueChanged;
event EventHandler<FormClosingEventArgs> CloseForm;
#endregion
int SelectedContactIndex { get; }
void DisplayContacts(BindingList<Contact> contacts);
void DisplayContactDetail(vCard card, string FileName);
bool AskMessage(string msg, string caption);
}
}

View File

@@ -53,13 +53,8 @@
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();
@@ -67,6 +62,11 @@
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.menuStrip1.SuspendLayout();
this.toolStrip1.SuspendLayout();
this.groupBox1.SuspendLayout();
@@ -127,7 +127,7 @@
// miAbout
//
this.miAbout.Name = "miAbout";
this.miAbout.Size = new System.Drawing.Size(152, 22);
this.miAbout.Size = new System.Drawing.Size(107, 22);
this.miAbout.Text = "&About";
this.miAbout.Click += new System.EventHandler(this.tbsAbout_Click);
//
@@ -200,7 +200,8 @@
//
// openFileDialog
//
this.openFileDialog.FileName = "openFileDialog1";
this.openFileDialog.Filter = "vCard Files|*.vcf";
this.openFileDialog.Title = "Open vCard File";
//
// FormattedNameLabel
//
@@ -283,17 +284,6 @@
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);
@@ -303,28 +293,6 @@
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)));
@@ -336,28 +304,6 @@
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)
@@ -432,6 +378,61 @@
this.Column2.Name = "Column2";
this.Column2.ReadOnly = true;
//
// 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);
//
// 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);
//
// MainForm
//
this.AllowDrop = true;
@@ -446,6 +447,7 @@
this.MainMenuStrip = this.menuStrip1;
this.Name = "MainForm";
this.Text = "vCard Editor";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing);
this.DragDrop += new System.Windows.Forms.DragEventHandler(this.MainForm_DragDrop);
this.DragEnter += new System.Windows.Forms.DragEventHandler(this.MainForm_DragEnter);
this.menuStrip1.ResumeLayout(false);

View File

@@ -15,6 +15,7 @@ namespace vCardEditor.View
{
public partial class MainForm : Form, IMainView
{
#region event list
public event EventHandler SaveContactsSelected;
public event EventHandler DeleteContact;
public event EventHandler<EventArg<string>> NewFileOpened;
@@ -22,7 +23,8 @@ namespace vCardEditor.View
public event EventHandler<EventArg<vCard>> BeforeLeavingContact;
public event EventHandler<EventArg<string>> FilterTextChanged;
public event EventHandler TextBoxValueChanged;
public event EventHandler<FormClosingEventArgs> CloseForm;
#endregion
ComponentResourceManager resources;
public int SelectedContactIndex
@@ -183,6 +185,11 @@ namespace vCardEditor.View
private void textBoxFilter_TextChanged(object sender, EventArgs e)
{
//Save before leaving contact.
if (BeforeLeavingContact != null)
BeforeLeavingContact(sender, new EventArg<vCard>(getvCard()));
//filter.
if (FilterTextChanged != null)
FilterTextChanged(sender, new EventArg<string>(textBoxFilter.Text));
}
@@ -277,9 +284,34 @@ namespace vCardEditor.View
NewFileOpened(sender, new EventArg<string>(file));
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (CloseForm != null)
{
this.Validate();
CloseForm(sender, e);
}
}
/// <summary>
/// Ask user a question
/// </summary>
/// <param name="msg">question</param>
/// <param name="caption">caption</param>
/// <returns>true for yes, false for no</returns>
public bool AskMessage(string msg, string caption)
{
bool result = true; // true == yes
DialogResult window = MessageBox.Show(msg, caption, MessageBoxButtons.YesNo);
if (window != DialogResult.No)
result = false;
return result;
}

View File

@@ -112,21 +112,21 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>132, 17</value>
</metadata>
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>248, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="tbsOpen.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
@@ -193,7 +193,7 @@
E9ew//AVxE8OItv/9O/Cf0ck8gud2vKswuxNZgAAAABJRU5ErkJggg==
</value>
</data>
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>353, 17</value>
</metadata>
<data name="PhotoBox.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
@@ -223,7 +223,7 @@
vTbyOlxa5+ld4YsXL178Z3h7+w1PM1gbWuVRlwAAAABJRU5ErkJggg==
</value>
</data>
<metadata name="bsContacts.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="bsContacts.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>486, 17</value>
</metadata>
<data name="btnClearFilter.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
@@ -243,10 +243,10 @@
SbPSrCTkJAAAAABJRU5ErkJggg==
</value>
</data>
<metadata name="Column1.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<metadata name="Column1.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column2.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<metadata name="Column2.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>