Forráskód Böngészése

finish action before undo

circular17 6 éve
szülő
commit
e3a0e351dc

+ 2 - 2
lazpaint/image/uimageaction.pas

@@ -274,8 +274,8 @@ end;
 procedure TImageActions.Undo;
 begin
   try
-    if CurrentTool in[ptTextureMapping,ptLayerMapping,ptMoveSelection,ptRotateSelection] then
-      ChooseTool(ptHand);
+    if CurrentTool in[ptMoveSelection,ptRotateSelection] then ChooseTool(ptHand);
+    if ToolManager.ToolProvideCommand(tcFinish) then ToolManager.ToolCommand(tcFinish);
     if image.CanUndo then
     begin
       ToolManager.ToolCloseDontReopen;

+ 1 - 1
lazpaint/lazpaintmainform.pas

@@ -1698,7 +1698,7 @@ end;
 
 procedure TFMain.EditUndoUpdate(Sender: TObject);
 begin
-  EditUndo.Enabled := image.CanUndo;
+  EditUndo.Enabled := image.CanUndo or ToolManager.ToolProvideCommand(tcFinish);
 end;
 
 procedure TFMain.EmbeddedCancelExecute(Sender: TObject);

+ 5 - 2
lazpaint/tools/utool.pas

@@ -44,7 +44,7 @@ type
   TBitmapToVirtualScreenFunction = function(PtF: TPointF): TPointF of object;
 
   TEraserMode = (emEraseAlpha, emSoften);
-  TToolCommand = (tcCut, tcCopy, tcPaste, tcDelete, tcMoveUp, tcMoveDown, tcMoveToFront, tcMoveToBack,
+  TToolCommand = (tcCut, tcCopy, tcPaste, tcDelete, tcFinish, tcMoveUp, tcMoveDown, tcMoveToFront, tcMoveToBack,
     tcAlignLeft, tcCenterHorizontally, tcAlignRight, tcAlignTop, tcCenterVertically, tcAlignBottom,
     tcShapeToSpline);
 
@@ -1732,7 +1732,10 @@ end;
 function TToolManager.ToolCommand(ACommand: TToolCommand): boolean;
 begin
   if Assigned(FCurrentTool) then
-    result := FCurrentTool.ToolCommand(ACommand)
+  begin
+    result := FCurrentTool.ToolCommand(ACommand);
+    CheckExitTool;
+  end
   else
     result := false;
 end;

+ 52 - 5
lazpaint/tools/utooldeformationgrid.pas

@@ -36,7 +36,9 @@ type
     function GetContextualToolbars: TContextualToolbars; override;
     function Render(VirtualScreen: TBGRABitmap; {%H-}VirtualScreenWidth, {%H-}VirtualScreenHeight: integer; BitmapToVirtualScreen: TBitmapToVirtualScreenFunction): TRect; override;
     procedure BeforeGridSizeChange; override;
-    procedure AfterGridSizeChange(NewNbX,NewNbY: Integer); override;
+    procedure AfterGridSizeChange({%H-}NewNbX,{%H-}NewNbY: Integer); override;
+    function ToolCommand(ACommand: TToolCommand): boolean; override;
+    function ToolProvideCommand(ACommand: TToolCommand): boolean; override;
     destructor Destroy; override;
   end;
 
@@ -84,6 +86,8 @@ type
     function ToolUp: TRect; override;
     function GetContextualToolbars: TContextualToolbars; override;
     function Render(VirtualScreen: TBGRABitmap; {%H-}VirtualScreenWidth, {%H-}VirtualScreenHeight: integer; BitmapToVirtualScreen: TBitmapToVirtualScreenFunction):TRect; override;
+    function ToolProvideCommand(ACommand: TToolCommand): boolean; override;
+    function ToolCommand(ACommand: TToolCommand): boolean; override;
     destructor Destroy; override;
   end;
 
@@ -717,6 +721,29 @@ begin
     DrawPoints(quad,192);
 end;
 
+function TToolTextureMapping.ToolProvideCommand(ACommand: TToolCommand
+  ): boolean;
+begin
+  case ACommand of
+    tcFinish: result := quadDefined;
+  else result := false;
+  end;
+end;
+
+function TToolTextureMapping.ToolCommand(ACommand: TToolCommand): boolean;
+begin
+  case ACommand of
+    tcFinish: if quadDefined then
+      begin
+        ValidateQuad;
+        Manager.QueryExitTool;
+        result := true;
+      end  else
+        result := false;
+  else result := false;
+  end;
+end;
+
 destructor TToolTextureMapping.Destroy;
 begin
   ValidateAction;
@@ -758,12 +785,32 @@ begin
   DeformationGridTexCoord := nil;
 end;
 
-{$hints off}
 procedure TToolDeformationGrid.AfterGridSizeChange(NewNbX,NewNbY: Integer);
 begin
   //grid will be created when needed
 end;
-{$hints on}
+
+function TToolDeformationGrid.ToolCommand(ACommand: TToolCommand): boolean;
+begin
+  case ACommand of
+    tcFinish: if DoingDeformation then
+      begin
+        ValidateDeformationGrid;
+        result := true;
+      end
+      else result := false;
+  else result := false;
+  end;
+end;
+
+function TToolDeformationGrid.ToolProvideCommand(ACommand: TToolCommand
+  ): boolean;
+begin
+  case ACommand of
+    tcFinish: result := DoingDeformation;
+  else result := false;
+  end;
+end;
 
 destructor TToolDeformationGrid.Destroy;
 begin
@@ -1012,7 +1059,7 @@ begin
   result := EmptyRect;
   if Key = VK_RETURN then
   begin
-    if Action <> nil then
+    if DoingDeformation then
     begin
       ValidateDeformationGrid;
       result := EmptyRect;
@@ -1022,7 +1069,7 @@ begin
   end else
   if Key = VK_ESCAPE then
   begin
-    if Action <> nil then
+    if DoingDeformation then
     begin
       CancelActionPartially;
       result := OnlyRenderChange;

+ 6 - 0
lazpaint/tools/utoolvectorial.pas

@@ -1884,6 +1884,11 @@ begin
       end else
         result := false;
     end;
+  tcFinish: begin
+            r := ValidateShape;
+            Action.NotifyChange(toolDest, r);
+            result := true;
+          end;
   tcAlignLeft..tcAlignBottom:
       if ToolProvideCommand(ACommand) then
         AlignShape(FShape, ACommand,
@@ -1898,6 +1903,7 @@ function TVectorialTool.ToolProvideCommand(ACommand: TToolCommand): boolean;
 begin
   case ACommand of
   tcCopy,tcCut: Result:= not IsSelectingTool and not FQuickDefine and Assigned(FShape);
+  tcFinish: result := not IsIdle;
   tcShapeToSpline: result:= not IsSelectingTool and not FQuickDefine and Assigned(FShape)
                             and TCurveShape.CanCreateFrom(FShape);
   tcAlignLeft..tcAlignBottom: Result:= not FQuickDefine and Assigned(FShape);