summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2010-03-19 16:06:59 +0200
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2010-03-19 16:06:59 +0200
commit1c516562ba61082672c9fc83ad40f8687b140f7b (patch)
treed7382c380a9f01951c00b0e98197382d8ca00689 /src
parent39cf147a084c16824fa253609b11b4cea4845a18 (diff)
downloadfpGUI-1c516562ba61082672c9fc83ad40f8687b140f7b.tar.xz
SelectDir Dialog changes - initial selection directory now works.
* SelectedDir is now a read/write property * SelectDirDialog() now handles the AStartDir parameter.
Diffstat (limited to 'src')
-rw-r--r--src/gui/fpg_dialogs.pas1
-rw-r--r--src/gui/selectdirdialog.inc55
2 files changed, 48 insertions, 8 deletions
diff --git a/src/gui/fpg_dialogs.pas b/src/gui/fpg_dialogs.pas
index 8de175f7..1136ea0b 100644
--- a/src/gui/fpg_dialogs.pas
+++ b/src/gui/fpg_dialogs.pas
@@ -384,6 +384,7 @@ var
begin
dlg := TfpgSelectDirDialog.Create(nil);
try
+ dlg.SelectedDir := AStartDir;
if dlg.ShowModal = mrOK then
Result := dlg.SelectedDir
else
diff --git a/src/gui/selectdirdialog.inc b/src/gui/selectdirdialog.inc
index b8a4b116..b9da189b 100644
--- a/src/gui/selectdirdialog.inc
+++ b/src/gui/selectdirdialog.inc
@@ -15,14 +15,16 @@
procedure SetRootDir(const AValue: TfpgString);
procedure AddDirectories(Node: TfpgTreeNode; Dir: TfpgString);
procedure NodeExpanded(Sender: TObject; ANode: TfpgTreeNode);
+ function GetSelectedDir: TfpgString;
+ procedure SetSelectedDir(const AValue: TfpgString);
{$IFDEF MSWINDOWS}
procedure AddWindowsDriveLetters;
{$ENDIF}
public
constructor Create(AOwner: TComponent); override;
procedure AfterCreate; override;
- { return the selected directory }
- function SelectedDir: TfpgString;
+ { return the selected directory or set initial selected dir }
+ property SelectedDir: TfpgString read GetSelectedDir write SetSelectedDir;
{ Directory the treeview starts from }
property RootDirectory: TfpgString read FRootDir write SetRootDir;
end;
@@ -182,6 +184,49 @@ begin
AddDirectories(ANode, GetAbsolutePath(ANode));
end;
+function TfpgSelectDirDialog.GetSelectedDir: TfpgString;
+begin
+ Result := '';
+ if tv.Selection <> nil then
+ Result := GetAbsolutePath(tv.Selection);
+end;
+
+procedure TfpgSelectDirDialog.SetSelectedDir(const AValue: TfpgString);
+var
+ s: TfpgString;
+ dir: TfpgString;
+ i: integer;
+ p: integer;
+ prevn, nextn: TfpgTreeNode;
+begin
+ if AValue = '' then
+ Exit;
+ s := fpgAppendPathDelim(AValue);
+ prevn := tv.RootNode;
+ nextn := prevn;
+ while nextn <> nil do
+ begin
+ if s = '' then
+ break;
+ i := UTF8Pos(PathDelim, s);
+ if i = 1 then
+ dir := PathDelim
+ else
+ dir := UTF8Copy(s, 1, i-1);
+ UTF8Delete(s, 1, i); // delete leading dir + PathDelim
+ if (prevn = tv.RootNode) and (pos(':', dir) > 0) then
+ dir += PathDelim; // Windows drive letter. eg: C:\ or D:\ etc.
+ nextn := prevn.FindSubNode(dir, True);
+ if Assigned(nextn) then
+ begin
+ prevn := nextn;
+ prevn.Expand;
+ NodeExpanded(self, prevn);
+ end;
+ end;
+ tv.Selection := prevn;
+end;
+
{$IFDEF MSWINDOWS}
procedure TfpgSelectDirDialog.AddWindowsDriveLetters;
const
@@ -238,12 +283,6 @@ begin
InitializeTreeview;
end;
-function TfpgSelectDirDialog.SelectedDir: TfpgString;
-begin
- Result := '';
- if tv.Selection <> nil then
- Result := GetAbsolutePath(tv.Selection);
-end;
{$ENDIF read_implementation}