Skip to content

Commit 804e606

Browse files
committed
Merge pull request #1057 from wise0704/ShortcutDialog
ShortcutDialog Load/Save Functionality
2 parents 61243e6 + b7b1863 commit 804e606

File tree

5 files changed

+181
-48
lines changed

5 files changed

+181
-48
lines changed
Binary file not shown.

FlashDevelop/Dialogs/ShortcutDialog.cs

Lines changed: 103 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Drawing;
4+
using System.IO;
45
using System.Windows.Forms;
56
using FlashDevelop.Managers;
67
using PluginCore.Controls;
@@ -13,9 +14,9 @@ namespace FlashDevelop.Dialogs
1314
{
1415
public class ShortcutDialog : SmartForm
1516
{
16-
const string ViewConflictsKey = "?"; // TODO: Change the type to char after #969 is merged
17-
const string ViewCustomKey = "*"; // TODO: Change the type to char after #969 is merged
18-
17+
const char ViewConflictsKey = '?';
18+
const char ViewCustomKey = '*';
19+
1920
Timer updateTimer;
2021
ToolStripMenuItem removeShortcut;
2122
ToolStripMenuItem revertToDefault;
@@ -28,9 +29,10 @@ public class ShortcutDialog : SmartForm
2829
private System.Windows.Forms.ColumnHeader idHeader;
2930
private System.Windows.Forms.ColumnHeader keyHeader;
3031
private System.Windows.Forms.TextBox filterTextBox;
31-
private System.Windows.Forms.CheckBox viewCustom;
3232
private System.Windows.Forms.Button clearButton;
3333
private System.Windows.Forms.Button closeButton;
34+
private System.Windows.Forms.Button openButton;
35+
private System.Windows.Forms.Button saveButton;
3436

3537
ShortcutDialog()
3638
{
@@ -64,7 +66,8 @@ private void InitializeComponent()
6466
this.searchLabel = new System.Windows.Forms.Label();
6567
this.clearButton = new System.Windows.Forms.Button();
6668
this.filterTextBox = new System.Windows.Forms.TextBox();
67-
this.viewCustom = new System.Windows.Forms.CheckBox();
69+
this.openButton = new System.Windows.Forms.Button();
70+
this.saveButton = new System.Windows.Forms.Button();
6871
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
6972
this.SuspendLayout();
7073
//
@@ -79,15 +82,15 @@ private void InitializeComponent()
7982
this.keyHeader.Width = 208;
8083
//
8184
// listView
82-
//
85+
//
8386
this.listView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)));
8487
this.listView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {this.idHeader, this.keyHeader});
8588
this.listView.GridLines = true;
8689
this.listView.FullRowSelect = true;
87-
this.listView.Location = new System.Drawing.Point(12, 62);
90+
this.listView.Location = new System.Drawing.Point(12, 70);
8891
this.listView.MultiSelect = false;
8992
this.listView.Name = "listView";
90-
this.listView.Size = new System.Drawing.Size(562, 312);
93+
this.listView.Size = new System.Drawing.Size(562, 304);
9194
this.listView.TabIndex = 4;
9295
this.listView.UseCompatibleStateImageBehavior = false;
9396
this.listView.View = System.Windows.Forms.View.Details;
@@ -128,15 +131,15 @@ private void InitializeComponent()
128131
//
129132
this.searchLabel.AutoSize = true;
130133
this.searchLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)));
131-
this.searchLabel.Location = new System.Drawing.Point(10, 10);
134+
this.searchLabel.Location = new System.Drawing.Point(10, 25);
132135
this.searchLabel.Name = "searchLabel";
133136
this.searchLabel.TabIndex = 0;
134137
this.searchLabel.Text = "Search:";
135138
//
136139
// clearButton
137-
//
140+
//
138141
this.clearButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
139-
this.clearButton.Location = new System.Drawing.Point(549, 30);
142+
this.clearButton.Location = new System.Drawing.Point(549, 39);
140143
this.clearButton.Name = "clearButton";
141144
this.clearButton.Size = new System.Drawing.Size(26, 23);
142145
this.clearButton.TabIndex = 2;
@@ -146,20 +149,28 @@ private void InitializeComponent()
146149
// filterTextBox
147150
//
148151
this.filterTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)));
149-
this.filterTextBox.Location = new System.Drawing.Point(12, 32);
152+
this.filterTextBox.Location = new System.Drawing.Point(12, 41);
150153
this.filterTextBox.Name = "filterTextBox";
151-
this.filterTextBox.Size = new System.Drawing.Size(530, 20);
154+
this.filterTextBox.Size = new System.Drawing.Size(531, 20);
152155
this.filterTextBox.TabIndex = 1;
153156
this.filterTextBox.ForeColor = System.Drawing.SystemColors.GrayText;
154157
this.filterTextBox.TextChanged += new System.EventHandler(this.FilterTextChanged);
155158
//
156-
// viewCustom
157-
//
158-
this.viewCustom.AutoSize = true;
159-
this.viewCustom.CheckAlign = ContentAlignment.MiddleRight;
160-
this.viewCustom.Anchor = ((System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right));
161-
this.viewCustom.Location = new System.Drawing.Point(471, 9);
162-
this.viewCustom.CheckedChanged += new System.EventHandler(this.ViewCustomCheckedChanged);
159+
// openButton
160+
//
161+
this.openButton.Location = new System.Drawing.Point(369, 12);
162+
this.openButton.Name = "openButton";
163+
this.openButton.Size = new System.Drawing.Size(100, 23);
164+
this.openButton.UseVisualStyleBackColor = true;
165+
this.openButton.Click += new System.EventHandler(SelectCustomShortcut);
166+
//
167+
// saveButton
168+
//
169+
this.saveButton.Location = new System.Drawing.Point(475, 12);
170+
this.saveButton.Name = "saveButton";
171+
this.saveButton.Size = new System.Drawing.Size(100, 23);
172+
this.saveButton.UseVisualStyleBackColor = true;
173+
this.saveButton.Click += new System.EventHandler(SaveCustomShortcut);
163174
//
164175
// ShortcutDialog
165176
//
@@ -175,12 +186,13 @@ private void InitializeComponent()
175186
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
176187
this.ClientSize = new System.Drawing.Size(586, 416);
177188
this.MinimumSize = new System.Drawing.Size(400, 250);
189+
this.Controls.Add(this.saveButton);
190+
this.Controls.Add(this.openButton);
178191
this.Controls.Add(this.filterTextBox);
179192
this.Controls.Add(this.clearButton);
180193
this.Controls.Add(this.infoLabel);
181194
this.Controls.Add(this.pictureBox);
182195
this.Controls.Add(this.closeButton);
183-
this.Controls.Add(this.viewCustom);
184196
this.Controls.Add(this.listView);
185197
this.Controls.Add(this.searchLabel);
186198
this.FormClosing += new FormClosingEventHandler(this.DialogClosing);
@@ -219,11 +231,15 @@ void InitializeContextMenu()
219231
{
220232
var cms = new ContextMenuStrip();
221233
cms.Font = Globals.Settings.DefaultFont;
234+
cms.ImageScalingSize = ScaleHelper.Scale(new Size(16, 16));
222235
cms.Renderer = new DockPanelStripRenderer(false, false);
223236
this.removeShortcut = new ToolStripMenuItem(TextHelper.GetString("Label.RemoveShortcut"), null, this.RemoveShortcutClick);
224237
this.revertToDefault = new ToolStripMenuItem(TextHelper.GetString("Label.RevertToDefault"), null, this.RevertToDefaultClick);
225238
this.revertAllToDefault = new ToolStripMenuItem(TextHelper.GetString("Label.RevertAllToDefault"), null, this.RevertAllToDefaultClick);
226239
this.removeShortcut.ShortcutKeyDisplayString = DataConverter.KeysToString(Keys.Delete);
240+
this.removeShortcut.Image = Globals.MainForm.FindImage("153");
241+
this.revertToDefault.Image = Globals.MainForm.FindImage("69");
242+
this.revertAllToDefault.Image = Globals.MainForm.FindImage("224");
227243
cms.Items.Add(this.removeShortcut);
228244
cms.Items.Add(this.revertToDefault);
229245
cms.Items.Add(this.revertAllToDefault);
@@ -240,7 +256,8 @@ void ApplyLocalizedTexts()
240256
this.keyHeader.Text = TextHelper.GetString("Label.Shortcut");
241257
this.infoLabel.Text = TextHelper.GetString("Info.ShortcutEditInfo");
242258
this.closeButton.Text = TextHelper.GetString("Label.Close");
243-
this.viewCustom.Text = TextHelper.GetString("Label.ViewCustom");
259+
this.openButton.Text = TextHelper.GetString("Label.Open");
260+
this.saveButton.Text = TextHelper.GetString("Label.SaveAs");
244261
this.searchLabel.Text = TextHelper.GetStringWithoutMnemonics("Label.Search") + ":";
245262
this.Text = " " + TextHelper.GetString("Title.Shortcuts");
246263
}
@@ -253,7 +270,7 @@ void ApplyScaling()
253270
this.idHeader.Width = ScaleHelper.Scale(this.idHeader.Width);
254271
this.keyHeader.Width = ScaleHelper.Scale(this.keyHeader.Width);
255272
}
256-
273+
257274
/// <summary>
258275
/// Updates the font highlight of the item.
259276
/// </summary>
@@ -286,7 +303,14 @@ void InitializeShortcutListItems()
286303
this.shortcutListItems[counter++] = new ShortcutListItem(item);
287304
}
288305
Array.Sort(this.shortcutListItems, new ShorcutListItemComparer());
306+
this.UpdateAllShortcutsConflicts();
307+
}
289308

309+
/// <summary>
310+
/// Update conflicts statuses of all shortcut items.
311+
/// </summary>
312+
void UpdateAllShortcutsConflicts()
313+
{
290314
bool conflicts = false;
291315
for (int i = 0; i < this.shortcutListItems.Length; i++)
292316
{
@@ -307,6 +331,8 @@ bool ShowConflictsPresent()
307331
if (MessageBox.Show(this, text, " " + caption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
308332
{
309333
this.filterTextBox.Text = ViewConflictsKey.ToString();
334+
this.filterTextBox.SelectAll();
335+
this.filterTextBox.Focus();
310336
return true;
311337
}
312338
return false;
@@ -326,7 +352,7 @@ void PopulateListView(string filter)
326352
{
327353
var item = this.shortcutListItems[i];
328354
if (string.IsNullOrEmpty(filter) ||
329-
item.Id.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0 ||
355+
item.Id.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0 ||
330356
item.KeysString.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0)
331357
{
332358
if (viewCustom && !item.IsModified) continue;
@@ -342,17 +368,17 @@ void PopulateListView(string filter)
342368

343369
/// <summary>
344370
/// Reads and removes filter keywords from the start of the filter.
345-
/// Order of the keywords is irrelevant.
371+
/// The order of the keywords is irrelevant.
346372
/// </summary>
347373
static string ExtractFilterKeywords(string filter, ref bool viewCustom, ref bool viewConflicts)
348374
{
349-
if (!viewCustom && filter.StartsWith(ViewCustomKey))
375+
if (!viewCustom && filter.Length != 0 && filter[0] == ViewCustomKey)
350376
{
351377
filter = filter.Substring(1);
352378
viewCustom = true;
353379
return ExtractFilterKeywords(filter, ref viewCustom, ref viewConflicts);
354380
}
355-
if (!viewConflicts && filter.StartsWith(ViewConflictsKey))
381+
if (!viewConflicts && filter.Length != 0 && filter[0] == ViewConflictsKey)
356382
{
357383
filter = filter.Substring(1);
358384
viewConflicts = true;
@@ -408,19 +434,23 @@ void AssignNewShortcut(ShortcutListItem item, Keys shortcut)
408434
else if (!ToolStripManager.IsValidShortcut(shortcut)) return;
409435

410436
if (item.Custom == shortcut) return;
437+
this.listView.BeginUpdate();
411438
var oldShortcut = item.Custom;
412439
item.Custom = shortcut;
413440
item.Selected = true;
414441
this.GetConflictItems(item);
442+
this.listView.EndUpdate();
415443
if (item.HasConflicts)
416444
{
417445
string text = TextHelper.GetString("Info.ShortcutIsAlreadyUsed");
418446
string caption = TextHelper.GetString("Title.WarningDialog");
419447
switch (MessageBox.Show(Globals.MainForm, text, " " + caption, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning))
420448
{
421449
case DialogResult.Abort:
450+
this.listView.BeginUpdate();
422451
item.Custom = oldShortcut;
423452
this.GetConflictItems(item);
453+
this.listView.EndUpdate();
424454
break;
425455
case DialogResult.Retry:
426456
this.filterTextBox.Text = ViewConflictsKey + item.KeysString;
@@ -430,7 +460,7 @@ void AssignNewShortcut(ShortcutListItem item, Keys shortcut)
430460
}
431461
}
432462
}
433-
463+
434464
/// <summary>
435465
/// Resets the conflicts status of an item.
436466
/// </summary>
@@ -449,23 +479,6 @@ static void ResetConflicts(ShortcutListItem item)
449479
}
450480
}
451481

452-
/// <summary>
453-
/// [Deprecated] Filter the list view for custom items.
454-
/// </summary>
455-
void ViewCustomCheckedChanged(object sender, EventArgs e)
456-
{
457-
if (this.filterTextBox.Text.StartsWith(ViewCustomKey))
458-
{
459-
if (!this.viewCustom.Checked)
460-
this.filterTextBox.Text = this.filterTextBox.Text.Substring(1);
461-
}
462-
else
463-
{
464-
if (this.viewCustom.Checked)
465-
this.filterTextBox.Text = ViewCustomKey + this.filterTextBox.Text;
466-
}
467-
}
468-
469482
/// <summary>
470483
/// Gets a list of all conflicting entries.
471484
/// </summary>
@@ -528,7 +541,6 @@ void RemoveShortcutClick(object sender, EventArgs e)
528541
/// </summary>
529542
void ClearFilterClick(object sender, EventArgs e)
530543
{
531-
this.viewCustom.Checked = false;
532544
this.filterTextBox.Text = string.Empty;
533545
this.filterTextBox.Select();
534546
}
@@ -562,6 +574,48 @@ void FilterTextChanged(object sender, EventArgs e)
562574
this.updateTimer.Start();
563575
}
564576

577+
/// <summary>
578+
/// Switch to a custom shortcut set.
579+
/// </summary>
580+
void SelectCustomShortcut(object sender, EventArgs e)
581+
{
582+
var dialog = new OpenFileDialog
583+
{
584+
Filter = TextHelper.GetString("Info.ArgumentFilter") + "|*.fda",
585+
InitialDirectory = PathHelper.ShortcutsDir,
586+
Title = " " + TextHelper.GetString("Title.OpenFileDialog")
587+
};
588+
589+
if (dialog.ShowDialog(this) == DialogResult.OK)
590+
{
591+
this.listView.BeginUpdate();
592+
ShortcutManager.LoadCustomShortcuts(dialog.FileName, this.shortcutListItems);
593+
this.UpdateAllShortcutsConflicts();
594+
this.listView.EndUpdate();
595+
}
596+
}
597+
598+
/// <summary>
599+
/// Save the current shortcut set to a file.
600+
/// </summary>
601+
void SaveCustomShortcut(object sender, EventArgs e)
602+
{
603+
var dialog = new SaveFileDialog
604+
{
605+
AddExtension = true,
606+
DefaultExt = ".fda",
607+
Filter = TextHelper.GetString("Info.ArgumentFilter") + "|*.fda",
608+
InitialDirectory = PathHelper.ShortcutsDir,
609+
OverwritePrompt = true,
610+
Title = " " + TextHelper.GetString("Title.SaveFileDialog")
611+
};
612+
613+
if (dialog.ShowDialog(this) == DialogResult.OK)
614+
{
615+
ShortcutManager.SaveCustomShortcuts(dialog.FileName, this.shortcutListItems);
616+
}
617+
}
618+
565619
/// <summary>
566620
/// Closes the shortcut dialog.
567621
/// </summary>
@@ -629,7 +683,7 @@ int IComparer<ShortcutListItem>.Compare(ShortcutListItem x, ShortcutListItem y)
629683
/// <summary>
630684
/// Represents a visual representation of a <see cref="ShortcutItem"/> object.
631685
/// </summary>
632-
class ShortcutListItem : ListViewItem
686+
class ShortcutListItem : ListViewItem, IShortcutItem
633687
{
634688
readonly ShortcutItem item;
635689
List<ShortcutListItem> conflicts;
@@ -659,6 +713,7 @@ public List<ShortcutListItem> Conflicts
659713
get { return this.conflicts; }
660714
set
661715
{
716+
if (this.conflicts == value) return;
662717
this.conflicts = value;
663718
UpdateItemHighlightFont(this);
664719
}
@@ -688,6 +743,7 @@ public Keys Custom
688743
get { return this.custom; }
689744
set
690745
{
746+
if (this.custom == value) return;
691747
this.custom = value;
692748
this.KeysString = DataConverter.KeysToString(this.custom);
693749
this.SubItems[1].Text = this.KeysString;

FlashDevelop/Helpers/FileNameHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public static String ShortcutData
112112
{
113113
get
114114
{
115+
//Alternative: Path.Combine(PathHelper.ShortcutsDir, "CURRENT");
115116
return Path.Combine(PathHelper.SettingDir, "ShortcutData.fda");
116117
}
117118
}

0 commit comments

Comments
 (0)