Browse Source

Did what flabbet and Equbuxu forced me to do

CPK 4 years ago
parent
commit
803524f1b9

+ 1 - 1
PixiEditor/Models/Controllers/BitmapOperationsUtility.cs

@@ -58,7 +58,7 @@ namespace PixiEditor.Models.Controllers
         /// <param name="tool">Tool to execute.</param>
         /// <param name="tool">Tool to execute.</param>
         public void ExecuteTool(Coordinates newPos, List<Coordinates> mouseMove, BitmapOperationTool tool)
         public void ExecuteTool(Coordinates newPos, List<Coordinates> mouseMove, BitmapOperationTool tool)
         {
         {
-            if (Manager.ActiveDocument != null && tool != null/* && tool.ToolType != ToolType.None*/)
+            if (Manager.ActiveDocument != null && tool != null)
             {
             {
                 if (Manager.ActiveDocument.Layers.Count == 0 || mouseMove.Count == 0)
                 if (Manager.ActiveDocument.Layers.Count == 0 || mouseMove.Count == 0)
                 {
                 {

+ 16 - 5
PixiEditor/Models/Tools/Tool.cs

@@ -9,14 +9,25 @@ namespace PixiEditor.Models.Tools
 {
 {
     public abstract class Tool : NotifyableObject
     public abstract class Tool : NotifyableObject
     {
     {
+        protected string name;
         private bool isActive;
         private bool isActive;
-        private string actionDisplay = string.Empty;
+        private string actionDisplay = string.Empty;
+        
 
 
-        public string Name => GetType().Name.Replace("Tool", string.Empty);
+        public string ToolName
+        {
+            get
+            {
+                if (string.IsNullOrWhiteSpace(name))
+                {
+                    return GetType().Name.Replace("Tool", string.Empty);
+                }
 
 
-        public Type Type => GetType();
+                return name;
+            }
+        }
 
 
-        public string ImagePath => $"/Images/{Name}Image.png";
+        public string ImagePath => $"/Images/{ToolName}Image.png";
 
 
         public bool HideHighlight { get; set; } = false;
         public bool HideHighlight { get; set; } = false;
 
 
@@ -46,7 +57,7 @@ namespace PixiEditor.Models.Tools
 
 
         public Toolbar Toolbar { get; set; } = new EmptyToolbar();
         public Toolbar Toolbar { get; set; } = new EmptyToolbar();
 
 
-        public bool CanStartOutsideCanvas { get; set; } = false;
+        public bool CanStartOutsideCanvas { get; set; } = false;
 
 
         public virtual void OnMouseDown(MouseEventArgs e)
         public virtual void OnMouseDown(MouseEventArgs e)
         {
         {

+ 16 - 9
PixiEditor/ViewModels/SubViewModels/Main/ToolsViewModel.cs

@@ -45,15 +45,10 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             SetActiveTool(typeof(MoveTool));
             SetActiveTool(typeof(MoveTool));
         }
         }
 
 
-        public void SetActiveTool(Type toolType)
+        public void SetActiveTool<T>()
+            where T : Tool
         {
         {
-            if (toolType == null)
-            {
-                return;
-            }
-
-            Tool foundTool = ToolSet.First(x => x.GetType() == toolType);
-            SetActiveTool(foundTool);
+            SetActiveTool(typeof(T));
         }
         }
 
 
         public void SetActiveTool(Tool tool)
         public void SetActiveTool(Tool tool)
@@ -72,7 +67,8 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
 
 
         public void SetTool(object parameter)
         public void SetTool(object parameter)
         {
         {
-            SetActiveTool((Type)parameter);
+            Tool tool = (Tool)parameter;
+            SetActiveTool(tool.GetType());
         }
         }
 
 
         private void ChangeToolSize(object parameter)
         private void ChangeToolSize(object parameter)
@@ -85,6 +81,17 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             }
             }
         }
         }
 
 
+        private void SetActiveTool(Type toolType)
+        {
+            if (toolType == null)
+            {
+                return;
+            }
+
+            Tool foundTool = ToolSet.First(x => x.GetType() == toolType);
+            SetActiveTool(foundTool);
+        }
+
         private void SetToolCursor(Type tool)
         private void SetToolCursor(Type tool)
         {
         {
             if (tool != null)
             if (tool != null)

+ 1 - 1
PixiEditor/Views/MainWindow.xaml

@@ -208,7 +208,7 @@
                                 Style="{StaticResource ToolButtonStyle}"
                                 Style="{StaticResource ToolButtonStyle}"
                                 Command="{Binding Path=DataContext.ToolsSubViewModel.SelectToolCommand,
                                 Command="{Binding Path=DataContext.ToolsSubViewModel.SelectToolCommand,
                             RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
                             RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
-                                CommandParameter="{Binding Type}" ToolTip="{Binding Tooltip}">
+                                CommandParameter="{Binding}" ToolTip="{Binding Tooltip}">
                             <Button.Background>
                             <Button.Background>
                                 <ImageBrush ImageSource="{Binding ImagePath}" Stretch="Uniform" />
                                 <ImageBrush ImageSource="{Binding ImagePath}" Stretch="Uniform" />
                             </Button.Background>
                             </Button.Background>