16#include "../FileDialog.h"
22#include <wx/filename.h>
23#include <wx/tokenzr.h>
25#include <wx/modalhook.h>
28#define wxGTK_CONV(s) (s).utf8_str()
29#define wxGTK_CONV_FN(s) (s).fn_str()
43 operator gchar *()
const {
return m_str; }
58 int style = dialog->GetWindowStyle();
59 wxGtkString filename(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)));
63#if GTK_CHECK_VERSION(2,7,3)
64 if (gtk_check_version(2, 7, 3) != NULL)
67 if ((style & wxFD_SAVE) && (style & wxFD_OVERWRITE_PROMPT))
69 if ( g_file_test(filename, G_FILE_TEST_EXISTS) )
72 XO(
"File '%s' already exists, do you really want to overwrite it?")
73 .
Format(wxString::FromUTF8(filename)),
75 wxYES_NO | wxICON_QUESTION);
76 if (result != wxID_YES)
85 if (style & wxFD_FILE_MUST_EXIST)
87 if ( !g_file_test(filename, G_FILE_TEST_EXISTS) )
97 if (style & wxFD_CHANGE_DIR)
104 wxCommandEvent event(wxEVT_BUTTON, wxID_OK);
105 event.SetEventObject(dialog);
106 dialog->HandleWindowEvent(event);
121 event.SetEventObject(dialog);
122 dialog->HandleWindowEvent(event);
129 if (response == GTK_RESPONSE_ACCEPT)
138 wxGtkString filename(gtk_file_chooser_get_preview_filename(chooser));
146 GtkWidget *preview = GTK_WIDGET(user_data);
148 wxGtkString filename(gtk_file_chooser_get_preview_filename(chooser));
153 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_size(filename, 128, 128, NULL);
154 gboolean have_preview = pixbuf != NULL;
156 gtk_image_set_from_pixbuf(GTK_IMAGE(preview), pixbuf);
158 g_object_unref (pixbuf);
160 gtk_file_chooser_set_preview_widget_active(chooser, have_preview);
180 GtkWidget *widget = NULL;
181 if (g_ascii_strncasecmp(gtk_widget_get_name(parent),
name, strlen(
name)) == 0)
186 if (GTK_IS_BIN(parent))
188 return find_widget(gtk_bin_get_child(GTK_BIN(parent)),
name, depth + 1);
191 if (GTK_IS_CONTAINER(parent))
193 GList *list = gtk_container_get_children(GTK_CONTAINER(parent));
194 for (GList *node = list; node; node = node->next)
213 gtk_widget_set_size_request(
214 child->m_widget, child->GetMinWidth(), child->m_height);
220#if GTK_CHECK_VERSION(3,0,0)
221 GtkWidget *actionbar =
find_widget(m_widget,
"GtkActionBar", 0);
224 GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
225 gtk_container_add(GTK_CONTAINER(vbox), child->m_widget);
226 gtk_box_set_child_packing(GTK_BOX(vbox), child->m_widget, TRUE, TRUE, 0, GTK_PACK_START);
227 gtk_widget_show(vbox);
229 GtkWidget *abparent = gtk_widget_get_parent(actionbar);
230 gtk_container_add(GTK_CONTAINER(abparent), vbox);
231 gtk_box_set_child_packing(GTK_BOX(abparent), vbox, FALSE, FALSE, 0, GTK_PACK_END);
232 gtk_box_reorder_child(GTK_BOX(abparent), actionbar, -2);
235 gtk_file_chooser_set_extra_widget(
236 GTK_FILE_CHOOSER(m_widget), child->m_widget);
252 const wxString& defaultDir,
253 const wxString& defaultFileName,
254 const wxString& wildCard,
255 long style, const wxPoint& pos,
257 const wxString&
name)
260 Create(parent, message, defaultDir, defaultFileName, wildCard, style, pos, sz,
name);
264 const wxString& defaultDir,
265 const wxString& defaultFileName,
266 const wxString& wildCard,
267 long style,
const wxPoint& pos,
269 const wxString&
name)
271 parent = GetParentForModalDialog(parent, style);
273 if (!FileDialogBase::Create(parent, message, defaultDir, defaultFileName,
274 wildCard, style, pos, sz,
name))
279 if (!PreCreation(parent, pos, wxDefaultSize) ||
280 !CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style,
281 wxDefaultValidator,
wxT(
"filedialog")))
283 wxFAIL_MSG(
wxT(
"FileDialog creation failed") );
287 GtkFileChooserAction gtk_action;
288 GtkWindow* gtk_parent = NULL;
290 gtk_parent = GTK_WINDOW( gtk_widget_get_toplevel(parent->m_widget) );
292 const gchar* ok_btn_stock;
293 if ( style & wxFD_SAVE )
295 gtk_action = GTK_FILE_CHOOSER_ACTION_SAVE;
296 ok_btn_stock = GTK_STOCK_SAVE;
300 gtk_action = GTK_FILE_CHOOSER_ACTION_OPEN;
301 ok_btn_stock = GTK_STOCK_OPEN;
304 m_widget = gtk_file_chooser_dialog_new(
308 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
309 ok_btn_stock, GTK_RESPONSE_ACCEPT,
311 g_object_ref(m_widget);
312 GtkFileChooser* file_chooser = GTK_FILE_CHOOSER(m_widget);
314 m_fc.SetWidget(file_chooser);
316 gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_ACCEPT);
318 if ( style & wxFD_MULTIPLE )
319 gtk_file_chooser_set_select_multiple(file_chooser,
true);
329 g_signal_connect (m_widget,
"response",
332 g_signal_connect (m_widget,
"selection-changed",
335 g_signal_connect (m_widget,
"current-folder-changed",
338 g_signal_connect (m_widget,
"notify::filter",
344 wxString defaultFileNameWithExt = defaultFileName;
345 if ( !wildCard.empty() && !defaultFileName.empty() &&
346 !wxFileName(defaultFileName).HasExt() )
350 const wxFileName fnWC(
m_fc.GetCurrentWildCard());
356 const wxString& ext = fnWC.GetExt();
357 if ( ext.find_first_of(
"?*") == wxString::npos )
358 defaultFileNameWithExt <<
"." << ext;
367 if ( defaultDir.empty() )
368 fn.Assign(defaultFileNameWithExt);
369 else if ( !defaultFileNameWithExt.empty() )
370 fn.Assign(defaultDir, defaultFileNameWithExt);
372 fn.AssignDir(defaultDir);
376 const wxString dir =
fn.GetPath();
379 gtk_file_chooser_set_current_folder(file_chooser,
wxGTK_CONV_FN(dir));
382 const wxString fname =
fn.GetFullName();
383 if ( style & wxFD_SAVE )
385 if ( !fname.empty() )
387 gtk_file_chooser_set_current_name(file_chooser,
wxGTK_CONV_FN(fname));
390#if GTK_CHECK_VERSION(2,7,3)
391 if ((style & wxFD_OVERWRITE_PROMPT)
393 && gtk_check_version(2,7,3) == NULL
397 gtk_file_chooser_set_do_overwrite_confirmation(file_chooser,
true);
403 if ( !fname.empty() )
405 gtk_file_chooser_set_filename(file_chooser,
410 if ( style & wxFD_PREVIEW )
412 GtkWidget *previewImage = gtk_image_new();
414 gtk_file_chooser_set_preview_widget(file_chooser, previewImage);
415 g_signal_connect(m_widget,
"update-preview",
429 gtk_file_chooser_set_extra_widget(
430 GTK_FILE_CHOOSER(m_widget), NULL);
439 str(gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(m_widget)));
440 m_dir = wxString::FromUTF8(
str);
447 WX_HOOK_MODAL_DIALOG();
450 wxBoxSizer *verticalSizer =
new wxBoxSizer(wxVERTICAL);
451 wxPanel *root =
new wxPanel(
this, wxID_ANY);
455 wxPanel *userpane =
new wxPanel(root, wxID_ANY);
458 wxBoxSizer *horizontalSizer =
new wxBoxSizer(wxHORIZONTAL);
459 horizontalSizer->Add(userpane, 1, wxEXPAND, 0);
460 verticalSizer->Add(horizontalSizer, 1, wxEXPAND|wxALL, 0);
463 root->SetSizer(verticalSizer);
465 verticalSizer->SetSizeHints(root);
470 return wxDialog::ShowModal();
478#if defined(__WXGTK3__)
479 filename = wxString::FromUTF8(gtk_file_chooser_get_current_name(GTK_FILE_CHOOSER(m_widget)));
484 filename = wxString::FromUTF8(gtk_entry_get_text(GTK_ENTRY(
entry)));
488 if (filename == wxEmptyString)
490 filename =
m_fc.GetFilename();
493 if (filename != wxEmptyString)
495 wxFileName
fn(filename);
496 fn.SetExt(extension);
498 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(m_widget),
fn.GetFullName().utf8_str());
503 int WXUNUSED(width),
int WXUNUSED(height),
504 int WXUNUSED(sizeFlags))
516 return m_fc.GetPath();
521 m_fc.GetFilenames( files );
526 m_fc.GetPaths( paths );
537 FileDialogBase::SetPath(path);
549 fn.MakeAbsolute(m_dir);
550 m_fc.SetPath(
fn.GetFullPath());
555 FileDialogBase::SetDirectory(dir);
557 m_fc.SetDirectory(dir);
562 FileDialogBase::SetFilename(
name);
564 if (HasFdFlag(wxFD_SAVE))
566 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(m_widget),
wxGTK_CONV(
name));
571 wxString path( GetDirectory() );
583 wxString currentFilename(
m_fc.GetFilename() );
584 if (currentFilename.empty())
588 currentFilename = m_fileName;
590 return currentFilename;
595 FileDialogBase::SetWildcard(wildCard);
596 m_fc.SetWildcard( GetWildcard() );
601 m_fc.SetFilterIndex( filterIndex );
606 return m_fc.GetFilterIndex();
611 m_currentlySelectedFilename = filename;
613 wxFileCtrlEvent event(wxEVT_FILECTRL_SELECTIONCHANGED,
this, GetId());
615 wxArrayString filenames;
618 event.SetDirectory(GetDirectory());
619 event.SetFiles(filenames);
621 GetEventHandler()->ProcessEvent(event);
626 wxFileCtrlEvent event(wxEVT_FILECTRL_FOLDERCHANGED,
this, GetId());
628 event.SetDirectory(GetDirectory());
630 GetEventHandler()->ProcessEvent(event);
637#if defined(__WXGTK3__)
638 filename.SetFullName(wxString::FromUTF8(gtk_file_chooser_get_current_name(GTK_FILE_CHOOSER(m_widget))));
643 filename.SetFullName(wxString::FromUTF8(gtk_entry_get_text(GTK_ENTRY(
entry))));
647 if (filename.HasName())
649 wxString ext =
m_fc.GetCurrentWildCard().AfterLast(
wxT(
'.')).Lower();
650 if (!ext.empty() && ext !=
wxT(
"*") && ext != filename.GetExt())
656 wxFileCtrlEvent event(wxEVT_FILECTRL_FILTERCHANGED,
this, GetId());
660 GetEventHandler()->ProcessEvent(event);
wxEVT_COMMAND_BUTTON_CLICKED
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
const TranslatableString name
IMPLEMENT_DYNAMIC_CLASS(PluginHostModule, wxModule)
static ProjectFileIORegistry::AttributeWriterEntry entry
void CreateUserPane(wxWindow *parent)
virtual bool HasUserPaneCreator() const
Dialog used to present platform specific "Save As" dialog with custom controls.
virtual void SetDirectory(const wxString &dir)
virtual int GetFilterIndex() const
virtual wxString GetPath() const
virtual wxString GetFilename() const
virtual void SetFileExtension(const wxString &extension)
virtual void SetPath(const wxString &path)
wxString GetFullPath(HWND hwnd, int itm)
virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO)
virtual void GetFilenames(wxArrayString &files) const
virtual void GetPaths(wxArrayString &paths) const
void OnSize(wxSizeEvent &)
void GTKSelectionChanged(const wxString &filename)
virtual void SetMessage(const wxString &message)
virtual void SetFilename(const wxString &name)
void OnFakeOk(wxCommandEvent &event)
virtual void SetFilterIndex(int filterIndex)
virtual void AddChildGTK(wxWindowGTK *child)
virtual void SetWildcard(const wxString &wildCard)
bool Create(wxWindow *parent, const wxString &message=wxFileSelectorPromptStr, const wxString &defaultDir=wxEmptyString, const wxString &defaultFile=wxEmptyString, const wxString &wildCard=wxFileSelectorDefaultWildcardStr, long style=wxFD_DEFAULT_STYLE, const wxPoint &pos=wxDefaultPosition, const wxSize &sz=wxDefaultSize, const wxString &name=wxFileDialogNameStr)
const gchar * c_str() const
wxDECLARE_NO_COPY_CLASS(wxGtkString)
static void gtk_filedialog_response_callback(GtkWidget *w, gint response, FileDialog *dialog)
static void gtk_filedialog_update_preview_callback(GtkFileChooser *chooser, gpointer user_data)
static void gtk_filedialog_folderchanged_callback(GtkFileChooser *chooser, FileDialog *dialog)
static void gtk_filedialog_ok_callback(GtkWidget *widget, FileDialog *dialog)
static void gtk_filedialog_selchanged_callback(GtkFileChooser *chooser, FileDialog *dialog)
static GtkWidget * find_widget(GtkWidget *parent, const gchar *name, int depth)
static void gtk_filedialog_filterchanged_callback(GtkFileChooser *chooser, GParamSpec *pspec, FileDialog *dialog)
static void gtk_filedialog_cancel_callback(GtkWidget *WXUNUSED(w), FileDialog *dialog)