Store the selected directory in wxGTK wxDirDialog.

This should help with the selected directory not being remembered since
GTK+ 2.24.11 as apparently gtk_file_chooser_get_filename() doesn't work any
more now after hiding the dialog -- so call it before doing this and save the
result.

Also get rid of the ugly and apparently completely unnecessary OnFakeOk().

Closes #14525.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72779 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2012-10-25 23:26:36 +00:00
parent 656b9f4467
commit 5a7c1881a1
2 changed files with 26 additions and 48 deletions

View File

@ -42,6 +42,11 @@ public: // overrides from wxGenericDirDialog
void SetPath(const wxString& path);
// Implementation only.
void GTKOnAccept();
void GTKOnCancel();
protected:
// override this from wxTLW since the native
// form doesn't have any m_wxwindow
@ -51,10 +56,9 @@ protected:
private:
void OnFakeOk( wxCommandEvent &event );
wxString m_selectedDirectory;
DECLARE_DYNAMIC_CLASS(wxDirDialog)
DECLARE_EVENT_TABLE()
};
#endif // __GTKDIRDLGH__

View File

@ -35,49 +35,15 @@
#include <unistd.h> // chdir
#endif
//-----------------------------------------------------------------------------
// "clicked" for OK-button
//-----------------------------------------------------------------------------
extern "C" {
static void gtk_dirdialog_ok_callback(GtkWidget *widget, wxDirDialog *dialog)
{
// change to the directory where the user went if asked
if (dialog->HasFlag(wxDD_CHANGE_DIR))
{
wxGtkString filename(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)));
chdir(filename);
}
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
event.SetEventObject(dialog);
dialog->HandleWindowEvent(event);
}
}
//-----------------------------------------------------------------------------
// "clicked" for Cancel-button
//-----------------------------------------------------------------------------
extern "C" {
static void gtk_dirdialog_cancel_callback(GtkWidget *WXUNUSED(w),
wxDirDialog *dialog)
{
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
event.SetEventObject(dialog);
dialog->HandleWindowEvent(event);
}
}
extern "C" {
static void gtk_dirdialog_response_callback(GtkWidget *w,
static void gtk_dirdialog_response_callback(GtkWidget * WXUNUSED(w),
gint response,
wxDirDialog *dialog)
{
if (response == GTK_RESPONSE_ACCEPT)
gtk_dirdialog_ok_callback(w, dialog);
dialog->GTKOnAccept();
else // GTK_RESPONSE_CANCEL or GTK_RESPONSE_NONE
gtk_dirdialog_cancel_callback(w, dialog);
dialog->GTKOnCancel();
}
}
@ -87,10 +53,6 @@ static void gtk_dirdialog_response_callback(GtkWidget *w,
IMPLEMENT_DYNAMIC_CLASS(wxDirDialog, wxDialog)
BEGIN_EVENT_TABLE(wxDirDialog, wxDirDialogBase)
EVT_BUTTON(wxID_OK, wxDirDialog::OnFakeOk)
END_EVENT_TABLE()
wxDirDialog::wxDirDialog(wxWindow* parent,
const wxString& title,
const wxString& defaultPath,
@ -156,17 +118,30 @@ bool wxDirDialog::Create(wxWindow* parent,
G_CALLBACK (gtk_dirdialog_response_callback), this);
if ( !defaultPath.empty() )
gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(m_widget),
wxGTK_CONV_FN(defaultPath) );
SetPath(defaultPath);
return true;
}
void wxDirDialog::OnFakeOk(wxCommandEvent& WXUNUSED(event))
void wxDirDialog::GTKOnAccept()
{
wxGtkString str(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(m_widget)));
m_selectedDirectory = wxString::FromUTF8(str);
// change to the directory where the user went if asked
if (HasFlag(wxDD_CHANGE_DIR))
{
chdir(m_selectedDirectory);
}
EndDialog(wxID_OK);
}
void wxDirDialog::GTKOnCancel()
{
EndDialog(wxID_CANCEL);
}
void wxDirDialog::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{
if (!m_wxwindow)
@ -186,8 +161,7 @@ void wxDirDialog::SetPath(const wxString& dir)
wxString wxDirDialog::GetPath() const
{
wxGtkString str(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(m_widget)));
return wxString::FromUTF8(str);
return m_selectedDirectory;
}
#endif // wxUSE_DIRDLG