fix #263 - Project explorer, display a tree instead of full paths

This commit is contained in:
Basile Burg 2018-03-16 22:56:17 +01:00
parent 4d3ab5b142
commit ddf8e9b0fa
3 changed files with 128 additions and 29 deletions

View File

@ -189,7 +189,7 @@ var
x, y: integer; x, y: integer;
begin begin
inherited; inherited;
if (fResourceName <> '') and (style in [tbsButton, tbsDropDown]) then if (fResourceName <> '') and (style in [tbsButton, tbsDropDown, tbsCheck]) then
begin begin
rc := ClientRect; rc := ClientRect;
if Style = tbsDropDown then if Style = tbsDropDown then

View File

@ -1,32 +1,32 @@
inherited CEProjectInspectWidget: TCEProjectInspectWidget inherited CEProjectInspectWidget: TCEProjectInspectWidget
Left = 1571 Left = 1443
Height = 258 Height = 258
Top = 91 Top = 213
Width = 341 Width = 376
ActiveControl = Tree ActiveControl = Tree
AllowDropFiles = True AllowDropFiles = True
Caption = 'Project inspector' Caption = 'Project inspector'
ClientHeight = 258 ClientHeight = 258
ClientWidth = 341 ClientWidth = 376
OnDropFiles = FormDropFiles OnDropFiles = FormDropFiles
inherited Back: TPanel inherited Back: TPanel
Height = 258 Height = 258
Width = 341 Width = 376
AutoSize = True AutoSize = True
ClientHeight = 258 ClientHeight = 258
ClientWidth = 341 ClientWidth = 376
inherited Content: TPanel inherited Content: TPanel
Height = 224 Height = 222
Top = 34 Top = 36
Width = 341 Width = 376
ClientHeight = 224 ClientHeight = 222
ClientWidth = 341 ClientWidth = 376
PopupMenu = nil PopupMenu = nil
object Tree: TTreeView[0] object Tree: TTreeView[0]
Left = 2 Left = 2
Height = 220 Height = 218
Top = 2 Top = 2
Width = 337 Width = 372
Align = alClient Align = alClient
AutoExpand = True AutoExpand = True
BorderSpacing.Around = 2 BorderSpacing.Around = 2
@ -51,10 +51,9 @@ inherited CEProjectInspectWidget: TCEProjectInspectWidget
end end
end end
inherited toolbar: TCEToolBar inherited toolbar: TCEToolBar
Height = 28 Width = 368
Width = 333
object btnRemFold: TCEToolButton[0] object btnRemFold: TCEToolButton[0]
Left = 85 Left = 113
Hint = 'remove the selected source parent folder from the project' Hint = 'remove the selected source parent folder from the project'
Top = 0 Top = 0
AutoSize = True AutoSize = True
@ -64,7 +63,7 @@ inherited CEProjectInspectWidget: TCEProjectInspectWidget
scaledSeparator = False scaledSeparator = False
end end
object btnAddFold: TCEToolButton[1] object btnAddFold: TCEToolButton[1]
Left = 57 Left = 85
Hint = 'add a folder of sources to the project' Hint = 'add a folder of sources to the project'
Top = 0 Top = 0
AutoSize = True AutoSize = True
@ -74,7 +73,7 @@ inherited CEProjectInspectWidget: TCEProjectInspectWidget
scaledSeparator = False scaledSeparator = False
end end
object btnRemFile: TCEToolButton[2] object btnRemFile: TCEToolButton[2]
Left = 29 Left = 57
Hint = 'remove selected source from the project' Hint = 'remove selected source from the project'
Top = 0 Top = 0
AutoSize = True AutoSize = True
@ -84,7 +83,7 @@ inherited CEProjectInspectWidget: TCEProjectInspectWidget
scaledSeparator = False scaledSeparator = False
end end
object btnAddFile: TCEToolButton[3] object btnAddFile: TCEToolButton[3]
Left = 1 Left = 29
Hint = 'add a source to the project' Hint = 'add a source to the project'
Top = 0 Top = 0
AutoSize = True AutoSize = True
@ -94,22 +93,33 @@ inherited CEProjectInspectWidget: TCEProjectInspectWidget
scaledSeparator = False scaledSeparator = False
end end
object TreeFilterEdit1: TTreeFilterEdit[4] object TreeFilterEdit1: TTreeFilterEdit[4]
Left = 117 Left = 145
Height = 24 Height = 26
Hint = 'filter the source names that contain the text typed here' Hint = 'filter the source names that contain the text typed here'
Top = 2 Top = 2
Width = 214 Width = 221
ButtonWidth = 28 ButtonWidth = 28
NumGlyphs = 1 NumGlyphs = 1
Align = alClient Align = alClient
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 114 BorderSpacing.Left = 142
BorderSpacing.Around = 2 BorderSpacing.Around = 2
MaxLength = 0 MaxLength = 0
TabOrder = 0 TabOrder = 0
FilteredTreeview = Tree FilteredTreeview = Tree
ExpandAllInitially = True ExpandAllInitially = True
end end
object btnTree: TCEToolButton[5]
Left = 1
Hint = 'display the file list as a tree'
Top = 0
AutoSize = True
Caption = 'btnTree'
OnClick = btnTreeClick
Style = tbsCheck
resourceName = 'FOLDERS_EXPLORER'
scaledSeparator = False
end
end end
end end
inherited contextMenu: TPopupMenu inherited contextMenu: TPopupMenu

View File

@ -8,10 +8,17 @@ uses
Classes, SysUtils, TreeFilterEdit, Forms, Controls, Graphics, actnlist, Classes, SysUtils, TreeFilterEdit, Forms, Controls, Graphics, actnlist,
Dialogs, ExtCtrls, ComCtrls, Menus, Buttons, lcltype, ce_ceproject, ce_interfaces, Dialogs, ExtCtrls, ComCtrls, Menus, Buttons, lcltype, ce_ceproject, ce_interfaces,
ce_common, ce_widget, ce_observer, ce_dialogs, ce_sharedres, ce_dsgncontrols, ce_common, ce_widget, ce_observer, ce_dialogs, ce_sharedres, ce_dsgncontrols,
ce_dubproject, ce_synmemo; ce_dubproject, ce_synmemo, ce_stringrange, ce_writableComponent;
type type
TCEProjectInspectorOptions = class(TWritableLfmTextComponent)
private
fFileListAsTree: boolean;
published
property fileListAsTree: boolean read fFileListAsTree write fFileListAsTree;
end;
{ TCEProjectInspectWidget } { TCEProjectInspectWidget }
TCEProjectInspectWidget = class(TCEWidget, ICEProjectObserver, ICEDocumentObserver) TCEProjectInspectWidget = class(TCEWidget, ICEProjectObserver, ICEDocumentObserver)
@ -19,12 +26,14 @@ type
btnAddFold: TCEToolButton; btnAddFold: TCEToolButton;
btnRemFile: TCEToolButton; btnRemFile: TCEToolButton;
btnRemFold: TCEToolButton; btnRemFold: TCEToolButton;
btnTree: TCEToolButton;
Tree: TTreeView; Tree: TTreeView;
TreeFilterEdit1: TTreeFilterEdit; TreeFilterEdit1: TTreeFilterEdit;
procedure btnAddFileClick(Sender: TObject); procedure btnAddFileClick(Sender: TObject);
procedure btnAddFoldClick(Sender: TObject); procedure btnAddFoldClick(Sender: TObject);
procedure btnRemFileClick(Sender: TObject); procedure btnRemFileClick(Sender: TObject);
procedure btnRemFoldClick(Sender: TObject); procedure btnRemFoldClick(Sender: TObject);
procedure btnTreeClick(Sender: TObject);
procedure FormDropFiles(Sender: TObject; const fnames: array of String); procedure FormDropFiles(Sender: TObject; const fnames: array of String);
procedure TreeClick(Sender: TObject); procedure TreeClick(Sender: TObject);
procedure TreeDeletion(Sender: TObject; Node: TTreeNode); procedure TreeDeletion(Sender: TObject; Node: TTreeNode);
@ -44,6 +53,7 @@ type
fLastFileOrFolder: string; fLastFileOrFolder: string;
fSymStringExpander: ICESymStringExpander; fSymStringExpander: ICESymStringExpander;
fImages: TImageList; fImages: TImageList;
fFileListAsTree: boolean;
procedure actUpdate(sender: TObject); procedure actUpdate(sender: TObject);
procedure DetectNewDubSources(const document: TCESynMemo); procedure DetectNewDubSources(const document: TCESynMemo);
procedure TreeDblClick(sender: TObject); procedure TreeDblClick(sender: TObject);
@ -57,6 +67,7 @@ type
procedure projCompiling(project: ICECommonProject); procedure projCompiling(project: ICECommonProject);
procedure projCompiled(project: ICECommonProject; success: boolean); procedure projCompiled(project: ICECommonProject; success: boolean);
procedure updateButtons; procedure updateButtons;
procedure setFileListAsTree(value: boolean);
// //
procedure docNew(document: TCESynMemo); procedure docNew(document: TCESynMemo);
procedure docFocused(document: TCESynMemo); procedure docFocused(document: TCESynMemo);
@ -69,13 +80,18 @@ type
public public
constructor create(aOwner: TComponent); override; constructor create(aOwner: TComponent); override;
destructor destroy; override; destructor destroy; override;
property fileListAsTree: boolean read fFileListAsTree write setFileListAsTree;
end; end;
implementation implementation
{$R *.lfm} {$R *.lfm}
const optFname = 'projinspect.txt';
{$REGION Standard Comp/Obj------------------------------------------------------} {$REGION Standard Comp/Obj------------------------------------------------------}
constructor TCEProjectInspectWidget.create(aOwner: TComponent); constructor TCEProjectInspectWidget.create(aOwner: TComponent);
var
fname: string;
begin begin
fSymStringExpander:= getSymStringExpander; fSymStringExpander:= getSymStringExpander;
@ -105,6 +121,7 @@ begin
fImages.AddResourceName(HINSTANCE, 'PAGE_TEXT'); fImages.AddResourceName(HINSTANCE, 'PAGE_TEXT');
fImages.AddResourceName(HINSTANCE, 'COG'); fImages.AddResourceName(HINSTANCE, 'COG');
fImages.AddResourceName(HINSTANCE, 'COG_GO'); fImages.AddResourceName(HINSTANCE, 'COG_GO');
fImages.AddResourceName(HINSTANCE, 'FOLDER');
AssignPng(TreeFilterEdit1.Glyph, 'FILTER_CLEAR'); AssignPng(TreeFilterEdit1.Glyph, 'FILTER_CLEAR');
end; end;
iss24: iss24:
@ -117,6 +134,7 @@ begin
fImages.AddResourceName(HINSTANCE, 'PAGE_TEXT24'); fImages.AddResourceName(HINSTANCE, 'PAGE_TEXT24');
fImages.AddResourceName(HINSTANCE, 'COG24'); fImages.AddResourceName(HINSTANCE, 'COG24');
fImages.AddResourceName(HINSTANCE, 'COG_GO24'); fImages.AddResourceName(HINSTANCE, 'COG_GO24');
fImages.AddResourceName(HINSTANCE, 'FOLDER24');
AssignPng(TreeFilterEdit1.Glyph, 'FILTER_CLEAR24'); AssignPng(TreeFilterEdit1.Glyph, 'FILTER_CLEAR24');
end; end;
iss32: iss32:
@ -129,6 +147,7 @@ begin
fImages.AddResourceName(HINSTANCE, 'PAGE_TEXT32'); fImages.AddResourceName(HINSTANCE, 'PAGE_TEXT32');
fImages.AddResourceName(HINSTANCE, 'COG32'); fImages.AddResourceName(HINSTANCE, 'COG32');
fImages.AddResourceName(HINSTANCE, 'COG_GO32'); fImages.AddResourceName(HINSTANCE, 'COG_GO32');
fImages.AddResourceName(HINSTANCE, 'FOLDER32');
AssignPng(TreeFilterEdit1.Glyph, 'FILTER_CLEAR32'); AssignPng(TreeFilterEdit1.Glyph, 'FILTER_CLEAR32');
end; end;
end; end;
@ -139,13 +158,33 @@ begin
Tree.Images := fImages; Tree.Images := fImages;
Tree.PopupMenu := contextMenu; Tree.PopupMenu := contextMenu;
TreeFilterEdit1.BorderSpacing.Left := ScaleX(114, 96); TreeFilterEdit1.BorderSpacing.Left := ScaleX(142, 96);
fname := getCoeditDocPath + optFname;
if fname.fileExists then
begin
with TCEProjectInspectorOptions.Create(nil) do
try
loadFromFile(fname);
self.setFileListAsTree(fileListAsTree);
btnTree.Down:=fileListAsTree;
finally
free;
end;
end;
EntitiesConnector.addObserver(self); EntitiesConnector.addObserver(self);
end; end;
destructor TCEProjectInspectWidget.destroy; destructor TCEProjectInspectWidget.destroy;
begin begin
with TCEProjectInspectorOptions.Create(nil) do
try
fileListAsTree:= self.fileListAsTree;
saveToFile(getCoeditDocPath + optFname);
finally
free;
end;
EntitiesConnector.removeObserver(self); EntitiesConnector.removeObserver(self);
inherited; inherited;
end; end;
@ -281,6 +320,14 @@ begin
btnAddFold.Enabled:= ce; btnAddFold.Enabled:= ce;
end; end;
procedure TCEProjectInspectWidget.setFileListAsTree(value: boolean);
begin
if fFileListAsTree = value then
exit;
fFileListAsTree:=value;
updateImperative;
end;
{$ENDREGION} {$ENDREGION}
{$REGION Inspector things -------------------------------------------------------} {$REGION Inspector things -------------------------------------------------------}
@ -335,7 +382,7 @@ begin
if not assigned(fProject) or Tree.Selected.isNil then if not assigned(fProject) or Tree.Selected.isNil then
exit; exit;
if Tree.Selected.Parent = fFileNode then if Tree.Selected.Parent <> fConfNode then
begin begin
if Tree.Selected.Data.isNotNil then if Tree.Selected.Data.isNotNil then
begin begin
@ -344,7 +391,7 @@ begin
getMultiDocHandler.openDocument(fname); getMultiDocHandler.openDocument(fname);
end; end;
end end
else if Tree.Selected.Parent = fConfNode then else
begin begin
i := Tree.Selected.Index; i := Tree.Selected.Index;
fProject.setActiveConfigurationIndex(i); fProject.setActiveConfigurationIndex(i);
@ -471,6 +518,11 @@ begin
proj.endUpdate; proj.endUpdate;
end; end;
procedure TCEProjectInspectWidget.btnTreeClick(Sender: TObject);
begin
setFileListAsTree(btnTree.Down);
end;
procedure TCEProjectInspectWidget.btnRemFileClick(Sender: TObject); procedure TCEProjectInspectWidget.btnRemFileClick(Sender: TObject);
var var
fname: string; fname: string;
@ -555,8 +607,11 @@ procedure TCEProjectInspectWidget.updateImperative;
var var
conf: string; conf: string;
itm: TTreeNode; itm: TTreeNode;
chd: TTreeNode;
i,j: integer; i,j: integer;
sel: string = ''; sel: string = '';
fld: string;
rng: TStringRange = (ptr:nil; pos:0; len:0);
begin begin
if Tree.Selected.isNotNil then if Tree.Selected.isNotNil then
sel := Tree.Selected.GetTextPath; sel := Tree.Selected.GetTextPath;
@ -567,13 +622,47 @@ begin
exit; exit;
Tree.BeginUpdate; Tree.BeginUpdate;
if not fFileListAsTree then
for i := 0 to fProject.sourcesCount-1 do for i := 0 to fProject.sourcesCount-1 do
begin begin
itm := Tree.Items.AddChild(fFileNode, fProject.sourceRelative(i)); itm := Tree.Items.AddChild(fFileNode, fProject.sourceRelative(i));
itm.Data:= NewStr(fProject.sourceAbsolute(i)); itm.Data:= NewStr(fProject.sourceAbsolute(i));
itm.ImageIndex := 2; itm.ImageIndex := 2;
itm.SelectedIndex := 2; itm.SelectedIndex := 2;
end
else
for i := 0 to fProject.sourcesCount-1 do
begin
fld := '';
rng.init(fProject.sourceRelative(i));
itm := fFileNode;
while not rng.empty do
begin
chd := nil;
fld := rng.takeUntil(['/','\']).yield;
chd := itm.FindNode(fld);
if chd.isNil then
chd := Tree.Items.AddChild(itm, fld);
itm := chd;
// reached fname
if rng.empty then
begin
itm.Data:= NewStr(fProject.sourceAbsolute(i));
itm.ImageIndex := 2;
itm.SelectedIndex := 2;
end
// next folder or fname
else
begin
rng.popWhile(['/','\']);
itm.ImageIndex := 5;
itm.SelectedIndex := 5;
end; end;
end;
end;
j := fProject.getActiveConfigurationIndex; j := fProject.getActiveConfigurationIndex;
for i := 0 to fProject.configurationCount-1 do for i := 0 to fProject.configurationCount-1 do
begin begin