mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-05-31 02:12:35 +02:00
filebrowser: dockable
git-svn-id: trunk@39611 -
This commit is contained in:
parent
994ee2832a
commit
798249cf3b
@ -1,4 +1,4 @@
|
||||
unit frmconfigfilebrowser;
|
||||
unit frmConfigFileBrowser;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
|
@ -38,12 +38,10 @@ type
|
||||
private
|
||||
FOnConfigure: TNotifyEvent;
|
||||
FOnOpenFile: TOpenFileEvent;
|
||||
FOnSaveLayout: TNotifyEvent;
|
||||
FOnSelectDir: TNotifyEvent;
|
||||
FRootDir: string;
|
||||
FDir: string;
|
||||
FShowHidden: Boolean;
|
||||
FOnLoadLayout: TNotifyEvent;
|
||||
procedure AddDirectories(Node: TTreeNode; Dir: string);
|
||||
function GetAbsolutePath(Node: TTreeNode): string;
|
||||
procedure SetDir(const Value: string);
|
||||
@ -67,9 +65,6 @@ type
|
||||
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;
|
||||
property OnLoadLayout: TNotifyEvent read FOnLoadLayout write FOnLoadLayout;
|
||||
end;
|
||||
|
||||
var
|
||||
@ -202,9 +197,7 @@ end;
|
||||
|
||||
procedure TFileBrowserForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
||||
begin
|
||||
if Assigned(FOnSaveLayout) then
|
||||
FOnSaveLayout(Self);
|
||||
CloseAction := caFree;
|
||||
|
||||
end;
|
||||
|
||||
procedure TFileBrowserForm.FormCreate(Sender: TObject);
|
||||
@ -216,8 +209,6 @@ end;
|
||||
|
||||
procedure TFileBrowserForm.FormShow(Sender: TObject);
|
||||
begin
|
||||
if Assigned(FOnLoadLayout) then
|
||||
FOnLoadLayout(Self);
|
||||
if TV.Selected <> nil then
|
||||
TV.Selected.Expand(False);
|
||||
end;
|
||||
|
@ -1,13 +1,19 @@
|
||||
<?xml version="1.0"?>
|
||||
<CONFIG>
|
||||
<Package Version="3">
|
||||
<Package Version="4">
|
||||
<Name Value="idefilebrowser"/>
|
||||
<AddToProjectUsesSection Value="True"/>
|
||||
<Author Value="Graeme Geldenhuys"/>
|
||||
<CompilerOptions>
|
||||
<Version Value="8"/>
|
||||
<Version Value="11"/>
|
||||
<SearchPaths>
|
||||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Parsing>
|
||||
<SyntaxOptions>
|
||||
<UseAnsiStrings Value="False"/>
|
||||
</SyntaxOptions>
|
||||
</Parsing>
|
||||
<Other>
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
@ -15,28 +21,24 @@
|
||||
<Description Value="File browsing window for the Lazarus IDE"/>
|
||||
<License Value="Modified LGPL"/>
|
||||
<Version Minor="2"/>
|
||||
<Files Count="5">
|
||||
<Files Count="4">
|
||||
<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>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<Filename Value="regidefilebrowser.pp"/>
|
||||
<HasRegisterProc Value="True"/>
|
||||
<UnitName Value="regidefilebrowser"/>
|
||||
</Item4>
|
||||
<Item5>
|
||||
</Item3>
|
||||
<Item4>
|
||||
<Filename Value="frmconfigfilebrowser.pp"/>
|
||||
<UnitName Value="frmconfigfilebrowser"/>
|
||||
</Item5>
|
||||
</Item4>
|
||||
</Files>
|
||||
<Type Value="DesignTime"/>
|
||||
<RequiredPkgs Count="3">
|
||||
|
@ -1,21 +1,21 @@
|
||||
{ This file was automatically created by Lazarus. do not edit!
|
||||
{ This file was automatically created by Lazarus. Do not edit!
|
||||
This source is only used to compile and install the package.
|
||||
}
|
||||
|
||||
unit idefilebrowser;
|
||||
unit idefilebrowser;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
frmFileBrowser, regidefilebrowser, frmconfigfilebrowser, LazarusPackageIntf;
|
||||
frmFileBrowser, RegIDEFileBrowser, frmConfigFileBrowser, LazarusPackageIntf;
|
||||
|
||||
implementation
|
||||
|
||||
procedure Register;
|
||||
procedure Register;
|
||||
begin
|
||||
RegisterUnit('regidefilebrowser', @regidefilebrowser.Register);
|
||||
end;
|
||||
RegisterUnit('RegIDEFileBrowser', @RegIDEFileBrowser.Register);
|
||||
end;
|
||||
|
||||
initialization
|
||||
RegisterPackage('idefilebrowser', @Register);
|
||||
RegisterPackage('idefilebrowser', @Register);
|
||||
end.
|
||||
|
@ -1,29 +1,34 @@
|
||||
unit regidefilebrowser;
|
||||
unit RegIDEFileBrowser;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes,
|
||||
SysUtils,
|
||||
frmfilebrowser,
|
||||
frmconfigfilebrowser;
|
||||
Classes, SysUtils,
|
||||
LazLogger,
|
||||
Controls, Forms,
|
||||
LazIDEIntf, MenuIntf, IDECommands, IDEWindowIntf, BaseIDEIntf,
|
||||
frmFileBrowser, frmConfigFileBrowser;
|
||||
|
||||
type
|
||||
|
||||
{ TFileBrowserController }
|
||||
|
||||
TFileBrowserController = class(TComponent)
|
||||
private
|
||||
FStartDir: TStartDir;
|
||||
FCustomDir: string;
|
||||
FWindow: TFileBrowserForm;
|
||||
FWindow: TFileBrowserForm; // same as FileBrowserForm, which one is redundant?
|
||||
FNeedSave: Boolean;
|
||||
procedure DoLoadLayout(Sender: TObject);
|
||||
FSplitterPos: integer;
|
||||
procedure DoSelectDir(Sender: TObject);
|
||||
procedure DoSaveLayout(Sender: TObject);
|
||||
procedure ReadConfig; virtual;
|
||||
procedure SetSplitterPos(AValue: integer);
|
||||
procedure WriteConfig; virtual;
|
||||
procedure OnFormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction);
|
||||
protected
|
||||
procedure CreateWindow; virtual;
|
||||
procedure CreateWindow(AForm: TFileBrowserForm); virtual;
|
||||
{ Called by file browser window }
|
||||
procedure DoOpenFile(Sender: TObject; const AFileName: string); virtual;
|
||||
{ Called by file browser window }
|
||||
@ -31,26 +36,22 @@ type
|
||||
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;
|
||||
property SplitterPos: integer read FSplitterPos write SetSplitterPos;
|
||||
end;
|
||||
|
||||
var
|
||||
FileBrowserCreator: TIDEWindowCreator; // set by Register procedure
|
||||
|
||||
procedure ShowFileBrowser(Sender: TObject);
|
||||
procedure Register;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
Controls,
|
||||
Forms,
|
||||
lazideintf,
|
||||
menuintf,
|
||||
baseideintf,
|
||||
idewindowintf;
|
||||
|
||||
const
|
||||
SConfigFile = 'idebrowserwin.xml';
|
||||
KeyStartDir = 'StartDir';
|
||||
@ -58,7 +59,6 @@ const
|
||||
KeySplitterPos = 'SplitterPos';
|
||||
|
||||
resourcestring
|
||||
SFileBrowserIDEMenu = 'IDEFileBrowser';
|
||||
SFileBrowserIDEMenuCaption = 'File Browser';
|
||||
|
||||
|
||||
@ -70,37 +70,45 @@ begin
|
||||
try
|
||||
FStartDir := TStartDir(GetValue(KeyStartDir, Ord(sdProjectDir)));
|
||||
FCustomDir := GetValue(KeyCustomDir, '');
|
||||
FSplitterPos:=GetValue(KeySplitterPos, 150);
|
||||
finally
|
||||
Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TFileBrowserController.SetSplitterPos(AValue: integer);
|
||||
begin
|
||||
if FSplitterPos=AValue then Exit;
|
||||
FSplitterPos:=AValue;
|
||||
FNeedSave:=true;
|
||||
end;
|
||||
|
||||
procedure TFileBrowserController.WriteConfig;
|
||||
begin
|
||||
with GetIDEConfigStorage(SConfigFile, True) do
|
||||
try
|
||||
SetValue(KeyStartDir, Ord(FstartDir));
|
||||
SetValue(KeyCustomDir, CustomDir);
|
||||
SetDeleteValue(KeyStartDir, Ord(FStartDir), ord('C'));
|
||||
SetDeleteValue(KeyCustomDir, CustomDir, '');
|
||||
SetDeleteValue(KeySplitterPos, FSplitterPos, 150);
|
||||
FNeedSave := False;
|
||||
finally
|
||||
Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TFileBrowserController.CreateWindow;
|
||||
procedure TFileBrowserController.CreateWindow(AForm: TFileBrowserForm);
|
||||
var
|
||||
D: string;
|
||||
begin
|
||||
FWindow := TFileBrowserForm.Create(Self);
|
||||
FWindow := AForm;
|
||||
FWindow.Caption:=SFileBrowserIDEMenuCaption;
|
||||
FWindow.FreeNotification(Self);
|
||||
FWindow.OnOpenFile := @DoOpenFile;
|
||||
FWindow.OnConfigure := @DoConfig;
|
||||
FWindow.OnSelectDir := @DoSelectDir;
|
||||
FWindow.OnSaveLayout := @DoSaveLayout;
|
||||
FWindow.OnLoadLayout := @DoLoadLayout;
|
||||
IDEDialogLayoutList.ApplyLayout(FWindow);
|
||||
D := FCustomDir;
|
||||
FWindow.AddHandlerClose(@OnFormClose);
|
||||
FWindow.TV.Height:=FSplitterPos;
|
||||
D := FCustomDir;
|
||||
if (FStartDir = sdProjectDir) and Assigned(LazarusIDE.ActiveProject) then
|
||||
D := ExtractFilePath(LazarusIDE.ActiveProject.ProjectInfoFile);
|
||||
FWindow.Directory := D;
|
||||
@ -115,18 +123,10 @@ begin
|
||||
LazarusIDE.DoOpenEditorFile(AFileName, 0, 0, Flags);
|
||||
end;
|
||||
|
||||
procedure TFileBrowserController.DoLoadLayout(Sender: TObject);
|
||||
procedure TFileBrowserController.OnFormClose(Sender: TObject;
|
||||
var CloseAction: TCloseAction);
|
||||
begin
|
||||
with GetIDEConfigStorage(SConfigFile, True) do
|
||||
begin
|
||||
try
|
||||
FWindow.Top := GetValue('Position/Top', FWindow.Top);
|
||||
FWindow.Left := GetValue('Position/Left', FWindow.Left);
|
||||
FWindow.TV.Height := GetValue(KeySplitterPos, FWindow.TV.Height);
|
||||
finally
|
||||
Free;
|
||||
end;
|
||||
end;
|
||||
SplitterPos:=FWindow.Splitter1.Top;
|
||||
end;
|
||||
|
||||
procedure TFileBrowserController.DoSelectDir(Sender: TObject);
|
||||
@ -138,20 +138,6 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TFileBrowserController.DoSaveLayout(Sender: TObject);
|
||||
begin
|
||||
IDEDialogLayoutList.SaveLayout(FWindow);
|
||||
with GetIDEConfigStorage(SConfigFile, True) do
|
||||
try
|
||||
SetValue(KeySplitterPos, FWindow.TV.Height);
|
||||
SetValue('Position/Top', FWindow.Top);
|
||||
SetValue('Position/Left', FWindow.Left);
|
||||
FNeedSave := False;
|
||||
finally
|
||||
Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TFileBrowserController.DoConfig(Sender: TObject);
|
||||
begin
|
||||
// Maybe later some reconfiguration of FWindow is needed after ShowConfig ?
|
||||
@ -174,17 +160,6 @@ begin
|
||||
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;
|
||||
@ -212,19 +187,54 @@ begin
|
||||
end;
|
||||
|
||||
procedure ShowFileBrowser(Sender: TObject);
|
||||
begin
|
||||
IDEWindowCreators.ShowForm(FileBrowserCreator.FormName,true);
|
||||
end;
|
||||
|
||||
procedure CreateFileBrowser(Sender: TObject; aFormName: string;
|
||||
var AForm: TCustomForm; DoDisableAutoSizing: boolean);
|
||||
var
|
||||
C: TFileBrowserController;
|
||||
begin
|
||||
C := Application.FindComponent('IDEFileBrowserController') as TFileBrowserController;
|
||||
// sanity check to avoid clashing with another package that has registered a window with the same name
|
||||
if CompareText(aFormName,'FileBrowser')<>0 then begin
|
||||
DebugLn(['ERROR: CreateFileBrowser: there is already a form with this name']);
|
||||
exit;
|
||||
end;
|
||||
C := LazarusIDE.OwningComponent.FindComponent('IDEFileBrowserController') as TFileBrowserController;
|
||||
if (C = nil) then
|
||||
C := TFileBrowserController.Create(Application);
|
||||
C.ShowWindow;
|
||||
C := TFileBrowserController.Create(LazarusIDE.OwningComponent);
|
||||
IDEWindowCreators.CreateForm(AForm,TFileBrowserForm,true,C);
|
||||
AForm.Name:=aFormName;
|
||||
FileBrowserForm:=AForm as TFileBrowserForm;
|
||||
C.CreateWindow(FileBrowserForm);
|
||||
if not DoDisableAutoSizing then
|
||||
AForm.EnableAutoSizing;
|
||||
end;
|
||||
|
||||
procedure Register;
|
||||
var
|
||||
CmdCatViewMenu: TIDECommandCategory;
|
||||
ViewFileBrowserCommand: TIDECommand;
|
||||
begin
|
||||
RegisterIDEMenuCommand(itmViewMainWindows, SFileBrowserIDEMEnu,
|
||||
SFileBrowserIDEMenuCaption, nil, @ShowFileBrowser, nil, '');
|
||||
// search shortcut category
|
||||
CmdCatViewMenu:=IDECommandList.FindCategoryByName(CommandCategoryViewName);
|
||||
// register shortcut
|
||||
ViewFileBrowserCommand:=RegisterIDECommand(CmdCatViewMenu,
|
||||
'ViewFileBrowser',SFileBrowserIDEMenuCaption,
|
||||
CleanIDEShortCut,nil,@ShowFileBrowser);
|
||||
// register menu item in View menu
|
||||
RegisterIDEMenuCommand(itmViewMainWindows,
|
||||
ViewFileBrowserCommand.Name,
|
||||
SFileBrowserIDEMenuCaption, nil, nil, ViewFileBrowserCommand);
|
||||
|
||||
// register dockable Window
|
||||
FileBrowserCreator:=IDEWindowCreators.Add(
|
||||
'FileBrowser',
|
||||
@CreateFileBrowser,nil,
|
||||
'200','100','400','400' // default place at left=200, top=100, right=400, bottom=400
|
||||
// you can also define percentage values of screen or relative positions, see wiki
|
||||
);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user