#include "wx/utils.h"
#include "wx/intl.h"
#include "wx/filename.h"
+#include "wx/msgdlg.h"
#include <gtk/gtk.h>
#include "wx/gtk/private.h"
}
}
- dialog->DoSetPath(filename);
+ dialog->SetPath(filename);
dialog->UpdateFromDialog();
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
{
wxapp_install_idle_handler();
- if (response == GTK_RESPONSE_CANCEL)
- gtk_filedialog_cancel_callback(w, dialog);
- else
+ if (response == GTK_RESPONSE_ACCEPT)
gtk_filedialog_ok_callback(w, dialog);
+ else if (response == GTK_RESPONSE_CANCEL)
+ gtk_filedialog_cancel_callback(w, dialog);
+ else // "delete"
+ {
+ gtk_filedialog_cancel_callback(w, dialog);
+ dialog->m_destroyed_by_delete = TRUE;
+ }
}
//-----------------------------------------------------------------------------
wildCard, style, pos)
{
m_needParent = FALSE;
+ m_destroyed_by_delete = FALSE;
if (!PreCreation(parent, pos, wxDefaultSize) ||
!CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style,
SetFilterIndex(0);
}
-void wxFileDialog::SetPath(const wxString& path)
+wxFileDialog::~wxFileDialog()
{
- DoSetPath(path);
- UpdateDialog();
+ if (m_destroyed_by_delete)
+ m_widget = NULL;
}
void wxFileDialog::GetFilenames(wxArrayString& files) const
files[n] = name;
}
}
+
void wxFileDialog::GetPaths(wxArrayString& paths) const
{
paths.Empty();
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();
+ UpdateDialog();
+}
+
void wxFileDialog::SetDirectory(const wxString& dir)
{
- wxFileName fn(dir,m_fileName);
- SetPath(fn.GetFullPath());
+ if (wxDirExists(dir))
+ {
+ m_dir = dir;
+ m_path = wxFileName(m_dir, m_fileName).GetFullPath();
+ UpdateDialog();
+ }
}
void wxFileDialog::SetFilename(const wxString& name)
{
m_fileName = name;
- wxFileName fn(m_dir,name);
- SetPath(fn.GetFullPath());
+ 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));
+ }
+ }
}
void wxFileDialog::SetWildcard(const wxString& wildCard)
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__)