diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-07-25 13:56:29 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-07-25 13:56:29 +0000 |
commit | 5c6676fba342effe70fcb2d34ab5543ccf3a3896 (patch) | |
tree | 42797498321daa2fea5f31948b5e90af756316b2 | |
parent | 75d3837ca94070bb7070beaa57e225de69a53a0b (diff) | |
download | fpGUI-5c6676fba342effe70fcb2d34ab5543ccf3a3896.tar.xz |
* Applied Vladimir's gui_dialog patch. Adding a helper function for file dialog usage.
* I move HighlightFile from public to private in TfpgFileDialog class. It's a internal function.
* Updated the filedialog example to show pre-highlighted files in the save dialog.
-rw-r--r-- | examples/gui/filedialog/filedialog.lpr | 2 | ||||
-rw-r--r-- | src/gui/gui_dialogs.pas | 43 |
2 files changed, 40 insertions, 5 deletions
diff --git a/examples/gui/filedialog/filedialog.lpr b/examples/gui/filedialog/filedialog.lpr index e7fa99ce..53e79b9a 100644 --- a/examples/gui/filedialog/filedialog.lpr +++ b/examples/gui/filedialog/filedialog.lpr @@ -122,6 +122,8 @@ var begin dlg := TfpgFileDialog.Create(nil); try + if edFilename.Text <> '' then + dlg.Filename := edFilename.Text; if dlg.RunSaveFile then edFilename.Text := dlg.FileName; finally diff --git a/src/gui/gui_dialogs.pas b/src/gui/gui_dialogs.pas index a3f497ec..9fa65eb8 100644 --- a/src/gui/gui_dialogs.pas +++ b/src/gui/gui_dialogs.pas @@ -63,6 +63,9 @@ const mbOKCancel = [mbOK, mbCancel]; mbAbortRetryIgnore = [mbAbort, mbRetry, mbIgnore]; + // make Select File Dialog calls more readable + sfdOpen = True; + sfdSave = False; cMsgDlgBtnText: array[TfpgMsgDlgBtn] of string = ( '', rsOK, rsCancel, rsYes, rsNo, rsAbort, rsRetry, rsIgnore, @@ -168,6 +171,7 @@ type procedure btnDirNewClicked(Sender: TObject); procedure edFilenameChanged(Sender: TObject); procedure UpdateButtonState; + function HighlightFile(const AFilename: string): boolean; protected procedure HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); override; procedure btnOKClick(Sender: TObject); override; @@ -176,7 +180,6 @@ type FileName: string; constructor Create(AOwner: TComponent); override; destructor Destroy; override; - function SelectFile(const AFilename: string): boolean; function RunOpenFile: boolean; function RunSaveFile: boolean; property Filter: string read FFilter write SetFilter; @@ -201,6 +204,8 @@ procedure ShowMessage(AMessage: string; ACentreText: Boolean = False); overload; function SelectFontDialog(var FontDesc: string): boolean; +function SelectFileDialog(aDialogType: boolean = sfdOpen; + const aFilter: TfpgString = ''): TfpgString; implementation @@ -335,6 +340,34 @@ begin frm.Free; end; +function SelectFileDialog(aDialogType: boolean = sfdOpen; + const aFilter: TfpgString = ''): TfpgString; +var + dlg: TfpgFileDialog; + dres: boolean; + DefaultFilter: TfpgString; +begin + DefaultFilter := rsAllFiles+' ('+AllFilesMask+')'+'|'+AllFilesMask; + dlg := TfpgFileDialog.Create(nil); + try + if aFilter = '' then + dlg.Filter := DefaultFilter + else + dlg.Filter := aFilter+'|'+DefaultFilter; + + if aDialogType = sfdOpen then + dres := dlg.RunOpenFile + else + dres := dlg.RunSaveFile; + + if dres then + Result := dlg.FileName + else + Result := ''; + finally + dlg.Free; + end; +end; { TfpgMessageBox } @@ -1208,7 +1241,7 @@ begin chlDir.OnChange := @DirChange; // restore event handler if fsel <> '' then - SelectFile(fsel) + HighlightFile(fsel) else grid.FocusRow := 0; @@ -1216,7 +1249,7 @@ begin grid.SetFocus; end; -function TfpgFileDialog.SelectFile(const AFilename: string): boolean; +function TfpgFileDialog.HighlightFile(const AFilename: string): boolean; var n: integer; begin @@ -1300,7 +1333,7 @@ begin SetCurrentDirectory(sdir); fname := ExtractFileName(FileName); - if not SelectFile(fname) then + if not HighlightFile(fname) then edFilename.Text := fname; WindowTitle := rsOpenAFile; @@ -1324,7 +1357,7 @@ begin sdir := '.'; SetCurrentDirectory(sdir); fname := ExtractFileName(FileName); - if not SelectFile(fname) then + if not HighlightFile(fname) then edFilename.Text := fname; WindowTitle := rsSaveAFile; |