Skip to content

Commit 9ae8aff

Browse files
committed
ShortcutDialog update 5
1 parent 9ba39d3 commit 9ae8aff

File tree

2 files changed

+24
-28
lines changed

2 files changed

+24
-28
lines changed

FlashDevelop/Dialogs/ShortcutDialog.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,14 @@ void InitializeShortcutListItems()
295295
this.shortcutListItems[counter++] = new ShortcutListItem(item);
296296
}
297297
Array.Sort(this.shortcutListItems, new ShorcutListItemComparer());
298+
this.UpdateAllShortcutsConflicts();
299+
}
298300

301+
/// <summary>
302+
/// Update conflicts statuses of all shortcut items.
303+
/// </summary>
304+
void UpdateAllShortcutsConflicts()
305+
{
299306
bool conflicts = false;
300307
for (int i = 0; i < this.shortcutListItems.Length; i++)
301308
{
@@ -400,7 +407,7 @@ void ListViewKeyDown(object sender, KeyEventArgs e)
400407
/// <summary>
401408
/// Assign the new shortcut.
402409
/// </summary>
403-
void AssignNewShortcut(ShortcutListItem item, Keys shortcut, bool suppressWarning = false)
410+
void AssignNewShortcut(ShortcutListItem item, Keys shortcut)
404411
{
405412
if (shortcut == 0 || shortcut == Keys.Delete) shortcut = 0;
406413
else if (!ToolStripManager.IsValidShortcut(shortcut)) return;
@@ -412,7 +419,6 @@ void AssignNewShortcut(ShortcutListItem item, Keys shortcut, bool suppressWarnin
412419
this.GetConflictItems(item);
413420
if (item.HasConflicts)
414421
{
415-
if (suppressWarning) return;
416422
ErrorManager.ShowWarning(TextHelper.GetString("Info.ShortcutIsAlreadyUsed"), null);
417423
this.filterTextBox.Focus(); // Set focus to filter...
418424
this.filterTextBox.Text = ViewConflictsKey + item.KeysString;
@@ -552,16 +558,10 @@ void SelectCustomShortcut(object sender, EventArgs e)
552558
string extension = Path.GetExtension(dialog.FileName);
553559
if (extension.Equals(".fda", StringComparison.OrdinalIgnoreCase))
554560
{
555-
var shortcuts = ShortcutManager.LoadCustomShortcuts(dialog.FileName, this.shortcutListItems);
556-
if (shortcuts != null)
557-
{
558-
this.listView.BeginUpdate();
559-
for (int i = 0; i < shortcuts.Length; i++)
560-
{
561-
this.AssignNewShortcut(this.shortcutListItems[i], shortcuts[i], true);
562-
}
563-
this.listView.EndUpdate();
564-
}
561+
this.listView.BeginUpdate();
562+
ShortcutManager.LoadCustomShortcuts(dialog.FileName, this.shortcutListItems);
563+
this.UpdateAllShortcutsConflicts();
564+
this.listView.EndUpdate();
565565
}
566566
}
567567
}

FlashDevelop/Managers/ShortcutManager.cs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -211,45 +211,41 @@ public static void SaveCustomShortcuts()
211211
}
212212

213213
/// <summary>
214-
/// Loads the custom shortcuts from a file and returns an array of new shortcut keys
215-
/// corresponding to the shortcut items in the specified array.
214+
/// Loads the custom shortcuts from a file to a list.
216215
/// </summary>
217-
public static Keys[] LoadCustomShortcuts(String file, IShortcutItem[] items)
216+
public static void LoadCustomShortcuts(String file, IEnumerable<IShortcutItem> items)
218217
{
219218
if (File.Exists(file))
220219
{
221220
try
222221
{
223-
Keys[] newShortcuts = new Keys[items.Length];
224-
225222
List<Argument> customShortcuts = new List<Argument>();
226223
customShortcuts = (List<Argument>) ObjectSerializer.Deserialize(file, customShortcuts, false);
227-
Int32 customCount = customShortcuts.Count;
224+
Int32 count = customShortcuts.Count;
228225

229-
for (int i = 0; i < items.Length; i++)
226+
foreach (IShortcutItem item in items)
230227
{
231-
IShortcutItem item = items[i];
232-
newShortcuts[i] = item.Default;
233-
for (int j = 0; j < customCount; j++)
228+
Keys newShortcut = item.Default;
229+
for (int i = 0; i < count; i++)
234230
{
235-
Argument arg = customShortcuts[j];
231+
Argument arg = customShortcuts[i];
236232
if (arg.Key == item.Id)
237233
{
238-
newShortcuts[i] = (Keys) Enum.Parse(typeof(Keys), arg.Value);
234+
newShortcut = (Keys) Enum.Parse(typeof(Keys), arg.Value);
235+
customShortcuts.RemoveAt(i);
239236
break;
240237
}
241238
}
239+
item.Custom = newShortcut;
242240
}
243-
return newShortcuts;
244241
}
245242
catch (Exception e)
246243
{
247244
ErrorManager.ShowError(e);
248245
}
249246
}
250-
return null;
251247
}
252-
248+
253249
/// <summary>
254250
/// Saves the list of custom shortcuts to a file.
255251
/// </summary>
@@ -304,7 +300,7 @@ public interface IShortcutItem
304300
{
305301
String Id { get; }
306302
Keys Default { get; }
307-
Keys Custom { get; }
303+
Keys Custom { get; set; }
308304
Boolean IsModified { get; }
309305
}
310306

0 commit comments

Comments
 (0)