View Issue Details

IDProjectCategoryView StatusLast Update
0038879LazarusIDEpublic2021-05-13 09:21
ReporterDomingo Galmés Assigned To 
PrioritynormalSeverityfeatureReproducibilityalways
Status newResolutionopen 
Summary0038879: [patch] Add a drop-down list with all macros to the "Macros..." toolbar button.
DescriptionThis patch improves the "Macros..." toolbar button by showing a drop-down list with all active macros, allowing them to be executed when clicking with the mouse.

I think it is more convenient to use this button to run macros than not having to open and keep active the "editor macros.." window.
Additional Informationlink to screenshoot image showing this button.

https://postimg.cc/HVd1zBCd
TagsNo tags attached.
Fixed in Revision
LazTarget
Widgetset
Attached Files

Activities

Domingo Galmés

2021-05-12 19:47

reporter  

AddDropDownListToMacrosToolbarButton.patch (3,427 bytes)   
From 8cb8cc8cf50b0154e27f45272febebc0d41e7122 Mon Sep 17 00:00:00 2001
From: DomingoGP <dgalmesp@gmail.com>
Date: Wed, 12 May 2021 21:22:51 +0200
Subject: [PATCH] add drop-down list to macros toolbar button.

---
 ide/editormacrolistviewer.pas | 66 ++++++++++++++++++++++++++++++++++-
 ide/main.pp                   |  2 +-
 2 files changed, 66 insertions(+), 2 deletions(-)

diff --git a/ide/editormacrolistviewer.pas b/ide/editormacrolistviewer.pas
index a13aa16a04..1b440756ab 100644
--- a/ide/editormacrolistviewer.pas
+++ b/ide/editormacrolistviewer.pas
@@ -18,7 +18,7 @@ uses
   LazIDEIntf, IDEDialogs,
   // IDE
   LazarusIDEStrConsts, ProjectDefs, LazConf, Project, KeyMapping,
-  KeyMapShortCutDlg, MainIntf;
+  KeyMapShortCutDlg, MainIntf, ToolBarIntf;
 
 type
   TSynEditorMacro = class(TSynMacroRecorder)
@@ -245,6 +245,15 @@ type
     procedure UpdateDisplay;
   end;
 
+  TMacrosToolButton = class(TIDEToolButton)
+  private
+    procedure RefreshMenu(Sender: TObject);
+    procedure mnuPlayMacro(Sender: TObject);
+  public
+    procedure DoOnAdded; override;
+  end;
+
+
 function MacroListViewer: TMacroListView;
 procedure ShowMacroListViewer;
 procedure UpdateMacroListViewer;
@@ -1642,6 +1651,61 @@ end;
 
 // itmMacroListView.enabled
 
+{ TMacrosToolButton }
+
+procedure TMacrosToolButton.DoOnAdded;
+begin
+  inherited DoOnAdded;
+  DropdownMenu := TPopupMenu.Create(Self);
+  DropdownMenu.OnPopup := @RefreshMenu;
+  Style := tbsDropDown;
+end;
+
+procedure TMacrosToolButton.mnuPlayMacro(Sender: TObject);
+var
+  M: TEditorMacro;
+  se: TSourceEditorInterface;
+begin
+  se := SourceEditorManagerIntf.ActiveEditor;
+  if se = nil then
+    Exit;
+  M := TEditorMacro(TMenuItem(Sender).Tag);
+  M.PlaybackMacro(TCustomSynEdit(se.EditorControl));
+end;
+
+procedure TMacrosToolButton.RefreshMenu(Sender: TObject);
+
+  procedure AddMenuItem(AMacro: TEditorMacro);
+  var
+    MenuItem: TMenuItem;
+  begin
+    MenuItem := TMenuItem.Create(DropdownMenu);
+    DropdownMenu.Items.Add(MenuItem);
+    MenuItem.OnClick := @mnuPlayMacro;
+    MenuItem.Caption := AMacro.MacroName+'  '+AMacro.KeyBinding.ShortCutAsText;
+    MenuItem.Tag := PtrInt(AMacro);
+  end;
+
+  procedure AddList(AList: TEditorMacroList);
+  var
+    Index: integer;
+  begin
+    if AList.Count = 0 then
+      Exit;
+    if DropdownMenu.Items.Count > 0 then
+      DropdownMenu.Items.AddSeparator;
+    for Index := 0 to Pred(AList.Count) do
+      AddMenuItem(AList.Macros[Index]);
+  end;
+
+begin
+  DropdownMenu.Items.Clear;
+  AddList(EditorMacroListGlob);
+  AddList(EditorMacroListProj);
+  AddList(EditorMacroListRec);
+end;
+
+
 {$R *.lfm}
 
 initialization
diff --git a/ide/main.pp b/ide/main.pp
index 31019cebb8..98c4e07198 100644
--- a/ide/main.pp
+++ b/ide/main.pp
@@ -2977,7 +2977,7 @@ begin
     itmViewCodeBrowser.Command:=GetIdeCmdRegToolBtn(ecToggleCodeBrowser);
     itmViewRestrictionBrowser.Command:=GetIdeCmdRegToolBtn(ecToggleRestrictionBrowser);
     itmViewComponents.Command:=GetIdeCmdRegToolBtn(ecViewComponents);
-    itmMacroListView.Command:=GetIdeCmdRegToolBtn(ecViewMacroList);
+    itmMacroListView.Command:=GetCommand(ecViewMacroList,nil,TMacrosToolButton);
     itmJumpHistory.Command:=GetIdeCmdRegToolBtn(ecViewJumpHistory);
     itmViewMessage.Command:=GetIdeCmdRegToolBtn(ecToggleMessages);
     itmViewSearchResults.Command:=GetIdeCmdRegToolBtn(ecToggleSearchResults);
-- 
2.31.1.windows.1

Sven Barth

2021-05-13 09:21

manager   ~0130848

(attached screenshot mentioned in the issue directly so that it won't get lost)
Macros-Screen-Shoot2.png (496,353 bytes)

Issue History

Date Modified Username Field Change
2021-05-12 19:47 Domingo Galmés New Issue
2021-05-12 19:47 Domingo Galmés File Added: AddDropDownListToMacrosToolbarButton.patch
2021-05-13 09:21 Sven Barth Note Added: 0130848
2021-05-13 09:21 Sven Barth File Added: Macros-Screen-Shoot2.png