Skip to content

Commit

Permalink
Minor function list customization
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Mar 12, 2024
1 parent c5e35ca commit e292e8b
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 13 deletions.
32 changes: 30 additions & 2 deletions Source/forms/simba.functionlistform.lfm
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
object SimbaFunctionListForm: TSimbaFunctionListForm
Left = 1530
Left = -943
Height = 301
Top = 748
Top = 765
Width = 765
Caption = 'Function List'
DesignTimePPI = 120
PopupMenu = ContextMenu
ShowInTaskBar = stAlways
LCLVersion = '3.0.0.3'
object ContextMenu: TPopupMenu
OnPopup = ContextMenuPopup
Left = 55
Top = 53
object PopupItemShowMouseoverHint: TMenuItem
AutoCheck = True
Caption = 'Show Mouseover Hint'
OnClick = PopupItemShowMouseoverHintClick
end
object Separator1: TMenuItem
Caption = '-'
end
object PopupItemShowHide: TMenuItem
Caption = 'Show/Hide Section ...'
end
object Separator2: TMenuItem
Caption = '-'
end
object MenuItemShowAll: TMenuItem
Caption = 'Show All Sections'
OnClick = MenuItemShowAllClick
end
object MenuItemHideAll: TMenuItem
Caption = 'Hide All Sections'
OnClick = MenuItemHideAllClick
end
end
end
130 changes: 119 additions & 11 deletions Source/forms/simba.functionlistform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
interface

uses
Classes, SysUtils, Forms, Controls, ComCtrls, ExtCtrls, StrUtils,
Classes, SysUtils, Forms, Controls, ComCtrls, ExtCtrls, Menus, StrUtils,
simba.base, simba.ide_codetools_parser, simba.ide_codetools_insight, simba.component_treeview, simba.dictionary;

type
Expand All @@ -28,6 +28,17 @@ TSimbaFunctionListNode = class(TTreeNode)
end;

TSimbaFunctionListForm = class(TForm)
MenuItemHideAll: TMenuItem;
MenuItemShowAll: TMenuItem;
PopupItemShowMouseoverHint: TMenuItem;
PopupItemShowHide: TMenuItem;
ContextMenu: TPopupMenu;
Separator1: TMenuItem;
Separator2: TMenuItem;
procedure MenuItemHideAllClick(Sender: TObject);
procedure MenuItemShowAllClick(Sender: TObject);
procedure PopupItemShowMouseoverHintClick(Sender: TObject);
procedure ContextMenuPopup(Sender: TObject);
protected
type
TFunctionListState = record
Expand Down Expand Up @@ -72,6 +83,7 @@ TFunctionListState = record
procedure DoTabBeforeChange(Sender: TObject);
procedure DoTabChange(Sender: TObject);
procedure DoTabClosed(Sender: TObject);
procedure DoPopupShowHideClick(Sender: TObject);

procedure AddPluginsNode(Plugins: TCodeParserList; Hash: String);
procedure AddIncludesNode(Includes: TCodeParserList; Hash: String);
Expand All @@ -81,6 +93,9 @@ TFunctionListState = record
function AddSimbaDecl(ParentNode: TTreeNode; Decl: TDeclaration): TTreeNode;
function AddPluginDecl(ParentNode: TTreeNode; Decl: TDeclaration): TTreeNode;

function ShouldSimbaNodeBeHidden(S: String): Boolean;
procedure SetSimbaNodeShouldBeHidden(S: String; Hidden: Boolean);

procedure AddSimbaNodes;

procedure ArrangeBaseNodes;
Expand All @@ -99,7 +114,7 @@ implementation
{$R *.lfm}

uses
simba.main, simba.ide_events, simba.threading,
simba.main, simba.ide_events, simba.threading, simba.settings,
simba.scripttabsform, simba.scripttab, simba.ide_showdeclaration, simba.nativeinterface;

function GetImage(const Decl: TDeclaration): Integer;
Expand Down Expand Up @@ -153,6 +168,7 @@ function GetURL(const Section: String): String;
Result := '';

case Section of
'Base': Result := ROOT + 'Base.html';
'TPoint': Result := ROOT + 'TPoint.html';
'TPointArray': Result := ROOT + 'TPointArray.html';
'TBox': Result := ROOT + 'TBox.html';
Expand All @@ -161,8 +177,6 @@ function GetURL(const Section: String): String;
'Random': Result := ROOT + 'Random.html';
'T2DPointArray': Result := ROOT + 'T2DPointArray.html';
'Debug Image': Result := ROOT + 'Debug Image.html';
'Script': Result := ROOT + 'Script.html';
'Variant': Result := ROOT + 'Variant.html';
'TWindowHandle': Result := ROOT + 'TWindowHandle.html';
'Image': Result := ROOT + 'Image.html';
'Finder': Result := ROOT + 'Finder.html';
Expand All @@ -180,13 +194,66 @@ function GetURL(const Section: String): String;
'Math': Result := ROOT + 'Math.html';
'Matrix': Result := ROOT + 'Matrix.html';
'Misc': Result := ROOT + 'Misc.html';
'Dialogs': Result := ROOT + 'Dialogs.html';
'DTM': Result := ROOT + 'DTM.html';
'System': Result := ROOT + 'System.html';
'TCircle': Result := ROOT + 'TCircle.html';
end;
end;

procedure TSimbaFunctionListForm.ContextMenuPopup(Sender: TObject);
var
I: Integer;
Item: TMenuItem;
Val: String;
begin
if (PopupItemShowHide.Count = 0) then
for I := 0 to FSimbaNode.Count - 1 do
begin
Item := TMenuItem.Create(PopupItemShowHide);
Item.Caption := FSimbaNode.Items[I].Text;
Item.AutoCheck := True;
Item.OnClick := @DoPopupShowHideClick;

PopupItemShowHide.Add(Item);
end;

Val := SimbaSettings.FunctionList.HiddenSimbaSections.Value;
for I := 0 to PopupItemShowHide.Count - 1 do
PopupItemShowHide.Items[i].Checked := not (PopupItemShowHide.Items[I].Caption + ',' in Val);

PopupItemShowMouseoverHint.Checked := SimbaSettings.FunctionList.ShowMouseoverHint.Value;
end;

procedure TSimbaFunctionListForm.PopupItemShowMouseoverHintClick(Sender: TObject);
begin
SimbaSettings.FunctionList.ShowMouseoverHint.Value := TMenuItem(Sender).Checked;
end;

procedure TSimbaFunctionListForm.MenuItemShowAllClick(Sender: TObject);
var
I: Integer;
begin
SimbaSettings.FunctionList.HiddenSimbaSections.Value := '';
for I := 0 to FSimbaNode.Count - 1 do
FSimbaNode.Items[I].Visible := True;
ContextMenu.Close();
end;

procedure TSimbaFunctionListForm.MenuItemHideAllClick(Sender: TObject);
var
I: Integer;
Val: String;
begin
Val := '';
for I := 0 to PopupItemShowHide.Count - 1 do
Val += PopupItemShowHide.Items[I].Caption + ',';

SimbaSettings.FunctionList.HiddenSimbaSections.Value := Val;
for I := 0 to FSimbaNode.Count - 1 do
FSimbaNode.Items[I].Visible := False;

ContextMenu.Close();
end;

procedure TSimbaFunctionListForm.ResetState;

procedure HideAllIncludePluginNodes(const ANode: TTreeNode);
Expand Down Expand Up @@ -390,6 +457,17 @@ procedure TSimbaFunctionListForm.DoTabClosed(Sender: TObject);
DeleteState(TSimbaScriptTab(Sender).UID);
end;

procedure TSimbaFunctionListForm.DoPopupShowHideClick(Sender: TObject);
var
Node: TTreeNode;
begin
SetSimbaNodeShouldBeHidden(TMenuItem(Sender).Caption, not TMenuItem(Sender).Checked);

Node := FSimbaNode.FindNode(TMenuItem(Sender).Caption);
if Assigned(Node) then
Node.Visible := TMenuItem(Sender).Checked;
end;

procedure TSimbaFunctionListForm.AddPluginsNode(Plugins: TCodeParserList; Hash: String);
var
PluginsNode: TTreeNode = nil;
Expand Down Expand Up @@ -552,10 +630,17 @@ procedure TSimbaFunctionListForm.PurgeNodes;

function TSimbaFunctionListForm.DoGetNodeHint(const Node: TTreeNode): String;
begin
if (Node is TSimbaFunctionListNode) then
Result := TSimbaFunctionListNode(Node).Hint
else
Result := '';
Result := '';

if SimbaSettings.FunctionList.ShowMouseoverHint.Value then
begin
if (Node is TSimbaFunctionListNode) then
begin
Result := TSimbaFunctionListNode(Node).Hint;
if (Length(Result) > 100) then
Result := Copy(Result, 1, 100) + ' ...';
end;
end;
end;

procedure TSimbaFunctionListForm.DoSelectionChanged(Sender: TObject);
Expand Down Expand Up @@ -638,6 +723,27 @@ function TSimbaFunctionListForm.AddPluginDecl(ParentNode: TTreeNode; Decl: TDecl
end;
end;

function TSimbaFunctionListForm.ShouldSimbaNodeBeHidden(S: String): Boolean;
var
Val: String;
begin
Val := SimbaSettings.FunctionList.HiddenSimbaSections.Value;

Result := Val.Contains(S + ',');
end;

procedure TSimbaFunctionListForm.SetSimbaNodeShouldBeHidden(S: String; Hidden: Boolean);
var
Val: String;
begin
Val := SimbaSettings.FunctionList.HiddenSimbaSections.Value;
Val := Val.Replace(S + ',', ''); // remove
if Hidden then
Val := Val + S + ','; // add

SimbaSettings.FunctionList.HiddenSimbaSections.Value := Val;
end;

procedure TSimbaFunctionListForm.AddSimbaNodes;
var
I: Integer;
Expand All @@ -659,14 +765,16 @@ procedure TSimbaFunctionListForm.AddSimbaNodes;
NodeType := ntSimbaSection;
FileName := GetURL(Parser.Lexer.FileName);
if (FileName <> '') then
Hint := Text + ' (double click to open online documentation)';
Hint := Text + ' (double click to open online docs)';
end;

for Decl in Parser.Items.ToArray do
if (Decl.Name <> '') and (not Decl.isOverrideMethod) and (Decl.Name[1] <> '_') then
AddSimbaDecl(ParentNode, Decl);

ParentNode.CustomSort(@CompareNodes);
if ShouldSimbaNodeBeHidden(ParentNode.Text) then
ParentNode.Visible := False;
end;

FSimbaNode.AlphaSort();
Expand Down
8 changes: 8 additions & 0 deletions Source/simba.settings.pas
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ TSimbaSettings = class
Interval: TSimbaSetting;
end;

FunctionList: record
ShowMouseoverHint: TSimbaSetting;
HiddenSimbaSections: TSimbaSetting;
end;

property FirstLaunch: Boolean read FFirstLaunch;
property IsLoading: Boolean read FIsLoading;

Expand Down Expand Up @@ -544,6 +549,9 @@ constructor TSimbaSettings.Create;

ScriptBackup.Enabled := TSimbaSetting_Boolean.Create(Self, 'ScriptBackup', 'Enabled', True);
ScriptBackup.Interval := TSimbaSetting_Integer.Create(Self, 'ScriptBackup', 'Interval', 3);

FunctionList.ShowMouseoverHint := TSimbaSetting_Boolean.Create(Self, 'FunctionList', 'ShowMouseoverHint', True);
FunctionList.HiddenSimbaSections := TSimbaSetting_BinaryString.Create(Self, 'FunctionList', 'HiddenSimbaSections', '');
end;

destructor TSimbaSettings.Destroy;
Expand Down

0 comments on commit e292e8b

Please sign in to comment.