Skip to content

Commit 38a21fb

Browse files
committed
Merge pull request #974 from wise0704/MainForm
Updates to MainForm (plus Related Things)
2 parents 97ff70c + 198f426 commit 38a21fb

File tree

7 files changed

+231
-153
lines changed

7 files changed

+231
-153
lines changed

External/Plugins/AS3Context/PluginMain.cs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -265,25 +265,23 @@ public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority)
265265
else if (inMXML)
266266
{
267267
DataEvent de = e as DataEvent;
268-
if (de.Action == "XMLCompletion.Element")
268+
switch (de.Action)
269269
{
270-
de.Handled = MxmlComplete.HandleElement(de.Data);
271-
}
272-
if (de.Action == "XMLCompletion.Namespace")
273-
{
274-
de.Handled = MxmlComplete.HandleNamespace(de.Data);
275-
}
276-
else if (de.Action == "XMLCompletion.CloseElement")
277-
{
278-
de.Handled = MxmlComplete.HandleElementClose(de.Data);
279-
}
280-
else if (de.Action == "XMLCompletion.Attribute")
281-
{
282-
de.Handled = MxmlComplete.HandleAttribute(de.Data);
283-
}
284-
else if (de.Action == "XMLCompletion.AttributeValue")
285-
{
286-
de.Handled = MxmlComplete.HandleAttributeValue(de.Data);
270+
case "XMLCompletion.Element":
271+
de.Handled = MxmlComplete.HandleElement(de.Data);
272+
break;
273+
case "XMLCompletion.Namespace":
274+
de.Handled = MxmlComplete.HandleNamespace(de.Data);
275+
break;
276+
case "XMLCompletion.CloseElement":
277+
de.Handled = MxmlComplete.HandleElementClose(de.Data);
278+
break;
279+
case "XMLCompletion.Attribute":
280+
de.Handled = MxmlComplete.HandleAttribute(de.Data);
281+
break;
282+
case "XMLCompletion.AttributeValue":
283+
de.Handled = MxmlComplete.HandleAttributeValue(de.Data);
284+
break;
287285
}
288286
}
289287
}

External/Plugins/ProjectManager/Helpers/LineEntryDialog.cs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Drawing;
33
using System.Collections;
4+
using System.Collections.Generic;
45
using System.ComponentModel;
56
using System.Windows.Forms;
67
using PluginCore;
@@ -13,13 +14,12 @@ namespace ProjectManager.Helpers
1314
/// </summary>
1415
public class LineEntryDialog : Form
1516
{
16-
readonly Keys shortcutToLowercase;
17-
readonly Keys shortcutToUppercase;
1817
string line;
18+
readonly Dictionary<Keys, string> shortcuts;
1919

2020
#region Form Designer Components
2121

22-
protected System.Windows.Forms.TextBox lineBox;
22+
private System.Windows.Forms.TextBox lineBox;
2323
private System.Windows.Forms.Button btnOK;
2424
private System.Windows.Forms.Button btnCancel;
2525
/// <summary>
@@ -40,17 +40,15 @@ public string Line
4040

4141
public LineEntryDialog(string captionText, string labelText, string defaultLine)
4242
{
43-
shortcutToLowercase = PluginBase.MainForm.GetShortcutItemKeys("EditMenu.ToLowercase");
44-
shortcutToUppercase = PluginBase.MainForm.GetShortcutItemKeys("EditMenu.ToUppercase");
4543
InitializeComponent();
4644
InititalizeLocalization();
4745
this.Font = PluginBase.Settings.DefaultFont;
4846
this.Text = " " + captionText;
4947
titleLabel.Text = labelText;
50-
lineBox.KeyDown += OnLineBoxOnKeyDown;
51-
lineBox.Text = (defaultLine != null) ? defaultLine : string.Empty;
48+
lineBox.Text = defaultLine ?? string.Empty;
5249
lineBox.SelectAll();
5350
lineBox.Focus();
51+
shortcuts = PluginBase.MainForm.GetShortcutItemsByKeys();
5452
}
5553

5654
#region Dispose
@@ -100,6 +98,7 @@ private void InitializeComponent()
10098
this.lineBox.Name = "lineBox";
10199
this.lineBox.Size = new System.Drawing.Size(260, 20);
102100
this.lineBox.TabIndex = 0;
101+
this.lineBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.LineBox_KeyDown);
103102
//
104103
// btnOK
105104
//
@@ -172,18 +171,22 @@ private void btnCancel_Click(object sender, System.EventArgs e)
172171
this.Close();
173172
}
174173

175-
void OnLineBoxOnKeyDown(object sender, KeyEventArgs args)
174+
void LineBox_KeyDown(object sender, KeyEventArgs e)
176175
{
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);
176+
string shortcutId;
177+
if (!shortcuts.TryGetValue(e.KeyData, out shortcutId)) return;
178+
switch (shortcutId)
179+
{
180+
case "EditMenu.ToLowercase":
181+
case "EditMenu.ToUppercase":
182+
string text = lineBox.SelectedText;
183+
if (string.IsNullOrEmpty(text)) break;
184+
text = shortcutId == "EditMenu.ToLowercase" ? text.ToLower() : text.ToUpper();
185+
int selectionStart = lineBox.SelectionStart;
186+
lineBox.Paste(text);
187+
SelectRange(selectionStart, text.Length);
188+
break;
189+
}
187190
}
188191

189192
public void SelectRange(int start, int length)

External/Plugins/ProjectManager/PluginMain.cs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -561,38 +561,38 @@ private bool HandleKeyEvent(KeyEvent ke)
561561
{
562562
if (activeProject == null) return false;
563563

564-
if (ke.Value == PluginBase.MainForm.GetShortcutItemKeys("ProjectMenu.ConfigurationSelector"))
564+
switch (PluginBase.MainForm.GetShortcutItemId(ke.Value))
565565
{
566-
pluginUI.menus.ConfigurationSelector.Focus();
567-
}
568-
else if (ke.Value == PluginBase.MainForm.GetShortcutItemKeys("ProjectMenu.ConfigurationSelectorToggle"))
569-
{
570-
pluginUI.menus.ToggleDebugRelease();
571-
}
572-
else if (ke.Value == PluginBase.MainForm.GetShortcutItemKeys("ProjectMenu.TargetBuildSelector"))
573-
{
574-
pluginUI.menus.TargetBuildSelector.Focus();
575-
}
576-
else if (ke.Value == PluginBase.MainForm.GetShortcutItemKeys("ProjectTree.LocateActiveFile"))
577-
{
578-
ToggleTrackActiveDocument();
566+
case "ProjectMenu.ConfigurationSelector":
567+
pluginUI.menus.ConfigurationSelector.Focus();
568+
break;
569+
case "ProjectMenu.ConfigurationSelectorToggle":
570+
pluginUI.menus.ToggleDebugRelease();
571+
break;
572+
case "ProjectMenu.TargetBuildSelector":
573+
pluginUI.menus.TargetBuildSelector.Focus();
574+
break;
575+
case "ProjectTree.LocateActiveFile":
576+
ToggleTrackActiveDocument();
577+
break;
578+
default:
579+
if (Tree.Focused && !pluginUI.IsEditingLabel)
580+
{
581+
if (ke.Value == (Keys.Control | Keys.C) && pluginUI.Menu.Contains(pluginUI.Menu.Copy)) TreeCopyItems();
582+
else if (ke.Value == (Keys.Control | Keys.X) && pluginUI.Menu.Contains(pluginUI.Menu.Cut)) TreeCutItems();
583+
else if (ke.Value == (Keys.Control | Keys.V) && pluginUI.Menu.Contains(pluginUI.Menu.Paste)) TreePasteItems();
584+
else if (ke.Value == Keys.Delete && pluginUI.Menu.Contains(pluginUI.Menu.Delete)) TreeDeleteItems();
585+
else if (ke.Value == Keys.Enter && pluginUI.Menu.Contains(pluginUI.Menu.Open)) TreeOpenItems();
586+
else if (ke.Value == Keys.Enter && pluginUI.Menu.Contains(pluginUI.Menu.Insert)) TreeInsertItem();
587+
else return false;
588+
}
589+
else return false;
590+
break;
579591
}
580592

581-
// Handle tree-level simple shortcuts like copy/paste/del
582-
else if (Tree.Focused && !pluginUI.IsEditingLabel && ke != null)
583-
{
584-
if (ke.Value == (Keys.Control | Keys.C) && pluginUI.Menu.Contains(pluginUI.Menu.Copy)) TreeCopyItems();
585-
else if (ke.Value == (Keys.Control | Keys.X) && pluginUI.Menu.Contains(pluginUI.Menu.Cut)) TreeCutItems();
586-
else if (ke.Value == (Keys.Control | Keys.V) && pluginUI.Menu.Contains(pluginUI.Menu.Paste)) TreePasteItems();
587-
else if (ke.Value == Keys.Delete && pluginUI.Menu.Contains(pluginUI.Menu.Delete)) TreeDeleteItems();
588-
else if (ke.Value == Keys.Enter && pluginUI.Menu.Contains(pluginUI.Menu.Open)) TreeOpenItems();
589-
else if (ke.Value == Keys.Enter && pluginUI.Menu.Contains(pluginUI.Menu.Insert)) TreeInsertItem();
590-
else return false;
591-
}
592-
else return false;
593593
return true;
594594
}
595-
595+
596596
#endregion
597597

598598
#region Custom Methods

FlashDevelop/Dialogs/ShortcutDialog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ private void PopulateListView(String filter, Boolean viewCustom)
284284
this.listView.BeginUpdate();
285285
this.listView.Items.Clear();
286286
this.listView.ListViewItemSorter = new ListViewComparer();
287-
foreach (ShortcutItem item in ShortcutManager.RegisteredItems)
287+
foreach (ShortcutItem item in ShortcutManager.RegisteredItems.Values)
288288
{
289289
if (!this.listView.Items.ContainsKey(item.Id) &&
290290
(item.Id.ToLower().Contains(filter.ToLower()) ||

FlashDevelop/MainForm.cs

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,8 +1710,7 @@ public Color GetThemeColor(String id)
17101710
public Color GetThemeColor(String id, Color fallback)
17111711
{
17121712
Color color = ThemeManager.GetThemeColor(id);
1713-
if (color != Color.Empty) return color;
1714-
else return fallback;
1713+
return color.IsEmpty ? fallback : color;
17151714
}
17161715

17171716
/// <summary>
@@ -1728,8 +1727,54 @@ public String GetThemeValue(String id)
17281727
public String GetThemeValue(String id, String fallback)
17291728
{
17301729
String value = ThemeManager.GetThemeValue(id);
1731-
if (!String.IsNullOrEmpty(value)) return value;
1732-
else return fallback;
1730+
return String.IsNullOrEmpty(value) ? fallback : value;
1731+
}
1732+
1733+
/// <summary>
1734+
/// Gets a theme flag value.
1735+
/// </summary>
1736+
public Boolean GetThemeFlag(String id)
1737+
{
1738+
return GetThemeFlag(id, false);
1739+
}
1740+
1741+
/// <summary>
1742+
/// Gets a theme flag value with a fallback.
1743+
/// </summary>
1744+
public Boolean GetThemeFlag(String id, Boolean fallback)
1745+
{
1746+
String value = ThemeManager.GetThemeValue(id);
1747+
if (String.IsNullOrEmpty(value)) return fallback;
1748+
switch (value.ToLower())
1749+
{
1750+
case "true": return true;
1751+
case "false": return false;
1752+
default: return fallback;
1753+
}
1754+
}
1755+
1756+
/// <summary>
1757+
/// Gets a theme enumeration value.
1758+
/// </summary>
1759+
public T GetThemeValue<T>(String id) where T : struct
1760+
{
1761+
return GetThemeValue(id, default(T));
1762+
}
1763+
1764+
/// <summary>
1765+
/// Gets a theme enumeration value with a fallback.
1766+
/// </summary>
1767+
public T GetThemeValue<T>(String id, T fallback) where T : struct
1768+
{
1769+
String value = ThemeManager.GetThemeValue(id);
1770+
try
1771+
{
1772+
return (T) Enum.Parse(typeof(T), value);
1773+
}
1774+
catch
1775+
{
1776+
return fallback;
1777+
}
17331778
}
17341779

17351780
/// <summary>
@@ -1763,8 +1808,32 @@ public void AutoUpdateMenuItem(ToolStripItem item, String action)
17631808
public Keys GetShortcutItemKeys(String id)
17641809
{
17651810
ShortcutItem item = ShortcutManager.GetRegisteredItem(id);
1766-
if (item != null) return item.Custom;
1767-
else return Keys.None;
1811+
return item != null ? item.Custom : Keys.None;
1812+
}
1813+
1814+
/// <summary>
1815+
/// Gets the shortcut id associated the keys.
1816+
/// </summary>
1817+
public string GetShortcutItemId(Keys keys)
1818+
{
1819+
ShortcutItem item = ShortcutManager.GetRegisteredItem(keys);
1820+
return item != null ? item.Id : null;
1821+
}
1822+
1823+
/// <summary>
1824+
/// Returns a <see cref="Dictionary{TKey, TValue}"/> object containing all registered
1825+
/// shortcuts with the shortcut values as keys.
1826+
/// </summary>
1827+
public Dictionary<Keys, String> GetShortcutItemsByKeys()
1828+
{
1829+
Dictionary<String, ShortcutItem>.ValueCollection list = ShortcutManager.RegisteredItems.Values;
1830+
Dictionary<Keys, String> items = new Dictionary<Keys, String>(list.Count);
1831+
foreach (ShortcutItem item in list)
1832+
{
1833+
if (item.Custom == Keys.None) continue;
1834+
items[item.Custom] = item.Id;
1835+
}
1836+
return items;
17681837
}
17691838

17701839
/// <summary>

0 commit comments

Comments
 (0)