@@ -193,7 +193,7 @@ public static void LoadCustomShortcuts()
193
193
}
194
194
195
195
/// <summary>
196
- /// Saves the custom shorcuts to a file
196
+ /// Saves the custom shortcuts to a file
197
197
/// </summary>
198
198
public static void SaveCustomShortcuts ( )
199
199
{
@@ -209,6 +209,58 @@ public static void SaveCustomShortcuts()
209
209
ObjectSerializer . Serialize ( file , shortcuts ) ;
210
210
}
211
211
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
+
212
264
}
213
265
214
266
#region Helper Classes
@@ -239,6 +291,14 @@ public override String ToString()
239
291
}
240
292
}
241
293
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
+
242
302
#endregion
243
303
244
304
}
0 commit comments