Skip to content

Commit

Permalink
New Application.RunInThreadAndWait methods for ide.
Browse files Browse the repository at this point in the history
Package changes:
Use rss feed to detect changes since unauth Github conditional requests were counting towards the rate limit.
  • Loading branch information
ollydev committed Mar 29, 2024
1 parent bee65a3 commit 179a5b3
Show file tree
Hide file tree
Showing 16 changed files with 696 additions and 538 deletions.
40 changes: 32 additions & 8 deletions Source/Simba.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir);$(LazarusDir)/components/synedit;../Third-Party/lape;shapebuilders"/>
<Libraries Value="../Third-Party/lape/extensions/ffi/bin/win32"/>
<OtherUnitFiles Value="$(ProjPath);../Third-Party;../Third-Party/lape;../Third-Party/lape/extensions/ffi;script/imports;script/imports/lcl;script;matchtemplate;algorithms;imagebox;components;image;hash;ide;tools"/>
<OtherUnitFiles Value="$(ProjPath);../Third-Party;../Third-Party/lape;../Third-Party/lape/extensions/ffi;script/imports;script/imports/lcl;script;matchtemplate;imagebox;components;image;hash;ide;tools"/>
<UnitOutputDirectory Value="$(ProjPath)../build/$(BuildMode)/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
Expand Down Expand Up @@ -101,7 +101,7 @@
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir);$(LazarusDir)/components/synedit;../Third-Party/lape;shapebuilders"/>
<Libraries Value="../Third-Party/lape/extensions/ffi/bin/win64"/>
<OtherUnitFiles Value="$(ProjPath);../Third-Party;../Third-Party/lape;../Third-Party/lape/extensions/ffi;script/imports;script/imports/lcl;script;matchtemplate;algorithms;imagebox;components;image;hash;ide;tools"/>
<OtherUnitFiles Value="$(ProjPath);../Third-Party;../Third-Party/lape;../Third-Party/lape/extensions/ffi;script/imports;script/imports/lcl;script;matchtemplate;imagebox;components;image;hash;ide;tools"/>
<UnitOutputDirectory Value="$(ProjPath)../build/$(BuildMode)/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
Expand Down Expand Up @@ -150,7 +150,7 @@
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir);$(LazarusDir)/components/synedit;../Third-Party/lape;shapebuilders"/>
<OtherUnitFiles Value="$(ProjPath);../Third-Party;../Third-Party/lape;../Third-Party/lape/extensions/ffi;script/imports;script/imports/lcl;script;matchtemplate;algorithms;imagebox;components;image;hash;ide;tools"/>
<OtherUnitFiles Value="$(ProjPath);../Third-Party;../Third-Party/lape;../Third-Party/lape/extensions/ffi;script/imports;script/imports/lcl;script;matchtemplate;imagebox;components;image;hash;ide;tools"/>
<UnitOutputDirectory Value="$(ProjPath)../build/$(BuildMode)/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
Expand Down Expand Up @@ -198,7 +198,7 @@
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir);$(LazarusDir)/components/synedit;../Third-Party/lape;shapebuilders"/>
<OtherUnitFiles Value="$(ProjPath);../Third-Party;../Third-Party/lape;../Third-Party/lape/extensions/ffi;script/imports;script/imports/lcl;script;matchtemplate;algorithms;imagebox;components;image;hash;ide;tools"/>
<OtherUnitFiles Value="$(ProjPath);../Third-Party;../Third-Party/lape;../Third-Party/lape/extensions/ffi;script/imports;script/imports/lcl;script;matchtemplate;imagebox;components;image;hash;ide;tools"/>
<UnitOutputDirectory Value="$(ProjPath)../build/$(BuildMode)/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
Expand Down Expand Up @@ -245,7 +245,7 @@
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir);$(LazarusDir)/components/synedit;../Third-Party/lape;shapebuilders"/>
<OtherUnitFiles Value="$(ProjPath);../Third-Party;../Third-Party/lape;../Third-Party/lape/extensions/ffi;script/imports;script/imports/lcl;script;matchtemplate;algorithms;imagebox;components;image;hash;ide;tools"/>
<OtherUnitFiles Value="$(ProjPath);../Third-Party;../Third-Party/lape;../Third-Party/lape/extensions/ffi;script/imports;script/imports/lcl;script;matchtemplate;imagebox;components;image;hash;ide;tools"/>
<UnitOutputDirectory Value="$(ProjPath)../build/$(BuildMode)/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
Expand Down Expand Up @@ -298,7 +298,7 @@
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir);$(LazarusDir)/components/synedit;../Third-Party/lape;shapebuilders"/>
<OtherUnitFiles Value="$(ProjPath);../Third-Party;../Third-Party/lape;../Third-Party/lape/extensions/ffi;script/imports;script/imports/lcl;script;matchtemplate;algorithms;imagebox;components;image;hash;ide;tools"/>
<OtherUnitFiles Value="$(ProjPath);../Third-Party;../Third-Party/lape;../Third-Party/lape/extensions/ffi;script/imports;script/imports/lcl;script;matchtemplate;imagebox;components;image;hash;ide;tools"/>
<UnitOutputDirectory Value="$(ProjPath)../build/$(BuildMode)/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
Expand Down Expand Up @@ -379,7 +379,7 @@
<PackageName Value="LCL"/>
</Item5>
</RequiredPackages>
<Units Count="49">
<Units Count="55">
<Unit0>
<Filename Value="Simba.lpr"/>
<IsPartOfProject Value="True"/>
Expand Down Expand Up @@ -636,6 +636,30 @@
<Filename Value="simba.array_algorithm.pas"/>
<IsPartOfProject Value="True"/>
</Unit48>
<Unit49>
<Filename Value="ide/simba.ide_package_autoupdater.pas"/>
<IsPartOfProject Value="True"/>
</Unit49>
<Unit50>
<Filename Value="ide/simba.ide_package_installer.pas"/>
<IsPartOfProject Value="True"/>
</Unit50>
<Unit51>
<Filename Value="ide/simba.ide_package.pas"/>
<IsPartOfProject Value="True"/>
</Unit51>
<Unit52>
<Filename Value="ide/simba.ide_package_components.pas"/>
<IsPartOfProject Value="True"/>
</Unit52>
<Unit53>
<Filename Value="ide/simba.ide_package_endpointcustom.pas"/>
<IsPartOfProject Value="True"/>
</Unit53>
<Unit54>
<Filename Value="ide/simba.ide_package_endpointgithub.pas"/>
<IsPartOfProject Value="True"/>
</Unit54>
</Units>
</ProjectOptions>
<CompilerOptions>
Expand All @@ -646,7 +670,7 @@
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir);$(LazarusDir)/components/synedit;../Third-Party/lape;shapebuilders"/>
<Libraries Value="../Third-Party/lape/extensions/ffi/bin/win64"/>
<OtherUnitFiles Value="$(ProjPath);../Third-Party;../Third-Party/lape;../Third-Party/lape/extensions/ffi;script/imports;script/imports/lcl;script;matchtemplate;algorithms;imagebox;components;image;hash;ide;tools"/>
<OtherUnitFiles Value="$(ProjPath);../Third-Party;../Third-Party/lape;../Third-Party/lape/extensions/ffi;script/imports;script/imports/lcl;script;matchtemplate;imagebox;components;image;hash;ide;tools"/>
<UnitOutputDirectory Value="$(ProjPath)../build/$(BuildMode)/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
Expand Down
137 changes: 71 additions & 66 deletions Source/ide/simba.form_openexample.pas
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ TSimbaOpenExampleForm = class(TForm)
procedure DoSplitterEnterExit(Sender: TObject);
procedure DoTreeViewSelectionChanged(Sender: TObject);

procedure AddPackageExamples;
procedure UpdateTreeSize;

procedure AddSimbaExamples;
public
procedure ClearPackageExamples;
procedure AddPackageExamples(PackageName: String; Files: TStringArray);
end;

var
Expand All @@ -45,8 +50,7 @@ implementation

uses
LCLType, AnchorDocking,
simba.form_main, simba.form_tabs, simba.ide_package, simba.files, simba.ide_theme,
simba.vartype_string;
simba.form_main, simba.form_tabs, simba.files, simba.ide_theme;

function ReadResourceString(ResourceName: String): String;
begin
Expand All @@ -69,63 +73,70 @@ TExampleNode = class(TTreeNode)
Script: String;
end;

procedure TSimbaOpenExampleForm.AddPackageExamples;
procedure TSimbaOpenExampleForm.AddSimbaExamples;
var
SimbaNode: TTreeNode;

procedure AddNode(const AParentNode: TTreeNode; const AFileName: String);
procedure AddNode(const Name, ResourceName: String);
begin
with TExampleNode(TreeView.AddNode(AParentNode, TSimbaPath.PathExtractNameWithoutExt(AFileName), IMG_SIMBA)) do
FileName := AFileName;
with TExampleNode(TreeView.AddNode(SimbaNode, Name, IMG_SIMBA)) do
Script := ReadResourceString(ResourceName);
end;

var
I, MaxWidth: Integer;
Node, ParentNode: TTreeNode;
FileName: String;
Files: TStringArray;
Packages: TSimbaPackageArray;
Str: String;
begin
TreeView.BeginUpdate();
for I := 1 to TreeView.Items.TopLvlCount - 1 do // I := 1 to skip Simba node
TreeView.Items.TopLvlItems[I].Free();

Packages := GetInstalledPackages();
for I := 0 to High(Packages) do
begin
Files := Packages[I].GetExamples();
if (Length(Files) = 0) then
Continue;

Str := Packages[I].URL;
while (Str.Count('/') > 1) do
Str := Str.After('/');
SimbaNode := TExampleNode(TreeView.AddNode('Simba', IMG_PACKAGE));

ParentNode := TreeView.AddNode(Str, IMG_PACKAGE);
for FileName in Files do
AddNode(ParentNode, FileName);
end;
FreePackages(Packages);
AddNode('Array', 'EXAMPLE_ARRAY' );
AddNode('Image', 'EXAMPLE_IMAGE' );
AddNode('Function', 'EXAMPLE_FUNCTION' );
AddNode('Loop', 'EXAMPLE_LOOP' );
AddNode('Stopwatch', 'EXAMPLE_STOPWATCH' );
AddNode('Point Cluster', 'EXAMPLE_CLUSTER_POINTS' );
AddNode('Mouse Teleport Event', 'EXAMPLE_MOUSE_TELEPORT_EVENT');
AddNode('Static Method', 'EXAMPLE_STATIC_METHOD' );
AddNode('JSON', 'EXAMPLE_JSON' );
AddNode('Form', 'EXAMPLE_FORM' );
AddNode('Image Box', 'EXAMPLE_IMAGEBOX' );
AddNode('IRC', 'EXAMPLE_IRC' );
AddNode('Draw Text', 'EXAMPLE_DRAWTEXT' );
AddNode('RandomLeft', 'EXAMPLE_RANDOMLEFT' );

TreeView.EndUpdate();
end;

MaxWidth := 0;
Node := TreeView.Items.GetFirstNode();
while Assigned(Node) do
begin
MaxWidth := Max(MaxWidth, Node.DisplayTextRight);
procedure TSimbaOpenExampleForm.ClearPackageExamples;
var
I: Integer;
begin
for I := TreeView.Items.TopLvlCount - 1 downto 1 do
TreeView.Items.TopLvlItems[I].Free();
end;

Node := Node.GetNext();
end;
procedure TSimbaOpenExampleForm.AddPackageExamples(PackageName: String; Files: TStringArray);
var
I: Integer;
Node: TTreeNode;
begin
TreeView.BeginUpdate();
if Assigned(TreeView.Items.FindTopLvlNode(PackageName)) then
TreeView.Items.FindTopLvlNode(PackageName).Free();

LeftPanel.Width := MaxWidth + TreeView.ScrollbarVert.Width+1;
Node := TreeView.AddNode(PackageName, IMG_PACKAGE);
for I := 0 to High(Files) do
with TExampleNode(TreeView.AddNode(Node, TSimbaPath.PathExtractNameWithoutExt(Files[I]), IMG_SIMBA)) do
FileName := Files[I];

TreeView.EndUpdate();

UpdateTreeSize();
end;

procedure TSimbaOpenExampleForm.FormShow(Sender: TObject);
begin
Splitter.Width := DockMaster.SplitterWidth;

AddPackageExamples();

TreeView.ClearSelection();
TreeView.FullExpand();
end;
Expand Down Expand Up @@ -161,15 +172,6 @@ procedure TSimbaOpenExampleForm.DoSplitterEnterExit(Sender: TObject);
end;

procedure TSimbaOpenExampleForm.FormCreate(Sender: TObject);
var
SimbaNode: TTreeNode;

procedure AddNode(const Name, ResourceName: String);
begin
with TExampleNode(TreeView.AddNode(SimbaNode, Name, IMG_SIMBA)) do
Script := ReadResourceString(ResourceName);
end;

begin
Width := Scale96ToScreen(800);
Height := Scale96ToScreen(600);
Expand All @@ -195,22 +197,8 @@ procedure TSimbaOpenExampleForm.FormCreate(Sender: TObject);
ButtonPanel.Parent := Self;
ButtonPanel.ButtonOk.OnClick := @DoButtonOkClick;

SimbaNode := TExampleNode(TreeView.AddNode('Simba', IMG_PACKAGE));

AddNode('Array', 'EXAMPLE_ARRAY' );
AddNode('Image', 'EXAMPLE_IMAGE' );
AddNode('Function', 'EXAMPLE_FUNCTION' );
AddNode('Loop', 'EXAMPLE_LOOP' );
AddNode('Stopwatch', 'EXAMPLE_STOPWATCH' );
AddNode('Point Cluster', 'EXAMPLE_CLUSTER_POINTS' );
AddNode('Mouse Teleport Event', 'EXAMPLE_MOUSE_TELEPORT_EVENT');
AddNode('Static Method', 'EXAMPLE_STATIC_METHOD' );
AddNode('JSON', 'EXAMPLE_JSON' );
AddNode('Form', 'EXAMPLE_FORM' );
AddNode('Image Box', 'EXAMPLE_IMAGEBOX' );
AddNode('IRC', 'EXAMPLE_IRC' );
AddNode('Draw Text', 'EXAMPLE_DRAWTEXT' );
AddNode('RandomLeft', 'EXAMPLE_RANDOMLEFT' );
AddSimbaExamples();
UpdateTreeSize();
end;

procedure TSimbaOpenExampleForm.DoTreeViewSelectionChanged(Sender: TObject);
Expand All @@ -236,5 +224,22 @@ procedure TSimbaOpenExampleForm.DoTreeViewSelectionChanged(Sender: TObject);
Editor.Visible := False;
end;

procedure TSimbaOpenExampleForm.UpdateTreeSize;
var
Node: TTreeNode;
MaxWidth: Integer;
begin
MaxWidth := 0;

Node := TreeView.Items.GetFirstNode();
while Assigned(Node) do
begin
MaxWidth := Max(MaxWidth, Node.DisplayTextRight);
Node := Node.GetNext();
end;

LeftPanel.Width := MaxWidth + TreeView.ScrollbarVert.Width + 1;
end;

end.

41 changes: 19 additions & 22 deletions Source/ide/simba.form_package.pas
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ implementation

uses
simba.form_packageinstall, simba.ide_package_installer, simba.ide_package_autoupdater,
simba.base, simba.dialog, simba.threading;
simba.base, simba.dialog, simba.ide_utils, simba.vartype_stringarray;

procedure TSimbaPackageForm.FormShow(Sender: TObject);
begin
Expand All @@ -97,27 +97,32 @@ procedure TSimbaPackageForm.DoAutoUpdateClicked(Sender: TObject);

procedure TSimbaPackageForm.DoRefresh(Data: PtrInt);
var
Packages: TSimbaPackageArray;
URLs: TStringArray;

procedure Load;
procedure DoLoadURLs;
begin
Packages := LoadPackages();
URLs := GetDefaultPackageURLs() + GetLocalPackageURLs(False);
URLs := URLs.Unique(); // remove duplicates if a default, but local package is installed
end;

var
Thread: TThread;
I: Integer;
Packages: TSimbaPackageArray;
Procs: array of TProcedureOfObject;
begin
BeginLoading();

Thread := RunInThread(@Load);
while (not Thread.Finished) do
begin
Application.ProcessMessages();
Application.RunInThreadAndWait(@DoLoadURLs);

Sleep(50);
SetLength(Packages, Length(URLs));
SetLength(Procs, Length(URLs));
for I := 0 to High(URLs) do
begin
Packages[I] := TSimbaPackage.Create(URLs[I]);
Procs[I] := @Packages[I].Load;
end;
Thread.Free();

Application.RunInThreadsAndWait(Procs);

FListBox.Items.BeginUpdate();
FListBox.Items.Clear();
Expand All @@ -134,13 +139,12 @@ procedure TSimbaPackageForm.ButtonAddRepositoryClick(Sender: TObject);
var
Package: TSimbaPackage;

procedure Load;
procedure DoLoad;
begin
Package.Load();
end;

var
Thread: TThread;
URL: String;
begin
URL := '';
Expand All @@ -155,14 +159,7 @@ procedure TSimbaPackageForm.ButtonAddRepositoryClick(Sender: TObject);

BeginLoading();

Thread := RunInThread(@Load);
while (not Thread.Finished) do
begin
Application.ProcessMessages();

Sleep(50);
end;
Thread.Free();
Application.RunInThreadAndWait(@DoLoad);

if Package.Exists then
begin
Expand Down Expand Up @@ -196,7 +193,7 @@ procedure TSimbaPackageForm.DoPackageSelectionChanged(Sender: TObject; User: Boo

PageVersions.Show();

FInfoBox.SetInfo(Package.Info.HomepageURL, Package.InstalledVersion, Package.LatestVersion);
FInfoBox.SetInfo(Package.Info.URL, Package.InstalledVersion, Package.LatestVersion);
FInfoBox.AutoUpdateChecked := Package.AutoUpdateEnabled;

FVersionBox.BeginUpdate();
Expand Down
Loading

0 comments on commit 179a5b3

Please sign in to comment.