| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,3 @@ | |||
| 1 | - using System; | ||
| 2 | - using System.Drawing; | ||
| 3 | - using System.Collections; | ||
| 4 | 1 | using System.ComponentModel; | |
| 5 | 2 | using System.Windows.Forms; | |
| 6 | 3 | using PluginCore; | |
@@ -13,13 +10,11 @@ namespace ProjectManager.Helpers | |||
| 13 | 10 | /// </summary> | |
| 14 | 11 | public class LineEntryDialog : Form | |
| 15 | 12 | { | |
| 16 | - readonly Keys shortcutToLowercase; | ||
| 17 | - readonly Keys shortcutToUppercase; | ||
| 18 | 13 | string line; | |
| 19 | 14 | ||
| 20 | 15 | #region Form Designer Components | |
| 21 | 16 | ||
| 22 | - protected System.Windows.Forms.TextBox lineBox; | ||
| 17 | + private System.Windows.Forms.TextBox lineBox; | ||
| 23 | 18 | private System.Windows.Forms.Button btnOK; | |
| 24 | 19 | private System.Windows.Forms.Button btnCancel; | |
| 25 | 20 | /// <summary> | |
@@ -40,8 +35,6 @@ public string Line | |||
| 40 | 35 | ||
| 41 | 36 | public LineEntryDialog(string captionText, string labelText, string defaultLine) | |
| 42 | 37 | { | |
| 43 | - shortcutToLowercase = PluginBase.MainForm.GetShortcutItemKeys("EditMenu.ToLowercase"); | ||
| 44 | - shortcutToUppercase = PluginBase.MainForm.GetShortcutItemKeys("EditMenu.ToUppercase"); | ||
| 45 | 38 | InitializeComponent(); | |
| 46 | 39 | InititalizeLocalization(); | |
| 47 | 40 | this.Font = PluginBase.Settings.DefaultFont; | |
@@ -174,16 +167,22 @@ private void btnCancel_Click(object sender, System.EventArgs e) | |||
| 174 | 167 | ||
| 175 | 168 | void OnLineBoxOnKeyDown(object sender, KeyEventArgs args) | |
| 176 | 169 | { | |
| 177 | - string selectedText = lineBox.SelectedText; | ||
| 178 | - if (string.IsNullOrEmpty(selectedText)) return; | ||
| 179 | - Keys keys = args.KeyData; | ||
| 180 | - if (keys == shortcutToLowercase) selectedText = selectedText.ToLower(); | ||
| 181 | - else if (keys == shortcutToUppercase) selectedText = selectedText.ToUpper(); | ||
| 182 | - else return; | ||
| 183 | - int selectionStart = lineBox.SelectionStart; | ||
| 184 | - int selectionLength = lineBox.SelectionLength; | ||
| 185 | - lineBox.Paste(selectedText); | ||
| 186 | - SelectRange(selectionStart, selectionLength); | ||
| 170 | + string shortcutId = PluginBase.MainForm.GetShortcutItemId(args.KeyData); | ||
| 171 | + if (string.IsNullOrEmpty(shortcutId)) return; | ||
| 172 | + | ||
| 173 | + switch (shortcutId) | ||
| 174 | + { | ||
| 175 | + case "EditMenu.ToLowercase": | ||
| 176 | + case "EditMenu.ToUppercase": | ||
| 177 | + string selectedText = lineBox.SelectedText; | ||
| 178 | + if (string.IsNullOrEmpty(selectedText)) break; | ||
| 179 | + selectedText = shortcutId == "EditMenu.ToLowercase" ? selectedText.ToLower() : selectedText.ToUpper(); | ||
| 180 | + int selectionStart = lineBox.SelectionStart; | ||
| 181 | + int selectionLength = lineBox.SelectionLength; | ||
| 182 | + lineBox.Paste(selectedText); | ||
| 183 | + SelectRange(selectionStart, selectionLength); | ||
| 184 | + break; | ||
| 185 | + } | ||
| 187 | 186 | } | |
| 188 | 187 | ||
| 189 | 188 | public void SelectRange(int start, int length) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -561,19 +561,21 @@ private bool HandleKeyEvent(KeyEvent ke) | |||
| 561 | 561 | { | |
| 562 | 562 | if (activeProject == null) return false; | |
| 563 | 563 | ||
| 564 | - if (ke.Value == PluginBase.MainForm.GetShortcutItemKeys("ProjectMenu.ConfigurationSelector")) | ||
| 564 | + string shortcutId = PluginBase.MainForm.GetShortcutItemId(ke.Value); | ||
| 565 | + | ||
| 566 | + if (shortcutId == "ProjectMenu.ConfigurationSelector") | ||
| 565 | 567 | { | |
| 566 | 568 | pluginUI.menus.ConfigurationSelector.Focus(); | |
| 567 | 569 | } | |
| 568 | - else if (ke.Value == PluginBase.MainForm.GetShortcutItemKeys("ProjectMenu.ConfigurationSelectorToggle")) | ||
| 570 | + else if (shortcutId == "ProjectMenu.ConfigurationSelectorToggle") | ||
| 569 | 571 | { | |
| 570 | 572 | pluginUI.menus.ToggleDebugRelease(); | |
| 571 | 573 | } | |
| 572 | - else if (ke.Value == PluginBase.MainForm.GetShortcutItemKeys("ProjectMenu.TargetBuildSelector")) | ||
| 574 | + else if (shortcutId == "ProjectMenu.TargetBuildSelector") | ||
| 573 | 575 | { | |
| 574 | 576 | pluginUI.menus.TargetBuildSelector.Focus(); | |
| 575 | 577 | } | |
| 576 | - else if (ke.Value == PluginBase.MainForm.GetShortcutItemKeys("ProjectTree.LocateActiveFile")) | ||
| 578 | + else if (shortcutId == "ProjectTree.LocateActiveFile") | ||
| 577 | 579 | { | |
| 578 | 580 | ToggleTrackActiveDocument(); | |
| 579 | 581 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -284,7 +284,7 @@ private void PopulateListView(String filter, Boolean viewCustom) | |||
| 284 | 284 | this.listView.BeginUpdate(); | |
| 285 | 285 | this.listView.Items.Clear(); | |
| 286 | 286 | this.listView.ListViewItemSorter = new ListViewComparer(); | |
| 287 | - foreach (ShortcutItem item in ShortcutManager.RegisteredItems) | ||
| 287 | + foreach (ShortcutItem item in ShortcutManager.RegisteredItems.Values) | ||
| 288 | 288 | { | |
| 289 | 289 | if (!this.listView.Items.ContainsKey(item.Id) && | |
| 290 | 290 | (item.Id.ToLower().Contains(filter.ToLower()) || | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1781,13 +1781,21 @@ public void AutoUpdateMenuItem(ToolStripItem item, String action) | |||
| 1781 | 1781 | } | |
| 1782 | 1782 | ||
| 1783 | 1783 | /// <summary> | |
| 1784 | - /// Gets the specified item's shortcut keys | ||
| 1784 | + /// Gets the specified item's shortcut keys. | ||
| 1785 | 1785 | /// </summary> | |
| 1786 | 1786 | public Keys GetShortcutItemKeys(String id) | |
| 1787 | 1787 | { | |
| 1788 | 1788 | ShortcutItem item = ShortcutManager.GetRegisteredItem(id); | |
| 1789 | - if (item != null) return item.Custom; | ||
| 1790 | - else return Keys.None; | ||
| 1789 | + return item == null ? Keys.None : item.Custom; | ||
| 1790 | + } | ||
| 1791 | + | ||
| 1792 | + /// <summary> | ||
| 1793 | + /// Gets the specified item's id. | ||
| 1794 | + /// </summary> | ||
| 1795 | + public String GetShortcutItemId(Keys keys) | ||
| 1796 | + { | ||
| 1797 | + ShortcutItem item = ShortcutManager.GetRegisteredItem(keys); | ||
| 1798 | + return item == null ? string.Empty : item.Id; | ||
| 1791 | 1799 | } | |
| 1792 | 1800 | ||
| 1793 | 1801 | /// <summary> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,28 +10,33 @@ | |||
| 10 | 10 | ||
| 11 | 11 | namespace FlashDevelop.Managers | |
| 12 | 12 | { | |
| 13 | - class ShortcutManager | ||
| 13 | + static class ShortcutManager | ||
| 14 | 14 | { | |
| 15 | - public static List<Keys> AllShortcuts = new List<Keys>(); | ||
| 16 | - public static List<ToolStripItem> SecondaryItems = new List<ToolStripItem>(); | ||
| 17 | - public static List<ShortcutItem> RegisteredItems = new List<ShortcutItem>(); | ||
| 15 | + public static readonly List<Keys> AllShortcuts; | ||
| 16 | + public static readonly List<ToolStripItem> SecondaryItems; | ||
| 17 | + public static readonly Dictionary<String, ShortcutItem> RegisteredItems; | ||
| 18 | + | ||
| 19 | + static ShortcutManager() | ||
| 20 | + { | ||
| 21 | + AllShortcuts = new List<Keys>(); | ||
| 22 | + SecondaryItems = new List<ToolStripItem>(); | ||
| 23 | + RegisteredItems = new Dictionary<string, ShortcutItem>(); | ||
| 24 | + } | ||
| 18 | 25 | ||
| 19 | 26 | /// <summary> | |
| 20 | 27 | /// Registers a shortcut item | |
| 21 | 28 | /// </summary> | |
| 22 | 29 | public static void RegisterItem(String key, Keys keys) | |
| 23 | 30 | { | |
| 24 | - ShortcutItem registered = new ShortcutItem(key, keys); | ||
| 25 | - RegisteredItems.Add(registered); | ||
| 31 | + RegisteredItems.Add(key, new ShortcutItem(key, keys)); | ||
| 26 | 32 | } | |
| 27 | 33 | ||
| 28 | 34 | /// <summary> | |
| 29 | 35 | /// Registers a shortcut item | |
| 30 | 36 | /// </summary> | |
| 31 | 37 | public static void RegisterItem(String key, ToolStripMenuItem item) | |
| 32 | 38 | { | |
| 33 | - ShortcutItem registered = new ShortcutItem(key, item); | ||
| 34 | - RegisteredItems.Add(registered); | ||
| 39 | + RegisteredItems.Add(key, new ShortcutItem(key, item)); | ||
| 35 | 40 | } | |
| 36 | 41 | ||
| 37 | 42 | /// <summary> | |
@@ -56,9 +61,19 @@ public static void RegisterSecondaryItem(String id, ToolStripItem item) | |||
| 56 | 61 | /// </summary> | |
| 57 | 62 | public static ShortcutItem GetRegisteredItem(String id) | |
| 58 | 63 | { | |
| 59 | - foreach (ShortcutItem item in RegisteredItems) | ||
| 64 | + ShortcutItem item; | ||
| 65 | + return RegisteredItems.TryGetValue(id, out item) ? item : null; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + /// <summary> | ||
| 69 | + /// Gets the specified registered shortcut item | ||
| 70 | + /// </summary> | ||
| 71 | + public static ShortcutItem GetRegisteredItem(Keys keys) | ||
| 72 | + { | ||
| 73 | + if (keys == Keys.None) return null; | ||
| 74 | + foreach (ShortcutItem item in RegisteredItems.Values) | ||
| 60 | 75 | { | |
| 61 | - if (item.Id == id) return item; | ||
| 76 | + if (item.Custom == keys) return item; | ||
| 62 | 77 | } | |
| 63 | 78 | return null; | |
| 64 | 79 | } | |
@@ -70,16 +85,11 @@ public static ToolStripItem GetSecondaryItem(String id) | |||
| 70 | 85 | { | |
| 71 | 86 | foreach (ToolStripItem item in SecondaryItems) | |
| 72 | 87 | { | |
| 73 | - String temp = String.Empty; | ||
| 74 | - String[] ids = ((ItemData)item.Tag).Id.Split(';'); | ||
| 75 | - if (ids.Length == 2 && String.IsNullOrEmpty(ids[1])) | ||
| 76 | - { | ||
| 77 | - temp = StripBarManager.GetMenuItemId(item); | ||
| 78 | - } | ||
| 79 | - else if (ids.Length == 2) temp = ids[1]; | ||
| 80 | - if (!String.IsNullOrEmpty(temp) && temp == id) | ||
| 88 | + String[] ids = ((ItemData) item.Tag).Id.Split(';'); | ||
| 89 | + if (ids.Length == 2) | ||
| 81 | 90 | { | |
| 82 | - return item; | ||
| 91 | + String temp = String.IsNullOrEmpty(ids[1]) ? StripBarManager.GetMenuItemId(item) : ids[1]; | ||
| 92 | + if (temp == id) return item; | ||
| 83 | 93 | } | |
| 84 | 94 | } | |
| 85 | 95 | return null; | |
@@ -90,7 +100,7 @@ public static ToolStripItem GetSecondaryItem(String id) | |||
| 90 | 100 | /// </summary> | |
| 91 | 101 | public static void UpdateAllShortcuts() | |
| 92 | 102 | { | |
| 93 | - foreach (ShortcutItem item in RegisteredItems) | ||
| 103 | + foreach (ShortcutItem item in RegisteredItems.Values) | ||
| 94 | 104 | { | |
| 95 | 105 | if (!AllShortcuts.Contains(item.Custom)) | |
| 96 | 106 | { | |
@@ -105,7 +115,7 @@ public static void UpdateAllShortcuts() | |||
| 105 | 115 | public static void ApplyAllShortcuts() | |
| 106 | 116 | { | |
| 107 | 117 | UpdateAllShortcuts(); | |
| 108 | - foreach (ShortcutItem item in RegisteredItems) | ||
| 118 | + foreach (ShortcutItem item in RegisteredItems.Values) | ||
| 109 | 119 | { | |
| 110 | 120 | if (item.Item != null) | |
| 111 | 121 | { | |
@@ -134,12 +144,11 @@ public static void ApplySecondaryShortcut(ToolStripItem item) | |||
| 134 | 144 | if (item != null && item.Tag != null) | |
| 135 | 145 | { | |
| 136 | 146 | String id = String.Empty; | |
| 137 | - String[] ids = ((ItemData)item.Tag).Id.Split(';'); | ||
| 138 | - if (ids.Length == 2 && String.IsNullOrEmpty(ids[1])) | ||
| 147 | + String[] ids = ((ItemData) item.Tag).Id.Split(';'); | ||
| 148 | + if (ids.Length == 2) | ||
| 139 | 149 | { | |
| 140 | - id = StripBarManager.GetMenuItemId(item); | ||
| 150 | + id = String.IsNullOrEmpty(ids[1]) ? StripBarManager.GetMenuItemId(item) : ids[1]; | ||
| 141 | 151 | } | |
| 142 | - else if (ids.Length == 2) id = ids[1]; | ||
| 143 | 152 | else return; // No work for us here... | |
| 144 | 153 | Keys keys = Globals.MainForm.GetShortcutItemKeys(id); | |
| 145 | 154 | if (keys != Keys.None) | |
@@ -165,7 +174,7 @@ public static void ApplySecondaryShortcut(ToolStripItem item) | |||
| 165 | 174 | } | |
| 166 | 175 | ||
| 167 | 176 | /// <summary> | |
| 168 | - /// Loads the custom shorcuts from a file | ||
| 177 | + /// Loads the custom shortcuts from a file | ||
| 169 | 178 | /// </summary> | |
| 170 | 179 | public static void LoadCustomShortcuts() | |
| 171 | 180 | { | |
@@ -174,11 +183,11 @@ public static void LoadCustomShortcuts() | |||
| 174 | 183 | if (File.Exists(file)) | |
| 175 | 184 | { | |
| 176 | 185 | List<Argument> shortcuts = new List<Argument>(); | |
| 177 | - shortcuts = (List<Argument>)ObjectSerializer.Deserialize(file, shortcuts, false); | ||
| 186 | + shortcuts = (List<Argument>) ObjectSerializer.Deserialize(file, shortcuts, false); | ||
| 178 | 187 | foreach (Argument arg in shortcuts) | |
| 179 | 188 | { | |
| 180 | 189 | ShortcutItem item = GetRegisteredItem(arg.Key); | |
| 181 | - if (item != null) item.Custom = (Keys)Enum.Parse(typeof(Keys), arg.Value); | ||
| 190 | + if (item != null) item.Custom = (Keys) Enum.Parse(typeof(Keys), arg.Value); | ||
| 182 | 191 | } | |
| 183 | 192 | } | |
| 184 | 193 | } | |
@@ -189,7 +198,7 @@ public static void LoadCustomShortcuts() | |||
| 189 | 198 | public static void SaveCustomShortcuts() | |
| 190 | 199 | { | |
| 191 | 200 | List<Argument> shortcuts = new List<Argument>(); | |
| 192 | - foreach (ShortcutItem item in RegisteredItems) | ||
| 201 | + foreach (ShortcutItem item in RegisteredItems.Values) | ||
| 193 | 202 | { | |
| 194 | 203 | if (item.Custom != item.Default) | |
| 195 | 204 | { | |
@@ -206,10 +215,10 @@ public static void SaveCustomShortcuts() | |||
| 206 | 215 | ||
| 207 | 216 | public class ShortcutItem | |
| 208 | 217 | { | |
| 209 | - public Keys Custom = Keys.None; | ||
| 210 | - public Keys Default = Keys.None; | ||
| 211 | - public ToolStripMenuItem Item = null; | ||
| 212 | - public String Id = String.Empty; | ||
| 218 | + public String Id; | ||
| 219 | + public Keys Default; | ||
| 220 | + public Keys Custom; | ||
| 221 | + public ToolStripMenuItem Item; | ||
| 213 | 222 | ||
| 214 | 223 | public ShortcutItem(String id, Keys keys) | |
| 215 | 224 | { | |
@@ -224,7 +233,7 @@ public ShortcutItem(String id, ToolStripMenuItem item) | |||
| 224 | 233 | this.Default = this.Custom = item.ShortcutKeys; | |
| 225 | 234 | } | |
| 226 | 235 | ||
| 227 | - public override string ToString() | ||
| 236 | + public override String ToString() | ||
| 228 | 237 | { | |
| 229 | 238 | return Id; | |
| 230 | 239 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -122,6 +122,7 @@ public interface IMainForm : IContainerControl, IWin32Window | |||
| 122 | 122 | ToolStripItem FindMenuItem(String name); | |
| 123 | 123 | String ProcessArgString(String args); | |
| 124 | 124 | Keys GetShortcutItemKeys(String id); | |
| 125 | + String GetShortcutItemId(Keys keys); | ||
| 125 | 126 | String GetThemeValue(String id); | |
| 126 | 127 | Color GetThemeColor(String id); | |
| 127 | 128 | Boolean GetThemeFlag(String id); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments