From 5116b507055435f28ed5a1f2812b5dc11eedd9e7 Mon Sep 17 00:00:00 2001
From: Basile Burg <basile.b@gmx.com>
Date: Sun, 5 Apr 2020 14:13:04 +0200
Subject: [PATCH] fix #15 - Add a way to kill a custom tool

---
 CHANGELOG.md                 |  2 ++
 docs/widgets_custom_tools.md |  4 +++-
 src/u_toolseditor.lfm        | 10 ++++++++++
 src/u_toolseditor.pas        | 16 +++++++++++++++-
 4 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7a2ff334..938979df 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
 
 ## Enhancements
 
+- Custom tools: A new property allows to set the background color of the item. (#16)
+- Custom tools: A new Toolbar button has for effect to terminate the process associated to a tool. (#15)
 - Messages, added an option, enabled by default, allowing to highlight the blocks enclosed by backticks. This works for the "find all" action, the compiler output, the custom tools output, etc. (#13)
 
 ## Bugs fixed
diff --git a/docs/widgets_custom_tools.md b/docs/widgets_custom_tools.md
index 4a7d4ee3..e94ced49 100644
--- a/docs/widgets_custom_tools.md
+++ b/docs/widgets_custom_tools.md
@@ -23,8 +23,10 @@ Toolbar:
 - ![](icons/window/application_add.png): Adds a new tool.
 - ![](icons/window/application_delete.png): Removes selected tool.
 - ![](icons/arrow/arrow_up.png) **/** ![](icons/arrow/arrow_down.png): Changes the position of the selected tool.
-- ![](icons/window/application_flash.png): Executes the tool that's selected, according to the options it's associated to. This also works by double-clicking the tool aliases.
 - ![](icons/window/application_double.png): Clones the tool that's selected.
+- ![](icons/window/application_flash.png): Executes the tool that's selected, according to the options it's associated to. This also works by double-clicking the tool aliases.
+- ![](icons/other/cancel.png): Terminates the process create for the tool.
+
 
 A tool can be selected from the left side of the widget. If selected, a property inspector displays the options that can be edited:
 
diff --git a/src/u_toolseditor.lfm b/src/u_toolseditor.lfm
index 5885058e..e526ad0e 100644
--- a/src/u_toolseditor.lfm
+++ b/src/u_toolseditor.lfm
@@ -150,6 +150,16 @@ inherited ToolsEditorWidget: TToolsEditorWidget
         resourceName = 'APPLICATION_EDIT'
         scaledSeparator = False
       end
+      object btnKill: TDexedToolButton[8]
+        Left = 202
+        Hint = 'if running, kills the process matching to the selected tool'
+        Top = 0
+        AutoSize = True
+        Caption = 'btnKill'
+        OnClick = btnKillClick
+        resourceName = 'CANCEL'
+        scaledSeparator = False
+      end
     end
   end
   inherited contextMenu: TPopupMenu
diff --git a/src/u_toolseditor.pas b/src/u_toolseditor.pas
index 12fd35d0..c9563299 100644
--- a/src/u_toolseditor.pas
+++ b/src/u_toolseditor.pas
@@ -7,7 +7,7 @@ interface
 uses
   Classes, SysUtils, FileUtil, RTTIGrids, Forms, Controls, Graphics, Dialogs,
   ExtCtrls, Menus, Buttons, StdCtrls, Types, LCLType,
-  u_widget, u_tools, u_sharedres, u_dsgncontrols;
+  u_widget, u_tools, u_sharedres, u_dsgncontrols, u_common, u_processes;
 
 type
 
@@ -16,6 +16,7 @@ type
     btnAddTool: TDexedToolButton;
     btnClone: TDexedToolButton;
     btnEdit: TDexedToolButton;
+    btnKill: TDexedToolButton;
     btnMoveDown: TDexedToolButton;
     btnMoveUp: TDexedToolButton;
     btnRemTool: TDexedToolButton;
@@ -27,6 +28,7 @@ type
     procedure BtnAddToolClick(Sender: TObject);
     procedure btnCloneClick(Sender: TObject);
     procedure btnEditClick(Sender: TObject);
+    procedure btnKillClick(Sender: TObject);
     procedure btnRemToolClick(Sender: TObject);
     procedure btnMoveUpClick(Sender: TObject);
     procedure btnMoveDownClick(Sender: TObject);
@@ -153,6 +155,18 @@ begin
   setReadOnly(not CustomTools.readOnly);
 end;
 
+procedure TToolsEditorWidget.btnKillClick(Sender: TObject);
+var
+  p: TDexedProcess;
+begin
+  if lstTools.ItemIndex = -1 then
+    exit;
+
+  p := CustomTools.tool[lstTools.ItemIndex].process;
+  if p.isNotNil and p.Running then
+    p.Terminate(1);
+end;
+
 procedure TToolsEditorWidget.btnRemToolClick(Sender: TObject);
 begin
   if lstTools.ItemIndex = -1 then