// Author: Francesco Montorsi
// Modified By:
// Created: 15/04/2006
-// Id: $Id$
// Copyright: (c) Francesco Montorsi
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// we need to know when the dialog has been dismissed clicking OK...
// NOTE: the "clicked" signal is not available for a GtkFileChooserButton
// thus we are forced to use wxFileDialog's event
- m_dialog->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
+ m_dialog->Connect(wxEVT_BUTTON,
wxCommandEventHandler(wxFileButton::OnDialogOK),
NULL, this);
wxFileButton::~wxFileButton()
{
+ if ( m_dialog )
+ {
+ // when m_dialog is deleted, it will destroy the widget it is sharing
+ // with GtkFileChooserButton, which results in a bunch of Gtk-CRITICAL
+ // errors from GtkFileChooserButton. To avoid this, call gtk_widget_destroy()
+ // on GtkFileChooserButton first (our base dtor will do it again, but
+ // that does no harm). m_dialog holds a reference to the shared widget,
+ // so it won't go away until m_dialog base dtor unrefs it.
+ gtk_widget_destroy(m_widget);
+ delete m_dialog;
+ }
}
void wxFileButton::OnDialogOK(wxCommandEvent& ev)
UpdatePathFromDialog(m_dialog);
// ...and fire an event
- wxFileDirPickerEvent event(wxEVT_COMMAND_FILEPICKER_CHANGED, this, GetId(), m_path);
+ wxFileDirPickerEvent event(wxEVT_FILEPICKER_CHANGED, this, GetId(), m_path);
HandleWindowEvent(event);
}
}
void wxFileButton::SetInitialDirectory(const wxString& dir)
{
if (m_dialog)
- DoSetInitialDirectory(static_cast<wxFileDialog*>(m_dialog), dir);
+ {
+ // Only change the directory if the default file name doesn't have any
+ // directory in it, otherwise it takes precedence.
+ if ( m_path.find_first_of(wxFileName::GetPathSeparators()) ==
+ wxString::npos )
+ {
+ static_cast<wxFileDialog*>(m_dialog)->SetDirectory(dir);
+ }
+ }
else
wxGenericFileButton::SetInitialDirectory(dir);
}
chdir(filename);
// ...and fire an event
- wxFileDirPickerEvent event(wxEVT_COMMAND_DIRPICKER_CHANGED, p, p->GetId(), p->GetPath());
+ wxFileDirPickerEvent event(wxEVT_DIRPICKER_CHANGED, p, p->GetId(), p->GetPath());
p->HandleWindowEvent(event);
}
}
wxDirButton::~wxDirButton()
{
+ if (m_dialog)
+ {
+ // see ~wxFileButton() comment
+ gtk_widget_destroy(m_widget);
+ delete m_dialog;
+ }
}
void wxDirButton::GTKUpdatePath(const char *gtkpath)