mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-19 05:19:25 +02:00
IDE: make grouping in component palette popup window more generic. Group pages by first word.
git-svn-id: trunk@42592 -
This commit is contained in:
parent
0fbcba1669
commit
e5384bc98b
@ -28,24 +28,12 @@ type
|
||||
procedure FormShow(Sender: TObject);
|
||||
procedure TreeView1Click(Sender: TObject);
|
||||
private
|
||||
fPopupItemIndy,
|
||||
fPopupItemGLScene,
|
||||
fPopupItemCindy,
|
||||
fPopupItemExtra,
|
||||
fPopupItemBGRA,
|
||||
fPopupItemDCP,
|
||||
fPopupItemACS,
|
||||
fPopupItemASIOVST,
|
||||
fPopupItemVirtual,
|
||||
fPopupItemSCADA,
|
||||
fPopupItemFZControls,
|
||||
fPopupItemLuiControls,
|
||||
fPopupItemShapes,
|
||||
fPopupItemRX :TTreeNode;
|
||||
fGroups: TStringList; // Objects have group TreeNodes
|
||||
procedure FindGroups;
|
||||
procedure BuildTreeItem(aPageCapt: string);
|
||||
procedure BuildList;
|
||||
public
|
||||
procedure FixBounds;
|
||||
procedure ClearList;
|
||||
procedure BuildList;
|
||||
end;
|
||||
|
||||
var
|
||||
@ -56,6 +44,17 @@ implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
function FirstWord(aStr: string): string;
|
||||
var
|
||||
spPos: integer;
|
||||
begin
|
||||
spPos := Pos(' ', aStr);
|
||||
if spPos > 0 then
|
||||
Result := Copy(aStr, 1, spPos-1)
|
||||
else
|
||||
Result := '';
|
||||
end;
|
||||
|
||||
{ TDlgCompPagesPopup }
|
||||
|
||||
procedure TDlgCompPagesPopup.FormShow(Sender: TObject);
|
||||
@ -65,7 +64,7 @@ end;
|
||||
|
||||
procedure TDlgCompPagesPopup.FormDeactivate(Sender: TObject);
|
||||
begin
|
||||
close;
|
||||
Close;
|
||||
end;
|
||||
|
||||
procedure TDlgCompPagesPopup.cBtnCloseClick(Sender: TObject);
|
||||
@ -76,149 +75,106 @@ end;
|
||||
procedure TDlgCompPagesPopup.FixBounds;
|
||||
begin
|
||||
if (self.Height+100)>screen.Height then
|
||||
self.Height:=screen.Height-self.Top-100 else
|
||||
self.Height:=Round(2*screen.Height/3) - self.Top;
|
||||
self.Height:=screen.Height-self.Top-100
|
||||
else
|
||||
self.Height:=Round(2*screen.Height/3) - self.Top;
|
||||
|
||||
if (self.Left+self.Width+50)>screen.Width then
|
||||
self.Left:=self.Left-(self.Width div 2)+10;
|
||||
self.Left:=self.Left-(self.Width div 2)+10;
|
||||
|
||||
if self.Height<400 then self.Height:=400;
|
||||
if self.Height<400 then
|
||||
self.Height:=400;
|
||||
end;
|
||||
|
||||
//---------------------------------------------------------------
|
||||
procedure TDlgCompPagesPopup.ClearList;
|
||||
begin
|
||||
TreeView1.Items.Clear;
|
||||
fPopupItemIndy:=nil;
|
||||
fPopupItemGLScene:=nil;
|
||||
fPopupItemCindy:=nil;
|
||||
fPopupItemExtra:=nil;
|
||||
fPopupItemBGRA:=nil;
|
||||
fPopupItemDCP:=nil;
|
||||
fPopupItemACS:=nil;
|
||||
fPopupItemASIOVST:=nil;
|
||||
fPopupItemVirtual:=nil;
|
||||
fPopupItemSCADA:=nil;
|
||||
fPopupItemRX:=nil;
|
||||
fPopupItemFZControls:=nil;
|
||||
fPopupItemLuiControls:=nil;
|
||||
fPopupItemShapes:=nil;
|
||||
end;
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
procedure TDlgCompPagesPopup.TreeView1Click(Sender: TObject);
|
||||
var
|
||||
id:integer;
|
||||
|
||||
procedure _findPage(const aname:string);
|
||||
var
|
||||
ix:integer;
|
||||
begin
|
||||
id:=-1;
|
||||
if MainIDEBar.ComponentPageControl=nil then exit;
|
||||
if MainIDEBar.ComponentPageControl.PageCount=0 then exit;
|
||||
|
||||
for ix:=0 to MainIDEBar.ComponentPageControl.PageCount-1 do
|
||||
if SameText(aname,MainIDEBar.ComponentPageControl.Page[ix].Caption) then
|
||||
begin
|
||||
id:=ix;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
i: integer;
|
||||
begin
|
||||
if TreeView1.Selected=nil then exit;
|
||||
if TreeView1.Selected.ImageIndex=1 then exit;
|
||||
|
||||
_findPage(TreeView1.Selected.Text);
|
||||
if id>-1 then
|
||||
MainIDEBar.ComponentPageControl.PageIndex:=id;
|
||||
|
||||
if (TreeView1.Selected=nil) or (TreeView1.Selected.ImageIndex=1) then exit;
|
||||
with MainIDEBar do
|
||||
if Assigned(ComponentPageControl) and (ComponentPageControl.PageCount>0) then
|
||||
for i:=0 to ComponentPageControl.PageCount-1 do
|
||||
if SameText(TreeView1.Selected.Text, ComponentPageControl.Page[i].Caption) then
|
||||
begin
|
||||
ComponentPageControl.PageIndex:=i;
|
||||
Break;
|
||||
end;
|
||||
Close;
|
||||
end;
|
||||
|
||||
procedure TDlgCompPagesPopup.FindGroups;
|
||||
// Find groups. Page names with many words are grouped by the first word.
|
||||
var
|
||||
i, grInd: integer;
|
||||
Word1: string;
|
||||
begin
|
||||
for i:=0 to MainIDEBar.ComponentPageControl.PageCount-1 do
|
||||
begin
|
||||
Word1 := FirstWord(MainIDEBar.ComponentPageControl.Page[i].Caption);
|
||||
if (Word1 <> '') and (Word1 <> 'Data') then // "Data" is an exception
|
||||
begin
|
||||
grInd := fGroups.IndexOf(Word1);
|
||||
if grInd > -1 then // Found, mark as group. TreeNode will be created later.
|
||||
fGroups.Objects[grInd] := TObject(0)
|
||||
else // Will be a group only if other members are found.
|
||||
fGroups.AddObject(Word1, TObject(1)); // "1" means a single item now.
|
||||
end;
|
||||
end;
|
||||
// Delete single items (marked with "1") from groups list.
|
||||
for i := fGroups.Count-1 downto 0 do
|
||||
if Assigned(fGroups.Objects[i]) then
|
||||
fGroups.Delete(i);
|
||||
end;
|
||||
|
||||
procedure TDlgCompPagesPopup.BuildTreeItem(aPageCapt: string);
|
||||
// Create items in tree, grouping as needed.
|
||||
var
|
||||
grInd: integer;
|
||||
Word1: string;
|
||||
GroupNode, ItemNode: TTreeNode;
|
||||
begin
|
||||
GroupNode := Nil;
|
||||
Word1 := FirstWord(aPageCapt);
|
||||
if Word1 <> '' then
|
||||
begin
|
||||
grInd := fGroups.IndexOf(Word1);
|
||||
if grInd > -1 then // Group found
|
||||
begin
|
||||
if Assigned(fGroups.Objects[grInd]) then
|
||||
GroupNode := TTreeNode(fGroups.Objects[grInd])
|
||||
else begin
|
||||
GroupNode := TreeView1.Items.AddChild(nil, Word1+' pages');
|
||||
fGroups.Objects[grInd] := GroupNode;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
ItemNode:=TreeView1.Items.AddChild(GroupNode, aPageCapt);
|
||||
ItemNode.ImageIndex:=0;
|
||||
ItemNode.SelectedIndex:=0;
|
||||
end;
|
||||
|
||||
procedure TDlgCompPagesPopup.BuildList;
|
||||
var
|
||||
isSubItem: boolean;
|
||||
|
||||
procedure AddGroup(var aGroupNode: TTreeNode; aGroupTitle, aPageTitle: string);
|
||||
var
|
||||
PageNode: TTreeNode;
|
||||
begin
|
||||
if aGroupNode=nil then
|
||||
begin
|
||||
aGroupNode:=TreeView1.Items.AddChild(nil, aGroupTitle);
|
||||
aGroupNode.ImageIndex:=1;
|
||||
aGroupNode.SelectedIndex:=1;
|
||||
end;
|
||||
PageNode:=TreeView1.Items.AddChild(aGroupNode, aPageTitle);
|
||||
PageNode.ImageIndex:=0;
|
||||
PageNode.SelectedIndex:=0;
|
||||
isSubItem:=true;
|
||||
end;
|
||||
|
||||
var
|
||||
i: integer;
|
||||
Node: TTreeNode;
|
||||
PageCapt: string;
|
||||
begin
|
||||
ClearList;
|
||||
TreeView1.Items.Clear;
|
||||
TreeView1.BeginUpdate;
|
||||
|
||||
if MainIDEBar.ComponentPageControl=nil then
|
||||
begin
|
||||
Node:=TreeView1.Items.AddChild(nil,'Sorry, NO Pages');
|
||||
Exit;
|
||||
end;
|
||||
|
||||
for i:=0 to MainIDEBar.ComponentPageControl.PageCount-1 do
|
||||
begin
|
||||
isSubItem:=false;
|
||||
PageCapt:=MainIDEBar.ComponentPageControl.Page[i].Caption;
|
||||
|
||||
//====================================================================
|
||||
if AnsiStartsText('Indy', PageCapt) then
|
||||
AddGroup(fPopupItemIndy, 'Indy pages', PageCapt)
|
||||
else if AnsiStartsText('GLScene', PageCapt) then
|
||||
AddGroup(fPopupItemGLScene, 'GLScene pages', PageCapt)
|
||||
else if AnsiStartsText('Cindy', PageCapt) then
|
||||
AddGroup(fPopupItemCindy, 'Cindy pages', PageCapt)
|
||||
else if AnsiStartsText('Extra', PageCapt) then
|
||||
AddGroup(fPopupItemExtra, 'Extra pages', PageCapt)
|
||||
else if AnsiStartsText('BGRA', PageCapt) then
|
||||
AddGroup(fPopupItemBGRA, 'BGRA pages', PageCapt)
|
||||
else if AnsiStartsText('DCP', PageCapt) then
|
||||
AddGroup(fPopupItemDCP, 'DCP pages', PageCapt)
|
||||
else if AnsiStartsText('RX', PageCapt) then
|
||||
AddGroup(fPopupItemRX, 'RX pages', PageCapt)
|
||||
else if AnsiStartsText('ACS', PageCapt) then
|
||||
AddGroup(fPopupItemACS, 'Audio ACS pages', PageCapt)
|
||||
else if AnsiStartsText('ASIO/VST', PageCapt) then
|
||||
AddGroup(fPopupItemASIOVST, 'Audio ASIO-VST pages', PageCapt)
|
||||
else if AnsiStartsText('Virtual Controls', PageCapt) then
|
||||
AddGroup(fPopupItemVirtual, 'Virtual Controls pages', PageCapt)
|
||||
else if AnsiStartsText('PascalSCADA', PageCapt) then
|
||||
AddGroup(fPopupItemSCADA, 'PascalSCADA pages', PageCapt)
|
||||
else if AnsiStartsText('FZControls', PageCapt) then
|
||||
AddGroup(fPopupItemFZControls, 'FZControls pages', PageCapt)
|
||||
else if AnsiStartsText('LuiControls', PageCapt) then
|
||||
AddGroup(fPopupItemLuiControls, 'LuiControls pages', PageCapt)
|
||||
else if AnsiStartsText('Shapes', PageCapt) then
|
||||
AddGroup(fPopupItemShapes, 'Shapes pages', PageCapt)
|
||||
;
|
||||
//====================================================================
|
||||
|
||||
if not isSubItem then
|
||||
begin
|
||||
Node:=TreeView1.Items.AddChild(nil,PageCapt);
|
||||
Node.ImageIndex:=0;
|
||||
Node.SelectedIndex:=0;
|
||||
end;
|
||||
fGroups := TStringList.Create;
|
||||
try
|
||||
FindGroups;
|
||||
for i:=0 to MainIDEBar.ComponentPageControl.PageCount-1 do
|
||||
BuildTreeItem(MainIDEBar.ComponentPageControl.Page[i].Caption);
|
||||
finally
|
||||
fGroups.Free;
|
||||
end;
|
||||
TreeView1.EndUpdate;
|
||||
TreeView1.FullExpand;
|
||||
//......
|
||||
Panel2.Caption:='Total Pages: '+IntToStr(MainIDEBar.ComponentPageControl.PageCount);
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user