|
|
@@ -26,6 +26,7 @@ using PixiEditor.Helpers;
|
|
|
using PixiEditor.Helpers.UI;
|
|
|
using PixiEditor.Models.BrushEngine;
|
|
|
using PixiEditor.Models.Commands;
|
|
|
+using PixiEditor.Models.DocumentModels.Public;
|
|
|
using PixiEditor.Models.Handlers.Toolbars;
|
|
|
using PixiEditor.Models.Handlers.Tools;
|
|
|
using PixiEditor.Models.Input;
|
|
|
@@ -382,11 +383,13 @@ internal class ToolsViewModel : SubViewModel<ViewModelMain>, IToolsHandler
|
|
|
LastActionTool = ActiveTool;
|
|
|
ActiveTool = tool;
|
|
|
|
|
|
- ActiveTool.Toolbar.SettingChanged += ToolbarSettingChanged;
|
|
|
-
|
|
|
- if (shareToolbar)
|
|
|
+ if (ActiveTool != null)
|
|
|
{
|
|
|
- ActiveTool.Toolbar.LoadSharedSettings();
|
|
|
+ ActiveTool.Toolbar.SettingChanged += ToolbarSettingChanged;
|
|
|
+ if (shareToolbar)
|
|
|
+ {
|
|
|
+ ActiveTool.Toolbar.LoadSharedSettings();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (LastActionTool != ActiveTool)
|
|
|
@@ -394,15 +397,19 @@ internal class ToolsViewModel : SubViewModel<ViewModelMain>, IToolsHandler
|
|
|
SelectedToolChanged?.Invoke(this, new SelectedToolEventArgs(LastActionTool, ActiveTool));
|
|
|
}
|
|
|
|
|
|
- //update old tool
|
|
|
+
|
|
|
LastActionTool?.KeyChanged(false, false, false, Key.None);
|
|
|
- //update new tool
|
|
|
- ActiveTool.KeyChanged(ctrlIsDown, shiftIsDown, altIsDown, lastKey);
|
|
|
- ActiveTool.OnToolSelected(wasTransient);
|
|
|
|
|
|
- tool.IsActive = true;
|
|
|
- ActiveTool.IsTransient = transient;
|
|
|
- SetToolCursor(tool.GetType());
|
|
|
+ ActiveTool?.KeyChanged(ctrlIsDown, shiftIsDown, altIsDown, lastKey);
|
|
|
+ ActiveTool?.OnToolSelected(wasTransient);
|
|
|
+
|
|
|
+ if (ActiveTool != null)
|
|
|
+ {
|
|
|
+ tool.IsActive = true;
|
|
|
+ ActiveTool.IsTransient = transient;
|
|
|
+ SetToolCursor(tool.GetType());
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
if (Owner.StylusSubViewModel != null)
|
|
|
{
|
|
|
@@ -448,6 +455,41 @@ internal class ToolsViewModel : SubViewModel<ViewModelMain>, IToolsHandler
|
|
|
toolbar.ToolSize = newSize;
|
|
|
}
|
|
|
|
|
|
+ public bool CreateLayerIfNeeded()
|
|
|
+ {
|
|
|
+ bool created = false;
|
|
|
+ if (NeedsNewLayerForActiveTool())
|
|
|
+ {
|
|
|
+ using var changeBlock = Owner.DocumentManagerSubViewModel.ActiveDocument.Operations.StartChangeBlock();
|
|
|
+ Guid? createdLayer = Owner.LayersSubViewModel.NewLayer(
|
|
|
+ ActiveTool.LayerTypeToCreateOnEmptyUse,
|
|
|
+ ActionSource.Automated,
|
|
|
+ ActiveTool.DefaultNewLayerName);
|
|
|
+ if (createdLayer is not null)
|
|
|
+ {
|
|
|
+ Owner.DocumentManagerSubViewModel.ActiveDocument.Operations.SetSelectedMember(createdLayer.Value);
|
|
|
+ }
|
|
|
+
|
|
|
+ changeBlock.ExecuteQueuedActions();
|
|
|
+ created = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return created;
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool NeedsNewLayerForActiveTool()
|
|
|
+ {
|
|
|
+ return ActiveTool is not { CanBeUsedOnActiveLayer: true } && ActiveTool?.LayerTypeToCreateOnEmptyUse != null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void DeselectActiveTool()
|
|
|
+ {
|
|
|
+ if (ActiveTool != null)
|
|
|
+ {
|
|
|
+ SetActiveTool((IToolHandler)null, false, null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
[Evaluator.CanExecute("PixiEditor.Tools.CanChangeToolSize",
|
|
|
nameof(ActiveTool))]
|
|
|
public bool CanChangeToolSize() => Owner.ToolsSubViewModel.ActiveTool?.Toolbar is IToolSizeToolbar
|
|
|
@@ -574,31 +616,15 @@ internal class ToolsViewModel : SubViewModel<ViewModelMain>, IToolsHandler
|
|
|
|
|
|
public void UseToolEventInlet(VecD canvasPos, MouseButton button)
|
|
|
{
|
|
|
+ if (ActiveTool is null)
|
|
|
+ return;
|
|
|
+
|
|
|
ActiveTool.UsedWith = button;
|
|
|
if (ActiveTool.StopsLinkedToolOnUse)
|
|
|
{
|
|
|
ViewModelMain.Current.DocumentManagerSubViewModel.ActiveDocument?.Operations.TryStopToolLinkedExecutor();
|
|
|
}
|
|
|
|
|
|
- bool waitForChange = false;
|
|
|
-
|
|
|
- if (ActiveTool is not { CanBeUsedOnActiveLayer: true })
|
|
|
- {
|
|
|
- if (ActiveTool.LayerTypeToCreateOnEmptyUse == null) return;
|
|
|
-
|
|
|
- using var changeBlock = Owner.DocumentManagerSubViewModel.ActiveDocument.Operations.StartChangeBlock();
|
|
|
- Guid? createdLayer = Owner.LayersSubViewModel.NewLayer(
|
|
|
- ActiveTool.LayerTypeToCreateOnEmptyUse,
|
|
|
- ActionSource.Automated,
|
|
|
- ActiveTool.DefaultNewLayerName);
|
|
|
- if (createdLayer is not null)
|
|
|
- {
|
|
|
- Owner.DocumentManagerSubViewModel.ActiveDocument.Operations.SetSelectedMember(createdLayer.Value);
|
|
|
- }
|
|
|
-
|
|
|
- changeBlock.ExecuteQueuedActions();
|
|
|
- }
|
|
|
-
|
|
|
ActiveTool.UseTool(canvasPos);
|
|
|
}
|
|
|
|
|
|
@@ -727,7 +753,8 @@ internal class ToolsViewModel : SubViewModel<ViewModelMain>, IToolsHandler
|
|
|
{
|
|
|
var brush = new Brush(uri, "TOOL_CONFIG");
|
|
|
KeyCombination? shortcut = TryParseShortcut(toolFromToolset.DefaultShortcut);
|
|
|
- return new BrushBasedToolViewModel(new BrushViewModel(brush), toolFromToolset.ToolTip, toolFromToolset.ToolName,
|
|
|
+ return new BrushBasedToolViewModel(new BrushViewModel(brush), toolFromToolset.ToolTip,
|
|
|
+ toolFromToolset.ToolName,
|
|
|
shortcut, toolFromToolset.ActionDisplays, toolFromToolset.SupportsSecondaryActionOnRightClick);
|
|
|
}
|
|
|
}
|