From 9217c2841ce7cced7750c735586d0def3b2847e2 Mon Sep 17 00:00:00 2001 From: lazarus Date: Thu, 30 May 2002 14:11:12 +0000 Subject: [PATCH] MG: added filters and history to TOpenDialog git-svn-id: trunk@1713 - --- lcl/dialogs.pp | 11 ++++--- lcl/include/filedialog.inc | 20 +++++++----- lcl/interfaces/gtk/gtkcallback.inc | 52 ++++++++++++++++++++++++++---- 3 files changed, 64 insertions(+), 19 deletions(-) diff --git a/lcl/dialogs.pp b/lcl/dialogs.pp index 80dfc8673e..a0d974ff1b 100644 --- a/lcl/dialogs.pp +++ b/lcl/dialogs.pp @@ -62,8 +62,8 @@ type TCommonDialog = class(TComponent) private FHandle : integer; - FInitialHeight: integer; - FInitialWidth: integer; + FHeight: integer; + FWidth: integer; FOnCanClose: TCloseQueryEvent; FOnShow, FOnClose : TNotifyEvent; FTitle : string; @@ -85,8 +85,8 @@ type property OnCanClose: TCloseQueryEvent read FOnCanClose write FOnCanClose; property OnShow : TNotifyEvent read FOnShow write FOnShow; property HelpContext: THelpContext read FHelpContext write FHelpContext default 0; - property InitialWidth: integer read FInitialWidth write FInitialWidth; - property InitialHeight: integer read FInitialHeight write FInitialHeight; + property Width: integer read FWidth write FWidth; + property Height: integer read FHeight write FHeight; end; @@ -305,6 +305,9 @@ end. { ============================================================================= $Log$ + Revision 1.13 2002/05/30 14:11:11 lazarus + MG: added filters and history to TOpenDialog + Revision 1.12 2002/05/29 21:44:37 lazarus MG: improved TCommon/File/OpenDialog, fixed TListView scrolling and broder diff --git a/lcl/include/filedialog.inc b/lcl/include/filedialog.inc index 11d474ef4c..8fa26e8206 100644 --- a/lcl/include/filedialog.inc +++ b/lcl/include/filedialog.inc @@ -77,9 +77,6 @@ end; {------------------------------------------------------------------------------} function TFileDialog.DoExecute : boolean; begin - CNSendMessage(LM_SETFILTER, Self, nil); - CNSendMessage(LM_SETFILENAME, Self, nil); - Result:= inherited DoExecute; end; @@ -115,10 +112,12 @@ function TOpenDialog.DoExecute: boolean; procedure DereferenceLinks; var i: integer; begin - Filename:=ExpandFilename(Filename); + if Filename<>'' then + Filename:=ExpandFilename(Filename); if Files<>nil then begin for i:=0 to Files.Count-1 do begin - Files[i]:=ExpandFilename(Files[i]); + if Files[i]<>'' then + Files[i]:=ExpandFilename(Files[i]); end; end; end; @@ -128,9 +127,11 @@ begin if (not (ofNoDereferenceLinks in Options)) then begin DereferenceLinks; end; - if (not (ofNoChangeDir in Options)) and (ExtractFilePath(Filename)<>'') then - begin - InitialDir:=ExtractFilePath(Filename); + if (not (ofNoChangeDir in Options)) then begin + if (ExtractFilePath(Filename)<>'') then + InitialDir:=ExtractFilePath(Filename) + else if (Files.Count>0) and (ExtractFilePath(Files[0])<>'') then + InitialDir:=ExtractFilePath(Files[0]); end; if Result then begin if (DefaultExt<>'') and (ExtractFileExt(Filename)='') @@ -202,6 +203,9 @@ end; { ============================================================================= $Log$ + Revision 1.6 2002/05/30 14:11:11 lazarus + MG: added filters and history to TOpenDialog + Revision 1.5 2002/05/29 21:44:38 lazarus MG: improved TCommon/File/OpenDialog, fixed TListView scrolling and broder diff --git a/lcl/interfaces/gtk/gtkcallback.inc b/lcl/interfaces/gtk/gtkcallback.inc index a791caf137..62fd2f27fb 100644 --- a/lcl/interfaces/gtk/gtkcallback.inc +++ b/lcl/interfaces/gtk/gtkcallback.inc @@ -860,7 +860,10 @@ begin CanClose:=True; theDialog.OnCanClose(theDialog,CanClose); Result:=not CanClose; - if CanClose then StoreCommonDialogSetup(theDialog); + end; + if not Result then begin + StoreCommonDialogSetup(theDialog); + DestroyCommonDialogAddOns(theDialog); end; end; @@ -894,7 +897,7 @@ begin if FileExists(Filename) then begin Details:=GetFileDescription(Filename); end else begin - Details:='(file does not exist)'; + Details:='(file not found: "'+Filename+'")'; end; gtk_label_set_text(PGtkLabel(FileDetailLabel),PChar(Details)); end; @@ -991,16 +994,48 @@ function GTKDialogMenuActivateCB(widget: PGtkWidget; data: gPointer): GBoolean; cdecl; var theDialog: TCommonDialog; - //NewFilename: string; + + procedure CheckFilterActivated(FilterWidget: PGtkWidget); + var AFilterEntry: PFileSelFilterEntry; + begin + if FilterWidget=nil then exit; + AFilterEntry:=gtk_object_get_data(PGtkObject(FilterWidget), + 'LCLIsFilterMenuItem'); + if (AFilterEntry<>nil) and (AFilterEntry^.Mask<>nil) then begin + gtk_file_selection_complete(GTK_FILE_SELECTION(theDialog.Handle), + AFilterEntry^.Mask); + UpdateDetailView(TOpenDialog(theDialog)); + end; + end; + +var + AHistoryEntry: PFileSelHistoryEntry; + FilterMenu, ActiveFilterMenuItem: PGtkWidget; begin Result:=false; theDialog:=TCommonDialog(GetLCLObject(Widget)); if (theDialog is TOpenDialog) then begin - if gtk_object_get_data(PGtkObject(Widget), 'IsHistoryMenuItem')<>nil then - begin - - //UpdateDetailView(TOpenDialog(theDialog)); + // check if history activated + AHistoryEntry:=gtk_object_get_data(PGtkObject(Widget), + 'LCLIsHistoryMenuItem'); + if (AHistoryEntry<>nil) and (AHistoryEntry^.Filename<>nil) then begin + // use has choosen a history file + // -> select it in the filedialog + gtk_file_selection_complete(GTK_FILE_SELECTION(theDialog.Handle), + AHistoryEntry^.Filename); + // restore filter + if DirectoryExists(AHistoryEntry^.Filename) then begin + FilterMenu:=gtk_object_get_data(PGtkObject(theDialog.Handle), + 'LCLFilterMenu'); + if FilterMenu<>nil then begin + ActiveFilterMenuItem:=gtk_menu_get_active(GTK_MENU(FilterMenu)); + CheckFilterActivated(ActiveFilterMenuItem); + end; + end; + UpdateDetailView(TOpenDialog(theDialog)); end; + // check if filter activated + CheckFilterActivated(Widget); end; end; @@ -1946,6 +1981,9 @@ end; { ============================================================================= $Log$ + Revision 1.77 2002/05/30 14:11:12 lazarus + MG: added filters and history to TOpenDialog + Revision 1.76 2002/05/29 21:44:38 lazarus MG: improved TCommon/File/OpenDialog, fixed TListView scrolling and broder