mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-26 15:20:22 +02:00
LCL: TFilenameEdit: check if Filename exists, use InitialDir
git-svn-id: trunk@35450 -
This commit is contained in:
parent
588639f160
commit
bbe475b828
@ -27,9 +27,9 @@ unit Dialogs;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Types, Classes, LResources, SysUtils, LCLIntf, InterfaceBase, FileUtil,
|
Types, typinfo, Classes, LResources, SysUtils, LCLIntf, InterfaceBase,
|
||||||
LCLStrConsts, LCLType, LCLProc, Forms, Controls, Themes,
|
FileUtil, LCLStrConsts, LCLType, LCLProc, Forms, Controls, Themes, GraphType,
|
||||||
GraphType, Graphics, Buttons, ButtonPanel, StdCtrls, ExtCtrls, LCLClasses;
|
Graphics, Buttons, ButtonPanel, StdCtrls, ExtCtrls, LCLClasses;
|
||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -539,6 +539,9 @@ function ExtractColorIndexAndColor(const AColorList: TStrings; const AIndex: Int
|
|||||||
function GetDialogCaption(idDiag: Integer): String;
|
function GetDialogCaption(idDiag: Integer): String;
|
||||||
function GetDialogIcon(idDiag: Integer): TCustomBitmap;
|
function GetDialogIcon(idDiag: Integer): TCustomBitmap;
|
||||||
|
|
||||||
|
function dbgs(Option: TOpenOption): string; overload;
|
||||||
|
function dbgs(Options: TOpenOptions): string; overload;
|
||||||
|
|
||||||
procedure Register;
|
procedure Register;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -581,6 +584,20 @@ const
|
|||||||
type
|
type
|
||||||
TBitBtnAccess = class(TBitBtn);
|
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;
|
procedure Register;
|
||||||
begin
|
begin
|
||||||
RegisterComponents('Dialogs',[TOpenDialog,TSaveDialog,TSelectDirectoryDialog,
|
RegisterComponents('Dialogs',[TOpenDialog,TSaveDialog,TSelectDirectoryDialog,
|
||||||
|
@ -295,7 +295,7 @@ type
|
|||||||
property OnFolderChange: TNotifyEvent read FOnFolderChange write FOnFolderChange;
|
property OnFolderChange: TNotifyEvent read FOnFolderChange write FOnFolderChange;
|
||||||
property DialogKind: TDialogKind read FDialogKind write FDialogKind default dkOpen;
|
property DialogKind: TDialogKind read FDialogKind write FDialogKind default dkOpen;
|
||||||
property DialogTitle: String read FDialogTitle write FDialogTitle;
|
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 Filter: String read FFilter write FFilter;
|
||||||
property FilterIndex: Integer read FFilterIndex write FFIlterIndex;
|
property FilterIndex: Integer read FFilterIndex write FFIlterIndex;
|
||||||
property DefaultExt: String read FDefaultExt write FDefaultExt;
|
property DefaultExt: String read FDefaultExt write FDefaultExt;
|
||||||
@ -1000,29 +1000,37 @@ function TFileNameEdit.CreateDialog(AKind: TDialogKind): TCommonDialog;
|
|||||||
var
|
var
|
||||||
O: TOpenDialog;
|
O: TOpenDialog;
|
||||||
S: TSaveDialog;
|
S: TSaveDialog;
|
||||||
|
Dir: String;
|
||||||
begin
|
begin
|
||||||
case AKind of
|
case AKind of
|
||||||
dkopen, dkPictureOpen:
|
dkOpen, dkPictureOpen:
|
||||||
begin
|
begin
|
||||||
O := TOpenDialog.Create(Self);
|
O := TOpenDialog.Create(Self);
|
||||||
O.FileName := FileName;
|
|
||||||
O.Options := DialogOptions;
|
|
||||||
O.InitialDir := InitialDir;
|
|
||||||
O.Filter := Filter;
|
|
||||||
O.FilterIndex := FilterIndex;
|
|
||||||
Result := O;
|
Result := O;
|
||||||
end;
|
end;
|
||||||
dkSave, dkPictureSave:
|
dkSave, dkPictureSave:
|
||||||
begin
|
begin
|
||||||
S:=TSaveDialog.Create(Self);
|
S:=TSaveDialog.Create(Self);
|
||||||
S.DefaultExt := FDefaultExt;
|
S.DefaultExt := FDefaultExt;
|
||||||
S.Options := DialogOptions;
|
|
||||||
S.InitialDir := InitialDir;
|
|
||||||
S.Filter := Filter;
|
|
||||||
S.FilterIndex := FilterIndex;
|
|
||||||
Result := S;
|
Result := S;
|
||||||
end;
|
end;
|
||||||
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.
|
// Set some common things.
|
||||||
Result.Title := DialogTitle;
|
Result.Title := DialogTitle;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user