Skip to content

Commit

Permalink
Improve ide initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Sep 5, 2023
1 parent 69db362 commit f527efd
Show file tree
Hide file tree
Showing 18 changed files with 281 additions and 177 deletions.
7 changes: 5 additions & 2 deletions Source/Simba.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
simba.settingsform, simba.associate, simba.openexampleform,
simba.package_form, simba.shapeboxform, simba.backupsform,
simba.compiler_dump, simba.plugin_dump,
simba.scriptthread;
simba.scriptthread, simba.ide_initialization, simba.threading,
simba.openssl, simba.ide_codetools_setup;

begin
{$IF DECLARED(SetHeapTraceOutput)}
Expand Down Expand Up @@ -98,6 +99,8 @@
begin
SimbaProcessType := ESimbaProcessType.IDE;

SimbaIDEInitialization_CallBeforeCreate();

Application.ShowMainForm := False;
Application.CreateForm(TSimbaForm, SimbaForm);
Application.CreateForm(TSimbaFunctionListForm, SimbaFunctionListForm);
Expand All @@ -115,7 +118,7 @@
Application.CreateForm(TSimbaShapeBoxForm, SimbaShapeBoxForm);
Application.CreateForm(TSimbaBackupsForm, SimbaBackupsForm);

Application.QueueAsyncCall(@SimbaForm.Setup, 0);
SimbaIDEInitialization_CallBeforeShow();
end;

Application.Run();
Expand Down
2 changes: 1 addition & 1 deletion Source/codetools/mpaslextypes.pas
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ procedure SetupKeywordDictionary;
end;

initialization
SimbaIDEInitialization.RegisterMethodOnBeforeCreate(@SetupKeywordDictionary, 'Keyword Dictionary');
SimbaIDEInitialization_AddBeforeCreate(@SetupKeywordDictionary, 'Create KeywordDictionary');

finalization
if (KeywordDictionary <> nil) then
Expand Down
2 changes: 1 addition & 1 deletion Source/codetools/simba.ide_codetools_arrayhelpers.pas
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ procedure CreateArrayHelperGenerator;
end;

initialization
SimbaIDEInitialization.RegisterMethodOnBeforeCreate(@CreateArrayHelperGenerator, 'Codetools ArrayHelperGenerator');
SimbaIDEInitialization_AddBeforeCreate(@CreateArrayHelperGenerator, 'Codetools ArrayHelper Generator');

finalization
if (ArrayHelperGenerator <> nil) then
Expand Down
2 changes: 1 addition & 1 deletion Source/codetools/simba.ide_codetools_includes.pas
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ procedure CreateCodetoolsIncludes;
end;

initialization
SimbaIDEInitialization.RegisterMethodOnBeforeCreate(@CreateCodetoolsIncludes, 'Create CodetoolsIncludes');
SimbaIDEInitialization_AddBeforeCreate(@CreateCodetoolsIncludes, 'Codetools Includes');

finalization
if Assigned(CodetoolsIncludes) then
Expand Down
2 changes: 1 addition & 1 deletion Source/codetools/simba.ide_codetools_plugins.pas
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ procedure CreateCodetoolsPlugins;
end;

initialization
SimbaIDEInitialization.RegisterMethodOnBeforeCreate(@CreateCodetoolsPlugins, 'Create CodetoolsPlugins');
SimbaIDEInitialization_AddBeforeCreate(@CreateCodetoolsPlugins, 'Create CodetoolsPlugins');

finalization
if Assigned(CodetoolsPlugins) then
Expand Down
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 @@ -52,6 +52,6 @@ procedure SetupCodeTools;
end;

initialization
SimbaIDEInitialization.RegisterMethodOnAfterCreate(@SetupCodeTools, 'CodeTools');
SimbaIDEInitialization_AddBeforeShow(@SetupCodeTools, 'Setup CodeTools', True);

end.
6 changes: 3 additions & 3 deletions Source/forms/simba.filebrowserform.lfm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
object SimbaFileBrowserForm: TSimbaFileBrowserForm
Left = 1938
Left = 349
Height = 309
Top = 792
Width = 185
Top = 672
Width = 1824
Caption = 'File Browser'
DesignTimePPI = 120
LCLVersion = '3.0.0.1'
Expand Down
1 change: 0 additions & 1 deletion Source/forms/simba.main.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ object SimbaForm: TSimbaForm
DesignTimePPI = 120
KeyPreview = True
OnClose = FormClose
OnCreate = FormCreate
OnDestroy = FormDestroy
Position = poScreenCenter
LCLVersion = '3.0.0.1'
Expand Down
147 changes: 75 additions & 72 deletions Source/forms/simba.main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ TSimbaForm = class(TForm)
TrayPopupExit: TMenuItem;

procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormShortCut(var Msg: TLMKey; var Handled: Boolean);
procedure ImagesGetWidthForPPI(Sender: TCustomImageList; AImageWidth, APPI: Integer; var AResultWidth: Integer);
Expand Down Expand Up @@ -237,7 +236,9 @@ TSimbaForm = class(TForm)
procedure AddRecentFile(FileName: String);
procedure SetButtonStates(Instance: TSimbaScriptInstance);

procedure SetDefaultDocking(IsResetting: Boolean = False);
procedure DoResetDocking;
procedure DoDefaultDocking;

procedure SetupDocking;
procedure SetupCompleted;

Expand Down Expand Up @@ -266,7 +267,7 @@ TSimbaForm = class(TForm)
property ProcessSelection: TProcessID read FProcessSelection;
property MenuBar: TSimbaMainMenuBar read FMenuBar;

procedure Setup(Data: PtrInt);
procedure Setup;
end;

var
Expand All @@ -283,18 +284,14 @@ implementation
simba.debugimageform, simba.imagetostringform, simba.aboutform,
simba.outputform, simba.filebrowserform, simba.notesform, simba.settingsform,
simba.functionlistform, simba.scripttabsform, simba.ide_mainstatusbar,

simba.package_form, simba.package_autoupdater,

simba.associate, simba.ide_initialization, simba.ide_events,
simba.aca, simba.dtmeditor,

simba.windowselector, simba.colorpicker,

simba.openssl, simba.env,
simba.env,
simba.dockinghelpers, simba.nativeinterface,
simba.scriptformatter, simba.windowhandle, simba.scripttab, simba.theme,
simba.scriptbackup, simba.backupsform, simba.ide_utils;
simba.scriptbackup, simba.backupsform, simba.ide_utils, simba.threading;

procedure TSimbaForm.HandleException(Sender: TObject; E: Exception);

Expand Down Expand Up @@ -584,32 +581,35 @@ procedure TSimbaForm.SetButtonStates(Instance: TSimbaScriptInstance);
end;
end;

procedure TSimbaForm.SetDefaultDocking(IsResetting: Boolean);
procedure TSimbaForm.DoResetDocking;
var
I: Integer;
Splitter: TAnchorDockSplitter;
begin
if IsResetting then
begin
if (MessageDlg('Reset to default layout?', mtConfirmation, [mbYes, mbNo], 0) <> mrYes) then
Exit;
if (MessageDlg('Reset to default layout?', mtConfirmation, [mbYes, mbNo], 0) <> mrYes) then
Exit;

SimbaSettings.General.Layout.Value := '';
SimbaSettings.General.LockLayout.Value := False;
SimbaSettings.General.Layout.Value := '';
SimbaSettings.General.LockLayout.Value := False;

Hide();
WindowState := wsNormal;
for I := 0 to Screen.CustomFormCount - 1 do
if (Screen.CustomForms[I].HostDockSite is TCustomForm) then
begin
Screen.CustomForms[I].Hide();
Hide();
WindowState := wsNormal;
for I := 0 to Screen.CustomFormCount - 1 do
if (Screen.CustomForms[I].HostDockSite is TCustomForm) then
begin
Screen.CustomForms[I].Hide();

DockMaster.ManualFloat(Screen.CustomForms[I]);
if (DockMaster.GetAnchorSite(Screen.CustomForms[I]) <> nil) then
DockMaster.GetAnchorSite(Screen.CustomForms[I]).Header.Visible := True;
end;
end;
DockMaster.ManualFloat(Screen.CustomForms[I]);
if (DockMaster.GetAnchorSite(Screen.CustomForms[I]) <> nil) then
DockMaster.GetAnchorSite(Screen.CustomForms[I]).Header.Visible := True;
end;

DoDefaultDocking();
end;

procedure TSimbaForm.DoDefaultDocking;
var
Splitter: TAnchorDockSplitter;
begin
DockMaster.ManualDock(DockMaster.GetAnchorSite(SimbaScriptTabsForm), DockPanel, alClient);
DockMaster.ManualDock(DockMaster.GetAnchorSite(SimbaOutputForm), DockPanel, alBottom);
DockMaster.ManualDock(DockMaster.GetAnchorSite(SimbaFunctionListForm), DockPanel, alLeft);
Expand All @@ -619,54 +619,35 @@ procedure TSimbaForm.SetDefaultDocking(IsResetting: Boolean);
DockMaster.MakeVisible(SimbaOutputForm, False);
DockMaster.MakeVisible(SimbaFunctionListForm, False);
DockMaster.MakeVisible(SimbaFileBrowserForm, False);
DockMaster.ScaleOnResize:=False;

// Default size
Width := 1250;
Width := 1200;
Height := 850;

if GetDockSplitter(DockMaster.GetAnchorSite(SimbaScriptTabsForm), akLeft, Splitter) then
Splitter.SetSplitterPosition(180);
Splitter.SetSplitterPosition(250);
if GetDockSplitter(DockMaster.GetAnchorSite(SimbaScriptTabsForm), akRight, Splitter) then
Splitter.SetSplitterPosition(720);
Splitter.SetSplitterPosition(1200 - 250);
if GetDockSplitter(DockMaster.GetAnchorSite(SimbaScriptTabsForm), akBottom, Splitter) then
Splitter.SetSplitterPosition(350);

Dockmaster.ScaleOnResize := True;

DockMaster.GetAnchorSite(SimbaScriptTabsForm).Header.Visible := False;
DockMaster.GetAnchorSite(SimbaOutputForm).Header.Visible := False;

MoveToDefaultPosition();
EnsureVisible();
end;

procedure TSimbaForm.Setup(Data: PtrInt);
procedure TSimbaForm.Setup;
begin
SimbaIDEInitialization.CallOnCreatedMethods();

SimbaIDEEvents.RegisterMethodOnEditorLoaded(@DoTabLoaded);
SimbaIDEEvents.RegisterMethodOnEditorModified(@DoTabModified);
SimbaIDEEvents.RegisterMethodOnScriptTabChange(@DoTabModified); // Also do this
SimbaIDEEvents.RegisterMethodOnScriptTabChange(@DoScriptTabChange);
SimbaIDEEvents.RegisterMethodOnScriptStateChange(@DoScriptStateChange);

SimbaScriptTabsForm.AddTab();

SetupDocking();

FMouseLogger := TSimbaMouseLogger.Create();
FMouseLogger.Hotkey := VK_F1;

SimbaIDEInitialization.CallOnAfterCreateMethods();

FMenuBar := TSimbaMainMenuBar.Create(Self);
FMenuBar.Parent := MainMenuPanel;
FMenuBar.Align := alTop;
FMenuBar.AddMenu('File', MainMenuFile);
FMenuBar.AddMenu('Edit', MainMenuEdit);
FMenuBar.AddMenu('Script', MainMenuScript);
FMenuBar.AddMenu('Tools', MainMenuTools);
FMenuBar.AddMenu('View', MainMenuView);
FMenuBar.AddMenu('Help', MainMenuHelp);

SimbaSettings.RegisterChangeHandler(@SimbaSettingChanged);

with SimbaSettings do
Expand All @@ -681,18 +662,6 @@ procedure TSimbaForm.Setup(Data: PtrInt);
SimbaSettingChanged(SimbaSettings.General.TrayIconVisible);
SimbaSettingChanged(SimbaSettings.General.ConsoleVisible);

// Finally, give the editor focus as default.
if Assigned(SimbaScriptTabsForm.CurrentEditor) then
if SimbaScriptTabsForm.CurrentEditor.CanSetFocus() then
SimbaScriptTabsForm.CurrentEditor.SetFocus();

SetupCompleted();
end;

procedure TSimbaForm.FormCreate(Sender: TObject);
begin
SimbaIDEInitialization.CallOnBeforeCreateMethods();

Application.CaptureExceptions := True;
Application.OnException := @Self.HandleException;
Application.OnShortcut := @Self.FormShortCut;
Expand All @@ -705,9 +674,34 @@ procedure TSimbaForm.FormCreate(Sender: TObject);
FToolbarImages := TImageList.Create(Self); // Create a copy so ImagesGetWidthForPPI is not used for toolbar
FToolbarImages.Assign(Images);

Self.Color := SimbaTheme.ColorFrame;
ToolBar.Color := SimbaTheme.ColorFrame;
ToolBar.Images := FToolbarImages;

FMouseLogger := TSimbaMouseLogger.Create();
FMouseLogger.Hotkey := VK_F1;

FMenuBar := TSimbaMainMenuBar.Create(Self);
FMenuBar.Parent := MainMenuPanel;
FMenuBar.Align := alTop;
FMenuBar.AddMenu('File', MainMenuFile);
FMenuBar.AddMenu('Edit', MainMenuEdit);
FMenuBar.AddMenu('Script', MainMenuScript);
FMenuBar.AddMenu('Tools', MainMenuTools);
FMenuBar.AddMenu('View', MainMenuView);
FMenuBar.AddMenu('Help', MainMenuHelp);

Color := SimbaTheme.ColorFrame;

SimbaScriptTabsForm.AddTab();

SetupDocking();

// Finally, give the editor focus as default.
if Assigned(SimbaScriptTabsForm.CurrentEditor) then
if SimbaScriptTabsForm.CurrentEditor.CanSetFocus() then
SimbaScriptTabsForm.CurrentEditor.SetFocus();

SetupCompleted();
end;

procedure TSimbaForm.FormDestroy(Sender: TObject);
Expand Down Expand Up @@ -773,7 +767,7 @@ procedure TSimbaForm.MenuItemScriptStateClick(Sender: TObject);
if (Sender = MenuItemCompile) or (Sender = ToolbarButtonCompile) then Exit(Compile);
if (Sender = MenuItemRun) or (Sender = ToolbarButtonRun) then Exit(Run);
if (Sender = MenuItemPause) or (Sender = ToolbarButtonPause) then Exit(Pause);
if (Sender = MenuItemStop) or (Sender = ToolbarButtonStop) then Exit(Stop);
if (Sender = MenuItemStop) or (Sender = ToolbarButtonStop) then Exit(Stop);

DebugLn('[TSimbaForm.MenuItemScriptStateClick]: Unknown component "' + Sender.ClassName + '"');
end;
Expand Down Expand Up @@ -849,9 +843,7 @@ procedure TSimbaForm.DoSettingChanged_Toolbar(Setting: TSimbaSetting);
end;

if Setting.Equals(SimbaSettings.General.ToolBarSpacing) then
begin
ToolBar.BorderSpacing.Around := Setting.Value;
end;
end;

procedure TSimbaForm.SimbaSettingChanged(Setting: TSimbaSetting);
Expand Down Expand Up @@ -1022,7 +1014,7 @@ procedure TSimbaForm.MenuUndoClick(Sender: TObject);

procedure TSimbaForm.MenuItemResetLayoutClick(Sender: TObject);
begin
SetDefaultDocking(True);
QueueOnMainThread(@DoResetDocking);
end;

procedure TSimbaForm.MenuItemConsoleClick(Sender: TObject);
Expand Down Expand Up @@ -1312,7 +1304,7 @@ procedure TSimbaForm.SetupDocking;

EnsureVisible();
end else
SetDefaultDocking();
QueueOnMainThread(@DoDefaultDocking);
finally
DockMaster.EndUpdate();

Expand Down Expand Up @@ -1344,4 +1336,15 @@ procedure TSimbaForm.SetupCompleted;
end;
end;

procedure SetupSimbaForm;
begin
if (SimbaForm = nil) then
SimbaException('SimbaForm is nil');

SimbaForm.Setup();
end;

initialization
SimbaIDEInitialization_AddBeforeShow(@SetupSimbaForm, 'Setup SimbaForm');

end.
Binary file modified Source/macosbundle/Simba.app/Contents/Resources/Simba.icns
Binary file not shown.
2 changes: 1 addition & 1 deletion Source/simba.darwin_axui.pas
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function AXUI_GetWindowInfo(PID: UInt32): TAXUIWindowInfo;
end;

initialization
SimbaIDEInitialization.RegisterMethodOnAfterCreate(@RequestAccessibility, 'RequestAccessibility');
SimbaIDEInitialization_AddBeforeShow(@RequestAccessibility, 'RequestAccessibility');

CreateCFStrings();

Expand Down
Loading

0 comments on commit f527efd

Please sign in to comment.