From 1b2c221be7d9e48b4cbf7ac560455f14018f86ed Mon Sep 17 00:00:00 2001 From: Olly Date: Sat, 25 Nov 2023 22:10:26 +0000 Subject: [PATCH] SimbaIDEEvents refactor --- .../codetools/simba.ide_codetools_setup.pas | 2 +- Source/editor/simba.editor.pas | 2 +- Source/editor/simba.editor_findreplace.pas | 2 +- Source/editor/simba.editor_popupmenu.pas | 37 +-- Source/forms/simba.functionlistform.pas | 12 +- Source/forms/simba.main.pas | 15 +- Source/forms/simba.outputform.pas | 9 +- Source/forms/simba.scripttabsform.pas | 4 +- Source/simba.ide_events.pas | 281 +++++------------- Source/simba.ide_mainstatusbar.pas | 48 ++- Source/simba.mouselogger.pas | 2 +- Source/simba.scripttab.pas | 31 +- 12 files changed, 155 insertions(+), 290 deletions(-) diff --git a/Source/codetools/simba.ide_codetools_setup.pas b/Source/codetools/simba.ide_codetools_setup.pas index f02431124..8821132b4 100644 --- a/Source/codetools/simba.ide_codetools_setup.pas +++ b/Source/codetools/simba.ide_codetools_setup.pas @@ -48,7 +48,7 @@ procedure SetupCodeTools; CodetoolsSetup := True; - SimbaIDEEvents.CallOnCodetoolsSetup(nil); + SimbaIDEEvents.Notify(SimbaIDEEvent.CODETOOLS_SETUP, nil); end; initialization diff --git a/Source/editor/simba.editor.pas b/Source/editor/simba.editor.pas index c00267447..fb3b9c483 100644 --- a/Source/editor/simba.editor.pas +++ b/Source/editor/simba.editor.pas @@ -422,7 +422,7 @@ constructor TSimbaEditor.Create(AOwner: TComponent); OnDragDrop := @DoDragDrop; OnDragOver := @DoDragOver; - PopupMenu := GetSimbaEditorPopupMenu(); + PopupMenu := TSimbaEditorPopupMenu.Create(Self); Options := Options + [eoTabIndent, eoKeepCaretX, eoDragDropEditing, eoScrollPastEof] - [eoSmartTabs]; Options2 := Options2 + [eoCaretSkipsSelection]; diff --git a/Source/editor/simba.editor_findreplace.pas b/Source/editor/simba.editor_findreplace.pas index 930df2d66..192836a66 100644 --- a/Source/editor/simba.editor_findreplace.pas +++ b/Source/editor/simba.editor_findreplace.pas @@ -321,7 +321,7 @@ procedure TSimbaEditorFind.ExecuteNoDialog(Editor: TSynEdit; FindText: String; C SearchReplaceEx(FDialog.FindText, '', SearchOptions, Point(1, 1)); end; - SimbaIDEEvents.CallOnEditorSearchMethods(Self); + SimbaIDEEvents.Notify(SimbaIDEEvent.TAB_SEARCH, Self); end; procedure TSimbaEditorFind.FindPrev(Editor: TSynEdit); diff --git a/Source/editor/simba.editor_popupmenu.pas b/Source/editor/simba.editor_popupmenu.pas index dc12748ca..e5ce792f7 100644 --- a/Source/editor/simba.editor_popupmenu.pas +++ b/Source/editor/simba.editor_popupmenu.pas @@ -1,3 +1,8 @@ +{ + Author: Raymond van Venetiƫ and Merlijn Wajer + Project: Simba (https://github.com/MerlijnWajer/Simba) + License: GNU General Public License (https://www.gnu.org/licenses/gpl-3.0) +} unit simba.editor_popupmenu; {$i simba.inc} @@ -10,9 +15,8 @@ interface type TSimbaEditorPopupMenu = class(TPopupMenu) protected - procedure DoPopup(Sender: TObject); + procedure DoPopup(Sender: TObject); override; procedure DoClick(Sender: TObject); - procedure DoScriptTabChange(Sender: TObject); procedure DoMeasureItem(Sender: TObject; ACanvas: TCanvas; var AWidth, AHeight: Integer); public FindDeclaration: TMenuItem; @@ -32,28 +36,12 @@ TSimbaEditorPopupMenu = class(TPopupMenu) constructor Create(AOwner: TComponent); override; end; -function GetSimbaEditorPopupMenu: TPopupMenu; - implementation uses simba.main, simba.editor, simba.editor_docgenerator, simba.nativeinterface, simba.scripttab, simba.scripttabsform, - simba.ide_events, simba.ide_utils; - -var - SimbaEditorPopupMenu: TSimbaEditorPopupMenu; - -function GetSimbaEditorPopupMenu: TPopupMenu; -begin - if (SimbaEditorPopupMenu = nil) then - begin - SimbaEditorPopupMenu := TSimbaEditorPopupMenu.Create(Application.MainForm); - SimbaIDEEvents.RegisterMethodOnScriptTabChange(@SimbaEditorPopupMenu.DoScriptTabChange); - end; - - Result := SimbaEditorPopupMenu; -end; + simba.ide_utils; procedure TSimbaEditorPopupMenu.DoPopup(Sender: TObject); var @@ -107,12 +95,6 @@ procedure TSimbaEditorPopupMenu.DoClick(Sender: TObject); end; end; -procedure TSimbaEditorPopupMenu.DoScriptTabChange(Sender: TObject); -begin - if (Sender is TSimbaScriptTab) then - PopupComponent := TSimbaScriptTab(Sender).Editor; -end; - procedure TSimbaEditorPopupMenu.DoMeasureItem(Sender: TObject; ACanvas: TCanvas; var AWidth, AHeight: Integer); begin MenuItemHeight(Sender as TMenuItem, ACanvas, AHeight); @@ -137,14 +119,13 @@ constructor TSimbaEditorPopupMenu.Create(AOwner: TComponent); begin inherited Create(AOwner); - OnPopup := @DoPopup; OnMeasureItem := @DoMeasureItem; Images := SimbaForm.Images; FindDeclaration := Add('Find Declaration', IMG_NONE, ShortCut(VK_UNKNOWN, []), True ); - Undo := Add('Redo', IMG_UNDO, ShortCut(VK_Z, [ssCtrl]), False); - Redo := Add('Undo', IMG_REDO, ShortCut(VK_Z, [ssShift, ssCtrl]), True ); + Undo := Add('Undo', IMG_UNDO, ShortCut(VK_Z, [ssCtrl]), False); + Redo := Add('Redo', IMG_REDO, ShortCut(VK_Z, [ssShift, ssCtrl]), True ); Cut := Add('Cut', IMG_CUT, ShortCut(VK_X, [ssCtrl]), False); Copy := Add('Copy', IMG_COPY, ShortCut(VK_C, [ssCtrl]), False); Paste := Add('Paste', IMG_PASTE, ShortCut(VK_V, [ssCtrl]), False); diff --git a/Source/forms/simba.functionlistform.pas b/Source/forms/simba.functionlistform.pas index 9da81382c..b65286830 100644 --- a/Source/forms/simba.functionlistform.pas +++ b/Source/forms/simba.functionlistform.pas @@ -538,7 +538,7 @@ function TSimbaFunctionListForm.DoGetNodeHint(const Node: TTreeNode): String; procedure TSimbaFunctionListForm.DoSelectionChanged(Sender: TObject); begin - SimbaIDEEvents.CallOnFunctionListNodeSelection(FTreeView.Selected); + SimbaIDEEvents.Notify(SimbaIDEEvent.FUNCTIONLIST_SELECTION, FTreeView.Selected); end; function TSimbaFunctionListForm.AddDecl(ParentNode: TTreeNode; Decl: TDeclaration): TTreeNode; @@ -684,11 +684,11 @@ constructor TSimbaFunctionListForm.Create(TheOwner: TComponent); FSavedStates := TFunctionListStateDict.Create(@HashInt32); - SimbaIDEEvents.RegisterOnCodetoolsSetup(@DoCodetoolsSetup); - SimbaIDEEvents.RegisterMethodOnEditorModified(@DoEditorModified); - SimbaIDEEvents.RegisterMethodOnScriptTabChange(@DoTabChange); - SimbaIDEEvents.RegisterOnBeforeTabChange(@DoTabBeforeChange); - SimbaIDEEvents.RegisterOnTabClosed(@DoTabClosed); + SimbaIDEEvents.Register(Self, SimbaIDEEvent.CODETOOLS_SETUP, @DoCodetoolsSetup); + SimbaIDEEvents.Register(Self, SimbaIDEEvent.TAB_MODIFIED, @DoEditorModified); + SimbaIDEEvents.Register(Self, SimbaIDEEvent.TAB_CHANGE, @DoTabChange); + SimbaIDEEvents.Register(Self, SimbaIDEEvent.TAB_BEFORECHANGE, @DoTabBeforeChange); + SimbaIDEEvents.Register(Self, SimbaIDEEvent.TAB_CLOSED, @DoTabClosed); with TIdleTimer.Create(Self) do begin diff --git a/Source/forms/simba.main.pas b/Source/forms/simba.main.pas index d0eb1e168..18cd0dcff 100644 --- a/Source/forms/simba.main.pas +++ b/Source/forms/simba.main.pas @@ -606,11 +606,14 @@ procedure TSimbaForm.DoDefaultDocking; procedure TSimbaForm.Setup; begin - SimbaIDEEvents.RegisterMethodOnEditorLoaded(@DoTabLoaded); - SimbaIDEEvents.RegisterMethodOnEditorModified(@DoTabModified); - SimbaIDEEvents.RegisterMethodOnScriptTabChange(@DoTabModified); // Also do this - SimbaIDEEvents.RegisterMethodOnScriptTabChange(@DoScriptTabChange); - SimbaIDEEvents.RegisterActiveScriptStateChange(@DoScriptStateChange); + with SimbaIDEEvents do + begin + Register(Self, SimbaIDEEvent.TAB_LOADED, @DoTabLoaded); + Register(Self, SimbaIDEEvent.TAB_MODIFIED, @DoTabModified); + Register(Self, SimbaIDEEvent.TAB_CHANGE, @DoTabModified); // Also do this + Register(Self, SimbaIDEEvent.TAB_CHANGE, @DoScriptTabChange); + Register(Self, SimbaIDEEvent.TAB_SCRIPTSTATE_CHANGE, @DoScriptStateChange); + end; with SimbaSettings do begin @@ -1141,7 +1144,7 @@ procedure TSimbaForm.DoScriptTabChange(Sender: TObject); procedure TSimbaForm.DoScriptStateChange(Sender: TObject); begin - if (Sender is TSimbaScriptTab) then + if (Sender is TSimbaScriptTab) and TSimbaScriptTab(Sender).IsActiveTab() then SetButtonStates(TSimbaScriptTab(Sender)); end; diff --git a/Source/forms/simba.outputform.pas b/Source/forms/simba.outputform.pas index dda51379a..ee28059a5 100644 --- a/Source/forms/simba.outputform.pas +++ b/Source/forms/simba.outputform.pas @@ -125,14 +125,14 @@ TSimbaOutputTab = class(TSimbaTab) protected FOutputBox: TSimbaOutputBox; - procedure DoScriptStateChange(Sender: TObject); + procedure DoTabScriptStateChange(Sender: TObject); public constructor Create(AOwner: TComponent); override; property OutputBox: TSimbaOutputBox read FOutputBox; end; -procedure TSimbaOutputTab.DoScriptStateChange(Sender: TObject); +procedure TSimbaOutputTab.DoTabScriptStateChange(Sender: TObject); begin if (Sender is TSimbaScriptTab) and (TSimbaScriptTab(Sender).OutputBox = FOutputBox) then begin @@ -153,8 +153,7 @@ constructor TSimbaOutputTab.Create(AOwner: TComponent); FOutputBox.Parent := Self; FOutputBox.Align := alClient; - SimbaIDEEvents.RegisterMethodOnScriptStateChange(@DoScriptStateChange); - SimbaIDEEvents.RegisterActiveScriptStateChange(@DoScriptStateChange); + SimbaIDEEvents.Register(Self, SimbaIDEEvent.TAB_SCRIPTSTATE_CHANGE, @DoTabScriptStateChange); end; function TSimbaOutputBox.GetTabTitle: String; @@ -634,7 +633,7 @@ constructor TSimbaOutputForm.Create(AOwner: TComponent); DoSimbaDebugLn := @DebugLn; - SimbaIDEEvents.RegisterMethodOnScriptTabChange(@DoScriptTabChange); + SimbaIDEEvents.Register(Self, SimbaIDEEvent.TAB_CHANGE, @DoScriptTabChange); end; end. diff --git a/Source/forms/simba.scripttabsform.pas b/Source/forms/simba.scripttabsform.pas index 7e8a41cce..e642292eb 100644 --- a/Source/forms/simba.scripttabsform.pas +++ b/Source/forms/simba.scripttabsform.pas @@ -288,12 +288,12 @@ procedure TSimbaScriptTabsForm.DoFindPanelVisibleChanged(Sender: TObject); procedure TSimbaScriptTabsForm.DoTabCanChange(Sender: TSimbaTabControl; OldTab, NewTab: TSimbaTab; var AllowChange: Boolean); begin if Assigned(OldTab) then - SimbaIDEEvents.CallOnBeforeTabChange(OldTab); + SimbaIDEEvents.Notify(SimbaIDEEvent.TAB_BEFORECHANGE, OldTab); end; procedure TSimbaScriptTabsForm.DoTabChange(Sender: TSimbaTabControl; NewTab: TSimbaTab); begin - SimbaIDEEvents.CallOnScriptTabChange(NewTab); + SimbaIDEEvents.Notify(SimbaIDEEvent.TAB_CHANGE, NewTab); if (NewTab is TSimbaScriptTab) and TSimbaScriptTab(NewTab).Editor.CanSetFocus() then TSimbaScriptTab(NewTab).Editor.SetFocus(); diff --git a/Source/simba.ide_events.pas b/Source/simba.ide_events.pas index 3da55437e..a871a4d6e 100644 --- a/Source/simba.ide_events.pas +++ b/Source/simba.ide_events.pas @@ -1,3 +1,8 @@ +{ + Author: Raymond van Venetiƫ and Merlijn Wajer + Project: Simba (https://github.com/MerlijnWajer/Simba) + License: GNU General Public License (https://www.gnu.org/licenses/gpl-3.0) +} unit simba.ide_events; {$i simba.inc} @@ -9,244 +14,122 @@ interface simba.mufasatypes; type - SimbaIDEEvents = class + {$PUSH} + {$SCOPEDENUMS ON} + SimbaIDEEvent = ( + // Event called when codetools is setup. Sender=nil + CODETOOLS_SETUP, + // Event called on editor caret moved. Sender=TSimbaScriptTab + TAB_CARETMOVED, + TAB_MODIFIED, + TAB_LOADED, + TAB_SEARCH, + TAB_BEFORECHANGE, + TAB_CHANGE, + TAB_CLOSED, + // Event called when a tabs script state changes. Sender=TSimbaScriptTab + TAB_SCRIPTSTATE_CHANGE, + // Event called on mouselogger change. Sender=TSimbaMouseLogger + MOUSELOGGER_CHANGE, + // Function list selection changed. Sender=TSimbaFunctionListNode + FUNCTIONLIST_SELECTION + ); + {$POP} + + TSimbaIDEEvents = class(TObject) private - type - EMethodType = ( - CODETOOLS_SETUP, - TAB_CARETMOVED, TAB_MODIFIED, TAB_LOADED, TAB_SEARCH, TAB_BEFORECHANGE, TAB_CHANGE, TAB_CLOSED, - MOUSELOGGER_CHANGE, - SCRIPTSTATE_CHANGE, - FUNCTIONLIST_NODE_SELECTION, - ACTIVE_SCRIPTSTATE_CHANGE - ); - class var - FMethodLists: array[EMethodType] of TMethodList; - - class procedure Call(Typ: EMethodType; Sender: TObject); - class procedure RegisterMethod(Typ: EMethodType; Proc: TNotifyEvent); - class procedure UnRegisterMethod(Typ: EMethodType; Proc: TNotifyEvent); + FEvents: array[SimbaIDEEvent] of TMethodList; public - class constructor Create; - class destructor Destroy; - - // Sender = TSimbaScriptTab - class procedure RegisterOnTabClosed(Proc: TNotifyEvent); - class procedure CallOnScriptTabClose(Sender: TObject); - - // When a function list node is selected. - // Sender=TSimbaFunctionListNode - class procedure RegisterOnFunctionListNodeSelection(Proc: TNotifyEvent); - class procedure CallOnFunctionListNodeSelection(Sender: TObject); - - // When the script state of the active tab changes. - // Sender=TSimbaScriptTab - class procedure RegisterActiveScriptStateChange(Proc: TNotifyEvent); - class procedure CallOnActiveScriptStateChange(Sender: TObject); - - class procedure CallOnScriptStateChange(Sender: TObject); // Sender = TSimbaScriptTab - class procedure CallOnBeforeTabChange(Sender: TObject); - class procedure CallOnScriptTabChange(Sender: TObject); // Sender = TSimbaScriptTab - class procedure CallOnEditorLoadedMethods(Sender: TObject); - class procedure CallOnEditorSearchMethods(Sender: TObject); - class procedure CallOnEditorCaretMoved(Sender: TObject); - class procedure CallOnEditorModified(Sender: TObject); - class procedure CallOnMouseLoggerChange(Sender: TObject); - - class procedure RegisterMethodOnScriptStateChange(Proc: TNotifyEvent); - class procedure RegisterMethodOnScriptTabChange(Proc: TNotifyEvent); - class procedure RegisterOnBeforeTabChange(Proc: TNotifyEvent); - - class procedure RegisterMethodOnMouseLoggerChange(Proc: TNotifyEvent); - class procedure UnRegisterMethodOnMouseLoggerChange(Proc: TNotifyEvent); - - class procedure UnRegisterMethodOnEditorLoaded(Proc: TNotifyEvent); - class procedure UnRegisterMethodOnEditorSearch(Proc: TNotifyEvent); - - class procedure RegisterMethodOnEditorCaretMoved(Proc: TNotifyEvent); // Sender = TSimbaEditor - class procedure RegisterMethodOnEditorModified(Proc: TNotifyEvent); // Sender = TSimbaEditor - - class procedure RegisterMethodOnEditorLoaded(Proc: TNotifyEvent); // Sender = TSimbaScriptTab - class procedure RegisterMethodOnEditorSearch(Proc: TNotifyEvent); // Sender = TSimbaEditorFind - - class procedure RegisterOnCodetoolsSetup(Proc: TNotifyEvent); - class procedure UnRegisterOnCodetoolsSetup(Proc: TNotifyEvent); - class procedure CallOnCodetoolsSetup(Sender: TObject); - end; - -implementation - -class procedure SimbaIDEEvents.Call(Typ: EMethodType; Sender: TObject); -begin - FMethodLists[Typ].CallNotifyEvents(Sender); -end; + procedure Notify(EventType: SimbaIDEEvent; Sender: TObject); + procedure Register(Owner: TComponent; EventType: SimbaIDEEvent; Method: TNotifyEvent); + procedure UnRegister(EventType: SimbaIDEEvent; Proc: TNotifyEvent); -class procedure SimbaIDEEvents.RegisterMethod(Typ: EMethodType; Proc: TNotifyEvent); -begin - FMethodLists[Typ].Add(TMethod(Proc)); -end; - -class procedure SimbaIDEEvents.UnRegisterMethod(Typ: EMethodType; Proc: TNotifyEvent); -begin - FMethodLists[Typ].Remove(TMethod(Proc)); -end; - -class constructor SimbaIDEEvents.Create; -var - Typ: EMethodType; -begin - for Typ in EMethodType do - FMethodLists[Typ] := TMethodList.Create(); -end; + constructor Create; + destructor Destroy; override; + end; -class destructor SimbaIDEEvents.Destroy; var - Typ: EMethodType; -begin - for Typ in EMethodType do - if (FMethodLists[Typ] <> nil) then - FreeAndNil(FMethodLists[Typ]); -end; - -class procedure SimbaIDEEvents.RegisterOnTabClosed(Proc: TNotifyEvent); -begin - RegisterMethod(TAB_CLOSED, Proc); -end; - -class procedure SimbaIDEEvents.CallOnScriptTabClose(Sender: TObject); -begin - Call(TAB_CLOSED, Sender); -end; + SimbaIDEEvents: TSimbaIDEEvents; -class procedure SimbaIDEEvents.RegisterOnFunctionListNodeSelection(Proc: TNotifyEvent); -begin - RegisterMethod(FUNCTIONLIST_NODE_SELECTION, Proc); -end; - -class procedure SimbaIDEEvents.CallOnFunctionListNodeSelection(Sender: TObject); -begin - Call(FUNCTIONLIST_NODE_SELECTION, Sender); -end; - -class procedure SimbaIDEEvents.RegisterActiveScriptStateChange(Proc: TNotifyEvent); -begin - RegisterMethod(ACTIVE_SCRIPTSTATE_CHANGE, Proc); -end; - -class procedure SimbaIDEEvents.CallOnActiveScriptStateChange(Sender: TObject); -begin - Call(ACTIVE_SCRIPTSTATE_CHANGE, Sender); -end; - -class procedure SimbaIDEEvents.CallOnScriptStateChange(Sender: TObject); -begin - Call(SCRIPTSTATE_CHANGE, Sender); -end; - -class procedure SimbaIDEEvents.CallOnBeforeTabChange(Sender: TObject); -begin - Call(TAB_BEFORECHANGE, Sender); -end; - -class procedure SimbaIDEEvents.CallOnScriptTabChange(Sender: TObject); -begin - Call(TAB_CHANGE, Sender); -end; - -class procedure SimbaIDEEvents.CallOnEditorLoadedMethods(Sender: TObject); -begin - Call(TAB_LOADED, Sender); -end; - -class procedure SimbaIDEEvents.CallOnEditorSearchMethods(Sender: TObject); -begin - Call(TAB_SEARCH, Sender); -end; +implementation -class procedure SimbaIDEEvents.CallOnEditorCaretMoved(Sender: TObject); -begin - Call(TAB_CARETMOVED, Sender); -end; +uses + simba.ide_initialization; -class procedure SimbaIDEEvents.CallOnEditorModified(Sender: TObject); -begin - Call(TAB_MODIFIED, Sender); -end; +type + TManagedEvent = class(TComponent) + protected + FMethod: TMethod; + FList: TMethodList; + public + constructor Create(AOwner: TComponent; AMethod: TMethod; AList: TMethodList); reintroduce; + destructor Destroy; override; + end; -class procedure SimbaIDEEvents.CallOnMouseLoggerChange(Sender: TObject); +constructor TManagedEvent.Create(AOwner: TComponent; AMethod: TMethod; AList: TMethodList); begin - Call(MOUSELOGGER_CHANGE, Sender); -end; + inherited Create(AOwner); -class procedure SimbaIDEEvents.RegisterMethodOnScriptStateChange(Proc: TNotifyEvent); -begin - RegisterMethod(SCRIPTSTATE_CHANGE, Proc); -end; + FMethod := AMethod; -class procedure SimbaIDEEvents.RegisterMethodOnScriptTabChange(Proc: TNotifyEvent); -begin - RegisterMethod(TAB_CHANGE, Proc); + FList := AList; + FList.Add(FMethod); end; -class procedure SimbaIDEEvents.RegisterOnBeforeTabChange(Proc: TNotifyEvent); +destructor TManagedEvent.Destroy; begin - RegisterMethod(TAB_BEFORECHANGE, Proc); -end; + FList.Remove(FMethod); -class procedure SimbaIDEEvents.RegisterMethodOnMouseLoggerChange(Proc: TNotifyEvent); -begin - RegisterMethod(MOUSELOGGER_CHANGE, Proc); + inherited Destroy(); end; -class procedure SimbaIDEEvents.UnRegisterMethodOnMouseLoggerChange(Proc: TNotifyEvent); +procedure TSimbaIDEEvents.Notify(EventType: SimbaIDEEvent; Sender: TObject); begin - UnRegisterMethod(MOUSELOGGER_CHANGE, Proc); + FEvents[EventType].CallNotifyEvents(Sender); end; -class procedure SimbaIDEEvents.UnRegisterMethodOnEditorLoaded(Proc: TNotifyEvent); +procedure TSimbaIDEEvents.Register(Owner: TComponent; EventType: SimbaIDEEvent; Method: TNotifyEvent); begin - UnRegisterMethod(TAB_LOADED, Proc); + TManagedEvent.Create(Owner, TMethod(Method), FEvents[EventType]); end; -class procedure SimbaIDEEvents.UnRegisterMethodOnEditorSearch(Proc: TNotifyEvent); +procedure TSimbaIDEEvents.UnRegister(EventType: SimbaIDEEvent; Proc: TNotifyEvent); begin - UnRegisterMethod(TAB_SEARCH, Proc); + FEvents[EventType].Remove(TMethod(Proc)); end; -class procedure SimbaIDEEvents.RegisterMethodOnEditorCaretMoved(Proc: TNotifyEvent); +constructor TSimbaIDEEvents.Create; +var + EventType: SimbaIDEEvent; begin - RegisterMethod(TAB_CARETMOVED, Proc); -end; + inherited Create(); -class procedure SimbaIDEEvents.RegisterMethodOnEditorModified(Proc: TNotifyEvent); -begin - RegisterMethod(TAB_MODIFIED, Proc); + for EventType in SimbaIDEEvent do + FEvents[EventType] := TMethodList.Create(); end; -class procedure SimbaIDEEvents.RegisterMethodOnEditorLoaded(Proc: TNotifyEvent); +destructor TSimbaIDEEvents.Destroy; +var + EventType: SimbaIDEEvent; begin - RegisterMethod(TAB_LOADED, Proc); -end; + for EventType in SimbaIDEEvent do + if (FEvents[EventType] <> nil) then + FreeAndNil(FEvents[EventType]); -class procedure SimbaIDEEvents.RegisterMethodOnEditorSearch(Proc: TNotifyEvent); -begin - RegisterMethod(TAB_SEARCH, Proc); + inherited Destroy(); end; -class procedure SimbaIDEEvents.RegisterOnCodetoolsSetup(Proc: TNotifyEvent); +procedure CreateSimbaIDEEvents; begin - RegisterMethod(CODETOOLS_SETUP, Proc); + SimbaIDEEvents := TSimbaIDEEvents.Create(); end; -class procedure SimbaIDEEvents.UnRegisterOnCodetoolsSetup(Proc: TNotifyEvent); -begin - UnRegisterMethod(CODETOOLS_SETUP, Proc); -end; +initialization + SimbaIDEInitialization_AddBeforeCreate(@CreateSimbaIDEEvents, 'Create SimbaIDEEvents'); -class procedure SimbaIDEEvents.CallOnCodetoolsSetup(Sender: TObject); -begin - Call(CODETOOLS_SETUP, Sender); -end; +finalization + if Assigned(SimbaIDEEvents) then + FreeAndNil(SimbaIDEEvents); end. diff --git a/Source/simba.ide_mainstatusbar.pas b/Source/simba.ide_mainstatusbar.pas index b07c49408..16d1b0df2 100644 --- a/Source/simba.ide_mainstatusbar.pas +++ b/Source/simba.ide_mainstatusbar.pas @@ -14,19 +14,21 @@ interface simba.mufasatypes, simba.component_statusbar; type - TSimbaMainStatusBar = class + TSimbaMainStatusBar = class(TComponent) protected FStatusBar: TSimbaStatusBar; + procedure DoUpdateScriptStatus(Sender: TObject); + procedure DoMouseLoggerChange(Sender: TObject); procedure DoTabCaretMoved(Sender: TObject); procedure DoTabLoaded(Sender: TObject); procedure DoTabSearch(Sender: TObject); procedure DoTabChange(Sender: TObject); - procedure DoScriptStateChange(Sender: TObject); - procedure DoFunctionListNodeSelection(Sender: TObject); + procedure DoTabScriptStateChange(Sender: TObject); + procedure DoFunctionListSelection(Sender: TObject); public - constructor Create; + constructor Create; reintroduce; end; var @@ -35,9 +37,15 @@ TSimbaMainStatusBar = class implementation uses - simba.ide_initialization, simba.ide_events, simba.mouselogger, simba.scripttab, + simba.ide_initialization, simba.ide_events, simba.mouselogger, simba.scripttab, simba.scripttabsform, simba.editor_findreplace, simba.functionlistform; +procedure TSimbaMainStatusBar.DoUpdateScriptStatus(Sender: TObject); +begin + if Assigned(SimbaScriptTabsForm) and Assigned(SimbaScriptTabsForm.CurrentTab) then + FStatusBar.PanelText[1] := SimbaScriptTabsForm.CurrentTab.ScriptStateStr; +end; + procedure TSimbaMainStatusBar.DoMouseLoggerChange(Sender: TObject); begin if (Sender is TSimbaMouseLogger) then @@ -74,13 +82,13 @@ procedure TSimbaMainStatusBar.DoTabChange(Sender: TObject); FStatusBar.PanelText[1] := TSimbaScriptTab(Sender).ScriptStateStr; end; -procedure TSimbaMainStatusBar.DoScriptStateChange(Sender: TObject); +procedure TSimbaMainStatusBar.DoTabScriptStateChange(Sender: TObject); begin if (Sender is TSimbaScriptTab) and TSimbaScriptTab(Sender).IsActiveTab() then FStatusBar.PanelText[1] := TSimbaScriptTab(Sender).ScriptStateStr; end; -procedure TSimbaMainStatusBar.DoFunctionListNodeSelection(Sender: TObject); +procedure TSimbaMainStatusBar.DoFunctionListSelection(Sender: TObject); begin if (Sender is TSimbaFunctionListNode) then FStatusBar.PanelText[3] := TSimbaFunctionListNode(Sender).Hint; @@ -88,6 +96,17 @@ procedure TSimbaMainStatusBar.DoFunctionListNodeSelection(Sender: TObject); constructor TSimbaMainStatusBar.Create; begin + inherited Create(nil); + + with TIdleTimer.Create(Self) do + begin + AutoEnabled := True; + AutoStartEvent := itaOnIdle; + AutoEndEvent := itaOnUserInput; + Interval := 750; + OnTimer := @DoUpdateScriptStatus; + end; + FStatusBar := TSimbaStatusBar.Create(Application.MainForm); FStatusBar.Parent := Application.MainForm; FStatusBar.Align := alBottom; @@ -96,14 +115,13 @@ constructor TSimbaMainStatusBar.Create; FStatusBar.PanelTextMeasure[1] := '[000:000:000]'; FStatusBar.PanelTextMeasure[2] := 'Line 1000, Col 1000'; - SimbaIDEEvents.RegisterMethodOnMouseLoggerChange(@DoMouseLoggerChange); - SimbaIDEEvents.RegisterMethodOnEditorCaretMoved(@DoTabCaretMoved); - SimbaIDEEvents.RegisterMethodOnEditorLoaded(@DoTabLoaded); - SimbaIDEEvents.RegisterMethodOnEditorSearch(@DoTabSearch); - SimbaIDEEvents.RegisterMethodOnScriptTabChange(@DoTabLoaded); - SimbaIDEEvents.RegisterMethodOnScriptStateChange(@DoScriptStateChange); - SimbaIDEEvents.RegisterMethodOnScriptTabChange(@DoTabChange); - SimbaIDEEvents.RegisterOnFunctionListNodeSelection(@DoFunctionListNodeSelection); + SimbaIDEEvents.Register(Self, SimbaIDEEvent.MOUSELOGGER_CHANGE, @DoMouseLoggerChange); + SimbaIDEEvents.Register(Self, SimbaIDEEvent.TAB_CARETMOVED, @DoTabCaretMoved); + SimbaIDEEvents.Register(Self, SimbaIDEEvent.TAB_LOADED, @DoTabLoaded); + SimbaIDEEvents.Register(Self, SimbaIDEEvent.TAB_SEARCH, @DoTabSearch); + SimbaIDEEvents.Register(Self, SimbaIDEEvent.TAB_CHANGE, @DoTabChange); + SimbaIDEEvents.Register(Self, SimbaIDEEvent.TAB_SCRIPTSTATE_CHANGE, @DoTabScriptStateChange); + SimbaIDEEvents.Register(Self, SimbaIDEEvent.FUNCTIONLIST_SELECTION, @DoFunctionListSelection); end; procedure CreateMainStatusBar; diff --git a/Source/simba.mouselogger.pas b/Source/simba.mouselogger.pas index 25af2612d..cf20cb7fa 100644 --- a/Source/simba.mouselogger.pas +++ b/Source/simba.mouselogger.pas @@ -73,7 +73,7 @@ procedure TSimbaMouseLogger.DoChange(Data: PtrInt); Y := Point.Y; HotkeyPressed := (Hotkey <> VK_UNKNOWN) and ((GetKeyState(FHotkey) and $8000) <> 0); - SimbaIDEEvents.CallOnMouseLoggerChange(Self); + SimbaIDEEvents.Notify(SimbaIDEEvent.MOUSELOGGER_CHANGE, Self); end; procedure TSimbaMouseLogger.Execute; diff --git a/Source/simba.scripttab.pas b/Source/simba.scripttab.pas index d4355b788..00d7a3188 100644 --- a/Source/simba.scripttab.pas +++ b/Source/simba.scripttab.pas @@ -12,9 +12,7 @@ interface uses Classes, SysUtils, ComCtrls, Controls, Dialogs, Process, SynEdit, SynEditTypes, - simba.mufasatypes, simba.editor, - simba.outputform, simba.component_tabcontrol, - simba.windowhandle; + simba.mufasatypes, simba.editor, simba.outputform, simba.component_tabcontrol, simba.windowhandle; type TSimbaScriptTab = class; @@ -69,8 +67,6 @@ TSimbaScriptTabRunner = class(TComponent) procedure SetError(Message, FileName: String; Line, Col: Integer); - //function IsActiveTab: Boolean; - constructor Create(ATab: TSimbaScriptTab); reintroduce; destructor Destroy; override; end; @@ -132,7 +128,6 @@ TSimbaScriptTab = class(TSimbaTab) function ScriptStateStr: String; function ScriptState: ESimbaScriptState; - function ScriptTimeRunning: UInt64; procedure Run(Target: TWindowHandle); procedure Compile; @@ -165,8 +160,6 @@ procedure TSimbaScriptTabRunner.DoOutputThread; if (Count > 0) then RemainingBuffer := FTab.OutputBox.Add(RemainingBuffer + Copy(ReadBuffer, 1, Count)); end; - - //SimbaIDEEvents.CallOnScriptRunning(FTab); end; begin @@ -215,14 +208,9 @@ function TSimbaScriptTabRunner.GetTimeRunning: UInt64; procedure TSimbaScriptTabRunner.SetState(Value: ESimbaScriptState); begin - CheckMainThread('SimbaScriptTabRunner.SetState'); - FState := Value; - if FTab.IsActiveTab() then - SimbaIDEEvents.CallOnActiveScriptStateChange(FTab) - else - SimbaIDEEvents.CallOnScriptStateChange(FTab); + SimbaIDEEvents.Notify(SimbaIDEEvent.TAB_SCRIPTSTATE_CHANGE, FTab); end; procedure TSimbaScriptTabRunner.Start(Args: TStringArray); @@ -377,7 +365,7 @@ procedure TSimbaScriptTab.DoFindAndShowDeclaration; procedure TSimbaScriptTab.DoEditorModified(Sender: TObject); begin - SimbaIDEEvents.CallOnEditorModified(Self); + SimbaIDEEvents.Notify(SimbaIDEEvent.TAB_MODIFIED, Self); end; procedure TSimbaScriptTab.DoEditorLinkClick(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); @@ -398,7 +386,7 @@ procedure TSimbaScriptTab.DoEditorLinkClick(Sender: TObject; Button: TMouseButto procedure TSimbaScriptTab.DoEditorStatusChanges(Sender: TObject; Changes: TSynStatusChanges); begin - SimbaIDEEvents.CallOnEditorCaretMoved(Self); + SimbaIDEEvents.Notify(SimbaIDEEvent.TAB_CARETMOVED, Self); end; function TSimbaScriptTab.SaveAsDialog: String; @@ -488,7 +476,7 @@ function TSimbaScriptTab.Load(FileName: String): Boolean; Caption := FScriptTitle; if Result then - SimbaIDEEvents.CallOnEditorLoadedMethods(Self); + SimbaIDEEvents.Notify(SimbaIDEEvent.TAB_LOADED, Self); end; procedure TSimbaScriptTab.Undo; @@ -566,13 +554,6 @@ function TSimbaScriptTab.ScriptState: ESimbaScriptState; Result := FScriptRunner.State; end; -function TSimbaScriptTab.ScriptTimeRunning: UInt64; -begin - Result := 0; - if (FScriptRunner <> nil) then - Result := FScriptRunner.TimeRunning; -end; - procedure TSimbaScriptTab.Run(Target: TWindowHandle); begin DebugLn('TSimbaScriptTab.Run :: ' + ScriptTitle + ' ' + ScriptFileName); @@ -648,7 +629,7 @@ constructor TSimbaScriptTab.Create(AOwner: TComponent); destructor TSimbaScriptTab.Destroy; begin - SimbaIDEEvents.CallOnScriptTabClose(Self); + SimbaIDEEvents.Notify(SimbaIDEEvent.TAB_CLOSED, Self); if Assigned(SimbaOutputForm) then SimbaOutputForm.RemoveTab(FOutputBox);