diff --git a/AdvancedDataGridView/AdvancedDataGridView.cs b/AdvancedDataGridView/AdvancedDataGridView.cs index a791a1c..1c9085d 100644 --- a/AdvancedDataGridView/AdvancedDataGridView.cs +++ b/AdvancedDataGridView/AdvancedDataGridView.cs @@ -9,8 +9,10 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; +using System.Web.Script.Serialization; using System.Windows.Forms; namespace Zuby.ADGV @@ -53,6 +55,107 @@ public FilterEventArgs() #endregion + #region translations + + /// + /// Available translation keys + /// + public enum TranslationKey + { + ADGVSortDateTimeASC, + ADGVSortDateTimeDESC, + ADGVSortBoolASC, + ADGVSortBoolDESC, + ADGVSortNumASC, + ADGVSortNumDESC, + ADGVSortTextASC, + ADGVSortTextDESC, + ADGVAddCustomFilter, + ADGVCustomFilter, + ADGVClearFilter, + ADGVClearSort, + ADGVButtonFilter, + ADGVButtonUndofilter, + ADGVNodeSelectAll, + ADGVNodeSelectEmpty, + ADGVFilterChecklistDisable, + ADGVEquals, + ADGVDoesNotEqual, + ADGVEarlierThan, + ADGVEarlierThanOrEqualTo, + ADGVLaterThan, + ADGVLaterThanOrEqualTo, + ADGVBetween, + ADGVGreaterThan, + ADGVGreaterThanOrEqualTo, + ADGVLessThan, + ADGVLessThanOrEqualTo, + ADGVBeginsWith, + ADGVDoesNotBeginWith, + ADGVEndsWith, + ADGVDoesNotEndWith, + ADGVContains, + ADGVDoesNotContain, + ADGVInvalidValue, + ADGVFilterStringDescription, + ADGVFormTitle, + ADGVLabelColumnNameText, + ADGVLabelAnd, + ADGVButtonOk, + ADGVButtonCancel + } + + /// + /// Internationalization strings + /// + public static Dictionary Translations = new Dictionary() + { + { TranslationKey.ADGVSortDateTimeASC.ToString(), "Sort Oldest to Newest" }, + { TranslationKey.ADGVSortDateTimeDESC.ToString(), "Sort Newest to Oldest" }, + { TranslationKey.ADGVSortBoolASC.ToString(), "Sort by False/True" }, + { TranslationKey.ADGVSortBoolDESC.ToString(), "Sort by True/False" }, + { TranslationKey.ADGVSortNumASC.ToString(), "Sort Smallest to Largest" }, + { TranslationKey.ADGVSortNumDESC.ToString(), "Sort Largest to Smallest" }, + { TranslationKey.ADGVSortTextASC.ToString(), "Sort А to Z" }, + { TranslationKey.ADGVSortTextDESC.ToString(), "Sort Z to A" }, + { TranslationKey.ADGVAddCustomFilter.ToString(), "Add a Custom Filter" }, + { TranslationKey.ADGVCustomFilter.ToString(), "Custom Filter" }, + { TranslationKey.ADGVClearFilter.ToString(), "Clear Filter" }, + { TranslationKey.ADGVClearSort.ToString(), "Clear Sort" }, + { TranslationKey.ADGVButtonFilter.ToString(), "Filter" }, + { TranslationKey.ADGVButtonUndofilter.ToString(), "Cancel" }, + { TranslationKey.ADGVNodeSelectAll.ToString(), "(Select All)" }, + { TranslationKey.ADGVNodeSelectEmpty.ToString(), "(Blanks)" }, + { TranslationKey.ADGVFilterChecklistDisable.ToString(), "Filter list is disabled" }, + { TranslationKey.ADGVEquals.ToString(), "equals" }, + { TranslationKey.ADGVDoesNotEqual.ToString(), "does not equal" }, + { TranslationKey.ADGVEarlierThan.ToString(), "earlier than" }, + { TranslationKey.ADGVEarlierThanOrEqualTo.ToString(), "earlier than or equal to" }, + { TranslationKey.ADGVLaterThan.ToString(), "later than"}, + { TranslationKey.ADGVLaterThanOrEqualTo.ToString(), "later than or equal to" }, + { TranslationKey.ADGVBetween.ToString(), "between" }, + { TranslationKey.ADGVGreaterThan.ToString(), "greater than" }, + { TranslationKey.ADGVGreaterThanOrEqualTo.ToString(), "greater than or equal to" }, + { TranslationKey.ADGVLessThan.ToString(), "less than" }, + { TranslationKey.ADGVLessThanOrEqualTo.ToString(), "less than or equal to" }, + { TranslationKey.ADGVBeginsWith.ToString(), "begins with" }, + { TranslationKey.ADGVDoesNotBeginWith.ToString(), "does not begin with" }, + { TranslationKey.ADGVEndsWith.ToString(), "ends with" }, + { TranslationKey.ADGVDoesNotEndWith.ToString(), "does not end with" }, + { TranslationKey.ADGVContains.ToString(), "contains" }, + { TranslationKey.ADGVDoesNotContain.ToString(), "does not contain" }, + { TranslationKey.ADGVInvalidValue.ToString(), "Invalid Value" }, + { TranslationKey.ADGVFilterStringDescription.ToString(), "Show rows where value {0} \"{1}\"" }, + { TranslationKey.ADGVFormTitle.ToString(), "Custom Filter" }, + { TranslationKey.ADGVLabelColumnNameText.ToString(), "Show rows where value" }, + { TranslationKey.ADGVLabelAnd.ToString(), "And" }, + { TranslationKey.ADGVButtonOk.ToString(), "OK" }, + { TranslationKey.ADGVButtonCancel.ToString(), "Cancel" } + }; + + #endregion + + #region class properties private List _sortOrderList = new List(); @@ -77,6 +180,72 @@ public AdvancedDataGridView() #endregion + #region translations methods + + /// + /// Set translation dictionary + /// + /// + public static void SetTranslations(IDictionary translations) + { + //set localization strings + if (translations != null) + { + foreach (KeyValuePair translation in translations) + { + if (Translations.ContainsKey(translation.Key)) + Translations[translation.Key] = translation.Value; + } + } + } + + /// + /// Get translation dictionary + /// + /// + public static IDictionary GetTranslations() + { + return Translations; + } + + /// + /// Load translations from file + /// + /// + /// + public static IDictionary LoadTranslationsFromFile(string filename) + { + IDictionary ret = new Dictionary(); + + if (!String.IsNullOrEmpty(filename)) + { + //deserialize the file + try + { + string jsontext = File.ReadAllText(filename); + Dictionary translations = new JavaScriptSerializer().Deserialize>(jsontext); + foreach (KeyValuePair translation in translations) + { + if (!ret.ContainsKey(translation.Key) && Translations.ContainsKey(translation.Key)) + ret.Add(translation.Key, translation.Value); + } + } + catch { } + } + + //add default translations if not in files + foreach (KeyValuePair translation in GetTranslations()) + { + if (!ret.ContainsKey(translation.Key)) + ret.Add(translation.Key, translation.Value); + } + + return ret; + } + + #endregion + + #region Helper methods /// diff --git a/AdvancedDataGridView/AdvancedDataGridView.csproj b/AdvancedDataGridView/AdvancedDataGridView.csproj index f538920..3d37f02 100644 --- a/AdvancedDataGridView/AdvancedDataGridView.csproj +++ b/AdvancedDataGridView/AdvancedDataGridView.csproj @@ -44,6 +44,7 @@ + diff --git a/AdvancedDataGridView/AdvancedDataGridViewSearchToolBar.cs b/AdvancedDataGridView/AdvancedDataGridViewSearchToolBar.cs index 2eee349..12386be 100644 --- a/AdvancedDataGridView/AdvancedDataGridViewSearchToolBar.cs +++ b/AdvancedDataGridView/AdvancedDataGridViewSearchToolBar.cs @@ -8,9 +8,11 @@ #endregion using System; -using System.Collections; +using System.Collections.Generic; using System.Drawing; +using System.IO; using System.Linq; +using System.Web.Script.Serialization; using System.Windows.Forms; namespace Zuby.ADGV @@ -32,7 +34,46 @@ public partial class AdvancedDataGridViewSearchToolBar : ToolStrip private DataGridViewColumnCollection _columnsList = null; private const bool ButtonCloseEnabled = false; - private Hashtable _textStrings = new Hashtable(); + + #endregion + + + #region translations + + /// + /// Available translation keys + /// + public enum TranslationKey + { + ADGVSTBLabelSearch, + ADGVSTBButtonFromBegin, + ADGVSTBButtonCaseSensitiveToolTip, + ADGVSTBButtonSearchToolTip, + ADGVSTBButtonCloseToolTip, + ADGVSTBButtonWholeWordToolTip, + ADGVSTBComboBoxColumnsAll, + ADGVSTBTextBoxSearchToolTip + } + + /// + /// Internationalization strings + /// + public static Dictionary Translations = new Dictionary() + { + { TranslationKey.ADGVSTBLabelSearch.ToString(), "Search:" }, + { TranslationKey.ADGVSTBButtonFromBegin.ToString(), "From Begin" }, + { TranslationKey.ADGVSTBButtonCaseSensitiveToolTip.ToString(), "Case Sensitivity" }, + { TranslationKey.ADGVSTBButtonSearchToolTip.ToString(), "Find Next" }, + { TranslationKey.ADGVSTBButtonCloseToolTip.ToString(), "Hide" }, + { TranslationKey.ADGVSTBButtonWholeWordToolTip.ToString(), "Search only Whole Word" }, + { TranslationKey.ADGVSTBComboBoxColumnsAll.ToString(), "(All Columns)" }, + { TranslationKey.ADGVSTBTextBoxSearchToolTip.ToString(), "Value for Search" } + }; + + /// + /// Used to check if components translations has to be updated + /// + private Dictionary _translationsRefreshComponentTranslationsCheck = new Dictionary() { }; #endregion @@ -44,38 +85,102 @@ public partial class AdvancedDataGridViewSearchToolBar : ToolStrip /// public AdvancedDataGridViewSearchToolBar() { - //set localization strings - _textStrings.Add("LABELSEARCH", "Search:"); - _textStrings.Add("BUTTONFROMBEGINTOOLTIP", "From Begin"); - _textStrings.Add("BUTTONCASESENSITIVETOOLTIP", "Case Sensitivity"); - _textStrings.Add("BUTTONSEARCHTOOLTIP", "Find Next"); - _textStrings.Add("BUTTONCLOSETOOLTIP", "Hide"); - _textStrings.Add("BUTTONWHOLEWORDTOOLTIP", "Search only Whole Word"); - _textStrings.Add("COMBOBOXCOLUMNSALL", "(All Columns)"); - _textStrings.Add("TEXTBOXSEARCHTOOLTIP", "Value for Search"); - //initialize components InitializeComponent(); - this.comboBox_columns.Items.AddRange(new object[] { _textStrings["COMBOBOXCOLUMNSALL"].ToString() }); - this.button_close.ToolTipText = _textStrings["BUTTONCLOSETOOLTIP"].ToString(); - this.label_search.Text = _textStrings["LABELSEARCH"].ToString(); - this.textBox_search.ToolTipText = _textStrings["TEXTBOXSEARCHTOOLTIP"].ToString(); - this.button_frombegin.ToolTipText = _textStrings["BUTTONFROMBEGINTOOLTIP"].ToString(); - this.button_casesensitive.ToolTipText = _textStrings["BUTTONCASESENSITIVETOOLTIP"].ToString(); - this.button_search.ToolTipText = _textStrings["BUTTONSEARCHTOOLTIP"].ToString(); - this.button_wholeword.ToolTipText = _textStrings["BUTTONWHOLEWORDTOOLTIP"].ToString(); + RefreshComponentTranslations(); //set default values if (!ButtonCloseEnabled) this.Items.RemoveAt(0); - textBox_search.Text = textBox_search.ToolTipText; comboBox_columns.SelectedIndex = 0; } #endregion + #region translations methods + + /// + /// Set translation dictionary + /// + /// + public static void SetTranslations(IDictionary translations) + { + //set localization strings + if (translations != null) + { + foreach (KeyValuePair translation in translations) + { + if (Translations.ContainsKey(translation.Key)) + Translations[translation.Key] = translation.Value; + } + } + } + + /// + /// Get translation dictionary + /// + /// + public static IDictionary GetTranslations() + { + return Translations; + } + + /// + /// Load translations from file + /// + /// + /// + public static IDictionary LoadTranslationsFromFile(string filename) + { + IDictionary ret = new Dictionary(); + + if (!String.IsNullOrEmpty(filename)) + { + //deserialize the file + try + { + string jsontext = File.ReadAllText(filename); + Dictionary translations = new JavaScriptSerializer().Deserialize>(jsontext); + foreach (KeyValuePair translation in translations) + { + if (!ret.ContainsKey(translation.Key) && Translations.ContainsKey(translation.Key)) + ret.Add(translation.Key, translation.Value); + } + } + catch { } + } + + //add default translations if not in files + foreach (KeyValuePair translation in GetTranslations()) + { + if (!ret.ContainsKey(translation.Key)) + ret.Add(translation.Key, translation.Value); + } + + return ret; + } + + /// + /// Update components translations + /// + private void RefreshComponentTranslations() + { + this.comboBox_columns.Items.AddRange(new object[] { Translations[TranslationKey.ADGVSTBComboBoxColumnsAll.ToString()] }); + this.button_close.ToolTipText = Translations[TranslationKey.ADGVSTBButtonCloseToolTip.ToString()]; + this.label_search.Text = Translations[TranslationKey.ADGVSTBLabelSearch.ToString()]; + this.textBox_search.ToolTipText = Translations[TranslationKey.ADGVSTBTextBoxSearchToolTip.ToString()]; + this.button_frombegin.ToolTipText = Translations[TranslationKey.ADGVSTBButtonFromBegin.ToString()]; + this.button_casesensitive.ToolTipText = Translations[TranslationKey.ADGVSTBButtonCaseSensitiveToolTip.ToString()]; + this.button_search.ToolTipText = Translations[TranslationKey.ADGVSTBButtonSearchToolTip.ToString()]; + this.button_wholeword.ToolTipText = Translations[TranslationKey.ADGVSTBButtonWholeWordToolTip.ToString()]; + this.textBox_search.Text = textBox_search.ToolTipText; + } + + #endregion + + #region button events /// @@ -83,7 +188,7 @@ public AdvancedDataGridViewSearchToolBar() /// /// /// - void button_search_Click(object sender, System.EventArgs e) + void button_search_Click(object sender, EventArgs e) { if (textBox_search.TextLength > 0 && textBox_search.Text != textBox_search.ToolTipText && Search != null) { @@ -115,7 +220,7 @@ void button_search_Click(object sender, System.EventArgs e) /// /// /// - void button_close_Click(object sender, System.EventArgs e) + void button_close_Click(object sender, EventArgs e) { Hide(); } @@ -130,7 +235,7 @@ void button_close_Click(object sender, System.EventArgs e) /// /// /// - void textBox_search_TextChanged(object sender, System.EventArgs e) + void textBox_search_TextChanged(object sender, EventArgs e) { button_search.Enabled = textBox_search.TextLength > 0 && textBox_search.Text != textBox_search.ToolTipText; } @@ -141,9 +246,9 @@ void textBox_search_TextChanged(object sender, System.EventArgs e) /// /// /// - void textBox_search_Enter(object sender, System.EventArgs e) + void textBox_search_Enter(object sender, EventArgs e) { - if (textBox_search.Text == textBox_search.ToolTipText && textBox_search.ForeColor == System.Drawing.Color.LightGray) + if (textBox_search.Text == textBox_search.ToolTipText && textBox_search.ForeColor == Color.LightGray) textBox_search.Text = ""; else textBox_search.SelectAll(); @@ -156,12 +261,12 @@ void textBox_search_Enter(object sender, System.EventArgs e) /// /// /// - void textBox_search_Leave(object sender, System.EventArgs e) + void textBox_search_Leave(object sender, EventArgs e) { if (textBox_search.Text.Trim() == "") { textBox_search.Text = textBox_search.ToolTipText; - textBox_search.ForeColor = System.Drawing.Color.LightGray; + textBox_search.ForeColor = Color.LightGray; } } @@ -171,7 +276,7 @@ void textBox_search_Leave(object sender, System.EventArgs e) /// /// /// - void textBox_search_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) + void textBox_search_KeyDown(object sender, KeyEventArgs e) { if (textBox_search.TextLength > 0 && textBox_search.Text != textBox_search.ToolTipText && e.KeyData == Keys.Enter) { @@ -196,7 +301,7 @@ public void SetColumns(DataGridViewColumnCollection columns) comboBox_columns.BeginUpdate(); comboBox_columns.Items.Clear(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AdvancedDataGridViewSearchToolBar)); - comboBox_columns.Items.AddRange(new object[] { "(All columns)" }); + comboBox_columns.Items.AddRange(new object[] { Translations[TranslationKey.ADGVSTBComboBoxColumnsAll.ToString()] }); if (_columnsList != null) foreach (DataGridViewColumn c in _columnsList) if (c.Visible) @@ -215,13 +320,13 @@ public void SetColumns(DataGridViewColumnCollection columns) /// /// /// - private void ResizeMe(object sender, System.EventArgs e) + private void ResizeMe(object sender, EventArgs e) { SuspendLayout(); int w1 = 150; int w2 = 150; int oldW = comboBox_columns.Width + textBox_search.Width; - foreach (System.Windows.Forms.ToolStripItem c in Items) + foreach (ToolStripItem c in Items) { c.Overflow = ToolStripItemOverflow.Never; c.Visible = true; @@ -274,7 +379,7 @@ private void ResizeMe(object sender, System.EventArgs e) if (Width < width) { button_close.Overflow = ToolStripItemOverflow.Always; - textBox_search.Margin = new System.Windows.Forms.Padding(8, 2, 8, 2); + textBox_search.Margin = new Padding(8, 2, 8, 2); w2 = Math.Max(Width - PreferredSize.Width + textBox_search.Width, 75); width = PreferredSize.Width - textBox_search.Width + w2; } @@ -287,7 +392,7 @@ private void ResizeMe(object sender, System.EventArgs e) if (width > Width) { textBox_search.Overflow = ToolStripItemOverflow.Always; - textBox_search.Margin = new System.Windows.Forms.Padding(0, 2, 8, 2); + textBox_search.Margin = new Padding(0, 2, 8, 2); w2 = 150; } } @@ -304,8 +409,6 @@ private void ResizeMe(object sender, System.EventArgs e) ResumeLayout(); } - - /// /// Get a Resize Size for a box /// @@ -332,6 +435,27 @@ private void GetResizeBoxSize(int width, ref int w1, ref int w2) #endregion + + #region paint events + + /// + /// On Paint event + /// + /// + protected override void OnPaint(PaintEventArgs e) + { + //check if translations are changed and update components + if (!((_translationsRefreshComponentTranslationsCheck == Translations) || (_translationsRefreshComponentTranslationsCheck.Count == Translations.Count && !_translationsRefreshComponentTranslationsCheck.Except(Translations).Any()))) + { + _translationsRefreshComponentTranslationsCheck = Translations; + RefreshComponentTranslations(); + } + + base.OnPaint(e); + } + + #endregion + } public delegate void AdvancedDataGridViewSearchToolBarSearchEventHandler(object sender, AdvancedDataGridViewSearchToolBarSearchEventArgs e); diff --git a/AdvancedDataGridView/ColumnHeaderCell.cs b/AdvancedDataGridView/ColumnHeaderCell.cs index c5ecf0d..af6c474 100644 --- a/AdvancedDataGridView/ColumnHeaderCell.cs +++ b/AdvancedDataGridView/ColumnHeaderCell.cs @@ -51,6 +51,7 @@ internal class ColumnHeaderCell : DataGridViewColumnHeaderCell /// /// public ColumnHeaderCell(DataGridViewColumnHeaderCell oldCell, bool filterEnabled) + : base() { Tag = oldCell.Tag; ErrorText = oldCell.ErrorText; diff --git a/AdvancedDataGridView/FormCustomFilter.cs b/AdvancedDataGridView/FormCustomFilter.cs index 2e4c64d..86ab129 100644 --- a/AdvancedDataGridView/FormCustomFilter.cs +++ b/AdvancedDataGridView/FormCustomFilter.cs @@ -8,7 +8,6 @@ #endregion using System; -using System.Collections; using System.Globalization; using System.Linq; using System.Threading; @@ -40,8 +39,6 @@ private enum FilterType private string _filterString = null; private string _filterStringDescription = null; - private Hashtable _textStrings = new Hashtable(); - #endregion @@ -50,51 +47,20 @@ private enum FilterType /// /// Main constructor /// - private FormCustomFilter() - { - InitializeComponent(); - } - - /// - /// Form constructor - /// /// /// public FormCustomFilter(Type dataType, bool filterDateAndTimeEnabled) - : this() + : base() { - //set localization strings - _textStrings.Add("EQUALS", "equals"); - _textStrings.Add("DOES_NOT_EQUAL", "does not equal"); - _textStrings.Add("EARLIER_THAN", "earlier than"); - _textStrings.Add("EARLIER_THAN_OR_EQUAL_TO", "earlier than or equal to"); - _textStrings.Add("LATER_THAN", "later than"); - _textStrings.Add("LATER_THAN_OR_EQUAL_TO", "later than or equal to"); - _textStrings.Add("BETWEEN", "between"); - _textStrings.Add("GREATER_THAN", "greater than"); - _textStrings.Add("GREATER_THAN_OR_EQUAL_TO", "greater than or equal to"); - _textStrings.Add("LESS_THAN", "less than"); - _textStrings.Add("LESS_THAN_OR_EQUAL_TO", "less than or equal to"); - _textStrings.Add("BEGINS_WITH", "begins with"); - _textStrings.Add("DOES_NOT_BEGIN_WITH", "does not begin with"); - _textStrings.Add("ENDS_WITH", "ends with"); - _textStrings.Add("DOES_NOT_END_WITH", "does not end with"); - _textStrings.Add("CONTAINS", "contains"); - _textStrings.Add("DOES_NOT_CONTAIN", "does not contain"); - _textStrings.Add("INVALID_VALUE", "Invalid Value"); - _textStrings.Add("FILTER_STRING_DESCRIPTION", "Show rows where value {0} \"{1}\""); - _textStrings.Add("FORM_TITLE", "Custom Filter"); - _textStrings.Add("LABEL_COLUMNNAMETEXT", "Show rows where value"); - _textStrings.Add("LABEL_AND", "And"); - _textStrings.Add("BUTTON_OK", "OK"); - _textStrings.Add("BUTTON_CANCEL", "Cancel"); - - - this.Text = _textStrings["FORM_TITLE"].ToString(); - label_columnName.Text = _textStrings["LABEL_COLUMNNAMETEXT"].ToString(); - label_and.Text = _textStrings["LABEL_AND"].ToString(); - button_ok.Text = _textStrings["BUTTON_OK"].ToString(); - button_cancel.Text = _textStrings["BUTTON_CANCEL"].ToString(); + //initialize components + InitializeComponent(); + + //set component translations + this.Text = AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVFormTitle.ToString()]; + this.label_columnName.Text = AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVLabelColumnNameText.ToString()]; + this.label_and.Text = AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVLabelAnd.ToString()]; + this.button_ok.Text = AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVButtonOk.ToString()]; + this.button_cancel.Text = AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVButtonCancel.ToString()]; if (dataType == typeof(DateTime)) _filterType = FilterType.DateTime; @@ -134,13 +100,13 @@ public FormCustomFilter(Type dataType, bool filterDateAndTimeEnabled) } comboBox_filterType.Items.AddRange(new string[] { - _textStrings["EQUALS"].ToString(), - _textStrings["DOES_NOT_EQUAL"].ToString(), - _textStrings["EARLIER_THAN"].ToString(), - _textStrings["EARLIER_THAN_OR_EQUAL_TO"].ToString(), - _textStrings["LATER_THAN"].ToString(), - _textStrings["LATER_THAN_OR_EQUAL_TO"].ToString(), - _textStrings["BETWEEN"].ToString() + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVEquals.ToString()], + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVDoesNotEqual.ToString()], + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVEarlierThan.ToString()], + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVEarlierThanOrEqualTo.ToString()], + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVLaterThan.ToString()], + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVLaterThanOrEqualTo.ToString()], + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVBetween.ToString()] }); break; @@ -148,8 +114,8 @@ public FormCustomFilter(Type dataType, bool filterDateAndTimeEnabled) _valControl1 = new TextBox(); _valControl2 = new TextBox(); comboBox_filterType.Items.AddRange(new string[] { - _textStrings["CONTAINS"].ToString(), - _textStrings["DOES_NOT_CONTAIN"].ToString() + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVContains.ToString()], + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVDoesNotContain.ToString()] }); break; @@ -160,13 +126,13 @@ public FormCustomFilter(Type dataType, bool filterDateAndTimeEnabled) _valControl1.TextChanged += valControl_TextChanged; _valControl2.TextChanged += valControl_TextChanged; comboBox_filterType.Items.AddRange(new string[] { - _textStrings["EQUALS"].ToString(), - _textStrings["DOES_NOT_EQUAL"].ToString(), - _textStrings["GREATER_THAN"].ToString(), - _textStrings["GREATER_THAN_OR_EQUAL_TO"].ToString(), - _textStrings["LESS_THAN"].ToString(), - _textStrings["LESS_THAN_OR_EQUAL_TO"].ToString(), - _textStrings["BETWEEN"].ToString() + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVEquals.ToString()], + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVDoesNotEqual.ToString()], + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVGreaterThan.ToString()], + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVGreaterThanOrEqualTo.ToString()], + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVLessThan.ToString()], + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVLessThanOrEqualTo.ToString()], + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVBetween.ToString()] }); _valControl1.Tag = true; _valControl2.Tag = true; @@ -177,14 +143,14 @@ public FormCustomFilter(Type dataType, bool filterDateAndTimeEnabled) _valControl1 = new TextBox(); _valControl2 = new TextBox(); comboBox_filterType.Items.AddRange(new string[] { - _textStrings["EQUALS"].ToString(), - _textStrings["DOES_NOT_EQUAL"].ToString(), - _textStrings["BEGINS_WITH"].ToString(), - _textStrings["DOES_NOT_BEGIN_WITH"].ToString(), - _textStrings["ENDS_WITH"].ToString(), - _textStrings["DOES_NOT_END_WITH"].ToString(), - _textStrings["CONTAINS"].ToString(), - _textStrings["DOES_NOT_CONTAIN"].ToString() + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVEquals.ToString()], + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVDoesNotEqual.ToString()], + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVBeginsWith.ToString()], + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVDoesNotBeginWith.ToString()], + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVEndsWith.ToString()], + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVDoesNotEndWith.ToString()], + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVContains.ToString()], + AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVDoesNotContain.ToString()] }); break; } @@ -280,24 +246,24 @@ private string BuildCustomFilter(FilterType filterType, bool filterDateAndTimeEn DateTime dt = ((DateTimePicker)control1).Value; dt = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, 0); - if (filterTypeConditionText == _textStrings["EQUALS"].ToString()) + if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVEquals.ToString()]) filterString = "Convert([{0}], 'System.String') LIKE '%" + Convert.ToString((filterDateAndTimeEnabled ? dt : dt.Date), CultureInfo.CurrentCulture) + "%'"; - else if (filterTypeConditionText == _textStrings["EARLIER_THAN"].ToString()) + else if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVEarlierThan.ToString()]) filterString += "< '" + Convert.ToString((filterDateAndTimeEnabled ? dt : dt.Date), CultureInfo.CurrentCulture) + "'"; - else if (filterTypeConditionText == _textStrings["EARLIER_THAN_OR_EQUAL_TO"].ToString()) + else if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVEarlierThanOrEqualTo.ToString()]) filterString += "<= '" + Convert.ToString((filterDateAndTimeEnabled ? dt : dt.Date), CultureInfo.CurrentCulture) + "'"; - else if (filterTypeConditionText == _textStrings["LATER_THAN"].ToString()) + else if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVLaterThan.ToString()]) filterString += "> '" + Convert.ToString((filterDateAndTimeEnabled ? dt : dt.Date), CultureInfo.CurrentCulture) + "'"; - else if (filterTypeConditionText == _textStrings["LATER_THAN_OR_EQUAL_TO"].ToString()) + else if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVLaterThanOrEqualTo.ToString()]) filterString += ">= '" + Convert.ToString((filterDateAndTimeEnabled ? dt : dt.Date), CultureInfo.CurrentCulture) + "'"; - else if (filterTypeConditionText == _textStrings["BETWEEN"].ToString()) + else if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVBetween.ToString()]) { DateTime dt1 = ((DateTimePicker)control2).Value; dt1 = new DateTime(dt1.Year, dt1.Month, dt1.Day, dt1.Hour, dt1.Minute, 0); filterString += ">= '" + Convert.ToString((filterDateAndTimeEnabled ? dt : dt.Date), CultureInfo.CurrentCulture) + "'"; filterString += " AND " + column + "<= '" + Convert.ToString((filterDateAndTimeEnabled ? dt1 : dt1.Date), CultureInfo.CurrentCulture) + "'"; } - else if (filterTypeConditionText == _textStrings["DOES_NOT_EQUAL"].ToString()) + else if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVDoesNotEqual.ToString()]) filterString = "Convert([{0}], 'System.String') NOT LIKE '%" + Convert.ToString((filterDateAndTimeEnabled ? dt : dt.Date), CultureInfo.CurrentCulture) + "%'"; break; @@ -306,11 +272,11 @@ private string BuildCustomFilter(FilterType filterType, bool filterDateAndTimeEn { TimeSpan ts = TimeSpan.Parse(control1.Text); - if (filterTypeConditionText == _textStrings["CONTAINS"].ToString()) + if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVContains.ToString()]) { filterString = "(Convert([{0}], 'System.String') LIKE '%P" + ((int)ts.Days > 0 ? (int)ts.Days + "D" : "") + (ts.TotalHours > 0 ? "T" : "") + ((int)ts.Hours > 0 ? (int)ts.Hours + "H" : "") + ((int)ts.Minutes > 0 ? (int)ts.Minutes + "M" : "") + ((int)ts.Seconds > 0 ? (int)ts.Seconds + "S" : "") + "%')"; } - else if (filterTypeConditionText == _textStrings["DOES_NOT_CONTAIN"].ToString()) + else if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVDoesNotContain.ToString()]) { filterString = "(Convert([{0}], 'System.String') NOT LIKE '%P" + ((int)ts.Days > 0 ? (int)ts.Days + "D" : "") + (ts.TotalHours > 0 ? "T" : "") + ((int)ts.Hours > 0 ? (int)ts.Hours + "H" : "") + ((int)ts.Minutes > 0 ? (int)ts.Minutes + "M" : "") + ((int)ts.Seconds > 0 ? (int)ts.Seconds + "S" : "") + "%')"; } @@ -329,39 +295,39 @@ private string BuildCustomFilter(FilterType filterType, bool filterDateAndTimeEn if (filterType == FilterType.Float) num = num.Replace(",", "."); - if (filterTypeConditionText == _textStrings["EQUALS"].ToString()) + if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVEquals.ToString()]) filterString += "= " + num; - else if (filterTypeConditionText == _textStrings["BETWEEN"].ToString()) + else if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVBetween.ToString()]) filterString += ">= " + num + " AND " + column + "<= " + (filterType == FilterType.Float ? control2.Text.Replace(",", ".") : control2.Text); - else if (filterTypeConditionText == _textStrings["DOES_NOT_EQUAL"].ToString()) + else if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVDoesNotEqual.ToString()]) filterString += "<> " + num; - else if (filterTypeConditionText == _textStrings["GREATER_THAN"].ToString()) + else if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVGreaterThan.ToString()]) filterString += "> " + num; - else if (filterTypeConditionText == _textStrings["GREATER_THAN_OR_EQUAL_TO"].ToString()) + else if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVGreaterThanOrEqualTo.ToString()]) filterString += ">= " + num; - else if (filterTypeConditionText == _textStrings["LESS_THAN"].ToString()) + else if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVLessThan.ToString()]) filterString += "< " + num; - else if (filterTypeConditionText == _textStrings["LESS_THAN_OR_EQUAL_TO"].ToString()) + else if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVLessThanOrEqualTo.ToString()]) filterString += "<= " + num; break; default: string txt = FormatFilterString(control1.Text); - if (filterTypeConditionText == _textStrings["EQUALS"].ToString()) + if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVEquals.ToString()]) filterString += "LIKE '" + txt + "'"; - else if (filterTypeConditionText == _textStrings["DOES_NOT_EQUAL"].ToString()) + else if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVDoesNotEqual.ToString()]) filterString += "NOT LIKE '" + txt + "'"; - else if (filterTypeConditionText == _textStrings["BEGINS_WITH"].ToString()) + else if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVBeginsWith.ToString()]) filterString += "LIKE '" + txt + "%'"; - else if (filterTypeConditionText == _textStrings["ENDS_WITH"].ToString()) + else if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVEndsWith.ToString()]) filterString += "LIKE '%" + txt + "'"; - else if (filterTypeConditionText == _textStrings["DOES_NOT_BEGIN_WITH"].ToString()) + else if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVDoesNotBeginWith.ToString()]) filterString += "NOT LIKE '" + txt + "%'"; - else if (filterTypeConditionText == _textStrings["DOES_NOT_END_WITH"].ToString()) + else if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVDoesNotEndWith.ToString()]) filterString += "NOT LIKE '%" + txt + "'"; - else if (filterTypeConditionText == _textStrings["CONTAINS"].ToString()) + else if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVContains.ToString()]) filterString += "LIKE '%" + txt + "%'"; - else if (filterTypeConditionText == _textStrings["DOES_NOT_CONTAIN"].ToString()) + else if (filterTypeConditionText == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVDoesNotContain.ToString()]) filterString += "NOT LIKE '%" + txt + "%'"; break; } @@ -429,7 +395,7 @@ private void button_ok_Click(object sender, EventArgs e) if (!String.IsNullOrEmpty(filterString)) { _filterString = filterString; - _filterStringDescription = String.Format(_textStrings["FILTER_STRING_DESCRIPTION"].ToString(), comboBox_filterType.Text, _valControl1.Text); + _filterStringDescription = String.Format(AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVFilterStringDescription.ToString()], comboBox_filterType.Text, _valControl1.Text); if (_valControl2.Visible) _filterStringDescription += " " + label_and.Text + " \"" + _valControl2.Text + "\""; DialogResult = System.Windows.Forms.DialogResult.OK; @@ -456,7 +422,7 @@ private void button_ok_Click(object sender, EventArgs e) /// private void comboBox_filterType_SelectedIndexChanged(object sender, EventArgs e) { - _valControl2.Visible = comboBox_filterType.Text == _textStrings["BETWEEN"].ToString(); + _valControl2.Visible = comboBox_filterType.Text == AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVBetween.ToString()]; button_ok.Enabled = !(_valControl1.Visible && _valControl1.Tag != null && ((bool)_valControl1.Tag)) || (_valControl2.Visible && _valControl2.Tag != null && ((bool)_valControl2.Tag)); } @@ -495,7 +461,7 @@ private void valControl_TextChanged(object sender, EventArgs e) (sender as Control).Tag = hasErrors || (sender as TextBox).Text.Length == 0; if (hasErrors && (sender as TextBox).Text.Length > 0) - errorProvider.SetError((sender as Control), _textStrings["INVALID_VALUE"].ToString()); + errorProvider.SetError((sender as Control), AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVInvalidValue.ToString()]); else errorProvider.SetError((sender as Control), ""); diff --git a/AdvancedDataGridView/MenuStrip.cs b/AdvancedDataGridView/MenuStrip.cs index c456e5d..a04e8a1 100644 --- a/AdvancedDataGridView/MenuStrip.cs +++ b/AdvancedDataGridView/MenuStrip.cs @@ -8,7 +8,6 @@ #endregion using System; -using System.Collections; using System.Collections.Generic; using System.Drawing; using System.Globalization; @@ -52,8 +51,6 @@ public enum SortType : byte #region class properties - private Hashtable _textStrings = new Hashtable(); - private FilterType _activeFilterType = FilterType.None; private SortType _activeSortType = SortType.None; private TreeNodeItemSelector[] _startingNodes = null; @@ -70,7 +67,6 @@ public enum SortType : byte #endregion - #region costructors /// @@ -78,47 +74,35 @@ public enum SortType : byte /// /// public MenuStrip(Type dataType) - : base() - { - //set localization strings - _textStrings.Add("SORTDATETIMEASC", "Sort Oldest to Newest"); - _textStrings.Add("SORTDATETIMEDESC", "Sort Newest to Oldest"); - _textStrings.Add("SORTBOOLASC", "Sort by False/True"); - _textStrings.Add("SORTBOOLDESC", "Sort by True/False"); - _textStrings.Add("SORTNUMASC", "Sort Smallest to Largest"); - _textStrings.Add("SORTNUMDESC", "Sort Largest to Smallest"); - _textStrings.Add("SORTTEXTASC", "Sort А to Z"); - _textStrings.Add("SORTTEXTDESC", "Sort Z to A"); - _textStrings.Add("ADDCUSTOMFILTER", "Add a Custom Filter"); - _textStrings.Add("CUSTOMFILTER", "Custom Filter"); - _textStrings.Add("CLEARFILTER", "Clear Filter"); - _textStrings.Add("CLEARSORT", "Clear Sort"); - _textStrings.Add("BUTTONOK", "Filter"); - _textStrings.Add("BUTTONCANCEL", "Cancel"); - _textStrings.Add("NODESELECTALL", "(Select All)"); - _textStrings.Add("NODESELECTEMPTY", "(Blanks)"); - _textStrings.Add("FILTERCHECKLISTDISABLED", "Filter list is disabled"); - + : base() + { //initialize components InitializeComponent(); + //set component translations + this.cancelSortMenuItem.Text = AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVClearSort.ToString()]; + this.cancelFilterMenuItem.Text = AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVClearFilter.ToString()]; + this.customFilterMenuItem.Text = AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVAddCustomFilter.ToString()]; + this.button_filter.Text = AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVButtonFilter.ToString()]; + this.button_undofilter.Text = AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVButtonUndofilter.ToString()]; + //set type DataType = dataType; //set components values if (DataType == typeof(DateTime) || DataType == typeof(TimeSpan)) { - customFilterLastFiltersListMenuItem.Text = _textStrings["CUSTOMFILTER"].ToString(); - sortASCMenuItem.Text = _textStrings["SORTDATETIMEASC"].ToString(); - sortDESCMenuItem.Text = _textStrings["SORTDATETIMEDESC"].ToString(); + customFilterLastFiltersListMenuItem.Text = AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVCustomFilter.ToString()]; + sortASCMenuItem.Text = AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVSortDateTimeASC.ToString()]; + sortDESCMenuItem.Text = AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVSortDateTimeDESC.ToString()]; sortASCMenuItem.Image = Properties.Resources.MenuStrip_OrderASCnum; sortDESCMenuItem.Image = Properties.Resources.MenuStrip_OrderDESCnum; } else if (DataType == typeof(bool)) { - customFilterLastFiltersListMenuItem.Text = _textStrings["CUSTOMFILTER"].ToString(); - sortASCMenuItem.Text = _textStrings["SORTBOOLASC"].ToString(); - sortDESCMenuItem.Text = _textStrings["SORTBOOLDESC"].ToString(); + customFilterLastFiltersListMenuItem.Text = AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVCustomFilter.ToString()]; + sortASCMenuItem.Text = AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVSortBoolASC.ToString()]; + sortDESCMenuItem.Text = AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVSortBoolDESC.ToString()]; sortASCMenuItem.Image = Properties.Resources.MenuStrip_OrderASCbool; sortDESCMenuItem.Image = Properties.Resources.MenuStrip_OrderDESCbool; } @@ -127,17 +111,17 @@ public MenuStrip(Type dataType) DataType == typeof(Byte) || DataType == typeof(SByte) || DataType == typeof(Decimal) || DataType == typeof(Single) || DataType == typeof(Double)) { - customFilterLastFiltersListMenuItem.Text = _textStrings["CUSTOMFILTER"].ToString(); - sortASCMenuItem.Text = _textStrings["SORTNUMASC"].ToString(); - sortDESCMenuItem.Text = _textStrings["SORTNUMDESC"].ToString(); + customFilterLastFiltersListMenuItem.Text = AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVCustomFilter.ToString()]; + sortASCMenuItem.Text = AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVSortNumASC.ToString()]; + sortDESCMenuItem.Text = AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVSortNumDESC.ToString()]; sortASCMenuItem.Image = Properties.Resources.MenuStrip_OrderASCnum; sortDESCMenuItem.Image = Properties.Resources.MenuStrip_OrderDESCnum; } else { - customFilterLastFiltersListMenuItem.Text = _textStrings["CUSTOMFILTER"].ToString(); - sortASCMenuItem.Text = _textStrings["SORTTEXTASC"].ToString(); - sortDESCMenuItem.Text = _textStrings["SORTTEXTDESC"].ToString(); + customFilterLastFiltersListMenuItem.Text = AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVCustomFilter.ToString()]; + sortASCMenuItem.Text = AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVSortTextASC.ToString()]; + sortDESCMenuItem.Text = AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVSortTextDESC.ToString()]; sortASCMenuItem.Image = Properties.Resources.MenuStrip_OrderASCtxt; sortDESCMenuItem.Image = Properties.Resources.MenuStrip_OrderDESCtxt; } @@ -338,8 +322,8 @@ public void SetFilterEnabled(bool enabled) enabled = false; this.cancelFilterMenuItem.Enabled = enabled; - this.button_ok.Enabled = enabled; - this.button_cancel.Enabled = enabled; + this.button_filter.Enabled = enabled; + this.button_undofilter.Enabled = enabled; this.checkList.Enabled = enabled; this.checkTextFilter.Enabled = enabled; if (enabled) @@ -365,7 +349,7 @@ public void SetFilterChecklistEnabled(bool enabled) { checkList.BeginUpdate(); checkList.Nodes.Clear(); - TreeNodeItemSelector disablednode = TreeNodeItemSelector.CreateNode(_textStrings["FILTERCHECKLISTDISABLED"].ToString() + " ", null, CheckState.Checked, TreeNodeItemSelector.CustomNodeType.SelectAll); + TreeNodeItemSelector disablednode = TreeNodeItemSelector.CreateNode(AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVFilterChecklistDisable.ToString()] + " ", null, CheckState.Checked, TreeNodeItemSelector.CustomNodeType.SelectAll); disablednode.NodeFont = new Font(checkList.Font, FontStyle.Bold); checkList.Nodes.Add(disablednode); } @@ -590,7 +574,7 @@ public void CleanFilter() FilterString = null; _filterNodes = null; customFilterLastFiltersListMenuItem.Checked = false; - button_ok.Enabled = true; + button_filter.Enabled = true; } /// @@ -803,7 +787,7 @@ private void BuildNodes(IEnumerable vals) if (vals != null) { //add select all node - TreeNodeItemSelector allnode = TreeNodeItemSelector.CreateNode(_textStrings["NODESELECTALL"].ToString() + " ", null, CheckState.Checked, TreeNodeItemSelector.CustomNodeType.SelectAll); + TreeNodeItemSelector allnode = TreeNodeItemSelector.CreateNode(AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVNodeSelectAll.ToString()] + " ", null, CheckState.Checked, TreeNodeItemSelector.CustomNodeType.SelectAll); allnode.NodeFont = new Font(checkList.Font, FontStyle.Bold); checkList.Nodes.Add(allnode); @@ -814,7 +798,7 @@ private void BuildNodes(IEnumerable vals) //add select empty node if (vals.Count() != nonulls.Count()) { - TreeNodeItemSelector nullnode = TreeNodeItemSelector.CreateNode(_textStrings["NODESELECTEMPTY"].ToString() + " ", null, CheckState.Checked, TreeNodeItemSelector.CustomNodeType.SelectEmpty); + TreeNodeItemSelector nullnode = TreeNodeItemSelector.CreateNode(AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVNodeSelectEmpty.ToString()] + " ", null, CheckState.Checked, TreeNodeItemSelector.CustomNodeType.SelectEmpty); nullnode.NodeFont = new Font(checkList.Font, FontStyle.Bold); checkList.Nodes.Add(nullnode); } @@ -997,7 +981,7 @@ private void NodeCheckChange(TreeNodeItemSelector node) if (node.NodeType == TreeNodeItemSelector.CustomNodeType.SelectAll) { SetNodesCheckState(checkList.Nodes, node.Checked); - button_ok.Enabled = node.Checked; + button_filter.Enabled = node.Checked; } else { @@ -1010,7 +994,7 @@ private void NodeCheckChange(TreeNodeItemSelector node) CheckState state = UpdateNodesCheckState(checkList.Nodes); GetSelectAllNode().CheckState = state; - button_ok.Enabled = !(state == CheckState.Unchecked); + button_filter.Enabled = !(state == CheckState.Unchecked); } } @@ -1333,7 +1317,7 @@ private void SetCustomFilter(int filtersMenuItemIndex) DuplicateFilterNodes(); customFilterLastFiltersListMenuItem.Checked = true; - button_ok.Enabled = false; + button_filter.Enabled = false; //fire Filter changed if (oldfilter != FilterString && FilterChanged != null) @@ -1515,8 +1499,8 @@ private void CheckTextFilter_TextChanged(object sender, EventArgs e) checkList.BeginUpdate(); RestoreNodes(); } - TreeNodeItemSelector allnode = TreeNodeItemSelector.CreateNode(_textStrings["NODESELECTALL"].ToString() + " ", null, CheckState.Checked, TreeNodeItemSelector.CustomNodeType.SelectAll); - TreeNodeItemSelector nullnode = TreeNodeItemSelector.CreateNode(_textStrings["NODESELECTEMPTY"].ToString() + " ", null, CheckState.Checked, TreeNodeItemSelector.CustomNodeType.SelectEmpty); + TreeNodeItemSelector allnode = TreeNodeItemSelector.CreateNode(AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVNodeSelectAll.ToString()] + " ", null, CheckState.Checked, TreeNodeItemSelector.CustomNodeType.SelectAll); + TreeNodeItemSelector nullnode = TreeNodeItemSelector.CreateNode(AdvancedDataGridView.Translations[AdvancedDataGridView.TranslationKey.ADGVNodeSelectEmpty.ToString()] + " ", null, CheckState.Checked, TreeNodeItemSelector.CustomNodeType.SelectEmpty); TreeNodeItemSelector allnodesel = null; for (int i = checkList.Nodes.Count - 1; i >= 0; i--) { @@ -1700,8 +1684,8 @@ private void ResizeBox(int w, int h) checkTextFilterControlHost.Width = w - 35; checkList.Bounds = new Rectangle(4, 4, w - 35 - 8, h - 160 - 25 - 8); checkFilterListButtonsControlHost.Size = new Size(w - 35, 24); - button_ok.Location = new Point(w - 35 - 164, 0); - button_cancel.Location = new Point(w - 35 - 79, 0); + button_filter.Location = new Point(w - 35 - 164, 0); + button_undofilter.Location = new Point(w - 35 - 79, 0); resizeBoxControlHost.Margin = new Padding(w - 46, 0, 0, 0); Size = new Size(w, h); } diff --git a/AdvancedDataGridView/MenuStrip.designer.cs b/AdvancedDataGridView/MenuStrip.designer.cs index b2802c9..3bedbe5 100644 --- a/AdvancedDataGridView/MenuStrip.designer.cs +++ b/AdvancedDataGridView/MenuStrip.designer.cs @@ -45,8 +45,8 @@ private void InitializeComponent() this.customFilterLastFilter5MenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator3MenuItem = new System.Windows.Forms.ToolStripSeparator(); this.checkList = new System.Windows.Forms.TreeView(); - this.button_ok = new System.Windows.Forms.Button(); - this.button_cancel = new System.Windows.Forms.Button(); + this.button_filter = new System.Windows.Forms.Button(); + this.button_undofilter = new System.Windows.Forms.Button(); this.checkFilterListPanel = new System.Windows.Forms.Panel(); this.checkFilterListButtonsPanel = new System.Windows.Forms.Panel(); this.checkFilterListButtonsControlHost = new System.Windows.Forms.ToolStripControlHost(checkFilterListButtonsPanel); @@ -102,7 +102,7 @@ private void InitializeComponent() this.cancelSortMenuItem.Enabled = false; this.cancelSortMenuItem.AutoSize = false; this.cancelSortMenuItem.Size = new System.Drawing.Size(Width - 1, 22); - this.cancelSortMenuItem.Text = _textStrings["CLEARSORT"].ToString(); + this.cancelSortMenuItem.Text = "Clear Sort"; this.cancelSortMenuItem.Click += new System.EventHandler(CancelSortMenuItem_Click); this.cancelSortMenuItem.MouseEnter += new System.EventHandler(CancelSortMenuItem_MouseEnter); // @@ -117,7 +117,7 @@ private void InitializeComponent() this.cancelFilterMenuItem.Enabled = false; this.cancelFilterMenuItem.AutoSize = false; this.cancelFilterMenuItem.Size = new System.Drawing.Size(Width - 1, 22); - this.cancelFilterMenuItem.Text = _textStrings["CLEARFILTER"].ToString(); + this.cancelFilterMenuItem.Text = "Clear Filter"; this.cancelFilterMenuItem.Click += new System.EventHandler(CancelFilterMenuItem_Click); this.cancelFilterMenuItem.MouseEnter += new System.EventHandler(CancelFilterMenuItem_MouseEnter); // @@ -131,7 +131,7 @@ private void InitializeComponent() // this.customFilterMenuItem.Name = "customFilterMenuItem"; this.customFilterMenuItem.Size = new System.Drawing.Size(152, 22); - this.customFilterMenuItem.Text = _textStrings["ADDCUSTOMFILTER"].ToString(); + this.customFilterMenuItem.Text = "Add a Custom Filter"; this.customFilterMenuItem.Click += new System.EventHandler(CustomFilterMenuItem_Click); // // customFilterLastFilter1MenuItem @@ -208,27 +208,27 @@ private void InitializeComponent() this.toolStripSeparator3MenuItem.Name = "toolStripSeparator3MenuItem"; this.toolStripSeparator3MenuItem.Size = new System.Drawing.Size(Width - 4, 6); // - // button_ok + // button_filter // - this.button_ok.Name = "button_ok"; - this.button_ok.BackColor = System.Windows.Forms.Button.DefaultBackColor; - this.button_ok.UseVisualStyleBackColor = true; - this.button_ok.Margin = new System.Windows.Forms.Padding(0); - this.button_ok.Size = new System.Drawing.Size(75, 23); - this.button_ok.Text = _textStrings["BUTTONOK"].ToString(); - this.button_ok.Click += new System.EventHandler(Button_ok_Click); - this.button_ok.Location = new System.Drawing.Point(this.checkFilterListButtonsPanel.Width - 164, 0); + this.button_filter.Name = "button_filter"; + this.button_filter.BackColor = System.Windows.Forms.Button.DefaultBackColor; + this.button_filter.UseVisualStyleBackColor = true; + this.button_filter.Margin = new System.Windows.Forms.Padding(0); + this.button_filter.Size = new System.Drawing.Size(75, 23); + this.button_filter.Text = "Filter"; + this.button_filter.Click += new System.EventHandler(Button_ok_Click); + this.button_filter.Location = new System.Drawing.Point(this.checkFilterListButtonsPanel.Width - 164, 0); // - // button_cancel + // button_undofilter // - this.button_cancel.Name = "button_cancel"; - this.button_cancel.BackColor = System.Windows.Forms.Button.DefaultBackColor; - this.button_cancel.UseVisualStyleBackColor = true; - this.button_cancel.Margin = new System.Windows.Forms.Padding(0); - this.button_cancel.Size = new System.Drawing.Size(75, 23); - this.button_cancel.Text = _textStrings["BUTTONCANCEL"].ToString(); - this.button_cancel.Click += new System.EventHandler(Button_cancel_Click); - this.button_cancel.Location = new System.Drawing.Point(this.checkFilterListButtonsPanel.Width - 79, 0); + this.button_undofilter.Name = "button_undofilter"; + this.button_undofilter.BackColor = System.Windows.Forms.Button.DefaultBackColor; + this.button_undofilter.UseVisualStyleBackColor = true; + this.button_undofilter.Margin = new System.Windows.Forms.Padding(0); + this.button_undofilter.Size = new System.Drawing.Size(75, 23); + this.button_undofilter.Text = "Cancel"; + this.button_undofilter.Click += new System.EventHandler(Button_cancel_Click); + this.button_undofilter.Location = new System.Drawing.Point(this.checkFilterListButtonsPanel.Width - 79, 0); // // resizeBoxControlHost // @@ -312,8 +312,8 @@ private void InitializeComponent() this.checkFilterListButtonsPanel.BackColor = BackColor; this.checkFilterListButtonsPanel.BorderStyle = System.Windows.Forms.BorderStyle.None; this.checkFilterListButtonsPanel.Controls.AddRange(new System.Windows.Forms.Control[] { - button_ok, - button_cancel + button_filter, + button_undofilter }); this.ResumeLayout(false); this.PerformLayout(); @@ -337,8 +337,8 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem customFilterLastFilter4MenuItem; private System.Windows.Forms.ToolStripMenuItem customFilterLastFilter5MenuItem; private System.Windows.Forms.TreeView checkList; - private System.Windows.Forms.Button button_ok; - private System.Windows.Forms.Button button_cancel; + private System.Windows.Forms.Button button_filter; + private System.Windows.Forms.Button button_undofilter; private System.Windows.Forms.ToolStripControlHost checkFilterListControlHost; private System.Windows.Forms.ToolStripControlHost checkFilterListButtonsControlHost; private System.Windows.Forms.ToolStripControlHost resizeBoxControlHost; diff --git a/AdvancedDataGridView/Properties/AssemblyInfo.cs b/AdvancedDataGridView/Properties/AssemblyInfo.cs index af9ee7e..6d072d4 100644 Binary files a/AdvancedDataGridView/Properties/AssemblyInfo.cs and b/AdvancedDataGridView/Properties/AssemblyInfo.cs differ diff --git a/AdvancedDataGridViewSample/AdvancedDataGridViewSample.csproj b/AdvancedDataGridViewSample/AdvancedDataGridViewSample.csproj index b0e85fb..9f8f4c3 100644 --- a/AdvancedDataGridViewSample/AdvancedDataGridViewSample.csproj +++ b/AdvancedDataGridViewSample/AdvancedDataGridViewSample.csproj @@ -68,6 +68,9 @@ True + + Always + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/AdvancedDataGridViewSample/FormMain.cs b/AdvancedDataGridViewSample/FormMain.cs index f81246c..fa00f81 100644 --- a/AdvancedDataGridViewSample/FormMain.cs +++ b/AdvancedDataGridViewSample/FormMain.cs @@ -5,6 +5,7 @@ using System.Drawing; using System.IO; using System.Windows.Forms; +using Zuby.ADGV; namespace AdvancedDataGridViewSample { @@ -16,10 +17,36 @@ public partial class FormMain : Form private SortedDictionary _filtersaved = new SortedDictionary(); private SortedDictionary _sortsaved = new SortedDictionary(); + private bool _testtranslations = true; + private bool _testtranslationsFromFile = true; + public FormMain() { InitializeComponent(); + //set localization strings + Dictionary translations = new Dictionary(); + foreach (KeyValuePair translation in AdvancedDataGridView.Translations) + { + if (!translations.ContainsKey(translation.Key)) + translations.Add(translation.Key, "." + translation.Value); + } + foreach (KeyValuePair translation in AdvancedDataGridViewSearchToolBar.Translations) + { + if (!translations.ContainsKey(translation.Key)) + translations.Add(translation.Key, "." + translation.Value); + } + if (_testtranslations) + { + AdvancedDataGridView.SetTranslations(translations); + AdvancedDataGridViewSearchToolBar.SetTranslations(translations); + } + if (_testtranslationsFromFile) + { + AdvancedDataGridView.SetTranslations(AdvancedDataGridView.LoadTranslationsFromFile("lang.json")); + AdvancedDataGridViewSearchToolBar.SetTranslations(AdvancedDataGridViewSearchToolBar.LoadTranslationsFromFile("lang.json")); + } + //set filter and sort saved _filtersaved.Add(0, ""); _sortsaved.Add(0, ""); diff --git a/AdvancedDataGridViewSample/Properties/AssemblyInfo.cs b/AdvancedDataGridViewSample/Properties/AssemblyInfo.cs index d2fde77..eacba73 100644 Binary files a/AdvancedDataGridViewSample/Properties/AssemblyInfo.cs and b/AdvancedDataGridViewSample/Properties/AssemblyInfo.cs differ diff --git a/AdvancedDataGridViewSample/lang.json b/AdvancedDataGridViewSample/lang.json new file mode 100644 index 0000000..cdb0ec8 --- /dev/null +++ b/AdvancedDataGridViewSample/lang.json @@ -0,0 +1,51 @@ +{ + "ADGVSortDateTimeASC": "Sort Oldest to Newest", + "ADGVSortDateTimeDESC": "Sort Newest to Oldest", + "ADGVSortBoolASC": "Sort by False/True", + "ADGVSortBoolDESC": "Sort by True/False", + "ADGVSortNumASC": "Sort Smallest to Largest", + "ADGVSortNumDESC": "Sort Largest to Smallest", + "ADGVSortTextASC": "Sort А to Z", + "ADGVSortTextDESC": "Sort Z to A", + "ADGVAddCustomFilter": "Add a Custom Filter", + "ADGVCustomFilter": "Custom Filter", + "ADGVClearFilter": "Clear Filter", + "ADGVClearSort": "Clear Sort", + "ADGVButtonFilter": "Filter", + "ADGVButtonUndofilter": "Cancel", + "ADGVNodeSelectAll": "(Select All)", + "ADGVNodeSelectEmpty": "(Blanks)", + "ADGVFilterChecklistDisable": "Filter list is disabled", + "ADGVEquals": "equals", + "ADGVDoesNotEqual": "does not equal", + "ADGVEarlierThan": "earlier than", + "ADGVEarlierThanOrEqualTo": "earlier than or equal to", + "ADGVLaterThan": "later than", + "ADGVLaterThanOrEqualTo": "later than or equal to", + "ADGVBetween": "between", + "ADGVGreaterThan": "greater than", + "ADGVGreaterThanOrEqualTo": "greater than or equal to", + "ADGVLessThan": "less than", + "ADGVLessThanOrEqualTo": "less than or equal to", + "ADGVBeginsWith": "begins with", + "ADGVDoesNotBeginWith": "does not begin with", + "ADGVEndsWith": "ends with", + "ADGVDoesNotEndWith": "does not end with", + "ADGVContains": "contains", + "ADGVDoesNotContain": "does not contain", + "ADGVInvalidValue": "Invalid Value", + "ADGVFilterStringDescription": "Show rows where value {0} \"{1}\"", + "ADGVFormTitle": "Custom Filter", + "ADGVLabelColumnNameText": "Show rows where value", + "ADGVLabelAnd": "And", + "ADGVButtonOk": "OK", + "ADGVButtonCancel": "Cancel", + "ADGVSTBLabelSearch": "Search:", + "ADGVSTBButtonFromBegin": "From Begin", + "ADGVSTBButtonCaseSensitiveToolTip": "Case Sensitivity", + "ADGVSTBButtonSearchToolTip": "Find Next", + "ADGVSTBButtonCloseToolTip": "Hide", + "ADGVSTBButtonWholeWordToolTip": "Search only Whole Word", + "ADGVSTBComboBoxColumnsAll": "(All Columns)", + "ADGVSTBTextBoxSearchToolTip": "Value for Search" +} diff --git a/_DevTools/AutoBuilder.config.ps1 b/_DevTools/AutoBuilder.config.ps1 index 341236a..5fb1d08 100644 --- a/_DevTools/AutoBuilder.config.ps1 +++ b/_DevTools/AutoBuilder.config.ps1 @@ -6,7 +6,7 @@ $solutionName = "AdvancedDataGridView" $versionMajor = "1" $versionMinor = "1" $versionBuild = GetVersionBuild -$versionRevision = "2" +$versionRevision = "3" #build version number $assemblyVersion = GetVersion $versionMajor $versionMinor $versionBuild $versionRevision $fileVersion = $assemblyVersion