Browse Source

Fixed AsepriteProvier defaults and changed lasso shortcut

Krzysztof Krysiński 2 years ago
parent
commit
e4bc872be9

+ 1 - 1
src/PixiEditor/Data/ShortcutActionMaps/AsepriteShortcutMap.json

@@ -63,7 +63,7 @@
       },
       },
       "Parameters": []
       "Parameters": []
     },
     },
-    "Color": {
+    "": {
       "Command": "PixiEditor.Clipboard.PasteColor",
       "Command": "PixiEditor.Clipboard.PasteColor",
       "DefaultShortcut": {
       "DefaultShortcut": {
         "key": "None",
         "key": "None",

+ 1 - 0
src/PixiEditor/Models/Commands/CommandCollection.cs

@@ -17,6 +17,7 @@ internal class CommandCollection : ICollection<Command>
     public bool IsReadOnly => false;
     public bool IsReadOnly => false;
 
 
     public Command this[string name] => _commandInternalNames[name];
     public Command this[string name] => _commandInternalNames[name];
+    public bool ContainsKey(string key) => _commandInternalNames.ContainsKey(key);
 
 
     public IEnumerable<Command> this[KeyCombination shortcut] => _commandShortcuts[shortcut];
     public IEnumerable<Command> this[KeyCombination shortcut] => _commandShortcuts[shortcut];
 
 

+ 4 - 1
src/PixiEditor/Models/Commands/CommandController.cs

@@ -53,7 +53,10 @@ internal class CommandController
         {
         {
             foreach (var command in shortcut.Commands)
             foreach (var command in shortcut.Commands)
             {
             {
-                ReplaceShortcut(Commands[command], shortcut.KeyCombination);
+                if (Commands.ContainsKey(command))
+                {
+                    ReplaceShortcut(Commands[command], shortcut.KeyCombination);
+                }
             }
             }
         }
         }
 
 

+ 1 - 12
src/PixiEditor/Models/Commands/Templates/Providers/AsepriteProvider.cs

@@ -29,17 +29,6 @@ internal partial class ShortcutProvider
             return _parser.Parse(InstallationPath);
             return _parser.Parse(InstallationPath);
         }
         }
 
 
-        public List<Shortcut> DefaultShortcuts { get; } = new()
-        {
-            new Shortcut(Key.S, ModifierKeys.Control | ModifierKeys.Alt, "PixiEditor.File.SaveAsNew"),
-            new Shortcut(Key.K, ModifierKeys.Control, "PixiEditor.Window.OpenSettingsWindow"),
-            // Tools
-            new Shortcut(Key.U, ModifierKeys.Shift, "PixiEditor.Tools.Select.EllipseToolViewModel"),
-            new Shortcut(Key.I, ModifierKeys.None, "PixiEditor.Tools.Select.ColorPickerToolViewModel"),
-            new Shortcut(Key.U, ModifierKeys.None, "PixiEditor.Tools.Select.RectangleToolViewModel"),
-            new Shortcut(Key.V, ModifierKeys.None, "PixiEditor.Tools.Select.SelectToolViewModel"),
-            // Not actually in aseprite, but should be included
-            new Shortcut(Key.OemComma, ModifierKeys.Control, "PixiEditor.Search.Toggle")
-        };
+        public List<Shortcut> DefaultShortcuts => _parser.Defaults;
     }
     }
 }
 }

+ 1 - 3
src/PixiEditor/Models/Commands/Templates/Providers/Parsers/AsepriteKeysParser.cs

@@ -24,7 +24,7 @@ public class AsepriteKeysParser : KeysParser
     public AsepriteKeysParser(string mapFileName) : base(mapFileName)
     public AsepriteKeysParser(string mapFileName) : base(mapFileName)
     {
     {
     }
     }
-    
+
     public override ShortcutsTemplate Parse(string path)
     public override ShortcutsTemplate Parse(string path)
     {
     {
         if (!File.Exists(path))
         if (!File.Exists(path))
@@ -84,8 +84,6 @@ public class AsepriteKeysParser : KeysParser
                 continue;
                 continue;
             }
             }
 
 
-            string asepriteCommand = commandName;
-            
             var mappedEntry = Map[commandName];
             var mappedEntry = Map[commandName];
             commandName = mappedEntry.Command;
             commandName = mappedEntry.Command;
 
 

+ 18 - 1
src/PixiEditor/Models/Commands/Templates/Providers/Parsers/KeysParser.cs

@@ -11,7 +11,10 @@ public abstract class KeysParser
 
 
     public Dictionary<string, KeyDefinition> Map => _cachedMap ??= LoadKeysMap();
     public Dictionary<string, KeyDefinition> Map => _cachedMap ??= LoadKeysMap();
     private Dictionary<string, KeyDefinition> _cachedMap;
     private Dictionary<string, KeyDefinition> _cachedMap;
-
+    
+    public List<Shortcut> Defaults => _cachedDefaults ??= ParseDefaults();
+    private List<Shortcut> _cachedDefaults;
+    
     public KeysParser(string mapFileName)
     public KeysParser(string mapFileName)
     {
     {
         _fullMapFilePath = Path.Combine("Data", "ShortcutActionMaps", mapFileName);
         _fullMapFilePath = Path.Combine("Data", "ShortcutActionMaps", mapFileName);
@@ -33,4 +36,18 @@ public abstract class KeysParser
         if(dict.ContainsKey("")) dict.Remove("");
         if(dict.ContainsKey("")) dict.Remove("");
         return dict;
         return dict;
     }
     }
+    
+    private List<Shortcut> ParseDefaults()
+    {
+        var defaults = new List<Shortcut>();
+        foreach (var (key, value) in Map)
+        {
+            if (value.DefaultShortcut != null)
+            {
+                defaults.Add(new Shortcut(value.DefaultShortcut.ToKeyCombination(), Map[key].Command));
+            }
+        }
+        
+        return defaults;
+    }
 }
 }

+ 1 - 1
src/PixiEditor/Models/DocumentModels/Public/DocumentToolsModule.cs

@@ -52,5 +52,5 @@ internal class DocumentToolsModule
 
 
     public void UseFloodFillTool() => Internals.ChangeController.TryStartExecutor<FloodFillToolExecutor>();
     public void UseFloodFillTool() => Internals.ChangeController.TryStartExecutor<FloodFillToolExecutor>();
 
 
-    public void UseLassoTool() => Internals.ChangeController.TryStartExecutor<LassoToolExecuter>();
+    public void UseLassoTool() => Internals.ChangeController.TryStartExecutor<LassoToolExecutor>();
 }
 }

+ 1 - 1
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/LassoToolExecuter.cs → src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/LassoToolExecutor.cs

@@ -6,7 +6,7 @@ using PixiEditor.ViewModels.SubViewModels.Tools.ToolSettings.Toolbars;
 
 
 namespace PixiEditor.Models.DocumentModels.UpdateableChangeExecutors;
 namespace PixiEditor.Models.DocumentModels.UpdateableChangeExecutors;
 
 
-internal sealed class LassoToolExecuter : UpdateableChangeExecutor
+internal sealed class LassoToolExecutor : UpdateableChangeExecutor
 {
 {
     private SelectionMode? mode;
     private SelectionMode? mode;
     
     

+ 1 - 1
src/PixiEditor/ViewModels/SubViewModels/Tools/Tools/LassoToolViewModel.cs

@@ -7,7 +7,7 @@ using PixiEditor.Views.UserControls.BrushShapeOverlay;
 
 
 namespace PixiEditor.ViewModels.SubViewModels.Tools.Tools;
 namespace PixiEditor.ViewModels.SubViewModels.Tools.Tools;
 
 
-[Command.ToolAttribute(Key = Key.L)]
+[Command.ToolAttribute(Key = Key.Q)]
 internal class LassoToolViewModel : ToolViewModel
 internal class LassoToolViewModel : ToolViewModel
 {
 {
     public LassoToolViewModel()
     public LassoToolViewModel()