From 76840ed0db0051fc64de37911250bd5ce4d4a350 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sat, 27 Nov 2004 23:18:40 +0000 Subject: [PATCH] Fixes for file dialog. No longer spits out GTK error messages. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30799 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/filedlg.h | 4 +- include/wx/gtk1/filedlg.h | 4 +- src/gtk/filedlg.cpp | 99 +++++++++++++++++++-------------------- src/gtk1/filedlg.cpp | 99 +++++++++++++++++++-------------------- 4 files changed, 98 insertions(+), 108 deletions(-) diff --git a/include/wx/gtk/filedlg.h b/include/wx/gtk/filedlg.h index 51daa86bfc..31c9992dce 100644 --- a/include/wx/gtk/filedlg.h +++ b/include/wx/gtk/filedlg.h @@ -31,6 +31,8 @@ public: const wxString& wildCard = wxFileSelectorDefaultWildcardStr, long style = 0, const wxPoint& pos = wxDefaultPosition); + + ~wxFileDialog(); virtual void GetPaths(wxArrayString& paths) const; virtual void GetFilenames(wxArrayString& files) const; @@ -42,8 +44,6 @@ public: virtual void SetWildcard(const wxString& wildCard); virtual void SetFilterIndex(int filterIndex); void UpdateFromDialog(); - void UpdateDialog(); - void DoSetPath(const wxString& path); private: DECLARE_DYNAMIC_CLASS(wxFileDialog) }; diff --git a/include/wx/gtk1/filedlg.h b/include/wx/gtk1/filedlg.h index 51daa86bfc..31c9992dce 100644 --- a/include/wx/gtk1/filedlg.h +++ b/include/wx/gtk1/filedlg.h @@ -31,6 +31,8 @@ public: const wxString& wildCard = wxFileSelectorDefaultWildcardStr, long style = 0, const wxPoint& pos = wxDefaultPosition); + + ~wxFileDialog(); virtual void GetPaths(wxArrayString& paths) const; virtual void GetFilenames(wxArrayString& files) const; @@ -42,8 +44,6 @@ public: virtual void SetWildcard(const wxString& wildCard); virtual void SetFilterIndex(int filterIndex); void UpdateFromDialog(); - void UpdateDialog(); - void DoSetPath(const wxString& path); private: DECLARE_DYNAMIC_CLASS(wxFileDialog) }; diff --git a/src/gtk/filedlg.cpp b/src/gtk/filedlg.cpp index fa7e6e81af..04aa374d79 100644 --- a/src/gtk/filedlg.cpp +++ b/src/gtk/filedlg.cpp @@ -82,7 +82,7 @@ static void gtk_filedialog_ok_callback(GtkWidget *widget, wxFileDialog *dialog) } } - dialog->DoSetPath(filename); + dialog->SetPath(filename); dialog->UpdateFromDialog(); wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK); @@ -180,10 +180,9 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, SetFilterIndex(0); } -void wxFileDialog::SetPath(const wxString& path) +wxFileDialog::~wxFileDialog() { - DoSetPath(path); - UpdateDialog(); + m_widget = NULL; } void wxFileDialog::GetFilenames(wxArrayString& files) const @@ -201,6 +200,7 @@ void wxFileDialog::GetFilenames(wxArrayString& files) const files[n] = name; } } + void wxFileDialog::GetPaths(wxArrayString& paths) const { paths.Empty(); @@ -231,17 +231,56 @@ void wxFileDialog::SetMessage(const wxString& message) SetTitle(message); } +void wxFileDialog::SetPath(const wxString& path) +{ + if (path.empty()) return; + + wxFileName fn(path); + m_path = fn.GetFullPath(); + m_dir = fn.GetPath(); + m_fileName = fn.GetFullName(); + + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(m_widget), + wxGTK_CONV(m_dir)); + + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget), + wxGTK_CONV(m_path)); + + // pre-fill the filename, too: + if (GetWindowStyle() & wxSAVE) // Why only then?? + { + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(m_widget), + wxGTK_CONV(m_fileName)); + } +} + void wxFileDialog::SetDirectory(const wxString& dir) { - wxFileName fn(dir,m_fileName); - SetPath(fn.GetFullPath()); + if (wxDirExists(dir)) + { + m_dir = dir; + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(m_widget), + wxGTK_CONV(m_dir)); + wxFileName fn(m_dir,m_fileName); + m_path = fn.GetFullPath(); + } } void wxFileDialog::SetFilename(const wxString& name) { m_fileName = name; - wxFileName fn(m_dir,name); - SetPath(fn.GetFullPath()); + wxFileName fn(m_dir,m_fileName); + m_path = fn.GetFullPath(); + + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget), + wxGTK_CONV(m_path)); + + // pre-fill the filename, too: + if (GetWindowStyle() & wxSAVE) // Why only then?? + { + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(m_widget), + wxGTK_CONV(m_fileName)); + } } void wxFileDialog::SetWildcard(const wxString& wildCard) @@ -334,48 +373,4 @@ void wxFileDialog::UpdateFromDialog() g_slist_free(filters); } -void wxFileDialog::UpdateDialog() -{ - - if (wxDirExists(m_path)) - { - gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(m_widget), - wxGTK_CONV(m_path)); - } - else - { - gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget), - wxGTK_CONV(m_path)); - - // pre-fill the filename, too: - if (GetWindowStyle() & wxSAVE) - { - gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(m_widget), - wxGTK_CONV(m_fileName)); - } - } -} - -void wxFileDialog::DoSetPath(const wxString& path) -{ - if (!path.empty()) - { - wxFileName fn(path); - fn.MakeAbsolute(); - m_path = fn.GetFullPath(); - - wxString ext; - wxSplitPath(path, &m_dir, &m_fileName, &ext); - if (!ext.empty()) - { - m_fileName += wxT("."); - m_fileName += ext; - } - } - else - { - m_path = path; - } -} - #endif // wxUSE_FILEDLG && defined(__WXGTK24__) diff --git a/src/gtk1/filedlg.cpp b/src/gtk1/filedlg.cpp index fa7e6e81af..04aa374d79 100644 --- a/src/gtk1/filedlg.cpp +++ b/src/gtk1/filedlg.cpp @@ -82,7 +82,7 @@ static void gtk_filedialog_ok_callback(GtkWidget *widget, wxFileDialog *dialog) } } - dialog->DoSetPath(filename); + dialog->SetPath(filename); dialog->UpdateFromDialog(); wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK); @@ -180,10 +180,9 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, SetFilterIndex(0); } -void wxFileDialog::SetPath(const wxString& path) +wxFileDialog::~wxFileDialog() { - DoSetPath(path); - UpdateDialog(); + m_widget = NULL; } void wxFileDialog::GetFilenames(wxArrayString& files) const @@ -201,6 +200,7 @@ void wxFileDialog::GetFilenames(wxArrayString& files) const files[n] = name; } } + void wxFileDialog::GetPaths(wxArrayString& paths) const { paths.Empty(); @@ -231,17 +231,56 @@ void wxFileDialog::SetMessage(const wxString& message) SetTitle(message); } +void wxFileDialog::SetPath(const wxString& path) +{ + if (path.empty()) return; + + wxFileName fn(path); + m_path = fn.GetFullPath(); + m_dir = fn.GetPath(); + m_fileName = fn.GetFullName(); + + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(m_widget), + wxGTK_CONV(m_dir)); + + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget), + wxGTK_CONV(m_path)); + + // pre-fill the filename, too: + if (GetWindowStyle() & wxSAVE) // Why only then?? + { + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(m_widget), + wxGTK_CONV(m_fileName)); + } +} + void wxFileDialog::SetDirectory(const wxString& dir) { - wxFileName fn(dir,m_fileName); - SetPath(fn.GetFullPath()); + if (wxDirExists(dir)) + { + m_dir = dir; + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(m_widget), + wxGTK_CONV(m_dir)); + wxFileName fn(m_dir,m_fileName); + m_path = fn.GetFullPath(); + } } void wxFileDialog::SetFilename(const wxString& name) { m_fileName = name; - wxFileName fn(m_dir,name); - SetPath(fn.GetFullPath()); + wxFileName fn(m_dir,m_fileName); + m_path = fn.GetFullPath(); + + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget), + wxGTK_CONV(m_path)); + + // pre-fill the filename, too: + if (GetWindowStyle() & wxSAVE) // Why only then?? + { + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(m_widget), + wxGTK_CONV(m_fileName)); + } } void wxFileDialog::SetWildcard(const wxString& wildCard) @@ -334,48 +373,4 @@ void wxFileDialog::UpdateFromDialog() g_slist_free(filters); } -void wxFileDialog::UpdateDialog() -{ - - if (wxDirExists(m_path)) - { - gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(m_widget), - wxGTK_CONV(m_path)); - } - else - { - gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget), - wxGTK_CONV(m_path)); - - // pre-fill the filename, too: - if (GetWindowStyle() & wxSAVE) - { - gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(m_widget), - wxGTK_CONV(m_fileName)); - } - } -} - -void wxFileDialog::DoSetPath(const wxString& path) -{ - if (!path.empty()) - { - wxFileName fn(path); - fn.MakeAbsolute(); - m_path = fn.GetFullPath(); - - wxString ext; - wxSplitPath(path, &m_dir, &m_fileName, &ext); - if (!ext.empty()) - { - m_fileName += wxT("."); - m_fileName += ext; - } - } - else - { - m_path = path; - } -} - #endif // wxUSE_FILEDLG && defined(__WXGTK24__) -- 2.45.2