Skip to content

Commit

Permalink
SimbaIDEEvents refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Nov 25, 2023
1 parent 7240839 commit 1b2c221
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 290 deletions.
2 changes: 1 addition & 1 deletion Source/codetools/simba.ide_codetools_setup.pas
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ procedure SetupCodeTools;

CodetoolsSetup := True;

SimbaIDEEvents.CallOnCodetoolsSetup(nil);
SimbaIDEEvents.Notify(SimbaIDEEvent.CODETOOLS_SETUP, nil);
end;

initialization
Expand Down
2 changes: 1 addition & 1 deletion Source/editor/simba.editor.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion Source/editor/simba.editor_findreplace.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
37 changes: 9 additions & 28 deletions Source/editor/simba.editor_popupmenu.pas
Original file line number Diff line number Diff line change
@@ -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}
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions Source/forms/simba.functionlistform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions Source/forms/simba.main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
9 changes: 4 additions & 5 deletions Source/forms/simba.outputform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -634,7 +633,7 @@ constructor TSimbaOutputForm.Create(AOwner: TComponent);

DoSimbaDebugLn := @DebugLn;

SimbaIDEEvents.RegisterMethodOnScriptTabChange(@DoScriptTabChange);
SimbaIDEEvents.Register(Self, SimbaIDEEvent.TAB_CHANGE, @DoScriptTabChange);
end;

end.
Expand Down
4 changes: 2 additions & 2 deletions Source/forms/simba.scripttabsform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 1b2c221

Please sign in to comment.