|
@@ -11,6 +11,7 @@ using PixiEditor.Models.Commands.Attributes.Commands;
|
|
|
using PixiEditor.Models.Commands.Templates;
|
|
|
using PixiEditor.Models.UserPreferences;
|
|
|
using PixiEditor.Views.Dialogs;
|
|
|
+using PixiEditor.Exceptions;
|
|
|
|
|
|
namespace PixiEditor.ViewModels;
|
|
|
|
|
@@ -100,18 +101,8 @@ internal class SettingsWindowViewModel : ViewModelBase
|
|
|
if (dialog.ShowDialog().GetValueOrDefault())
|
|
|
{
|
|
|
List<Shortcut> shortcuts = new List<Shortcut>();
|
|
|
- try
|
|
|
- {
|
|
|
- if (!TryImport(dialog, ref shortcuts))
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- NoticeDialog.Show("Shortcuts file was not in a valid format", "Invalid file");
|
|
|
+ if (!TryImport(dialog, ref shortcuts))
|
|
|
return;
|
|
|
- }
|
|
|
|
|
|
CommandController.Current.ResetShortcuts();
|
|
|
CommandController.Current.Import(shortcuts, false);
|
|
@@ -126,7 +117,16 @@ internal class SettingsWindowViewModel : ViewModelBase
|
|
|
{
|
|
|
if (dialog.FileName.EndsWith(".pixisc") || dialog.FileName.EndsWith(".json"))
|
|
|
{
|
|
|
- shortcuts = ShortcutFile.LoadTemplate(dialog.FileName)?.Shortcuts.ToList();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ shortcuts = ShortcutFile.LoadTemplate(dialog.FileName)?.Shortcuts.ToList();
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+ NoticeDialog.Show(title: "Error", message: "Error while reading the file");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
if (shortcuts is null)
|
|
|
{
|
|
|
NoticeDialog.Show("Shortcuts file was not in a valid format", "Invalid file");
|
|
@@ -143,7 +143,15 @@ internal class SettingsWindowViewModel : ViewModelBase
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- shortcuts = provider.KeysParser.Parse(dialog.FileName, false)?.Shortcuts.ToList();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ shortcuts = provider.KeysParser.Parse(dialog.FileName, false)?.Shortcuts.ToList();
|
|
|
+ }
|
|
|
+ catch (RecoverableException e)
|
|
|
+ {
|
|
|
+ NoticeDialog.Show(title: "Error", message: e.Message);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return true;
|