Skip to content

Commit 4722c8c

Browse files
committed
ShortcutDialog update 2
Added required methods for loading/saving custom shortcut sets.
1 parent 5cb1b7b commit 4722c8c

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

FlashDevelop/Managers/ShortcutManager.cs

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public static void LoadCustomShortcuts()
193193
}
194194

195195
/// <summary>
196-
/// Saves the custom shorcuts to a file
196+
/// Saves the custom shortcuts to a file
197197
/// </summary>
198198
public static void SaveCustomShortcuts()
199199
{
@@ -209,6 +209,58 @@ public static void SaveCustomShortcuts()
209209
ObjectSerializer.Serialize(file, shortcuts);
210210
}
211211

212+
/// <summary>
213+
/// Loads the custom shortcuts from a file to a list.
214+
/// </summary>
215+
public static void LoadCustomShortcuts(String file, IEnumerable<IShortcutItem> items)
216+
{
217+
if (File.Exists(file))
218+
{
219+
try
220+
{
221+
List<Argument> customShortcuts = new List<Argument>();
222+
customShortcuts = (List<Argument>) ObjectSerializer.Deserialize(file, customShortcuts, false);
223+
foreach (IShortcutItem item in items)
224+
{
225+
Keys newShortcut = item.Default;
226+
foreach (Argument arg in customShortcuts)
227+
{
228+
if (arg.Key == item.Id)
229+
{
230+
newShortcut = (Keys) Enum.Parse(typeof(Keys), arg.Value);
231+
break;
232+
}
233+
}
234+
item.Custom = newShortcut;
235+
}
236+
}
237+
catch (Exception e)
238+
{
239+
ErrorManager.ShowError(e);
240+
}
241+
}
242+
}
243+
244+
/// <summary>
245+
/// Saves the list of custom shortcuts to a file.
246+
/// </summary>
247+
public static void SaveCustomShortcuts(String file, IEnumerable<IShortcutItem> items)
248+
{
249+
try
250+
{
251+
List<Argument> shortcuts = new List<Argument>();
252+
foreach (IShortcutItem item in items)
253+
{
254+
if (item.IsModified) shortcuts.Add(new Argument(item.Id, item.Custom.ToString()));
255+
}
256+
ObjectSerializer.Serialize(file, shortcuts);
257+
}
258+
catch (Exception e)
259+
{
260+
ErrorManager.ShowError(e);
261+
}
262+
}
263+
212264
}
213265

214266
#region Helper Classes
@@ -239,6 +291,14 @@ public override String ToString()
239291
}
240292
}
241293

294+
public class IShortcutItem
295+
{
296+
public String Id { get; }
297+
public Keys Default { get; }
298+
public Keys Custom { get; set; }
299+
public Boolean IsModified { get; }
300+
}
301+
242302
#endregion
243303

244304
}

PluginCore/PluginCore/Helpers/PathHelper.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ public static String SettingDir
119119
}
120120
}
121121

122+
/// <summary>
123+
/// Path to the custom shortcut directory
124+
/// </summary>
125+
public static String ShortcutsDir
126+
{
127+
get
128+
{
129+
return Path.Combine(SettingDir, "Shortcuts");
130+
}
131+
}
132+
122133
/// <summary>
123134
/// Path to the themes directory
124135
/// </summary>

0 commit comments

Comments
 (0)