Skip to content

Commit

Permalink
re-add package menu building
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Dec 2, 2023
1 parent 5800244 commit 9d49b88
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 55 deletions.
12 changes: 2 additions & 10 deletions Source/forms/simba.main.lfm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object SimbaForm: TSimbaForm
Left = 971
Left = 1428
Height = 539
Top = 548
Top = 583
Width = 1015
Caption = 'Simba'
ClientHeight = 539
Expand Down Expand Up @@ -92,14 +92,6 @@ object SimbaForm: TSimbaForm
OnClick = TrayPopupExitClick
end
end
object PackageUpdateTimer: TTimer
Enabled = False
Interval = 300000
OnTimer = DoPackageMenuTimer
OnStartTimer = DoPackageMenuTimer
Left = 60
Top = 130
end
object MainMenuFile: TPopupMenu
Images = Images
OnMeasureItem = MainMenuMeasureItem
Expand Down
12 changes: 2 additions & 10 deletions Source/forms/simba.main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ TSimbaForm = class(TForm)
MainMenuSearchSep2: TMenuItem;
MainMenuSearchSep3: TMenuItem;
Separator1: TMenuItem;
PackageUpdateTimer: TTimer;
TrayIcon: TTrayIcon;
TrayPopup: TPopupMenu;
TrayPopupExit: TMenuItem;
Expand Down Expand Up @@ -216,7 +215,6 @@ TSimbaForm = class(TForm)
procedure MenuSaveAsDefaultClick(Sender: TObject);
procedure MenuSelectAllClick(Sender: TObject);
procedure MenuUndoClick(Sender: TObject);
procedure DoPackageMenuTimer(Sender: TObject);
procedure RecentFilesPopupPopup(Sender: TObject);
procedure TrayIconClick(Sender: TObject);
procedure TrayPopupExitClick(Sender: TObject);
Expand Down Expand Up @@ -272,7 +270,7 @@ implementation
simba.dockinghelpers, simba.nativeinterface,
simba.scriptformatter, simba.theme,
simba.scriptbackup, simba.backupsform, simba.threading,
simba.downloadsimbaform, simba.package_autoupdater;
simba.downloadsimbaform;

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

Expand Down Expand Up @@ -398,11 +396,6 @@ procedure TSimbaForm.MenuNewTemplateClick(Sender: TObject);
SimbaOpenExampleForm.ShowModal();
end;

procedure TSimbaForm.DoPackageMenuTimer(Sender: TObject);
begin
UpdatePackages();
end;

procedure TSimbaForm.RecentFilesPopupPopup(Sender: TObject);
var
I: Integer;
Expand Down Expand Up @@ -992,8 +985,7 @@ procedure TSimbaForm.SetupDocking;

procedure TSimbaForm.SetupCompleted;
begin
PackageUpdateTimer.Enabled := True;

WriteLn('Setup completed');
if SimbaSettings.FirstLaunch then
MenuItemAssociateScripts.Click();

Expand Down
83 changes: 66 additions & 17 deletions Source/package/simba.package_autoupdater.pas
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,30 @@
interface

uses
Classes, SysUtils;
Classes, SysUtils, Forms, ExtCtrls;

procedure UpdatePackages;
type
TPackageAutoUpdater = class(TComponent)
protected
FTimer: TTimer;

procedure DoPackageFormClosed(Sender: TObject; var CloseAction: TCloseAction);
procedure DoTimer(Sender: TObject);
public
constructor Create; reintroduce;

procedure Run;
end;

var
PackageAutoUpdater: TPackageAutoUpdater;

implementation

uses
simba.mufasatypes, simba.package, simba.package_installer,
simba.main, simba.outputform, simba.package_menubuilder, simba.threading;
simba.main, simba.outputform, simba.package_menubuilder, simba.threading,
simba.ide_maintoolbar, simba.ide_initialization, simba.package_form;

type
TPackageUpdater = class(TThread)
Expand All @@ -33,23 +48,50 @@ TPackageUpdater = class(TThread)
destructor Destroy; override;
end;

procedure TPackageAutoUpdater.DoPackageFormClosed(Sender: TObject; var CloseAction: TCloseAction);
begin
Run();
end;

procedure TPackageAutoUpdater.DoTimer(Sender: TObject);
begin
Run();
end;

constructor TPackageAutoUpdater.Create;
begin
inherited Create(nil);

FTimer := TTimer.Create(Self);
FTimer.OnTimer := @DoTimer;
FTimer.Interval := 60000 * 5;
FTimer.Enabled := True;

SimbaPackageForm.AddHandlerClose(@DoPackageFormClosed);
end;

procedure TPackageAutoUpdater.Run;
begin
TPackageUpdater.Create();
end;

procedure TPackageUpdater.DoTerminateOnMainThread(Sender: TObject);
begin
CheckMainThread('TPackageUpdater');

// Update main menu
//BuildPackageMenus(FPackages, SimbaForm.MenuBar);
BuildPackageMenus(FPackages);

// Update icon
//if (FUpdates.Count > 0) then
//begin
// SimbaForm.ToolbarButtonPackages.Hint := 'Open packages' + LineEnding + FUpdates.Text;
// SimbaForm.ToolbarButtonPackages.ImageIndex := IMG_PACKAGE + Min(FUpdates.Count, 9);
//end else
//begin
// SimbaForm.ToolbarButtonPackages.Hint := 'Open packages';
// SimbaForm.ToolbarButtonPackages.ImageIndex := IMG_PACKAGE;
//end;
if (FUpdates.Count > 0) then
begin
SimbaMainToolBar.ButtonPackage.Hint := 'Open packages' + LineEnding + FUpdates.Text;
SimbaMainToolBar.ButtonPackage.ImageIndex := IMG_PACKAGE + Min(FUpdates.Count, 9);
end else
begin
SimbaMainToolBar.ButtonPackage.Hint := 'Open packages';
SimbaMainToolBar.ButtonPackage.ImageIndex := IMG_PACKAGE;
end;
end;

procedure TPackageUpdater.Execute;
Expand Down Expand Up @@ -87,8 +129,8 @@ procedure TPackageUpdater.Execute;
end;

for I := 0 to High(FPackages) do
if Package.HasUpdate() then
FUpdates.Add('%s can be updated to version %s', [Package.Info.FullName, Package.LatestVersion]);
if FPackages[I].HasUpdate() then
FUpdates.Add('%s can be updated to version %s', [FPackages[I].Info.FullName, FPackages[I].LatestVersion]);
end;

constructor TPackageUpdater.Create;
Expand All @@ -113,10 +155,17 @@ destructor TPackageUpdater.Destroy;
inherited Destroy();
end;

procedure UpdatePackages;
procedure SetupPackageAutoUpdater;
begin
TPackageUpdater.Create();
PackageAutoUpdater := TPackageAutoUpdater.Create();
end;

initialization
SimbaIDEInitialization_AddBeforeShow(@SetupPackageAutoUpdater, 'Setup Package AutoUpdater');

finalization
if Assigned(PackageAutoUpdater) then
FreeAndNil(PackageAutoUpdater);

end.

1 change: 0 additions & 1 deletion Source/package/simba.package_form.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ object SimbaPackageForm: TSimbaPackageForm
Constraints.MinHeight = 312
Constraints.MinWidth = 312
DesignTimePPI = 120
OnHide = FormHide
OnShow = FormShow
Position = poMainFormCenter
ShowInTaskBar = stAlways
Expand Down
10 changes: 2 additions & 8 deletions Source/package/simba.package_form.pas
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ TSimbaPackageForm = class(TForm)
ButtonAddRepository: TToolButton;
ToolButton1: TToolButton;

procedure FormHide(Sender: TObject);
procedure InstallingButtonClick(Sender: TObject);
procedure ButtonAddRepositoryClick(Sender: TObject);
procedure ButtonRefreshClick(Sender: TObject);
Expand Down Expand Up @@ -70,8 +69,8 @@ implementation
{$R *.lfm}

uses
simba.mufasatypes, simba.package_installform,
simba.package_installer, simba.package_autoupdater, simba.dialog, simba.threading;
simba.package_installform, simba.package_installer, simba.package_autoupdater,
simba.mufasatypes, simba.dialog, simba.threading;

procedure TSimbaPackageForm.FormShow(Sender: TObject);
begin
Expand Down Expand Up @@ -182,11 +181,6 @@ procedure TSimbaPackageForm.InstallingButtonClick(Sender: TObject);
BottomNotebook.ShowControl(PageVersions);
end;

procedure TSimbaPackageForm.FormHide(Sender: TObject);
begin
UpdatePackages();
end;

procedure TSimbaPackageForm.ButtonRefreshClick(Sender: TObject);
begin
Application.QueueAsyncCall(@DoRefresh, 0);
Expand Down
16 changes: 7 additions & 9 deletions Source/package/simba.package_menubuilder.pas
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ interface

uses
Classes, SysUtils,
simba.mufasatypes, simba.package, simba.component_menubar;
simba.mufasatypes, simba.package;

//procedure BuildPackageMenus(Packages: TSimbaPackageArray; MenuBar: TSimbaMainMenuBar);
procedure BuildPackageMenus(Packages: TSimbaPackageArray);

implementation

uses
Menus,
simba.main, simba.scripttabsform, simba.files;
simba.main, simba.scripttabsform, simba.files, simba.ide_mainmenubar;

type
TPackagePopupMenu = class(TPopupMenu)
Expand All @@ -41,21 +41,20 @@ procedure TPackageMenuItem.Click;
SimbaForm.MenuItemRun.Click();
end;

{
procedure BuildPackageMenus(Packages: TSimbaPackageArray; MenuBar: TSimbaMainMenuBar);
procedure BuildPackageMenus(Packages: TSimbaPackageArray);

function GetMenu(PackageFullName: String): TPackagePopupMenu;
var
Menu: TPopupMenu;
begin
for Menu in MenuBar.Menus do
for Menu in SimbaMainMenuBar.MenuBar.Menus do
if (Menu is TPackagePopupMenu) and (TPackagePopupMenu(Menu).PackageFullName = PackageFullName) then
begin
Result := TPackagePopupMenu(Menu);
Exit;
end;

Result := TPackagePopupMenu.Create(MenuBar);
Result := TPackagePopupMenu.Create(SimbaMainMenuBar.MenuBar);
end;

var
Expand Down Expand Up @@ -103,11 +102,10 @@ procedure BuildPackageMenus(Packages: TSimbaPackageArray; MenuBar: TSimbaMainMen
Menu.Items.Add(SubMenu);
end;

MenuBar.AddMenu(Packages[I].Info.Name, Menu);
SimbaMainMenuBar.MenuBar.AddMenu(Packages[I].Info.Name, Menu);
end;
end;
end;
}

end.

2 changes: 2 additions & 0 deletions Source/simba.ide_mainmenubar.pas
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ TSimbaMainMenuBar = class(TComponent)
procedure DoTabScriptStateChange(Sender: TObject);
public
constructor Create; reintroduce;

property MenuBar: TSimbaMenuBar read FMenuBar;
end;

var
Expand Down

0 comments on commit 9d49b88

Please sign in to comment.