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) )
73 XO(
"File '%s' already exists, do you really want to overwrite it?")
74 .
Format(wxString::FromUTF8(filename)),
77 .IconStyle(Icon::Question)
78 .ButtonStyle(Button::YesNo));
79 if (result != MessageBoxResult::Yes)
88 if (
style & wxFD_FILE_MUST_EXIST)
90 if ( !g_file_test(filename, G_FILE_TEST_EXISTS) )
96 .ButtonStyle(Button::Ok)
97 .IconStyle(Icon::Error));
103 if (
style & wxFD_CHANGE_DIR)
110 wxCommandEvent event(wxEVT_BUTTON, wxID_OK);
111 event.SetEventObject(dialog);
112 dialog->HandleWindowEvent(event);
127 event.SetEventObject(dialog);
128 dialog->HandleWindowEvent(event);
135 if (response == GTK_RESPONSE_ACCEPT)
144 wxGtkString filename(gtk_file_chooser_get_preview_filename(chooser));
152 GtkWidget *preview = GTK_WIDGET(user_data);
154 wxGtkString filename(gtk_file_chooser_get_preview_filename(chooser));
159 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_size(filename, 128, 128, NULL);
160 gboolean have_preview = pixbuf != NULL;
162 gtk_image_set_from_pixbuf(GTK_IMAGE(preview), pixbuf);
164 g_object_unref (pixbuf);
166 gtk_file_chooser_set_preview_widget_active(chooser, have_preview);
186 GtkWidget *widget = NULL;
187 if (g_ascii_strncasecmp(gtk_widget_get_name(parent),
name, strlen(
name)) == 0)
192 if (GTK_IS_BIN(parent))
194 return find_widget(gtk_bin_get_child(GTK_BIN(parent)),
name, depth + 1);
197 if (GTK_IS_CONTAINER(parent))
199 GList *list = gtk_container_get_children(GTK_CONTAINER(parent));
200 for (GList *node = list; node; node = node->next)
219 gtk_widget_set_size_request(
220 child->m_widget, child->GetMinWidth(), child->m_height);
226#if GTK_CHECK_VERSION(3,0,0)
227 GtkWidget *actionbar =
find_widget(m_widget,
"GtkActionBar", 0);
230 GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
231 gtk_container_add(GTK_CONTAINER(vbox), child->m_widget);
232 gtk_box_set_child_packing(GTK_BOX(vbox), child->m_widget, TRUE, TRUE, 0, GTK_PACK_START);
233 gtk_widget_show(vbox);
235 GtkWidget *abparent = gtk_widget_get_parent(actionbar);
236 gtk_container_add(GTK_CONTAINER(abparent), vbox);
237 gtk_box_set_child_packing(GTK_BOX(abparent), vbox, FALSE, FALSE, 0, GTK_PACK_END);
238 gtk_box_reorder_child(GTK_BOX(abparent), actionbar, -2);
241 gtk_file_chooser_set_extra_widget(
242 GTK_FILE_CHOOSER(m_widget), child->m_widget);
258 const wxString& defaultDir,
259 const wxString& defaultFileName,
260 const wxString& wildCard,
261 long style, const wxPoint& pos,
263 const wxString&
name)
266 Create(parent, message, defaultDir, defaultFileName, wildCard,
style, pos, sz,
name);
270 const wxString& defaultDir,
271 const wxString& defaultFileName,
272 const wxString& wildCard,
273 long style,
const wxPoint& pos,
275 const wxString&
name)
277 parent = GetParentForModalDialog(parent,
style);
279 if (!FileDialogBase::Create(parent, message, defaultDir, defaultFileName,
285 if (!PreCreation(parent, pos, wxDefaultSize) ||
286 !CreateBase(parent, wxID_ANY, pos, wxDefaultSize,
style,
287 wxDefaultValidator,
wxT(
"filedialog")))
289 wxFAIL_MSG(
wxT(
"FileDialog creation failed") );
293 GtkFileChooserAction gtk_action;
294 GtkWindow* gtk_parent = NULL;
296 gtk_parent = GTK_WINDOW( gtk_widget_get_toplevel(parent->m_widget) );
298 const gchar* ok_btn_stock;
299 if (
style & wxFD_SAVE )
301 gtk_action = GTK_FILE_CHOOSER_ACTION_SAVE;
302 ok_btn_stock = GTK_STOCK_SAVE;
306 gtk_action = GTK_FILE_CHOOSER_ACTION_OPEN;
307 ok_btn_stock = GTK_STOCK_OPEN;
310 m_widget = gtk_file_chooser_dialog_new(
314 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
315 ok_btn_stock, GTK_RESPONSE_ACCEPT,
317 g_object_ref(m_widget);
318 GtkFileChooser* file_chooser = GTK_FILE_CHOOSER(m_widget);
320 m_fc.SetWidget(file_chooser);
322 gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_ACCEPT);
324 if (
style & wxFD_MULTIPLE )
325 gtk_file_chooser_set_select_multiple(file_chooser,
true);
335 g_signal_connect (m_widget,
"response",
338 g_signal_connect (m_widget,
"selection-changed",
341 g_signal_connect (m_widget,
"current-folder-changed",
344 g_signal_connect (m_widget,
"notify::filter",
350 wxString defaultFileNameWithExt = defaultFileName;
351 if ( !wildCard.empty() && !defaultFileName.empty() &&
352 !wxFileName(defaultFileName).HasExt() )
356 const wxFileName fnWC(
m_fc.GetCurrentWildCard());
362 const wxString& ext = fnWC.GetExt();
364 defaultFileNameWithExt <<
"." << ext;
373 if ( defaultDir.empty() )
374 fn.Assign(defaultFileNameWithExt);
375 else if ( !defaultFileNameWithExt.empty() )
376 fn.Assign(defaultDir, defaultFileNameWithExt);
378 fn.AssignDir(defaultDir);
382 const wxString dir =
fn.GetPath();
385 gtk_file_chooser_set_current_folder(file_chooser,
wxGTK_CONV_FN(dir));
388 const wxString fname =
fn.GetFullName();
389 if (
style & wxFD_SAVE )
391 if ( !fname.empty() )
393 gtk_file_chooser_set_current_name(file_chooser,
wxGTK_CONV_FN(fname));
396#if GTK_CHECK_VERSION(2,7,3)
397 if ((
style & wxFD_OVERWRITE_PROMPT)
399 && gtk_check_version(2,7,3) == NULL
403 gtk_file_chooser_set_do_overwrite_confirmation(file_chooser,
true);
409 if ( !fname.empty() )
411 gtk_file_chooser_set_filename(file_chooser,
416 if (
style & wxFD_PREVIEW )
418 GtkWidget *previewImage = gtk_image_new();
420 gtk_file_chooser_set_preview_widget(file_chooser, previewImage);
421 g_signal_connect(m_widget,
"update-preview",
435 gtk_file_chooser_set_extra_widget(
436 GTK_FILE_CHOOSER(m_widget), NULL);
445 str(gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(m_widget)));
446 m_dir = wxString::FromUTF8(
str);
453 WX_HOOK_MODAL_DIALOG();
456 wxBoxSizer *verticalSizer =
new wxBoxSizer(wxVERTICAL);
457 wxPanel *root =
new wxPanel(
this, wxID_ANY);
461 wxPanel *userpane =
new wxPanel(root, wxID_ANY);
464 wxBoxSizer *horizontalSizer =
new wxBoxSizer(wxHORIZONTAL);
465 horizontalSizer->Add(userpane, 1, wxEXPAND, 0);
466 verticalSizer->Add(horizontalSizer, 1, wxEXPAND|wxALL, 0);
469 root->SetSizer(verticalSizer);
471 verticalSizer->SetSizeHints(root);
476 return wxDialog::ShowModal();
484#if defined(__WXGTK3__)
485 filename = wxString::FromUTF8(gtk_file_chooser_get_current_name(GTK_FILE_CHOOSER(m_widget)));
490 filename = wxString::FromUTF8(gtk_entry_get_text(GTK_ENTRY(
entry)));
494 if (filename == wxEmptyString)
496 filename =
m_fc.GetFilename();
499 if (filename != wxEmptyString)
501 wxFileName
fn(filename);
504 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(m_widget),
fn.GetFullName().utf8_str());
509 int WXUNUSED(width),
int WXUNUSED(height),
510 int WXUNUSED(sizeFlags))
522 return m_fc.GetPath();
527 m_fc.GetFilenames( files );
532 m_fc.GetPaths( paths );
543 FileDialogBase::SetPath(path);
555 fn.MakeAbsolute(m_dir);
556 m_fc.SetPath(
fn.GetFullPath());
561 FileDialogBase::SetDirectory(dir);
563 m_fc.SetDirectory(dir);
568 FileDialogBase::SetFilename(
name);
570 if (HasFdFlag(wxFD_SAVE))
572 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(m_widget),
wxGTK_CONV(
name));
577 wxString path( GetDirectory() );
589 wxString currentFilename(
m_fc.GetFilename() );
590 if (currentFilename.empty())
594 currentFilename = m_fileName;
596 return currentFilename;
601 FileDialogBase::SetWildcard(wildCard);
602 m_fc.SetWildcard( GetWildcard() );
607 m_fc.SetFilterIndex( filterIndex );
612 return m_fc.GetFilterIndex();
617 m_currentlySelectedFilename = filename;
619 wxFileCtrlEvent event(wxEVT_FILECTRL_SELECTIONCHANGED,
this, GetId());
621 wxArrayString filenames;
624 event.SetDirectory(GetDirectory());
625 event.SetFiles(filenames);
627 GetEventHandler()->ProcessEvent(event);
632 wxFileCtrlEvent event(wxEVT_FILECTRL_FOLDERCHANGED,
this, GetId());
634 event.SetDirectory(GetDirectory());
636 GetEventHandler()->ProcessEvent(event);
643#if defined(__WXGTK3__)
644 filename.SetFullName(wxString::FromUTF8(gtk_file_chooser_get_current_name(GTK_FILE_CHOOSER(m_widget))));
649 filename.SetFullName(wxString::FromUTF8(gtk_entry_get_text(GTK_ENTRY(
entry))));
653 if (filename.HasName())
655 wxString ext =
m_fc.GetCurrentWildCard().AfterLast(
wxT(
'.')).Lower();
656 if (!ext.empty() && ext !=
wxT(
"*") && ext != filename.GetExt())
662 wxFileCtrlEvent event(wxEVT_FILECTRL_FILTERCHANGED,
this, GetId());
666 GetEventHandler()->ProcessEvent(event);
wxEVT_COMMAND_BUTTON_CLICKED
Toolkit-neutral facade for basic user interface services.
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
static ProjectFileIORegistry::AttributeWriterEntry entry
IMPLEMENT_DYNAMIC_CLASS(PluginHostModule, wxModule)
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)
MessageBoxResult ShowMessageBox(const TranslatableString &message, MessageBoxOptions options={})
Show a modal message box with either Ok or Yes and No, and optionally Cancel.
constexpr size_t npos(-1)
ProjectFileIOExtensionRegistry::Extension extension
MessageBoxOptions && Caption(TranslatableString caption_) &&