LCL: TFilenameEdit: check if Filename exists, use InitialDir

git-svn-id: trunk@35450 -
This commit is contained in:
mattias 2012-02-18 15:52:39 +00:00
parent 588639f160
commit bbe475b828
2 changed files with 39 additions and 14 deletions

View File

@ -27,9 +27,9 @@ unit Dialogs;
interface
uses
Types, Classes, LResources, SysUtils, LCLIntf, InterfaceBase, FileUtil,
LCLStrConsts, LCLType, LCLProc, Forms, Controls, Themes,
GraphType, Graphics, Buttons, ButtonPanel, StdCtrls, ExtCtrls, LCLClasses;
Types, typinfo, Classes, LResources, SysUtils, LCLIntf, InterfaceBase,
FileUtil, LCLStrConsts, LCLType, LCLProc, Forms, Controls, Themes, GraphType,
Graphics, Buttons, ButtonPanel, StdCtrls, ExtCtrls, LCLClasses;
type
@ -539,6 +539,9 @@ function ExtractColorIndexAndColor(const AColorList: TStrings; const AIndex: Int
function GetDialogCaption(idDiag: Integer): String;
function GetDialogIcon(idDiag: Integer): TCustomBitmap;
function dbgs(Option: TOpenOption): string; overload;
function dbgs(Options: TOpenOptions): string; overload;
procedure Register;
implementation
@ -581,6 +584,20 @@ const
type
TBitBtnAccess = class(TBitBtn);
function dbgs(Option: TOpenOption): string;
begin
Result:=GetEnumName(typeinfo(TOpenOption),ord(Option));
end;
function dbgs(Options: TOpenOptions): string;
var
o: TOpenOption;
begin
for o in Options do
Result:=Result+dbgs(o)+',';
Result:='['+LeftStr(Result,length(Result)-1)+']';
end;
procedure Register;
begin
RegisterComponents('Dialogs',[TOpenDialog,TSaveDialog,TSelectDirectoryDialog,

View File

@ -295,7 +295,7 @@ type
property OnFolderChange: TNotifyEvent read FOnFolderChange write FOnFolderChange;
property DialogKind: TDialogKind read FDialogKind write FDialogKind default dkOpen;
property DialogTitle: String read FDialogTitle write FDialogTitle;
property DialogOptions: TOpenOptions read FDialogOptions write FDialogOptions;
property DialogOptions: TOpenOptions read FDialogOptions write FDialogOptions default DefaultOpenDialogOptions;
property Filter: String read FFilter write FFilter;
property FilterIndex: Integer read FFilterIndex write FFIlterIndex;
property DefaultExt: String read FDefaultExt write FDefaultExt;
@ -1000,29 +1000,37 @@ function TFileNameEdit.CreateDialog(AKind: TDialogKind): TCommonDialog;
var
O: TOpenDialog;
S: TSaveDialog;
Dir: String;
begin
case AKind of
dkopen, dkPictureOpen:
dkOpen, dkPictureOpen:
begin
O := TOpenDialog.Create(Self);
O.FileName := FileName;
O.Options := DialogOptions;
O.InitialDir := InitialDir;
O.Filter := Filter;
O.FilterIndex := FilterIndex;
Result := O;
end;
dkSave, dkPictureSave:
begin
S:=TSaveDialog.Create(Self);
S.DefaultExt := FDefaultExt;
S.Options := DialogOptions;
S.InitialDir := InitialDir;
S.Filter := Filter;
S.FilterIndex := FilterIndex;
Result := S;
end;
end;
if Result is TOpenDialog then
begin
O:=TOpenDialog(Result);
Dir:=ExtractFilePath(Filename);
if (Dir<>'') and DirPathExists(Dir) then
// setting a FileName with path disables InitialDir
O.FileName := FileName
else begin
// do not use path, so that InitialDir works
O.FileName := ExtractFileName(Filename);
end;
O.Options := DialogOptions;
O.Filter := Filter;
O.FilterIndex := FilterIndex;
O.InitialDir := CleanAndExpandDirectory(InitialDir);
end;
// Set some common things.
Result.Title := DialogTitle;
end;