/// <summary> /// リストを更新します /// </summary> private void updateList() { list.SelectedIndexChanged -= new EventHandler(list_SelectedIndexChanged); list.Items.Clear(); list.SelectedIndexChanged += new EventHandler(list_SelectedIndexChanged); mFieldName.Clear(); // 現在のカテゴリーを取得 int selected = comboCategory.SelectedIndex; if (selected < 0) { selected = 0; } string category = mCategories[selected]; // 現在のカテゴリーに合致するものについてのみ,リストに追加 foreach (var display in mDict.Keys) { ValuePair <string, Keys[]> item = mDict[display]; string field_name = item.getKey(); Keys[] keys = item.getValue(); bool add_this_one = false; if (category == ".other") { add_this_one = true; for (int i = 0; i < mCategories.Length; i++) { string c = mCategories[i]; if (c == ".other") { continue; } if (field_name.StartsWith(c)) { add_this_one = false; break; } } } else { if (field_name.StartsWith(category)) { add_this_one = true; } } if (add_this_one) { list.AddRow(new string[] { display, Utility.getShortcutDisplayString(keys) }); mFieldName.Add(field_name); } } updateColor(); //applyLanguage(); }
/// <summary> /// リストアイテムの背景色を更新します. /// 2つ以上のメニューに対して同じショートカットが割り当てられた場合に警告色で表示する. /// </summary> private void updateColor() { int size = list.Items.Count; for (int i = 0; i < size; i++) { //BListViewItem list_item = list.getItemAt( i ); string field_name = mFieldName[i]; string key_display = list.Items[i].SubItems[1].Text; if (key_display == "") { // ショートカットキーが割り当てられていないのでスルー list.Items[i].BackColor = System.Drawing.Color.White; continue; } bool found = false; foreach (var display1 in mDict.Keys) { ValuePair <string, Keys[]> item1 = mDict[display1]; string field_name1 = item1.getKey(); if (field_name == field_name1) { // 自分自身なのでスルー continue; } Keys[] keys1 = item1.getValue(); string key_display1 = Utility.getShortcutDisplayString(keys1); if (key_display == key_display1) { // 同じキーが割り当てられてる!! found = true; break; } } // 背景色を変える if (found) { list.Items[i].BackColor = System.Drawing.Color.Yellow; } else { list.Items[i].BackColor = System.Drawing.Color.White; } } }
public void list_SelectedIndexChanged(Object sender, EventArgs e) { if (list.SelectedIndices.Count == 0) { return; } int indx = list.SelectedIndices[0]; string display = list.Items[indx].SubItems[0].Text; if (!mDict.ContainsKey(display)) { return; } unRegisterHandlers(); ValuePair <string, Keys[]> item = mDict[display]; Keys[] keys = item.getValue(); List <Keys> vkeys = new List <Keys>(keys); checkCommand.Checked = vkeys.Contains(Keys.Menu); checkShift.Checked = vkeys.Contains(Keys.Shift); checkControl.Checked = vkeys.Contains(Keys.Control); checkOption.Checked = vkeys.Contains(Keys.Alt); int size = comboEditKey.Items.Count; comboEditKey.SelectedIndex = -1; for (int i = 0; i < size; i++) { Keys k = (Keys)comboEditKey.Items[i]; if (vkeys.Contains(k)) { comboEditKey.SelectedIndex = i; break; } } reRegisterHandlers(); }