diff --git a/include/wx/filedlg.h b/include/wx/filedlg.h index 21bd2595d5..3b4de90118 100644 --- a/include/wx/filedlg.h +++ b/include/wx/filedlg.h @@ -159,11 +159,7 @@ wxSaveFileSelector(const wxChar *what, #elif defined(__WXMOTIF__) #include "wx/motif/filedlg.h" #elif defined(__WXGTK__) -#ifdef __WXGTK24__ #include "wx/gtk/filedlg.h" -#else -#include "wx/generic/filedlgg.h" -#endif #elif defined(__WXX11__) #include "wx/generic/filedlgg.h" #elif defined(__WXMGL__) diff --git a/include/wx/generic/filedlgg.h b/include/wx/generic/filedlgg.h index 23203759db..62f6bf2481 100644 --- a/include/wx/generic/filedlgg.h +++ b/include/wx/generic/filedlgg.h @@ -34,7 +34,7 @@ class WXDLLEXPORT wxListItem; class WXDLLEXPORT wxStaticText; class WXDLLEXPORT wxTextCtrl; -#if defined(__WXUNIVERSAL__)||defined(__WXGTK__)||defined(__WXX11__)||defined(__WXMGL__)||defined(__WXCOCOA__) +#if defined(__WXUNIVERSAL__)||defined(__WXX11__)||defined(__WXMGL__)||defined(__WXCOCOA__) #define USE_GENERIC_FILEDIALOG #endif @@ -53,7 +53,15 @@ public: const wxString& defaultFile = wxEmptyString, const wxString& wildCard = wxFileSelectorDefaultWildcardStr, long style = 0, - const wxPoint& pos = wxDefaultPosition); + const wxPoint& pos = wxDefaultPosition, + bool bypassGenericImpl = false ); + bool Create( wxWindow *parent, + const wxString& message = wxFileSelectorPromptStr, + const wxString& defaultDir = wxEmptyString, + const wxString& defaultFile = wxEmptyString, + const wxString& wildCard = wxFileSelectorDefaultWildcardStr, + long style = 0, + const wxPoint& pos = wxDefaultPosition ); virtual ~wxGenericFileDialog(); virtual void SetMessage(const wxString& message) { SetTitle(message); } @@ -87,6 +95,10 @@ public: virtual void HandleAction( const wxString &fn ); virtual void UpdateControls(); + +private: + // Don't use this implementation at all :-) + bool m_bypassGenericImpl; protected: // use the filter with the given index @@ -114,8 +126,6 @@ private: class WXDLLEXPORT wxFileDialog: public wxGenericFileDialog { - DECLARE_DYNAMIC_CLASS(wxFileDialog) - public: wxFileDialog() {} @@ -129,6 +139,9 @@ public: :wxGenericFileDialog(parent, message, defaultDir, defaultFile, wildCard, style, pos) { } + +private: + DECLARE_DYNAMIC_CLASS(wxFileDialog) }; #endif // USE_GENERIC_FILEDIALOG diff --git a/include/wx/gtk/filedlg.h b/include/wx/gtk/filedlg.h index 4aa8521e9b..1e37455f3c 100644 --- a/include/wx/gtk/filedlg.h +++ b/include/wx/gtk/filedlg.h @@ -15,11 +15,13 @@ #pragma interface #endif +#include "wx/generic/filedlgg.h" + //------------------------------------------------------------------------- // wxFileDialog //------------------------------------------------------------------------- -class wxFileDialog: public wxFileDialogBase +class wxFileDialog: public wxGenericFileDialog { public: wxFileDialog() { } @@ -44,13 +46,20 @@ public: virtual void SetWildcard(const wxString& wildCard); virtual void SetFilterIndex(int filterIndex); + virtual int ShowModal(); + virtual bool Show( bool show = true ); + + void OnFakeOk( wxCommandEvent &event ); + //private: bool m_destroyed_by_delete; void UpdateFromDialog(); void UpdateDialog(); - + +private: DECLARE_DYNAMIC_CLASS(wxFileDialog) + DECLARE_EVENT_TABLE() }; #endif // __GTKFILEDLGH__ diff --git a/include/wx/gtk1/filedlg.h b/include/wx/gtk1/filedlg.h index 4aa8521e9b..1e37455f3c 100644 --- a/include/wx/gtk1/filedlg.h +++ b/include/wx/gtk1/filedlg.h @@ -15,11 +15,13 @@ #pragma interface #endif +#include "wx/generic/filedlgg.h" + //------------------------------------------------------------------------- // wxFileDialog //------------------------------------------------------------------------- -class wxFileDialog: public wxFileDialogBase +class wxFileDialog: public wxGenericFileDialog { public: wxFileDialog() { } @@ -44,13 +46,20 @@ public: virtual void SetWildcard(const wxString& wildCard); virtual void SetFilterIndex(int filterIndex); + virtual int ShowModal(); + virtual bool Show( bool show = true ); + + void OnFakeOk( wxCommandEvent &event ); + //private: bool m_destroyed_by_delete; void UpdateFromDialog(); void UpdateDialog(); - + +private: DECLARE_DYNAMIC_CLASS(wxFileDialog) + DECLARE_EVENT_TABLE() }; #endif // __GTKFILEDLGH__ diff --git a/src/generic/filedlgg.cpp b/src/generic/filedlgg.cpp index 4f6f0d3ec2..2b482b1356 100644 --- a/src/generic/filedlgg.cpp +++ b/src/generic/filedlgg.cpp @@ -20,7 +20,7 @@ #pragma hdrstop #endif -#if wxUSE_FILEDLG && !defined(__WXGTK24__) +#if wxUSE_FILEDLG // NOTE : it probably also supports MAC, untested #if !defined(__UNIX__) && !defined(__DOS__) && !defined(__WIN32__) && !defined(__OS2__) @@ -876,11 +876,29 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent, const wxString& defaultFile, const wxString& wildCard, long style, - const wxPoint& pos ) + const wxPoint& pos, + bool bypassGenericImpl ) :wxFileDialogBase(parent, message, defaultDir, defaultFile, wildCard, style, pos) { - wxDialog::Create( parent, wxID_ANY, message, pos, wxDefaultSize, - wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ); + m_bypassGenericImpl = bypassGenericImpl; + + if (!m_bypassGenericImpl) + Create( parent, message, defaultDir, defaultFile, wildCard, style, pos ); +} + +bool wxGenericFileDialog::Create( wxWindow *parent, + const wxString& message, + const wxString& defaultDir, + const wxString& defaultFile, + const wxString& wildCard, + long style, + const wxPoint& pos ) +{ + if (!wxDialog::Create( parent, wxID_ANY, message, pos, wxDefaultSize, + wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )) + { + return false; + } if (wxConfig::Get(false)) { @@ -1031,22 +1049,27 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent, Centre( wxBOTH ); m_text->SetFocus(); + + return true; } wxGenericFileDialog::~wxGenericFileDialog() { - if (wxConfig::Get(false)) + if (!m_bypassGenericImpl) { - wxConfig::Get()->Write(wxT("/wxWindows/wxFileDialog/ViewStyle"), - ms_lastViewStyle); - wxConfig::Get()->Write(wxT("/wxWindows/wxFileDialog/ShowHidden"), - ms_lastShowHidden); - } + if (wxConfig::Get(false)) + { + wxConfig::Get()->Write(wxT("/wxWindows/wxFileDialog/ViewStyle"), + ms_lastViewStyle); + wxConfig::Get()->Write(wxT("/wxWindows/wxFileDialog/ShowHidden"), + ms_lastShowHidden); + } - const int count = m_choice->GetCount(); - for ( int i = 0; i < count; i++ ) - { - delete (wxString *)m_choice->GetClientData(i); + const int count = m_choice->GetCount(); + for ( int i = 0; i < count; i++ ) + { + delete (wxString *)m_choice->GetClientData(i); + } } } @@ -1416,5 +1439,5 @@ IMPLEMENT_DYNAMIC_CLASS(wxFileDialog, wxGenericFileDialog); #endif // USE_GENERIC_FILEDIALOG -#endif // wxUSE_FILEDLG && !defined(__WXGTK24__) +#endif // wxUSE_FILEDLG diff --git a/src/gtk/filedlg.cpp b/src/gtk/filedlg.cpp index adb8f61207..b554a0de1b 100644 --- a/src/gtk/filedlg.cpp +++ b/src/gtk/filedlg.cpp @@ -14,7 +14,7 @@ // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" -#if wxUSE_FILEDLG && defined(__WXGTK24__) +#if wxUSE_FILEDLG #include "wx/filedlg.h" #include "wx/utils.h" @@ -23,6 +23,8 @@ #include "wx/msgdlg.h" #include + +#ifdef __WXGTK24__ #include "wx/gtk/private.h" //----------------------------------------------------------------------------- @@ -118,21 +120,27 @@ static void gtk_filedialog_response_callback(GtkWidget *w, dialog->m_destroyed_by_delete = TRUE; } } +#endif //----------------------------------------------------------------------------- // wxFileDialog //----------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxFileDialogBase) +IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxGenericFileDialog) + +BEGIN_EVENT_TABLE(wxFileDialog,wxGenericFileDialog) + EVT_BUTTON(wxID_OK, wxFileDialog::OnFakeOk) +END_EVENT_TABLE() wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard, long style, const wxPoint& pos) - : wxFileDialogBase(parent, message, defaultDir, defaultFileName, - wildCard, style, pos) + : wxGenericFileDialog(parent, message, defaultDir, defaultFileName, + wildCard, style, pos, true ) { +#ifdef __WXGTK24__ m_needParent = FALSE; m_destroyed_by_delete = FALSE; @@ -184,16 +192,49 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, SetWildcard(wildCard); SetFilterIndex(0); +#else + wxGenericFileDialog::Create( parent, message, defaultDir, defaultFileName, wildCard, style, pos ); +#endif } wxFileDialog::~wxFileDialog() { +#ifdef __WXGTK24__ if (m_destroyed_by_delete) m_widget = NULL; +#endif +} + +void wxFileDialog::OnFakeOk( wxCommandEvent &event ) +{ +#ifdef __WXGTK24__ + wxDialog::OnOK( event ); +#else + wxGenericFileDialog::OnListOk( event ); +#endif +} + +int wxFileDialog::ShowModal() +{ +#ifdef __WXGTK24__ + return wxDialog::ShowModal(); +#else + return wxGenericFileDialog::ShowModal(); +#endif +} + +bool wxFileDialog::Show( bool show ) +{ +#ifdef __WXGTK24__ + return wxDialog::Show( show ); +#else + return wxGenericFileDialog::Show( show ); +#endif } void wxFileDialog::GetFilenames(wxArrayString& files) const { +#ifdef __WXGTK24__ GetPaths(files); for (size_t n = 0; n < files.GetCount(); n++ ) { @@ -206,10 +247,14 @@ void wxFileDialog::GetFilenames(wxArrayString& files) const } files[n] = name; } +#else + wxGenericFileDialog::GetFilenames( files ); +#endif } void wxFileDialog::GetPaths(wxArrayString& paths) const { +#ifdef __WXGTK24__ paths.Empty(); if (GetWindowStyle() & wxMULTIPLE) { @@ -230,16 +275,24 @@ void wxFileDialog::GetPaths(wxArrayString& paths) const { paths.Add(m_fileName); } +#else + wxGenericFileDialog::GetPaths( paths ); +#endif } void wxFileDialog::SetMessage(const wxString& message) { +#ifdef __WXGTK24__ m_message = message; SetTitle(message); +#else + wxGenericFileDialog::SetMessage( message ); +#endif } void wxFileDialog::SetPath(const wxString& path) { +#ifdef __WXGTK24__ if (path.empty()) return; wxFileName fn(path); @@ -247,68 +300,39 @@ void wxFileDialog::SetPath(const wxString& path) m_dir = fn.GetPath(); m_fileName = fn.GetFullName(); UpdateDialog(); +#else + wxGenericFileDialog::SetPath( path ); +#endif } void wxFileDialog::SetDirectory(const wxString& dir) { +#ifdef __WXGTK24__ if (wxDirExists(dir)) { m_dir = dir; m_path = wxFileName(m_dir, m_fileName).GetFullPath(); UpdateDialog(); } +#else + wxGenericFileDialog::SetDirectory( dir ); +#endif } void wxFileDialog::SetFilename(const wxString& name) { +#ifdef __WXGTK24__ m_fileName = name; m_path = wxFileName(m_dir, m_fileName).GetFullPath(); UpdateDialog(); -} - -void wxFileDialog::UpdateDialog() -{ - // set currently selected directory to match the path: - if (!m_dir.empty() && wxDirExists(m_dir)) - { - // NB: This is important -- if we set directory only and not the path, - // then dialog will still remember old path set using previous - // call to gtk_chooser_set_filename. If the previous directory - // was a subdirectory of the directory we want to select now, - // the dialog would still contain directory selector controls - // for the subdirectory (with the parent directory selected), - // instead of showing only the parent directory as expected. - // This way, we force GtkFileChooser to really change the - // directory. Finally, it doesn't have to be done if filename - // is not empty because of the code that sets the filename below. - if (m_fileName.empty()) - gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget), - wxGTK_CONV(m_dir)); - - gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(m_widget), - wxGTK_CONV(m_dir)); - } - - // if the user set only the directory (e.g. by calling SetDirectory) - // and not the default filename, then we don't want to set the filename: - if (!m_fileName.empty()) - { - gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget), - wxGTK_CONV(m_path)); - - // pre-fill the filename when saving, too (there's no text entry - // control when opening a file, so it doesn't make sense to - // do this when opening files): - if (GetWindowStyle() & wxSAVE) - { - gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(m_widget), - wxGTK_CONV(m_fileName)); - } - } +#else + wxGenericFileDialog::SetFilename( name ); +#endif } void wxFileDialog::SetWildcard(const wxString& wildCard) { +#ifdef __WXGTK24__ m_wildCard = wildCard; GtkFileChooser* chooser = GTK_FILE_CHOOSER(m_widget); @@ -350,10 +374,14 @@ void wxFileDialog::SetWildcard(const wxString& wildCard) gtk_file_chooser_add_filter(chooser, filter); } } +#else + wxGenericFileDialog::SetWildcard( wildCard ); +#endif } void wxFileDialog::SetFilterIndex(int filterIndex) { +#ifdef __WXGTK24__ m_filterIndex = filterIndex; GtkFileChooser *chooser = GTK_FILE_CHOOSER(m_widget); @@ -372,10 +400,57 @@ void wxFileDialog::SetFilterIndex(int filterIndex) fnode = fnode->next; } g_slist_free(filters); +#else + wxGenericFileDialog::SetFilterIndex( filterIndex ); +#endif +} + +void wxFileDialog::UpdateDialog() +{ +#ifdef __WXGTK24__ + // set currently selected directory to match the path: + if (!m_dir.empty() && wxDirExists(m_dir)) + { + // NB: This is important -- if we set directory only and not the path, + // then dialog will still remember old path set using previous + // call to gtk_chooser_set_filename. If the previous directory + // was a subdirectory of the directory we want to select now, + // the dialog would still contain directory selector controls + // for the subdirectory (with the parent directory selected), + // instead of showing only the parent directory as expected. + // This way, we force GtkFileChooser to really change the + // directory. Finally, it doesn't have to be done if filename + // is not empty because of the code that sets the filename below. + if (m_fileName.empty()) + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget), + wxGTK_CONV(m_dir)); + + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(m_widget), + wxGTK_CONV(m_dir)); + } + + // if the user set only the directory (e.g. by calling SetDirectory) + // and not the default filename, then we don't want to set the filename: + if (!m_fileName.empty()) + { + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget), + wxGTK_CONV(m_path)); + + // pre-fill the filename when saving, too (there's no text entry + // control when opening a file, so it doesn't make sense to + // do this when opening files): + if (GetWindowStyle() & wxSAVE) + { + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(m_widget), + wxGTK_CONV(m_fileName)); + } + } +#endif } void wxFileDialog::UpdateFromDialog() { +#ifdef __WXGTK24__ // update filterIndex GSList *fnode = gtk_file_chooser_list_filters(GTK_FILE_CHOOSER(m_widget)); GSList *filters = fnode; @@ -395,6 +470,7 @@ void wxFileDialog::UpdateFromDialog() fnode = fnode->next; } g_slist_free(filters); +#endif } -#endif // wxUSE_FILEDLG && defined(__WXGTK24__) +#endif // wxUSE_FILEDLG diff --git a/src/gtk1/filedlg.cpp b/src/gtk1/filedlg.cpp index adb8f61207..b554a0de1b 100644 --- a/src/gtk1/filedlg.cpp +++ b/src/gtk1/filedlg.cpp @@ -14,7 +14,7 @@ // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" -#if wxUSE_FILEDLG && defined(__WXGTK24__) +#if wxUSE_FILEDLG #include "wx/filedlg.h" #include "wx/utils.h" @@ -23,6 +23,8 @@ #include "wx/msgdlg.h" #include + +#ifdef __WXGTK24__ #include "wx/gtk/private.h" //----------------------------------------------------------------------------- @@ -118,21 +120,27 @@ static void gtk_filedialog_response_callback(GtkWidget *w, dialog->m_destroyed_by_delete = TRUE; } } +#endif //----------------------------------------------------------------------------- // wxFileDialog //----------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxFileDialogBase) +IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxGenericFileDialog) + +BEGIN_EVENT_TABLE(wxFileDialog,wxGenericFileDialog) + EVT_BUTTON(wxID_OK, wxFileDialog::OnFakeOk) +END_EVENT_TABLE() wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard, long style, const wxPoint& pos) - : wxFileDialogBase(parent, message, defaultDir, defaultFileName, - wildCard, style, pos) + : wxGenericFileDialog(parent, message, defaultDir, defaultFileName, + wildCard, style, pos, true ) { +#ifdef __WXGTK24__ m_needParent = FALSE; m_destroyed_by_delete = FALSE; @@ -184,16 +192,49 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, SetWildcard(wildCard); SetFilterIndex(0); +#else + wxGenericFileDialog::Create( parent, message, defaultDir, defaultFileName, wildCard, style, pos ); +#endif } wxFileDialog::~wxFileDialog() { +#ifdef __WXGTK24__ if (m_destroyed_by_delete) m_widget = NULL; +#endif +} + +void wxFileDialog::OnFakeOk( wxCommandEvent &event ) +{ +#ifdef __WXGTK24__ + wxDialog::OnOK( event ); +#else + wxGenericFileDialog::OnListOk( event ); +#endif +} + +int wxFileDialog::ShowModal() +{ +#ifdef __WXGTK24__ + return wxDialog::ShowModal(); +#else + return wxGenericFileDialog::ShowModal(); +#endif +} + +bool wxFileDialog::Show( bool show ) +{ +#ifdef __WXGTK24__ + return wxDialog::Show( show ); +#else + return wxGenericFileDialog::Show( show ); +#endif } void wxFileDialog::GetFilenames(wxArrayString& files) const { +#ifdef __WXGTK24__ GetPaths(files); for (size_t n = 0; n < files.GetCount(); n++ ) { @@ -206,10 +247,14 @@ void wxFileDialog::GetFilenames(wxArrayString& files) const } files[n] = name; } +#else + wxGenericFileDialog::GetFilenames( files ); +#endif } void wxFileDialog::GetPaths(wxArrayString& paths) const { +#ifdef __WXGTK24__ paths.Empty(); if (GetWindowStyle() & wxMULTIPLE) { @@ -230,16 +275,24 @@ void wxFileDialog::GetPaths(wxArrayString& paths) const { paths.Add(m_fileName); } +#else + wxGenericFileDialog::GetPaths( paths ); +#endif } void wxFileDialog::SetMessage(const wxString& message) { +#ifdef __WXGTK24__ m_message = message; SetTitle(message); +#else + wxGenericFileDialog::SetMessage( message ); +#endif } void wxFileDialog::SetPath(const wxString& path) { +#ifdef __WXGTK24__ if (path.empty()) return; wxFileName fn(path); @@ -247,68 +300,39 @@ void wxFileDialog::SetPath(const wxString& path) m_dir = fn.GetPath(); m_fileName = fn.GetFullName(); UpdateDialog(); +#else + wxGenericFileDialog::SetPath( path ); +#endif } void wxFileDialog::SetDirectory(const wxString& dir) { +#ifdef __WXGTK24__ if (wxDirExists(dir)) { m_dir = dir; m_path = wxFileName(m_dir, m_fileName).GetFullPath(); UpdateDialog(); } +#else + wxGenericFileDialog::SetDirectory( dir ); +#endif } void wxFileDialog::SetFilename(const wxString& name) { +#ifdef __WXGTK24__ m_fileName = name; m_path = wxFileName(m_dir, m_fileName).GetFullPath(); UpdateDialog(); -} - -void wxFileDialog::UpdateDialog() -{ - // set currently selected directory to match the path: - if (!m_dir.empty() && wxDirExists(m_dir)) - { - // NB: This is important -- if we set directory only and not the path, - // then dialog will still remember old path set using previous - // call to gtk_chooser_set_filename. If the previous directory - // was a subdirectory of the directory we want to select now, - // the dialog would still contain directory selector controls - // for the subdirectory (with the parent directory selected), - // instead of showing only the parent directory as expected. - // This way, we force GtkFileChooser to really change the - // directory. Finally, it doesn't have to be done if filename - // is not empty because of the code that sets the filename below. - if (m_fileName.empty()) - gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget), - wxGTK_CONV(m_dir)); - - gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(m_widget), - wxGTK_CONV(m_dir)); - } - - // if the user set only the directory (e.g. by calling SetDirectory) - // and not the default filename, then we don't want to set the filename: - if (!m_fileName.empty()) - { - gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget), - wxGTK_CONV(m_path)); - - // pre-fill the filename when saving, too (there's no text entry - // control when opening a file, so it doesn't make sense to - // do this when opening files): - if (GetWindowStyle() & wxSAVE) - { - gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(m_widget), - wxGTK_CONV(m_fileName)); - } - } +#else + wxGenericFileDialog::SetFilename( name ); +#endif } void wxFileDialog::SetWildcard(const wxString& wildCard) { +#ifdef __WXGTK24__ m_wildCard = wildCard; GtkFileChooser* chooser = GTK_FILE_CHOOSER(m_widget); @@ -350,10 +374,14 @@ void wxFileDialog::SetWildcard(const wxString& wildCard) gtk_file_chooser_add_filter(chooser, filter); } } +#else + wxGenericFileDialog::SetWildcard( wildCard ); +#endif } void wxFileDialog::SetFilterIndex(int filterIndex) { +#ifdef __WXGTK24__ m_filterIndex = filterIndex; GtkFileChooser *chooser = GTK_FILE_CHOOSER(m_widget); @@ -372,10 +400,57 @@ void wxFileDialog::SetFilterIndex(int filterIndex) fnode = fnode->next; } g_slist_free(filters); +#else + wxGenericFileDialog::SetFilterIndex( filterIndex ); +#endif +} + +void wxFileDialog::UpdateDialog() +{ +#ifdef __WXGTK24__ + // set currently selected directory to match the path: + if (!m_dir.empty() && wxDirExists(m_dir)) + { + // NB: This is important -- if we set directory only and not the path, + // then dialog will still remember old path set using previous + // call to gtk_chooser_set_filename. If the previous directory + // was a subdirectory of the directory we want to select now, + // the dialog would still contain directory selector controls + // for the subdirectory (with the parent directory selected), + // instead of showing only the parent directory as expected. + // This way, we force GtkFileChooser to really change the + // directory. Finally, it doesn't have to be done if filename + // is not empty because of the code that sets the filename below. + if (m_fileName.empty()) + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget), + wxGTK_CONV(m_dir)); + + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(m_widget), + wxGTK_CONV(m_dir)); + } + + // if the user set only the directory (e.g. by calling SetDirectory) + // and not the default filename, then we don't want to set the filename: + if (!m_fileName.empty()) + { + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget), + wxGTK_CONV(m_path)); + + // pre-fill the filename when saving, too (there's no text entry + // control when opening a file, so it doesn't make sense to + // do this when opening files): + if (GetWindowStyle() & wxSAVE) + { + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(m_widget), + wxGTK_CONV(m_fileName)); + } + } +#endif } void wxFileDialog::UpdateFromDialog() { +#ifdef __WXGTK24__ // update filterIndex GSList *fnode = gtk_file_chooser_list_filters(GTK_FILE_CHOOSER(m_widget)); GSList *filters = fnode; @@ -395,6 +470,7 @@ void wxFileDialog::UpdateFromDialog() fnode = fnode->next; } g_slist_free(filters); +#endif } -#endif // wxUSE_FILEDLG && defined(__WXGTK24__) +#endif // wxUSE_FILEDLG