|
@@ -1,6 +1,7 @@
|
|
|
using PixiEditor.Helpers;
|
|
|
using PixiEditor.Models.Controllers;
|
|
|
using PixiEditor.Models.Controllers.Shortcuts;
|
|
|
+using PixiEditor.Models.Tools;
|
|
|
using PixiEditor.Models.Tools.Tools;
|
|
|
using System;
|
|
|
using System.Windows.Input;
|
|
@@ -55,8 +56,23 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
|
|
|
Owner.BitmapManager.InputTarget.OnKeyDown(key);
|
|
|
}
|
|
|
|
|
|
- if (args.Key == ShortcutController.MoveViewportToolTransientChangeKey)
|
|
|
- ChangeMoveViewportToolState(true);
|
|
|
+ HandleTransientKey(args, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void HandleTransientKey(KeyEventArgs args, bool state)
|
|
|
+ {
|
|
|
+ var controller = Owner.ShortcutController;
|
|
|
+
|
|
|
+ Key finalKey = args.Key;
|
|
|
+ if (finalKey == Key.System)
|
|
|
+ {
|
|
|
+ finalKey = args.SystemKey;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (controller.TransientShortcuts.ContainsKey(finalKey))
|
|
|
+ {
|
|
|
+ ChangeToolState(controller.TransientShortcuts[finalKey].GetType(), state);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void ProcessShortcutDown(bool isRepeat, Key key)
|
|
@@ -83,10 +99,7 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
|
|
|
if (Owner.BitmapManager.ActiveDocument != null)
|
|
|
Owner.BitmapManager.InputTarget.OnKeyUp(key);
|
|
|
|
|
|
- if (args.Key == ShortcutController.MoveViewportToolTransientChangeKey)
|
|
|
- {
|
|
|
- ChangeMoveViewportToolState(false);
|
|
|
- }
|
|
|
+ HandleTransientKey(args, false);
|
|
|
}
|
|
|
|
|
|
private void ProcessShortcutUp(Key key)
|
|
@@ -115,21 +128,27 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
|
|
|
|
|
|
private void OnPreviewMiddleMouseButton(object sender)
|
|
|
{
|
|
|
- ChangeMoveViewportToolState(true);
|
|
|
+ ChangeToolState<MoveViewportTool>(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ChangeToolState<T>(bool setOn)
|
|
|
+ where T : Tool
|
|
|
+ {
|
|
|
+ ChangeToolState(typeof(T), setOn);
|
|
|
}
|
|
|
|
|
|
- void ChangeMoveViewportToolState(bool setOn)
|
|
|
+ private void ChangeToolState(Type type, bool setOn)
|
|
|
{
|
|
|
if (setOn)
|
|
|
{
|
|
|
- var moveViewportToolIsActive = Owner.ToolsSubViewModel.ActiveTool is MoveViewportTool;
|
|
|
- if (!moveViewportToolIsActive)
|
|
|
+ var transientToolIsActive = Owner.ToolsSubViewModel.ActiveTool.GetType() == type;
|
|
|
+ if (!transientToolIsActive)
|
|
|
{
|
|
|
- Owner.ToolsSubViewModel.SetActiveTool<MoveViewportTool>();
|
|
|
- Owner.ToolsSubViewModel.MoveToolIsTransient = true;
|
|
|
+ Owner.ToolsSubViewModel.SetActiveTool(type);
|
|
|
+ Owner.ToolsSubViewModel.ActiveToolIsTransient = true;
|
|
|
}
|
|
|
}
|
|
|
- else if (Owner.ToolsSubViewModel.LastActionTool != null && Owner.ToolsSubViewModel.MoveToolIsTransient)
|
|
|
+ else if (Owner.ToolsSubViewModel.LastActionTool != null && Owner.ToolsSubViewModel.ActiveToolIsTransient)
|
|
|
{
|
|
|
Owner.ToolsSubViewModel.SetActiveTool(Owner.ToolsSubViewModel.LastActionTool);
|
|
|
restoreToolOnKeyUp = false;
|
|
@@ -155,7 +174,7 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
|
|
|
}
|
|
|
else if (button == MouseButton.Middle)
|
|
|
{
|
|
|
- ChangeMoveViewportToolState(false);
|
|
|
+ ChangeToolState<MoveViewportTool>(false);
|
|
|
}
|
|
|
}
|
|
|
}
|