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:
@@ -42,6 +42,11 @@ public: // overrides from wxGenericDirDialog
|
|||||||
void SetPath(const wxString& path);
|
void SetPath(const wxString& path);
|
||||||
|
|
||||||
|
|
||||||
|
// Implementation only.
|
||||||
|
|
||||||
|
void GTKOnAccept();
|
||||||
|
void GTKOnCancel();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// override this from wxTLW since the native
|
// override this from wxTLW since the native
|
||||||
// form doesn't have any m_wxwindow
|
// form doesn't have any m_wxwindow
|
||||||
@@ -51,10 +56,9 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void OnFakeOk( wxCommandEvent &event );
|
wxString m_selectedDirectory;
|
||||||
|
|
||||||
DECLARE_DYNAMIC_CLASS(wxDirDialog)
|
DECLARE_DYNAMIC_CLASS(wxDirDialog)
|
||||||
DECLARE_EVENT_TABLE()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __GTKDIRDLGH__
|
#endif // __GTKDIRDLGH__
|
||||||
|
@@ -35,49 +35,15 @@
|
|||||||
#include <unistd.h> // chdir
|
#include <unistd.h> // chdir
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// "clicked" for OK-button
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
static void gtk_dirdialog_ok_callback(GtkWidget *widget, wxDirDialog *dialog)
|
static void gtk_dirdialog_response_callback(GtkWidget * WXUNUSED(w),
|
||||||
{
|
|
||||||
// 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,
|
|
||||||
gint response,
|
gint response,
|
||||||
wxDirDialog *dialog)
|
wxDirDialog *dialog)
|
||||||
{
|
{
|
||||||
if (response == GTK_RESPONSE_ACCEPT)
|
if (response == GTK_RESPONSE_ACCEPT)
|
||||||
gtk_dirdialog_ok_callback(w, dialog);
|
dialog->GTKOnAccept();
|
||||||
else // GTK_RESPONSE_CANCEL or GTK_RESPONSE_NONE
|
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)
|
IMPLEMENT_DYNAMIC_CLASS(wxDirDialog, wxDialog)
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(wxDirDialog, wxDirDialogBase)
|
|
||||||
EVT_BUTTON(wxID_OK, wxDirDialog::OnFakeOk)
|
|
||||||
END_EVENT_TABLE()
|
|
||||||
|
|
||||||
wxDirDialog::wxDirDialog(wxWindow* parent,
|
wxDirDialog::wxDirDialog(wxWindow* parent,
|
||||||
const wxString& title,
|
const wxString& title,
|
||||||
const wxString& defaultPath,
|
const wxString& defaultPath,
|
||||||
@@ -156,17 +118,30 @@ bool wxDirDialog::Create(wxWindow* parent,
|
|||||||
G_CALLBACK (gtk_dirdialog_response_callback), this);
|
G_CALLBACK (gtk_dirdialog_response_callback), this);
|
||||||
|
|
||||||
if ( !defaultPath.empty() )
|
if ( !defaultPath.empty() )
|
||||||
gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(m_widget),
|
SetPath(defaultPath);
|
||||||
wxGTK_CONV_FN(defaultPath) );
|
|
||||||
|
|
||||||
return true;
|
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);
|
EndDialog(wxID_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxDirDialog::GTKOnCancel()
|
||||||
|
{
|
||||||
|
EndDialog(wxID_CANCEL);
|
||||||
|
}
|
||||||
|
|
||||||
void wxDirDialog::DoSetSize(int x, int y, int width, int height, int sizeFlags)
|
void wxDirDialog::DoSetSize(int x, int y, int width, int height, int sizeFlags)
|
||||||
{
|
{
|
||||||
if (!m_wxwindow)
|
if (!m_wxwindow)
|
||||||
@@ -186,8 +161,7 @@ void wxDirDialog::SetPath(const wxString& dir)
|
|||||||
|
|
||||||
wxString wxDirDialog::GetPath() const
|
wxString wxDirDialog::GetPath() const
|
||||||
{
|
{
|
||||||
wxGtkString str(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(m_widget)));
|
return m_selectedDirectory;
|
||||||
return wxString::FromUTF8(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_DIRDLG
|
#endif // wxUSE_DIRDLG
|
||||||
|
Reference in New Issue
Block a user