components: added filebrowser window from Graeme (issue #12178)

git-svn-id: trunk@16792 -
This commit is contained in:
vincents 2008-09-29 11:35:54 +00:00
parent 405c0f4928
commit 80244648f5
10 changed files with 952 additions and 0 deletions

9
.gitattributes vendored
View File

@ -303,6 +303,15 @@ components/editortoolbar/images/preferences16.xpm -text svneol=unset#image/x-xpi
components/editortoolbar/jumpto.pas svneol=native#text/plain
components/editortoolbar/jumpto_impl.pas svneol=native#text/plain
components/editortoolbar/toolbar.lrs svneol=native#text/plain
components/filebrowser/frmconfigfilebrowser.lfm svneol=native#text/plain
components/filebrowser/frmconfigfilebrowser.lrs svneol=native#text/plain
components/filebrowser/frmconfigfilebrowser.pp svneol=native#text/plain
components/filebrowser/frmfilebrowser.lfm svneol=native#text/plain
components/filebrowser/frmfilebrowser.lrs svneol=native#text/plain
components/filebrowser/frmfilebrowser.pas svneol=native#text/plain
components/filebrowser/idefilebrowser.lpk svneol=native#text/plain
components/filebrowser/idefilebrowser.pas svneol=native#text/plain
components/filebrowser/regidefilebrowser.pp svneol=native#text/plain
components/fpcunit/Makefile svneol=native#text/plain
components/fpcunit/Makefile.fpc svneol=native#text/plain
components/fpcunit/blueball.xpm svneol=native#text/plain

View File

@ -0,0 +1,69 @@
object FileBrowserConfigForm: TFileBrowserConfigForm
Left = 302
Height = 200
Top = 184
Width = 400
Caption = 'Configure file browser'
ClientHeight = 200
ClientWidth = 400
OnShow = FormShow
LCLVersion = '0.9.25'
object ButtonPanel1: TButtonPanel
Left = 6
Height = 46
Top = 154
Width = 388
Align = alBottom
AutoSize = True
TabOrder = 0
ShowButtons = [pbOK, pbCancel]
end
object GBStartDir: TGroupBox
Left = 6
Height = 136
Top = 8
Width = 386
Caption = 'Initial directory'
ClientHeight = 115
ClientWidth = 382
TabOrder = 1
object DEInitial: TDirectoryEdit
Left = 38
Height = 23
Top = 89
Width = 312
ButtonWidth = 23
ParentColor = False
TabOrder = 0
end
object RBThisDir: TRadioButton
Left = 14
Height = 24
Top = 65
Width = 205
Caption = 'Always use this directory'
OnClick = SelectInitialDir
TabOrder = 1
end
object RBLastDir: TRadioButton
Left = 14
Height = 24
Top = 36
Width = 211
Caption = 'Use last opened directory'
OnClick = SelectInitialDir
TabOrder = 2
end
object RBUseProjectDir: TRadioButton
Left = 14
Height = 24
Top = 9
Width = 231
Caption = 'Use current project directory'
Checked = True
OnClick = SelectInitialDir
State = cbChecked
TabOrder = 3
end
end
end

View File

@ -0,0 +1,23 @@
{ This is an automatically generated lazarus resource file }
LazarusResources.Add('TFileBrowserConfigForm','FORMDATA',[
'TPF0'#22'TFileBrowserConfigForm'#21'FileBrowserConfigForm'#4'Left'#3'.'#1#6
+'Height'#3#200#0#3'Top'#3#184#0#5'Width'#3#144#1#7'Caption'#6#22'Configure f'
+'ile browser'#12'ClientHeight'#3#200#0#11'ClientWidth'#3#144#1#6'OnShow'#7#8
+'FormShow'#10'LCLVersion'#6#6'0.9.25'#0#12'TButtonPanel'#12'ButtonPanel1'#4
+'Left'#2#6#6'Height'#2'.'#3'Top'#3#154#0#5'Width'#3#132#1#5'Align'#7#8'alBot'
+'tom'#8'AutoSize'#9#8'TabOrder'#2#0#11'ShowButtons'#11#4'pbOK'#8'pbCancel'#0
+#0#0#9'TGroupBox'#10'GBStartDir'#4'Left'#2#6#6'Height'#3#136#0#3'Top'#2#8#5
+'Width'#3#130#1#7'Caption'#6#17'Initial directory'#12'ClientHeight'#2's'#11
+'ClientWidth'#3'~'#1#8'TabOrder'#2#1#0#14'TDirectoryEdit'#9'DEInitial'#4'Lef'
+'t'#2'&'#6'Height'#2#23#3'Top'#2'Y'#5'Width'#3'8'#1#11'ButtonWidth'#2#23#11
+'ParentColor'#8#8'TabOrder'#2#0#0#0#12'TRadioButton'#9'RBThisDir'#4'Left'#2
+#14#6'Height'#2#24#3'Top'#2'A'#5'Width'#3#205#0#7'Caption'#6#25'Always use t'
+'his directory'#7'OnClick'#7#16'SelectInitialDir'#8'TabOrder'#2#1#0#0#12'TRa'
+'dioButton'#9'RBLastDir'#4'Left'#2#14#6'Height'#2#24#3'Top'#2'$'#5'Width'#3
+#211#0#7'Caption'#6#25'Use last opened directory'#7'OnClick'#7#16'SelectInit'
+'ialDir'#8'TabOrder'#2#2#0#0#12'TRadioButton'#15'RBUseProjectDir'#4'Left'#2
+#14#6'Height'#2#24#3'Top'#2#9#5'Width'#3#231#0#7'Caption'#6#29'Use current p'
+'roject directory'#7'Checked'#9#7'OnClick'#7#16'SelectInitialDir'#5'State'#7
+#9'cbChecked'#8'TabOrder'#2#3#0#0#0#0
]);

View File

@ -0,0 +1,96 @@
unit frmconfigfilebrowser;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
FileUtil,
LResources,
Forms,
Controls,
Graphics,
Dialogs,
StdCtrls,
EditBtn,
ButtonPanel;
type
TStartDir = (sdProjectDir, sdLastOpened, sdCustomDir);
TFileBrowserConfigForm = class(TForm)
ButtonPanel1: TButtonPanel;
DEInitial: TDirectoryEdit;
GBStartDir: TGroupBox;
RBThisDir: TRadioButton;
RBLastDir: TRadioButton;
RBUseProjectDir: TRadioButton;
procedure FormShow(Sender: TObject);
procedure SelectInitialDir(Sender: TObject);
private
function GetCustomDir: string;
function GetStartDir: TStartDir;
procedure SetCustomDir(const AValue: string);
procedure SetStartDir(const AValue: TStartDir);
public
property StartDir: TStartDir read GetStartDir write SetStartDir;
property CustomDir: string read GetCustomDir write SetCustomDir;
end;
var
FileBrowserConfigForm: TFileBrowserConfigForm;
implementation
{ TFileBrowserConfigForm }
procedure TFileBrowserConfigForm.SelectInitialDir(Sender: TObject);
begin
DEinitial.Enabled := RBThisDir.Checked;
end;
procedure TFileBrowserConfigForm.FormShow(Sender: TObject);
begin
SelectInitialDir(nil);
end;
function TFileBrowserConfigForm.GetCustomDir: string;
begin
Result := DEinitial.Directory;
end;
function TFileBrowserConfigForm.GetStartDir: TStartDir;
begin
if RBUseProjectDir.Checked then
Result := sdProjectDir
else if RBLastDir.Checked then
Result := sdLastOpened
else
Result := sdCustomDir;
end;
procedure TFileBrowserConfigForm.SetCustomDir(const AValue: string);
begin
DEinitial.Directory := AValue;
end;
procedure TFileBrowserConfigForm.SetStartDir(const AValue: TStartDir);
var
RB: TRadioButton;
begin
case AValue of
sdProjectDir: RB := RBUseProjectDir;
sdLastOpened: RB := RBLastDir;
sdCustomDir: RB := RBThisDir;
end;
RB.Checked := True;
end;
initialization
{$I frmconfigfilebrowser.lrs}
end.

View File

@ -0,0 +1,68 @@
object FileBrowserForm: TFileBrowserForm
Left = 305
Height = 434
Top = 466
Width = 385
Caption = 'File Browser'
ClientHeight = 434
ClientWidth = 385
OnClose = FormClose
OnCreate = FormCreate
OnShow = FormShow
LCLVersion = '0.9.25'
object FileListBox: TFileListBox
Height = 186
Top = 248
Width = 385
Align = alClient
Directory = '/home/graemeg'
FileType = [ftArchive, ftNormal]
OnDblClick = FileListBoxDblClick
TabOrder = 0
end
object TV: TTreeView
Height = 201
Top = 42
Width = 385
Align = alTop
DefaultItemHeight = 18
TabOrder = 1
OnExpanded = TVExpanded
OnSelectionChanged = TVSelectionChanged
end
object Panel1: TPanel
Height = 42
Width = 385
Align = alTop
BevelOuter = bvNone
ClientHeight = 42
ClientWidth = 385
TabOrder = 2
object cbHidden: TCheckBox
Left = 200
Height = 24
Top = 8
Width = 154
Caption = 'Show hidden files'
OnChange = cbHiddenChange
TabOrder = 0
end
object btnConfigure: TButton
Left = 8
Height = 25
Top = 7
Width = 90
Caption = 'Configure'
OnClick = btnConfigureClick
TabOrder = 1
end
end
object Splitter1: TSplitter
Cursor = crVSplit
Height = 5
Top = 243
Width = 385
Align = alTop
ResizeAnchor = akTop
end
end

View File

@ -0,0 +1,21 @@
LazarusResources.Add('TFileBrowserForm','FORMDATA',[
'TPF0'#16'TFileBrowserForm'#15'FileBrowserForm'#4'Left'#3'1'#1#6'Height'#3#178
+#1#3'Top'#3#210#1#5'Width'#3#129#1#7'Caption'#6#12'File Browser'#12'ClientHe'
+'ight'#3#178#1#11'ClientWidth'#3#129#1#7'OnClose'#7#9'FormClose'#8'OnCreate'
+#7#10'FormCreate'#6'OnShow'#7#8'FormShow'#10'LCLVersion'#6#6'0.9.25'#0#12'TF'
+'ileListBox'#11'FileListBox'#6'Height'#3#186#0#3'Top'#3#248#0#5'Width'#3#129
+#1#5'Align'#7#8'alClient'#9'Directory'#6#13'/home/graemeg'#8'FileType'#11#9
+'ftArchive'#8'ftNormal'#0#10'OnDblClick'#7#19'FileListBoxDblClick'#8'TabOrde'
+'r'#2#0#0#0#9'TTreeView'#2'TV'#6'Height'#3#201#0#3'Top'#2'*'#5'Width'#3#129#1
+#5'Align'#7#5'alTop'#17'DefaultItemHeight'#2#18#8'TabOrder'#2#1#10'OnExpande'
+'d'#7#10'TVExpanded'#18'OnSelectionChanged'#7#18'TVSelectionChanged'#0#0#6'T'
+'Panel'#6'Panel1'#6'Height'#2'*'#5'Width'#3#129#1#5'Align'#7#5'alTop'#10'Bev'
+'elOuter'#7#6'bvNone'#12'ClientHeight'#2'*'#11'ClientWidth'#3#129#1#8'TabOrd'
+'er'#2#2#0#9'TCheckBox'#8'cbHidden'#4'Left'#3#200#0#6'Height'#2#24#3'Top'#2#8
+#5'Width'#3#154#0#7'Caption'#6#17'Show hidden files'#8'OnChange'#7#14'cbHidd'
+'enChange'#8'TabOrder'#2#0#0#0#7'TButton'#12'btnConfigure'#4'Left'#2#8#6'Hei'
+'ght'#2#25#3'Top'#2#7#5'Width'#2'Z'#7'Caption'#6#9'Configure'#7'OnClick'#7#17
+'btnConfigureClick'#8'TabOrder'#2#1#0#0#0#9'TSplitter'#9'Splitter1'#6'Cursor'
+#7#8'crVSplit'#6'Height'#2#5#3'Top'#3#243#0#5'Width'#3#129#1#5'Align'#7#5'al'
+'Top'#12'ResizeAnchor'#7#5'akTop'#0#0#0
]);

View File

@ -0,0 +1,371 @@
unit frmFileBrowser;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
FileUtil,
LResources,
Forms,
Controls,
Graphics,
Dialogs,
EditBtn,
FileCtrl,
ComCtrls,
StdCtrls,
ExtCtrls;
type
TOpenFileEvent = procedure(Sender: TObject; const AFileName: string) of object;
{ TFileBrowserForm }
TFileBrowserForm = class(TForm)
btnConfigure: TButton;
cbHidden: TCheckBox;
FileListBox: TFileListBox;
Panel1: TPanel;
Splitter1: TSplitter;
TV: TTreeView;
procedure btnConfigureClick(Sender: TObject);
procedure cbHiddenChange(Sender: TObject);
procedure FileListBoxDblClick(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure TVExpanded(Sender: TObject; Node: TTreeNode);
procedure TVSelectionChanged(Sender: TObject);
private
FOnConfigure: TNotifyEvent;
FOnOpenFile: TOpenFileEvent;
FOnSaveLayout: TNotifyEvent;
FOnSelectDir: TNotifyEvent;
FRootDir: string;
FDir: string;
FShowHidden: Boolean;
procedure AddDirectories(Node: TTreeNode; Dir: string);
function GetAbsolutePath(Node: TTreeNode): string;
procedure SetDir(const Value: string);
procedure SetRootDir(const Value: string);
procedure InitializeTreeview;
{$IFDEF MSWINDOWS}
procedure AddWindowsDriveLetters;
{$ENDIF}
public
{ return the selected directory }
function SelectedDir: string;
{ The selected/opened directory }
property Directory: string read FDir write SetDir;
{ Directory the treeview starts from }
property RootDirectory: string read FRootDir write SetRootDir;
{ Must we show hidden directories - not working on unix type systems }
property ShowHidden: Boolean read FShowHidden write FShowHidden default False;
{ Called when user double-clicks file name }
property OnOpenFile: TOpenFileEvent read FOnOpenFile write FOnOpenFile;
{ Called when user clicks configure button }
property OnConfigure: TNotifyEvent read FOnConfigure write FOnConfigure;
{ Called when a new directory is selected }
property OnSelectDir: TNotifyEvent read FOnSelectDir write FOnSelectDir;
{ OnLoadLayout }
property OnSaveLayout: TNotifyEvent read FOnSaveLayout write FOnSaveLayout;
end;
var
FileBrowserForm: TFileBrowserForm;
implementation
{$IFDEF MSWINDOWS}
uses
Windows;
{$ENDIF}
{function HasSubDirs returns True if the directory passed has subdirectories}
function HasSubDirs(const Dir: string; AShowHidden: Boolean): Boolean;
var
FileInfo: TSearchRec;
FCurrentDir: string;
begin
//Assume No
Result := False;
if Dir <> '' then
begin
FCurrentDir := AppendPathDelim(Dir);
FCurrentDir := FCurrentDir + GetAllFilesMask;
try
if SysUtils.FindFirst(FCurrentDir, faAnyFile or $00000080, FileInfo) = 0 then
repeat
if FileInfo.Name = '' then
Continue;
// check if special file
if ((FileInfo.Name = '.') or (FileInfo.Name = '..')) or
// unix dot directories (aka hidden directories)
((FileInfo.Name[1] in ['.']) and AShowHidden) or
// check Hidden attribute
(((faHidden and FileInfo.Attr) > 0) and AShowHidden) then
Continue;
Result := ((faDirectory and FileInfo.Attr) > 0);
//We found at least one non special dir, that's all we need.
if Result then
break;
until SysUtils.FindNext(FileInfo) <> 0;
finally
SysUtils.FindClose(FileInfo);
end;
end;
end;
{ TFileBrowserForm }
procedure TFileBrowserForm.TVExpanded(Sender: TObject; Node: TTreeNode);
begin
if Node.Count = 0 then
AddDirectories(Node, GetAbsolutePath(Node));
end;
procedure TFileBrowserForm.TVSelectionChanged(Sender: TObject);
begin
FileListBox.Directory := ChompPathDelim(SelectedDir);
if Assigned(OnSelectDir) then
OnselectDir(Self);
end;
procedure TFileBrowserForm.btnConfigureClick(Sender: TObject);
begin
if Assigned(FOnConfigure) then
FOnConfigure(Self);
end;
procedure TFileBrowserForm.cbHiddenChange(Sender: TObject);
begin
ShowHidden := cbHidden.Checked;
if ShowHidden then
FileListBox.FileType := FileListBox.FileType + [ftHidden]
else
FileListBox.FileType := FileListBox.FileType - [ftHidden];
end;
procedure TFileBrowserForm.FileListBoxDblClick(Sender: TObject);
begin
if Assigned(FOnOpenFile) then
FOnOpenFile(Self, FileListBox.FileName);
end;
procedure TFileBrowserForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
if Assigned(FOnSaveLayout) then
FOnSaveLayout(Self);
CloseAction := caFree;
end;
procedure TFileBrowserForm.FormCreate(Sender: TObject);
begin
FShowHidden := False;
InitializeTreeview;
end;
procedure TFileBrowserForm.FormShow(Sender: TObject);
begin
if TV.Selected <> nil then
TV.Selected.Expand(False);
end;
{ Adds Subdirectories to a passed node if they exist }
procedure TFileBrowserForm.AddDirectories(Node: TTreeNode; Dir: string);
var
FileInfo: TSearchRec;
NewNode: TTreeNode;
i: integer;
FCurrentDir: string;
//used to sort the directories.
SortList: TStringList;
begin
if Dir <> '' then
begin
FCurrentDir := Dir;
FCurrentDir := AppendPathDelim(FCurrentDir);
i := length(FCurrentDir);
FCurrentDir := FCurrentDir + GetAllFilesMask;
try
if SysUtils.FindFirst(FCurrentDir, faAnyFile or $00000080, FileInfo) = 0 then
begin
try
SortList := TStringList.Create;
SortList.Sorted := True;
repeat
// check if special file
if (FileInfo.Name = '.') or (FileInfo.Name = '..') or (FileInfo.Name = '') then
Continue;
// if hidden files or directories must be filtered, we test for
// dot files, considered hidden under unix type OS's.
if not FShowHidden then
if (FileInfo.Name[1] in ['.']) then
Continue;
// if this is a directory then add it to the tree.
if ((faDirectory and FileInfo.Attr) > 0) then
begin
//if this is a hidden file and we have not been requested to show
//hidden files then do not add it to the list.
if ((faHidden and FileInfo.Attr) > 0) and not FShowHidden then
continue;
SortList.Add(FileInfo.Name);
end;
until SysUtils.FindNext(FileInfo) <> 0;
for i := 0 to SortList.Count - 1 do
begin
NewNode := TV.Items.AddChild(Node, SortList[i]);
// if subdirectories then indicate so.
NewNode.HasChildren := HasSubDirs(AppendPathDelim(Dir) + NewNode.Text, FShowHidden);
end;
finally
SortList.Free;
end;
end; { if FindFirst... }
finally
SysUtils.FindClose(FileInfo);
end;
end; { if Dir... }
if Node.Level = 0 then
Node.Text := Dir;
end;
function TFileBrowserForm.GetAbsolutePath(Node: TTreeNode): string;
begin
Result := '';
while Node <> nil do
begin
if Node.Text = PathDelim then
Result := Node.Text + Result
else
Result := Node.Text + PathDelim + Result;
Node := Node.Parent;
end;
end;
procedure TFileBrowserForm.SetDir(const Value: string);
var
StartDir: string;
Node: TTreeNode;
i, p: integer;
SubDir: PChar;
begin
FDir := Value;
StartDir := Value;
if TV.Items.Count = 0 then
Exit;
p := AnsiPos(FRootDir, StartDir);
if p = 1 then
Delete(StartDir, P, Length(FRootDir));
for i := 1 to Length(StartDir) do
if (StartDir[i] = PathDelim) then
StartDir[i] := #0;
SubDir := PChar(StartDir);
if SubDir[0] = #0 then
SubDir := @SubDir[1];
Node := TV.Items.GetFirstNode;
while SubDir[0] <> #0 do
begin
Node := Node.GetFirstChild;
while (Node <> nil) and (AnsiCompareStr(Node.Text, SubDir) <> 0) do
Node := Node.GetNextSibling;
if Node = nil then
break
else
Node.Expand(False);
SubDir := SubDir + StrLen(SubDir) + 1;
end;
TV.Selected := Node;
TV.MakeSelectionVisible;
end;
procedure TFileBrowserForm.SetRootDir(const Value: string);
var
RootNode: TTreeNode;
lNode: TTreeNode;
begin
{ Clear the list }
TV.Items.Clear;
FRootDir := Value;
{$IFDEF MSWINDOWS}
{ Add Windows drive letters }
AddWindowsDriveLetters;
{$ENDIF}
{ Remove the path delimiter unless this is root. }
if FRootDir = '' then
FRootDir := PathDelim;
if (FRootDir <> PathDelim) and (FRootDir[length(FRootDir)] = PathDelim) then
FRootDir := copy(FRootDir, 1, length(FRootDir) - 1);
{ Find or Create the root node and add it to the Tree View. }
RootNode := TV.Items.FindTopLvlNode(FRootDir + PathDelim);
if RootNode = nil then
RootNode := TV.Items.Add(nil, FRootDir);
{ Add the Subdirectories to Root nodes }
lNode := TV.Items.GetFirstNode;
while lNode <> nil do
begin
AddDirectories(lNode, lNode.Text);
lNode := lNode.GetNextSibling;
end;
{ Set the original root node as the selected node. }
TV.Selected := RootNode;
end;
procedure TFileBrowserForm.InitializeTreeview;
begin
{ I'm not sure what we should set these to. Maybe another Config option? }
{$IFDEF UNIX}
RootDirectory := '/';
{$ENDIF}
{$IFDEF MSWINDOWS}
RootDirectory := 'C:\';
{$ENDIF}
end;
{$IFDEF MSWINDOWS}
procedure TFileBrowserForm.AddWindowsDriveLetters;
const
MAX_DRIVES = 25;
var
n: integer;
drvs: string;
begin
// making drive list, skipping drives A: and B:
n := 2;
while n <= MAX_DRIVES do
begin
drvs := chr(n + Ord('A')) + ':\';
if Windows.GetDriveType(PChar(drvs)) <> 1 then
TV.Items.Add(nil, drvs);
Inc(n);
end;
end;
{$ENDIF}
function TFileBrowserForm.SelectedDir: string;
begin
Result := '';
if TV.Selected <> nil then
Result := GetAbsolutePath(TV.Selected);
end;
initialization
{$I frmfilebrowser.lrs}
end.

View File

@ -0,0 +1,62 @@
<?xml version="1.0"?>
<CONFIG>
<Package Version="3">
<Name Value="idefilebrowser"/>
<Author Value="Graeme Geldenhuys"/>
<CompilerOptions>
<Version Value="8"/>
<SearchPaths>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Description Value="File browsing window for the Lazarus IDE"/>
<License Value="Modified LGPL"/>
<Version Minor="1"/>
<Files Count="5">
<Item1>
<Filename Value="frmfilebrowser.lfm"/>
<Type Value="LFM"/>
</Item1>
<Item2>
<Filename Value="frmfilebrowser.lrs"/>
<Type Value="LRS"/>
</Item2>
<Item3>
<Filename Value="frmfilebrowser.pas"/>
<UnitName Value="frmFileBrowser"/>
</Item3>
<Item4>
<Filename Value="regidefilebrowser.pp"/>
<HasRegisterProc Value="True"/>
<UnitName Value="regidefilebrowser"/>
</Item4>
<Item5>
<Filename Value="frmconfigfilebrowser.pp"/>
<UnitName Value="frmconfigfilebrowser"/>
</Item5>
</Files>
<Type Value="DesignTime"/>
<RequiredPkgs Count="3">
<Item1>
<PackageName Value="LCL"/>
</Item1>
<Item2>
<PackageName Value="IDEIntf"/>
</Item2>
<Item3>
<PackageName Value="FCL"/>
<MinVersion Major="1" Valid="True"/>
</Item3>
</RequiredPkgs>
<UsageOptions>
<UnitPath Value="$(PkgOutDir)/"/>
</UsageOptions>
<PublishOptions>
<Version Value="2"/>
<IgnoreBinaries Value="False"/>
</PublishOptions>
</Package>
</CONFIG>

View File

@ -0,0 +1,21 @@
{ This file was automatically created by Lazarus. do not edit!
This source is only used to compile and install the package.
}
unit idefilebrowser;
interface
uses
frmFileBrowser, regidefilebrowser, frmconfigfilebrowser, LazarusPackageIntf;
implementation
procedure Register;
begin
RegisterUnit('regidefilebrowser', @regidefilebrowser.Register);
end;
initialization
RegisterPackage('idefilebrowser', @Register);
end.

View File

@ -0,0 +1,212 @@
unit regidefilebrowser;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
frmfilebrowser,
frmconfigfilebrowser;
type
TFileBrowserController = class(TComponent)
private
FStartDir: TStartDir;
FCustomDir: string;
FWindow: TFileBrowserForm;
FNeedSave: Boolean;
procedure DoSelectDir(Sender: TObject);
procedure DoSaveLayout(Sender: TObject);
procedure ReadConfig; virtual;
procedure WriteConfig; virtual;
protected
procedure CreateWindow; virtual;
{ Called by file browser window }
procedure DoOpenFile(Sender: TObject; const AFileName: string); virtual;
{ Called by file browser window }
procedure DoConfig(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure ShowWindow;
function ShowConfig: Boolean;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
property StartDir: TStartDir read FStartDir write FStartDir;
property CustomDir: string read FCustomDir write FCustomDir;
end;
procedure Register;
implementation
uses
Controls,
Forms,
lazideintf,
menuintf,
baseideintf,
idewindowintf;
const
SConfigFile = 'idebrowserwin.xml';
KeyStartDir = 'StartDir';
KeyCustomDir = 'CustomDir';
KeySplitterPos = 'SplitterPos';
resourcestring
SFileBrowserIDEMenu = 'IDEFileBrowser';
SFileBrowserIDEMenuCaption = 'File Browser window';
{ TFileBrowserController }
procedure TFileBrowserController.ReadConfig;
begin
with GetIDEConfigStorage(SConfigFile, True) do
try
FStartDir := TStartDir(GetValue(KeyStartDir, Ord(sdProjectDir)));
FCustomDir := GetValue(KeyCustomDir, '');
finally
Free;
end;
end;
procedure TFileBrowserController.WriteConfig;
begin
with GetIDEConfigStorage(SConfigFile, True) do
try
SetValue(KeyStartDir, Ord(FstartDir));
SetValue(KeyCustomDir, CustomDir);
FNeedSave := False;
finally
Free;
end;
end;
procedure TFileBrowserController.CreateWindow;
var
D: string;
begin
FWindow := TFileBrowserForm.Create(Self);
FWindow.FreeNotification(Self);
FWindow.OnOpenFile := @DoOpenFile;
FWindow.OnConfigure := @DoConfig;
FWindow.OnSelectDir := @DoSelectDir;
FWindow.OnSaveLayout := @DoSaveLayout;
IDEDialogLayoutList.ApplyLayout(FWindow);
D := FCustomDir;
if (FStartDir = sdProjectDir) and Assigned(LazarusIDE.ActiveProject) then
D := ExtractFilePath(LazarusIDE.ActiveProject.ProjectInfoFile);
FWindow.Directory := D;
end;
procedure TFileBrowserController.DoOpenFile(Sender: TObject; const AFileName: string);
var
Flags: TOpenFlags;
begin
// Set up as desired. Maybe create config settings;
Flags := [ofOnlyIfExists, ofAddToRecent, ofUseCache];
LazarusIDE.DoOpenEditorFile(AFileName, 0, Flags);
end;
procedure TFileBrowserController.DoSelectDir(Sender: TObject);
begin
if FStartDir = sdLastOpened then
begin
FCustomDir := FWindow.Directory;
FNeedSave := True;
end;
end;
procedure TFileBrowserController.DoSaveLayout(Sender: TObject);
begin
IDEDialogLayoutList.SaveLayout(FWindow);
with GetIDEConfigStorage(SConfigFile, True) do
try
SetValue(KeySplitterPos, FWindow.Splitter1.Top);
FNeedSave := False;
finally
Free;
end;
end;
procedure TFileBrowserController.DoConfig(Sender: TObject);
begin
// Maybe later some reconfiguration of FWindow is needed after ShowConfig ?
if ShowConfig then
WriteConfig;
end;
constructor TFileBrowserController.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ReadConfig;
end;
destructor TFileBrowserController.Destroy;
begin
if FNeedSave then
WriteConfig;
if Assigned(FWindow) then
FreeAndNil(FWindow);
inherited;
end;
procedure TFileBrowserController.ShowWindow;
begin
if (FWindow = nil) then
begin
CreateWindow;
FWindow.Show;
end
else
FWindow.BringToFront;
end;
function TFileBrowserController.ShowConfig: Boolean;
var
F: TFileBrowserConfigForm;
begin
F := TFileBrowserConfigForm.Create(Self);
try
F.CustomDir := Self.FCustomDir;
F.StartDir := Self.StartDir;
Result := F.ShowModal = mrOk;
if Result then
begin
FCustomDir := F.CustomDir;
FStartDir := F.StartDir;
end;
finally
F.Free;
end;
end;
procedure TFileBrowserController.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited;
if (AComponent = FWindow) and (opRemove = Operation) then
FWindow := nil;
end;
procedure ShowFileBrowser(Sender: TObject);
var
C: TFileBrowserController;
begin
C := Application.FindComponent('IDEFileBrowserController') as TFileBrowserController;
if (C = nil) then
C := TFileBrowserController.Create(Application);
C.ShowWindow;
end;
procedure Register;
begin
RegisterIDEMenuCommand(itmViewMainWindows, SFileBrowserIDEMEnu,
SFileBrowserIDEMenuCaption, nil, @ShowFileBrowser, nil, '');
end;
end.