wxQtFileDialog( wxWindow *parent, wxDialog *handler, const wxString& message, const wxString& defaultDir, const wxString& defaultFile, const wxString& wildCard, long style ) : wxQtEventSignalHandler(parent, handler) { setLabelText(QFileDialog::LookIn, wxQtConvertString(message)); setDirectory(wxQtConvertString(defaultDir)); selectFile(wxQtConvertString(defaultFile)); SetWildcard(wildCard); if (style & wxFD_FILE_MUST_EXIST) setFileMode(ExistingFile); else if (style & wxFD_MULTIPLE) setFileMode(ExistingFiles); if (style & wxFD_SAVE) setAcceptMode(AcceptSave); if (style & wxFD_CHANGE_DIR) connect(this, &QDialog::accepted, this, &wxQtFileDialog::changeDirectory); }
bool wxGenericFileDialog::Create( wxWindow *parent, const wxString& message, const wxString& defaultDir, const wxString& defaultFile, const wxString& wildCard, long style, const wxPoint& pos, bool bypassGenericImpl ) { m_bypassGenericImpl = bypassGenericImpl; if (!wxFileDialogBase::Create(parent, message, defaultDir, defaultFile, wildCard, style, pos)) { return false; } if (m_bypassGenericImpl) return true; if (!wxDialog::Create( parent, wxID_ANY, message, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )) { return false; } ignoreChanges = true; if (wxConfig::Get(false)) { wxConfig::Get()->Read(wxT("/wxWindows/wxFileDialog/ViewStyle"), &ms_lastViewStyle); wxConfig::Get()->Read(wxT("/wxWindows/wxFileDialog/ShowHidden"), &ms_lastShowHidden); } if (m_dialogStyle == 0) m_dialogStyle = wxOPEN; if ((m_dialogStyle & wxMULTIPLE ) && !(m_dialogStyle & wxOPEN)) m_dialogStyle |= wxOPEN; if ((m_dir.empty()) || (m_dir == wxT("."))) { m_dir = wxGetCwd(); if (m_dir.empty()) m_dir = wxFILE_SEP_PATH; } size_t len = m_dir.Len(); if ((len > 1) && (wxEndsWithPathSeparator(m_dir))) m_dir.Remove( len-1, 1 ); m_path = m_dir; m_path += wxFILE_SEP_PATH; m_path += defaultFile; m_filterExtension = wxEmptyString; // layout bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA); wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL ); wxBoxSizer *buttonsizer = new wxBoxSizer( wxHORIZONTAL ); wxBitmapButton *but; but = new wxBitmapButton(this, ID_LIST_MODE, wxArtProvider::GetBitmap(wxART_LIST_VIEW, wxART_BUTTON)); #if wxUSE_TOOLTIPS but->SetToolTip( _("View files as a list view") ); #endif buttonsizer->Add( but, 0, wxALL, 5 ); but = new wxBitmapButton(this, ID_REPORT_MODE, wxArtProvider::GetBitmap(wxART_REPORT_VIEW, wxART_BUTTON)); #if wxUSE_TOOLTIPS but->SetToolTip( _("View files as a detailed view") ); #endif buttonsizer->Add( but, 0, wxALL, 5 ); buttonsizer->Add( 30, 5, 1 ); m_upDirButton = new wxBitmapButton(this, ID_UP_DIR, wxArtProvider::GetBitmap(wxART_GO_DIR_UP, wxART_BUTTON)); #if wxUSE_TOOLTIPS m_upDirButton->SetToolTip( _("Go to parent directory") ); #endif buttonsizer->Add( m_upDirButton, 0, wxALL, 5 ); #ifndef __DOS__ // VS: Home directory is meaningless in MS-DOS... but = new wxBitmapButton(this, ID_PARENT_DIR, wxArtProvider::GetBitmap(wxART_GO_HOME, wxART_BUTTON)); #if wxUSE_TOOLTIPS but->SetToolTip( _("Go to home directory") ); #endif buttonsizer->Add( but, 0, wxALL, 5); buttonsizer->Add( 20, 20 ); #endif //!__DOS__ m_newDirButton = new wxBitmapButton(this, ID_NEW_DIR, wxArtProvider::GetBitmap(wxART_NEW_DIR, wxART_BUTTON)); #if wxUSE_TOOLTIPS m_newDirButton->SetToolTip( _("Create new directory") ); #endif buttonsizer->Add( m_newDirButton, 0, wxALL, 5 ); if (is_pda) mainsizer->Add( buttonsizer, 0, wxALL | wxEXPAND, 0 ); else mainsizer->Add( buttonsizer, 0, wxALL | wxEXPAND, 5 ); wxBoxSizer *staticsizer = new wxBoxSizer( wxHORIZONTAL ); if (!is_pda) staticsizer->Add( new wxStaticText( this, wxID_ANY, _("Current directory:") ), 0, wxRIGHT, 10 ); m_static = new wxStaticText( this, wxID_ANY, m_dir ); staticsizer->Add( m_static, 1 ); mainsizer->Add( staticsizer, 0, wxEXPAND | wxLEFT|wxRIGHT|wxBOTTOM, 10 ); long style2 = ms_lastViewStyle; if ( !(m_dialogStyle & wxMULTIPLE) ) style2 |= wxLC_SINGLE_SEL; #ifdef __WXWINCE__ style2 |= wxSIMPLE_BORDER; #else style2 |= wxSUNKEN_BORDER; #endif wxSize list_size(500,240); if (is_pda) list_size = wxSize(50,80); m_list = new wxFileCtrl( this, ID_LIST_CTRL, wxEmptyString, ms_lastShowHidden, wxDefaultPosition, list_size, style2); if (is_pda) { // PDAs have a different screen layout mainsizer->Add( m_list, 1, wxEXPAND|wxSHRINK | wxLEFT|wxRIGHT, 5 ); wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL ); m_text = new wxTextCtrl( this, ID_TEXT, m_fileName, wxDefaultPosition, wxDefaultSize, wxPROCESS_ENTER ); textsizer->Add( m_text, 1, wxCENTER | wxALL, 5 ); mainsizer->Add( textsizer, 0, wxEXPAND ); m_check = NULL; m_choice = new wxChoice( this, ID_CHOICE ); textsizer->Add( m_choice, 1, wxCENTER|wxALL, 5 ); buttonsizer = new wxBoxSizer( wxHORIZONTAL ); buttonsizer->Add( new wxButton( this, wxID_OK ), 0, wxCENTER | wxALL, 5 ); buttonsizer->Add( new wxButton( this, wxID_CANCEL ), 0, wxCENTER | wxALL, 5 ); mainsizer->Add( buttonsizer, 0, wxALIGN_RIGHT ); } else { mainsizer->Add( m_list, 1, wxEXPAND | wxLEFT|wxRIGHT, 10 ); wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL ); m_text = new wxTextCtrl( this, ID_TEXT, m_fileName, wxDefaultPosition, wxDefaultSize, wxPROCESS_ENTER ); textsizer->Add( m_text, 1, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 ); textsizer->Add( new wxButton( this, wxID_OK ), 0, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 ); mainsizer->Add( textsizer, 0, wxEXPAND ); wxBoxSizer *choicesizer = new wxBoxSizer( wxHORIZONTAL ); m_choice = new wxChoice( this, ID_CHOICE ); choicesizer->Add( m_choice, 1, wxCENTER|wxALL, 10 ); m_check = new wxCheckBox( this, ID_CHECK, _("Show hidden files") ); m_check->SetValue( ms_lastShowHidden ); choicesizer->Add( m_check, 0, wxCENTER|wxALL, 10 ); choicesizer->Add( new wxButton( this, wxID_CANCEL ), 0, wxCENTER | wxALL, 10 ); mainsizer->Add( choicesizer, 0, wxEXPAND ); } SetWildcard(wildCard); SetAutoLayout( true ); SetSizer( mainsizer ); if (!is_pda) { mainsizer->Fit( this ); mainsizer->SetSizeHints( this ); Centre( wxBOTH ); } m_text->SetFocus(); ignoreChanges = false; return true; }
bool wxGenericFileCtrl::Create( wxWindow *parent, wxWindowID id, const wxString& defaultDirectory, const wxString& defaultFileName, const wxString& wildCard, long style, const wxPoint& pos, const wxSize& size, const wxString& name ) { this->m_style = style; m_inSelected = false; m_noSelChgEvent = false; m_check = NULL; // check that the styles are not contradictory wxASSERT_MSG( !( ( m_style & wxFC_SAVE ) && ( m_style & wxFC_OPEN ) ), wxT( "can't specify both wxFC_SAVE and wxFC_OPEN at once" ) ); wxASSERT_MSG( !( ( m_style & wxFC_SAVE ) && ( m_style & wxFC_MULTIPLE ) ), wxT( "wxFC_MULTIPLE can't be used with wxFC_SAVE" ) ); wxNavigationEnabled<wxControl>::Create( parent, id, pos, size, wxTAB_TRAVERSAL, wxDefaultValidator, name ); m_dir = defaultDirectory; m_ignoreChanges = true; if ( ( m_dir.empty() ) || ( m_dir == wxT( "." ) ) ) { m_dir = wxGetCwd(); if ( m_dir.empty() ) m_dir = wxFILE_SEP_PATH; } const size_t len = m_dir.length(); if ( ( len > 1 ) && ( wxEndsWithPathSeparator( m_dir ) ) ) m_dir.Remove( len - 1, 1 ); m_filterExtension = wxEmptyString; // layout const bool is_pda = ( wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA ); wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL ); wxBoxSizer *staticsizer = new wxBoxSizer( wxHORIZONTAL ); if ( is_pda ) staticsizer->Add( new wxStaticText( this, wxID_ANY, _( "Current directory:" ) ), wxSizerFlags().DoubleBorder(wxRIGHT) ); m_static = new wxStaticText( this, wxID_ANY, m_dir ); staticsizer->Add( m_static, 1 ); mainsizer->Add( staticsizer, wxSizerFlags().Expand().Border()); long style2 = wxLC_LIST; if ( !( m_style & wxFC_MULTIPLE ) ) style2 |= wxLC_SINGLE_SEL; #ifdef __WXWINCE__ style2 |= wxSIMPLE_BORDER; #else style2 |= wxSUNKEN_BORDER; #endif m_list = new wxFileListCtrl( this, ID_FILELIST_CTRL, wxEmptyString, false, wxDefaultPosition, wxSize( 400, 140 ), style2 ); m_text = new wxTextCtrl( this, ID_TEXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); m_choice = new wxChoice( this, ID_CHOICE ); if ( is_pda ) { // PDAs have a different screen layout mainsizer->Add( m_list, wxSizerFlags( 1 ).Expand().HorzBorder() ); wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL ); textsizer->Add( m_text, wxSizerFlags( 1 ).Centre().Border() ); textsizer->Add( m_choice, wxSizerFlags( 1 ).Centre().Border() ); mainsizer->Add( textsizer, wxSizerFlags().Expand() ); } else // !is_pda { mainsizer->Add( m_list, wxSizerFlags( 1 ).Expand().Border() ); mainsizer->Add( m_text, wxSizerFlags().Expand().Border() ); wxBoxSizer *choicesizer = new wxBoxSizer( wxHORIZONTAL ); choicesizer->Add( m_choice, wxSizerFlags( 1 ).Centre() ); if ( !( m_style & wxFC_NOSHOWHIDDEN ) ) { m_check = new wxCheckBox( this, ID_CHECK, _( "Show &hidden files" ) ); choicesizer->Add( m_check, wxSizerFlags().Centre().DoubleBorder(wxLEFT) ); } mainsizer->Add( choicesizer, wxSizerFlags().Expand().Border() ); } SetWildcard( wildCard ); SetAutoLayout( true ); SetSizer( mainsizer ); if ( !is_pda ) { mainsizer->Fit( this ); } m_list->GoToDir( m_dir ); UpdateControls(); m_text->SetValue( m_fileName ); m_ignoreChanges = false; // must be after m_ignoreChanges = false SetFilename( defaultFileName ); return true; }
wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard, long style, const wxPoint& pos, const wxSize& sz, const wxString& name) : wxFileDialogBase() { parent = GetParentForModalDialog(parent, style); if (!wxFileDialogBase::Create(parent, message, defaultDir, defaultFileName, wildCard, style, pos, sz, name)) { return; } if (!PreCreation(parent, pos, wxDefaultSize) || !CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style, wxDefaultValidator, wxT("filedialog"))) { wxFAIL_MSG( wxT("wxFileDialog creation failed") ); return; } GtkFileChooserAction gtk_action; GtkWindow* gtk_parent = NULL; if (parent) gtk_parent = GTK_WINDOW( gtk_widget_get_toplevel(parent->m_widget) ); const gchar* ok_btn_stock; if ( style & wxFD_SAVE ) { gtk_action = GTK_FILE_CHOOSER_ACTION_SAVE; ok_btn_stock = GTK_STOCK_SAVE; } else { gtk_action = GTK_FILE_CHOOSER_ACTION_OPEN; ok_btn_stock = GTK_STOCK_OPEN; } m_widget = gtk_file_chooser_dialog_new( wxGTK_CONV(m_message), gtk_parent, gtk_action, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, ok_btn_stock, GTK_RESPONSE_ACCEPT, NULL); g_object_ref(m_widget); GtkFileChooser* file_chooser = GTK_FILE_CHOOSER(m_widget); m_fc.SetWidget(file_chooser); gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_ACCEPT); if ( style & wxFD_MULTIPLE ) gtk_file_chooser_set_select_multiple(file_chooser, true); // gtk_widget_hide_on_delete is used here to avoid that Gtk automatically // destroys the dialog when the user press ESC on the dialog: in that case // a second call to ShowModal() would result in a bunch of Gtk-CRITICAL // errors... g_signal_connect(m_widget, "delete_event", G_CALLBACK (gtk_widget_hide_on_delete), this); // local-only property could be set to false to allow non-local files to be // loaded. In that case get/set_uri(s) should be used instead of // get/set_filename(s) everywhere and the GtkFileChooserDialog should // probably also be created with a backend, e.g. "gnome-vfs", "default", ... // (gtk_file_chooser_dialog_new_with_backend). Currently local-only is kept // as the default - true: // gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(m_widget), true); g_signal_connect (m_widget, "response", G_CALLBACK (gtk_filedialog_response_callback), this); // deal with extensions/filters SetWildcard(wildCard); wxString defaultFileNameWithExt = defaultFileName; if ( !wildCard.empty() && !defaultFileName.empty() && !wxFileName(defaultFileName).HasExt() ) { // append the default extension to the initial file name: GTK won't do // it for us by default (unlike e.g. MSW) const wxString defaultExt = m_fc.GetCurrentWildCard().AfterFirst('.'); if ( defaultExt.find_first_of("?*") == wxString::npos ) defaultFileNameWithExt += "." + defaultExt; } // if defaultDir is specified it should contain the directory and // defaultFileName should contain the default name of the file, however if // directory is not given, defaultFileName contains both wxFileName fn; if ( defaultDir.empty() ) fn.Assign(defaultFileNameWithExt); else if ( !defaultFileNameWithExt.empty() ) fn.Assign(defaultDir, defaultFileNameWithExt); else fn.AssignDir(defaultDir); // set the initial file name and/or directory fn.MakeAbsolute(); // GTK+ needs absolute path const wxString dir = fn.GetPath(); if ( !dir.empty() ) { gtk_file_chooser_set_current_folder(file_chooser, dir.fn_str()); } const wxString fname = fn.GetFullName(); if ( style & wxFD_SAVE ) { if ( !fname.empty() ) { gtk_file_chooser_set_current_name(file_chooser, fname.fn_str()); } #if GTK_CHECK_VERSION(2,7,3) if ((style & wxFD_OVERWRITE_PROMPT) && !gtk_check_version(2,7,3)) gtk_file_chooser_set_do_overwrite_confirmation(file_chooser, true); #endif } else // wxFD_OPEN { if ( !fname.empty() ) { gtk_file_chooser_set_filename(file_chooser, fn.GetFullPath().fn_str()); } } if ( style & wxFD_PREVIEW ) { GtkWidget *previewImage = gtk_image_new(); gtk_file_chooser_set_preview_widget(file_chooser, previewImage); g_signal_connect(m_widget, "update-preview", G_CALLBACK(gtk_filedialog_update_preview_callback), previewImage); } }
wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard, long style, const wxPoint& pos) : wxGenericFileDialog(parent, message, defaultDir, defaultFileName, wildCard, style, pos, true ) { #ifdef __WXGTK24__ if (!gtk_check_version(2,4,0)) { wxASSERT_MSG( !( (style & wxSAVE) && (style & wxMULTIPLE) ), wxT("wxFileDialog - wxMULTIPLE used on a save dialog" ) ); m_needParent = false; m_destroyed_by_delete = false; if (!PreCreation(parent, pos, wxDefaultSize) || !CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style, wxDefaultValidator, wxT("filedialog"))) { wxFAIL_MSG( wxT("wxFileDialog creation failed") ); return; } GtkFileChooserAction gtk_action; GtkWindow* gtk_parent = NULL; if (parent) gtk_parent = GTK_WINDOW(parent->m_widget); gchar* ok_btn_stock; if ( style & wxSAVE ) { gtk_action = GTK_FILE_CHOOSER_ACTION_SAVE; ok_btn_stock = GTK_STOCK_SAVE; } else { gtk_action = GTK_FILE_CHOOSER_ACTION_OPEN; ok_btn_stock = GTK_STOCK_OPEN; } m_widget = gtk_file_chooser_dialog_new( wxGTK_CONV(m_message), gtk_parent, gtk_action, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, ok_btn_stock, GTK_RESPONSE_ACCEPT, NULL); if ( style & wxMULTIPLE ) gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(m_widget), true); // local-only property could be set to false to allow non-local files to be loaded. // In that case get/set_uri(s) should be used instead of get/set_filename(s) everywhere // and the GtkFileChooserDialog should probably also be created with a backend, // e.g "gnome-vfs", "default", ... (gtk_file_chooser_dialog_new_with_backend). // Currently local-only is kept as the default - true: // gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(m_widget), true); g_signal_connect(G_OBJECT(m_widget), "response", GTK_SIGNAL_FUNC(gtk_filedialog_response_callback), (gpointer)this); SetWildcard(wildCard); if ( style & wxSAVE ) { if ( !defaultDir.empty() ) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(m_widget), wxConvFileName->cWX2MB(defaultDir)); gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(m_widget), wxConvFileName->cWX2MB(defaultFileName)); } else { if ( !defaultFileName.empty() ) { wxString dir; if ( defaultDir.empty() ) dir = ::wxGetCwd(); else dir = defaultDir; gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(m_widget), wxConvFileName->cWX2MB( wxFileName(dir, defaultFileName).GetFullPath() ) ); } else if ( !defaultDir.empty() ) gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(m_widget), wxConvFileName->cWX2MB(defaultDir) ); } } else #endif wxGenericFileDialog::Create( parent, message, defaultDir, defaultFileName, wildCard, style, pos ); }
bool wxGtkFileCtrl::Create( wxWindow *parent, wxWindowID id, const wxString& defaultDirectory, const wxString& defaultFileName, const wxString& wildCard, long style, const wxPoint& pos, const wxSize& size, const wxString& name ) { if ( !PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ) ) { wxFAIL_MSG( wxT( "wxGtkFileCtrl creation failed" ) ); return false; } GtkFileChooserAction gtkAction = GTK_FILE_CHOOSER_ACTION_OPEN; if ( style & wxFC_SAVE ) gtkAction = GTK_FILE_CHOOSER_ACTION_SAVE; m_widget = gtk_alignment_new ( 0, 0, 1, 1 ); g_object_ref(m_widget); m_fcWidget = GTK_FILE_CHOOSER( gtk_file_chooser_widget_new(gtkAction) ); gtk_widget_show ( GTK_WIDGET( m_fcWidget ) ); gtk_container_add ( GTK_CONTAINER ( m_widget ), GTK_WIDGET( m_fcWidget ) ); m_focusWidget = GTK_WIDGET( m_fcWidget ); g_signal_connect ( m_fcWidget, "file-activated", G_CALLBACK ( gtkfilechooserwidget_file_activated_callback ), this ); g_signal_connect ( m_fcWidget, "current-folder-changed", G_CALLBACK ( gtkfilechooserwidget_folder_changed_callback ), this ); g_signal_connect ( m_fcWidget, "selection-changed", G_CALLBACK ( gtkfilechooserwidget_selection_changed_callback ), this ); m_fc.SetWidget( m_fcWidget ); if ( style & wxFC_MULTIPLE ) gtk_file_chooser_set_select_multiple( m_fcWidget, true ); SetWildcard( wildCard ); // if defaultDir is specified it should contain the directory and // defaultFileName should contain the default name of the file, however if // directory is not given, defaultFileName contains both wxFileName fn; if ( defaultDirectory.empty() ) fn.Assign( defaultFileName ); else if ( !defaultFileName.empty() ) fn.Assign( defaultDirectory, defaultFileName ); else fn.AssignDir( defaultDirectory ); // set the initial file name and/or directory const wxString dir = fn.GetPath(); if ( !dir.empty() ) { gtk_file_chooser_set_current_folder( m_fcWidget, dir.fn_str() ); } const wxString fname = fn.GetFullName(); if ( style & wxFC_SAVE ) { if ( !fname.empty() ) { gtk_file_chooser_set_current_name( m_fcWidget, fname.fn_str() ); } } else // wxFC_OPEN { if ( !fname.empty() ) { gtk_file_chooser_set_filename( m_fcWidget, fn.GetFullPath().fn_str() ); } } m_parent->DoAddChild( this ); PostCreation( size ); return TRUE; }
bool FileDialog::Create(wxWindow *parent, const wxString& message, const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard, long style, const wxPoint& pos, const wxSize& sz, const wxString& name) { parent = GetParentForModalDialog(parent, style); if (!FileDialogBase::Create(parent, message, defaultDir, defaultFileName, wildCard, style, pos, sz, name)) { return false; } if (!PreCreation(parent, pos, wxDefaultSize) || !CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style, wxDefaultValidator, wxT("filedialog"))) { wxFAIL_MSG( wxT("FileDialog creation failed") ); return false; } GtkFileChooserAction gtk_action; GtkWindow* gtk_parent = NULL; if (parent) gtk_parent = GTK_WINDOW( gtk_widget_get_toplevel(parent->m_widget) ); const gchar* ok_btn_stock; if ( style & wxFD_SAVE ) { gtk_action = GTK_FILE_CHOOSER_ACTION_SAVE; ok_btn_stock = GTK_STOCK_SAVE; } else { gtk_action = GTK_FILE_CHOOSER_ACTION_OPEN; ok_btn_stock = GTK_STOCK_OPEN; } m_widget = gtk_file_chooser_dialog_new( wxGTK_CONV(m_message), gtk_parent, gtk_action, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, ok_btn_stock, GTK_RESPONSE_ACCEPT, NULL); g_object_ref(m_widget); GtkFileChooser* file_chooser = GTK_FILE_CHOOSER(m_widget); m_fc.SetWidget(file_chooser); gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_ACCEPT); if ( style & wxFD_MULTIPLE ) gtk_file_chooser_set_select_multiple(file_chooser, true); // local-only property could be set to false to allow non-local files to be // loaded. In that case get/set_uri(s) should be used instead of // get/set_filename(s) everywhere and the GtkFileChooserDialog should // probably also be created with a backend, e.g. "gnome-vfs", "default", ... // (gtk_file_chooser_dialog_new_with_backend). Currently local-only is kept // as the default - true: // gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(m_widget), true); g_signal_connect (m_widget, "response", G_CALLBACK (gtk_filedialog_response_callback), this); g_signal_connect (m_widget, "selection-changed", G_CALLBACK (gtk_filedialog_selchanged_callback), this); g_signal_connect (m_widget, "current-folder-changed", G_CALLBACK (gtk_filedialog_folderchanged_callback), this); g_signal_connect (m_widget, "notify::filter", G_CALLBACK (gtk_filedialog_filterchanged_callback), this); // deal with extensions/filters SetWildcard(wildCard); wxString defaultFileNameWithExt = defaultFileName; if ( !wildCard.empty() && !defaultFileName.empty() && !wxFileName(defaultFileName).HasExt() ) { // append the default extension, if any, to the initial file name: GTK // won't do it for us by default (unlike e.g. MSW) const wxFileName fnWC(m_fc.GetCurrentWildCard()); if ( fnWC.HasExt() ) { // Notice that we shouldn't append the extension if it's a wildcard // because this is not useful: the user would need to change it to use // some fixed extension anyhow. const wxString& ext = fnWC.GetExt(); if ( ext.find_first_of("?*") == wxString::npos ) defaultFileNameWithExt << "." << ext; } } // if defaultDir is specified it should contain the directory and // defaultFileName should contain the default name of the file, however if // directory is not given, defaultFileName contains both wxFileName fn; if ( defaultDir.empty() ) fn.Assign(defaultFileNameWithExt); else if ( !defaultFileNameWithExt.empty() ) fn.Assign(defaultDir, defaultFileNameWithExt); else fn.AssignDir(defaultDir); // set the initial file name and/or directory fn.MakeAbsolute(); // GTK+ needs absolute path const wxString dir = fn.GetPath(); if ( !dir.empty() ) { gtk_file_chooser_set_current_folder(file_chooser, wxGTK_CONV_FN(dir)); } const wxString fname = fn.GetFullName(); if ( style & wxFD_SAVE ) { if ( !fname.empty() ) { gtk_file_chooser_set_current_name(file_chooser, wxGTK_CONV_FN(fname)); } #if GTK_CHECK_VERSION(2,7,3) if ((style & wxFD_OVERWRITE_PROMPT) #ifndef __WXGTK3__ && gtk_check_version(2,7,3) == NULL #endif ) { gtk_file_chooser_set_do_overwrite_confirmation(file_chooser, true); } #endif } else // wxFD_OPEN { if ( !fname.empty() ) { gtk_file_chooser_set_filename(file_chooser, wxGTK_CONV_FN(fn.GetFullPath())); } } if ( style & wxFD_PREVIEW ) { GtkWidget *previewImage = gtk_image_new(); gtk_file_chooser_set_preview_widget(file_chooser, previewImage); g_signal_connect(m_widget, "update-preview", G_CALLBACK(gtk_filedialog_update_preview_callback), previewImage); } return true; }
void wxGenericFileDialog::CreateDefaultControls(wxWindow *parent, const wxString& wildCard, bool is_pda) { // layout wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL ); wxBoxSizer *buttonsizer = new wxBoxSizer( wxHORIZONTAL ); wxBitmapButton *but; but = new wxBitmapButton(parent, ID_LIST_MODE, wxArtProvider::GetBitmap(wxART_LIST_VIEW, wxART_BUTTON)); #if wxUSE_TOOLTIPS but->SetToolTip( _("View files as a list view") ); #endif buttonsizer->Add( but, 0, wxALL, 5 ); but = new wxBitmapButton(parent, ID_REPORT_MODE, wxArtProvider::GetBitmap(wxART_REPORT_VIEW, wxART_BUTTON)); #if wxUSE_TOOLTIPS but->SetToolTip( _("View files as a detailed view") ); #endif buttonsizer->Add( but, 0, wxALL, 5 ); buttonsizer->Add( 30, 5, 1 ); m_upDirButton = new wxBitmapButton(parent, ID_UP_DIR, wxArtProvider::GetBitmap(wxART_GO_DIR_UP, wxART_BUTTON)); #if wxUSE_TOOLTIPS m_upDirButton->SetToolTip( _("Go to parent directory") ); #endif buttonsizer->Add( m_upDirButton, 0, wxALL, 5 ); #ifndef __DOS__ // VS: Home directory is meaningless in MS-DOS... but = new wxBitmapButton(parent, ID_PARENT_DIR, wxArtProvider::GetBitmap(wxART_GO_HOME, wxART_BUTTON)); #if wxUSE_TOOLTIPS but->SetToolTip( _("Go to home directory") ); #endif buttonsizer->Add( but, 0, wxALL, 5); buttonsizer->Add( 20, 20 ); #endif //!__DOS__ m_newDirButton = new wxBitmapButton(parent, ID_NEW_DIR, wxArtProvider::GetBitmap(wxART_NEW_DIR, wxART_BUTTON)); #if wxUSE_TOOLTIPS m_newDirButton->SetToolTip( _("Create new directory") ); #endif buttonsizer->Add( m_newDirButton, 0, wxALL, 5 ); if (is_pda) mainsizer->Add( buttonsizer, 0, wxALL | wxEXPAND, 0 ); else mainsizer->Add( buttonsizer, 0, wxALL | wxEXPAND, 5 ); wxBoxSizer *staticsizer = new wxBoxSizer( wxHORIZONTAL ); if (is_pda) staticsizer->Add( new wxStaticText( parent, wxID_ANY, _("Current directory:") ), 0, wxRIGHT, 10 ); m_static = new wxStaticText( parent, wxID_ANY, m_dir ); staticsizer->Add( m_static, 1 ); mainsizer->Add( staticsizer, 0, wxEXPAND | wxLEFT|wxRIGHT|wxBOTTOM, 10 ); long style2 = ms_lastViewStyle; if ( !HasFdFlag(wxFD_MULTIPLE) ) style2 |= wxLC_SINGLE_SEL; #ifdef __WXWINCE__ style2 |= wxSIMPLE_BORDER; #else style2 |= wxSUNKEN_BORDER; #endif #ifdef __WXGTK__ m_list = new wxFileCtrl( parent, ID_LIST_CTRL, wxEmptyString, wxEmptyString, wxFileSelectorDefaultWildcardStr, style2, wxDefaultPosition, wxSize(540,200)); #else m_list = new wxFileCtrl( parent, ID_LIST_CTRL, wxEmptyString, ms_lastShowHidden, wxDefaultPosition, wxSize(540,200), style2); #endif m_text = new wxTextCtrl(parent, ID_TEXT, m_fileName, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER); m_choice = new wxChoice(parent, ID_CHOICE); if (is_pda) { // PDAs have a different screen layout mainsizer->Add(m_list, wxSizerFlags(1).Expand().HorzBorder()); wxBoxSizer *textsizer = new wxBoxSizer(wxHORIZONTAL); textsizer->Add(m_text, wxSizerFlags(1).Centre().Border()); mainsizer->Add(textsizer, wxSizerFlags().Expand()); m_check = NULL; textsizer->Add(m_choice, wxSizerFlags(1).Centre().Border()); wxSizer *bsizer = CreateButtonSizer(wxOK | wxCANCEL); if ( bsizer ) mainsizer->Add(bsizer, wxSizerFlags().Expand().Border()); } else // !is_pda { mainsizer->Add(m_list, wxSizerFlags(1).Expand().DoubleHorzBorder()); wxBoxSizer *textsizer = new wxBoxSizer(wxHORIZONTAL); textsizer->Add(m_text, wxSizerFlags(1).Centre(). DoubleBorder(wxLEFT | wxRIGHT | wxTOP)); textsizer->Add(new wxButton(parent, wxID_OK), wxSizerFlags().Centre(). DoubleBorder(wxLEFT | wxRIGHT | wxTOP)); mainsizer->Add(textsizer, wxSizerFlags().Expand()); wxSizerFlags flagsCentre; flagsCentre.Centre().DoubleBorder(); wxBoxSizer *choicesizer = new wxBoxSizer(wxHORIZONTAL); choicesizer->Add(m_choice, wxSizerFlags(flagsCentre).Proportion(1)); m_check = new wxCheckBox(parent, ID_CHECK, _("Show &hidden files")); m_check->SetValue(ms_lastShowHidden); choicesizer->Add(m_check, flagsCentre); choicesizer->Add(new wxButton(parent, wxID_CANCEL), flagsCentre); mainsizer->Add(choicesizer, wxSizerFlags().Expand()); } SetWildcard(wildCard); parent->SetAutoLayout( true ); parent->SetSizer( mainsizer ); if (!is_pda) { mainsizer->Fit( parent ); mainsizer->SetSizeHints( parent ); } }