Changeset 3 for Common/FormFind.cs


Ignore:
Timestamp:
Feb 21, 2019, 2:13:01 PM (5 years ago)
Author:
chronos
Message:
  • Added: Extended ComboBox with text history support.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Common/FormFind.cs

    r2 r3  
    1616        public RichTextBoxEx richTextBox;
    1717        public string regSubKey;
    18         public int maxHistoryCount;
    1918
    2019        public FormFind()
     
    2221            InitializeComponent();
    2322            regSubKey = "Find";
    24             maxHistoryCount = 20;
    2523        }
    2624
     
    6058        private void SearchText(bool reverse = false)
    6159        {
    62             if (comboBoxWhat.Text.Trim() != "")
    63             {
    64                 string previousText = comboBoxWhat.Text;
    65                 int index = comboBoxWhat.Items.IndexOf(comboBoxWhat.Text);
    66                 if (index >= 0) comboBoxWhat.Items.RemoveAt(index);
    67                 comboBoxWhat.Text = previousText;
    68                 comboBoxWhat.Items.Insert(0, comboBoxWhat.Text);
    69                
    70                 while (comboBoxWhat.Items.Count > maxHistoryCount)
    71                     comboBoxWhat.Items.RemoveAt(comboBoxWhat.Items.Count - 1);
    72             }
     60            comboBoxWhat.UpdateHistory();
    7361
    7462            while (true)
     
    11199            new FormDimensions().Load(this, Owner);
    112100            comboBoxWhat.Focus();
     101            comboBoxWhat.regSubKey = regSubKey + "\\History";
    113102            LoadFromRegistry();
    114103            UpdateInterface();
     
    153142            checkBoxMatchCase.Checked = regKey.GetValueBool("MatchCase", false);
    154143
    155             regKey = Application.UserAppDataRegistry.OpenSubKey(regSubKey + "\\History");
    156             if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(regSubKey + "\\History");
    157             int count = regKey.GetValueInt("Count", 0);
    158             comboBoxWhat.BeginUpdate();
    159             while (comboBoxWhat.Items.Count > count) comboBoxWhat.Items.RemoveAt(comboBoxWhat.Items.Count - 1);
    160             while (comboBoxWhat.Items.Count < count) comboBoxWhat.Items.Add("");
    161             for (int i = 0; i < count; i++)
    162             {
    163                 comboBoxWhat.Items[i] = (string)regKey.GetValue(i.ToString(), "");
    164             }
    165             comboBoxWhat.EndUpdate();
     144            comboBoxWhat.LoadFromRegistry();
    166145        }
    167146
     
    171150            if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(regSubKey);
    172151
     152           
    173153            regKey.SetValue("MatchWholeWordOnly", checkBoxMatchWholeWordOnly.Checked);
    174154            regKey.SetValue("MatchCase", checkBoxMatchCase.Checked);
    175155
    176             regKey = Application.UserAppDataRegistry.OpenSubKey(regSubKey + "\\History", true);
    177             if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(regSubKey + "\\History");
    178 
    179             int i = 0;
    180             regKey.SetValue("Count", comboBoxWhat.Items.Count);
    181             foreach (var item in comboBoxWhat.Items)
    182             {
    183                 regKey.SetValue(i.ToString(), item);
    184                 i++;
    185             }
    186 
    187             while (true)
    188             {
    189                 List<string> names = regKey.GetValueNames().ToList();
    190                 if (names.IndexOf(i.ToString()) != -1)
    191                 {
    192                     regKey.DeleteValue(i.ToString());
    193                 }
    194                 else break;
    195                 i++;
    196             }
     156            comboBoxWhat.SaveToRegistry();
    197157        }
    198158    }
Note: See TracChangeset for help on using the changeset viewer.