\wxheading{Include files}
<wx/dirdlg.h>
-<wx/generic/dirdlgg.h>
\wxheading{Window styles}
-\twocolwidtha{5cm}
-\begin{twocollist}
+\begin{twocollist}\itemsep=0pt
\twocolitem{\windowstyle{wxDD\_DEFAULT\_STYLE}}{Equivalent to a combination of wxDEFAULT\_DIALOG\_STYLE, wxDD\_NEW\_DIR\_BUTTON and wxRESIZE\_BORDER (the last one is not used under wxWinCE).}
\twocolitem{\windowstyle{wxDD\_NEW\_DIR\_BUTTON}}{Add "Create new
directory" button and allow directory names to be editable. On
Windows the new directory button is only available with recent
versions of the common dialogs.}
+\twocolitem{\windowstyle{wxDD\_CHANGE\_DIR}}{Change the current working directory to the directory chosen by the user.}
\end{twocollist}
See also \helpref{Generic window styles}{windowstyles}.
Returns the message that will be displayed on the dialog.
-\membersection{wxDirDialog::GetStyle}\label{wxdirdialoggetstyle}
-
-\constfunc{long}{GetStyle}{\void}
-
-Returns the dialog style.
-
\membersection{wxDirDialog::SetMessage}\label{wxdirdialogsetmessage}
\func{void}{SetMessage}{\param{const wxString\& }{message}}
Sets the default path.
-\membersection{wxDirDialog::SetStyle}\label{wxdirdialogsetstyle}
-
-\func{void}{SetStyle}{\param{long }{style}}
-
-Sets the dialog style. This is currently unused.
-
\membersection{wxDirDialog::ShowModal}\label{wxdirdialogshowmodal}
\func{int}{ShowModal}{\void}
const wxString& name = wxDirDialogNameStr);
~wxDirDialog();
- long GetStyle() const { return m_dialogStyle; }
-
virtual int ShowModal();
inline WX_NSSavePanel GetNSSavePanel()
{ return (WX_NSSavePanel)m_cocoaNSWindow; }
protected:
- long m_dialogStyle;
wxString m_dir;
wxWindow * m_parent;
wxString m_fileName;
*/
#define wxDD_NEW_DIR_BUTTON 0x0080
+#define wxDD_CHANGE_DIR 0x0100
+
/*
* extended dialog specifiers. these values are stored in a different
class WXDLLEXPORT wxDirDialogBase : public wxDialog
{
public:
+ wxDirDialogBase() {}
wxDirDialogBase(wxWindow *parent,
const wxString& title = wxDirSelectorPromptStr,
const wxString& defaultPath = wxEmptyString,
const wxPoint& pos = wxDefaultPosition,
const wxSize& sz = wxDefaultSize,
const wxString& name = wxDirDialogNameStr)
- : wxDialog(parent, wxID_ANY, title, pos, sz, style, name)
- , m_path(defaultPath)
- {}
- wxDirDialogBase() {}
+ {
+ Create(parent, title, defaultPath, style, pos, sz, name);
+ }
virtual ~wxDirDialogBase() {}
+
+ bool Create(wxWindow *parent,
+ const wxString& title = wxDirSelectorPromptStr,
+ const wxString& defaultPath = wxEmptyString,
+ long style = wxDD_DEFAULT_STYLE,
+ const wxPoint& pos = wxDefaultPosition,
+ const wxSize& sz = wxDefaultSize,
+ const wxString& name = wxDirDialogNameStr)
+ {
+ if (!wxDialog::Create(parent, wxID_ANY, title, pos, sz, style, name))
+ return false;
+ m_path = defaultPath;
+ m_message = title;
+ return true;
+ }
+
+
virtual void SetMessage(const wxString& message) { m_message = message; }
virtual void SetPath(const wxString& path) { m_path = path; }
- virtual void SetStyle(long style) { SetWindowStyle(style); }
virtual wxString GetMessage() const { return m_message; }
virtual wxString GetPath() const { return m_path; }
- virtual long GetStyle() const { return GetWindowStyle(); }
protected:
wxString m_message;
// we may be included directly as well as from wx/dirdlg.h (FIXME)
extern WXDLLEXPORT_DATA(const wxChar) wxDirDialogNameStr[];
extern WXDLLEXPORT_DATA(const wxChar) wxDirSelectorPromptStr[];
-#ifndef wxDD_DEFAULT_STYLE
+#ifndef wxDD_DEFAULT_STYLE
#ifdef __WXWINCE__
#define wxDD_DEFAULT_STYLE \
(wxDEFAULT_DIALOG_STYLE | wxDD_NEW_DIR_BUTTON)
//// Accessors
void SetPath(const wxString& path);
- void SetStyle(long style) { m_dialogStyle = style; }
-
wxString GetPath() const;
- long GetStyle() const { return m_dialogStyle; }
//// Overrides
virtual int ShowModal();
+ virtual void EndModal(int retCode);
// this one is specific to wxGenericDirDialog
wxTextCtrl* GetInputCtrl() const { return m_input; }
void OnGoHome(wxCommandEvent& event);
void OnShowHidden(wxCommandEvent& event);
- long m_dialogStyle;
wxGenericDirCtrl* m_dirCtrl;
wxTextCtrl* m_input;
wxDirDialogGTK(wxWindow *parent,
const wxString& message = wxDirSelectorPromptStr,
- const wxString& defaultPath = _T(""),
+ const wxString& defaultPath = wxEmptyString,
long style = wxDD_DEFAULT_STYLE,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
const wxSize& size = wxDefaultSize,
const wxString& name = wxDirDialogNameStr);
- void SetStyle(long style) { m_dialogStyle = style; }
- long GetStyle() const { return m_dialogStyle; }
-
virtual int ShowModal();
protected:
- long m_dialogStyle;
wxWindow * m_parent;
DECLARE_DYNAMIC_CLASS(wxDirDialog)
const wxSize& size = wxDefaultSize,
const wxString& name = wxDirDialogNameStr);
- void SetStyle(long style) { m_dialogStyle = style; }
- long GetStyle() const { return m_dialogStyle; }
-
virtual int ShowModal();
protected:
- long m_dialogStyle;
wxWindow * m_parent;
DECLARE_DYNAMIC_CLASS(wxDirDialog)
class WXDLLEXPORT wxDirDialog: public wxDirDialogBase
{
-DECLARE_DYNAMIC_CLASS(wxDirDialog)
+ DECLARE_DYNAMIC_CLASS(wxDirDialog)
public:
wxDirDialog(wxWindow *parent, const wxString& message = wxFileSelectorPromptStr,
const wxString& defaultPath = "",
long style = 0, const wxPoint& pos = wxDefaultPosition);
- inline void SetStyle(long style) { m_dialogStyle = style; }
- inline long GetStyle() const { return m_dialogStyle; }
-
int ShowModal();
protected:
- long m_dialogStyle;
wxWindow * m_parent;
};
wxGenericDirDialog::wxGenericDirDialog(wxWindow* parent, const wxString& title,
const wxString& defaultPath, long style,
const wxPoint& pos, const wxSize& sz,
- const wxString& name):
- wxDirDialogBase(parent, title, defaultPath, style, pos, sz, name)
+ const wxString& name)
{
Create(parent, title, defaultPath, style, pos, sz, name);
}
-bool wxGenericDirDialog::Create(wxWindow* WXUNUSED(parent),
- const wxString& WXUNUSED(title),
+bool wxGenericDirDialog::Create(wxWindow* parent,
+ const wxString& title,
const wxString& defaultPath, long style,
- const wxPoint& WXUNUSED(pos),
- const wxSize& WXUNUSED(sz),
- const wxString& WXUNUSED(name))
+ const wxPoint& pos,
+ const wxSize& sz,
+ const wxString& name)
{
wxBusyCursor cursor;
+ if (!wxDirDialogBase::Create(parent, title, defaultPath, style, pos, sz, name))
+ return false;
+
m_path = defaultPath;
if (m_path == wxT("~"))
wxGetHomeDir(&m_path);
return true;
}
+void wxGenericDirDialog::EndModal(int retCode)
+{
+ // before proceeding, change the current working directory if user asked so
+ if (retCode == wxID_OK && HasFlag(wxDD_CHANGE_DIR))
+ wxSetWorkingDirectory(m_path);
+
+ wxDialog::EndModal(retCode);
+}
+
void wxGenericDirDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
{
EndModal(wxID_CANCEL);
void wxGenericDirDialog::OnOK(wxCommandEvent& WXUNUSED(event))
{
m_path = m_input->GetValue();
+
// Does the path exist? (User may have typed anything in m_input)
- if (wxDirExists(m_path)) {
+ if (wxDirExists(m_path))
+ {
// OK, path exists, we're done.
EndModal(wxID_OK);
return;
}
+
// Interact with user, find out if the dir is a typo or to be created
wxString msg;
msg.Printf(_("The directory '%s' does not exist\nCreate it now?"),
wxMessageDialog dialog(this, msg, _("Directory does not exist"),
wxYES_NO | wxICON_WARNING);
- if ( dialog.ShowModal() == wxID_YES ) {
+ if ( dialog.ShowModal() == wxID_YES )
+ {
// Okay, let's make it
wxLogNull log;
- if (wxMkdir(m_path)) {
+ if (wxMkdir(m_path))
+ {
// The new dir was created okay.
EndModal(wxID_OK);
return;
}
- else {
+ else
+ {
// Trouble...
msg.Printf(_("Failed to create directory '%s'\n(Do you have the required permissions?)"),
m_path.c_str());
/////////////////////////////////////////////////////////////////////////////
// Name: src/gtk/dirdlg.cpp
-// Purpose: native implementation of wxDirDialog
+// Purpose: native implementation of wxDirDialogGTK
// Author: Robert Roebling, Zbigniew Zagorski, Mart Raudsepp, Francesco Montorsi
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling, 2004 Zbigniew Zagorski, 2005 Mart Raudsepp
/*
- NOTE: the GtkFileChooser interface can be used both for wxFileDialog and for wxDirDialog.
+ NOTE: the GtkFileChooser interface can be used both for wxFileDialog and for wxDirDialogGTK.
Thus following code is very similar (even if not identic) to src/gtk/filedlg.cpp
If you find a problem in this code, remember to check also that file !
*/
#include "wx/filedlg.h"
#endif
-#ifdef __WXGTK24__
+#ifdef __WXGTK24__ // only for GTK+ > 2.4 there is GtkFileChooserDialog
#include <gtk/gtk.h>
#include "wx/gtk/private.h"
#include <unistd.h> // chdir
-#include "wx/filename.h" // wxFilename
-#include "wx/tokenzr.h" // wxStringTokenizer
-#include "wx/filefn.h" // ::wxGetCwd
-#include "wx/msgdlg.h" // wxMessageDialog
//-----------------------------------------------------------------------------
// idle system
//-----------------------------------------------------------------------------
extern "C" {
-static void gtk_filedialog_ok_callback(GtkWidget *widget, wxDirDialog *dialog)
+static void gtk_filedialog_ok_callback(GtkWidget *widget, wxDirDialogGTK *dialog)
{
- int style = dialog->GetStyle();
gchar* filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget));
- // gtk version numbers must be identical with the one in ctor (that calls set_do_overwrite_confirmation)
-#if GTK_CHECK_VERSION(2,7,3)
- if(gtk_check_version(2,7,3) != NULL)
-#endif
- if ((style & wxSAVE) && (style & wxOVERWRITE_PROMPT))
- {
- if ( g_file_test(filename, G_FILE_TEST_EXISTS) )
- {
- wxString msg;
-
- msg.Printf(
- _("File '%s' already exists, do you really want to overwrite it?"),
- wxString(wxConvFileName->cMB2WX(filename)).c_str());
-
- wxMessageDialog dlg(dialog, msg, _("Confirm"),
- wxYES_NO | wxICON_QUESTION);
- if (dlg.ShowModal() != wxID_YES)
- {
- g_free(filename);
- return;
- }
- }
- }
-
// change to the directory where the user went if asked
- if (style & wxCHANGE_DIR)
- {
- // Use chdir to not care about filename encodings
- gchar* folder = g_path_get_dirname(filename);
- chdir(folder);
- g_free(folder);
- }
+ if (dialog->HasFlag(wxDD_CHANGE_DIR))
+ chdir(filename);
g_free(filename);
extern "C" {
static void gtk_filedialog_cancel_callback(GtkWidget *WXUNUSED(w),
- wxDirDialog *dialog)
+ wxDirDialogGTK *dialog)
{
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
event.SetEventObject(dialog);
extern "C" {
static void gtk_filedialog_response_callback(GtkWidget *w,
gint response,
- wxDirDialog *dialog)
+ wxDirDialogGTK *dialog)
{
wxapp_install_idle_handler();
#endif // __WXGTK24__
//-----------------------------------------------------------------------------
-// wxDirDialog
+// wxDirDialogGTK
//-----------------------------------------------------------------------------
-IMPLEMENT_DYNAMIC_CLASS(wxDirDialog,wxGenericDirDialog)
+IMPLEMENT_DYNAMIC_CLASS(wxDirDialogGTK,wxGenericDirDialog)
-BEGIN_EVENT_TABLE(wxDirDialog,wxGenericDirDialog)
- EVT_BUTTON(wxID_OK, wxDirDialog::OnFakeOk)
+BEGIN_EVENT_TABLE(wxDirDialogGTK,wxGenericDirDialog)
+ EVT_BUTTON(wxID_OK, wxDirDialogGTK::OnFakeOk)
END_EVENT_TABLE()
-wxDirDialog::wxDirDialog(wxWindow* parent, const wxString& title,
+wxDirDialogGTK::wxDirDialogGTK(wxWindow* parent, const wxString& title,
const wxString& defaultPath, long style,
const wxPoint& pos, const wxSize& sz,
const wxString& name)
!CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style,
wxDefaultValidator, wxT("filedialog")))
{
- wxFAIL_MSG( wxT("wxDirDialog creation failed") );
+ wxFAIL_MSG( wxT("wxDirDialogGTK creation failed") );
return;
}
wxGenericDirDialog::Create(parent, title, defaultPath, style, pos, sz, name);
}
-wxDirDialog::~wxDirDialog()
+wxDirDialogGTK::~wxDirDialogGTK()
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
#endif
}
-void wxDirDialog::OnFakeOk( wxCommandEvent &event )
+void wxDirDialogGTK::OnFakeOk( wxCommandEvent &event )
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
wxGenericDirDialog::OnOK( event );
}
-int wxDirDialog::ShowModal()
+int wxDirDialogGTK::ShowModal()
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
return wxGenericDirDialog::ShowModal();
}
-bool wxDirDialog::Show( bool show )
+bool wxDirDialogGTK::Show( bool show )
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
return wxGenericDirDialog::Show( show );
}
-void wxDirDialog::DoSetSize(int x, int y, int width, int height, int sizeFlags )
+void wxDirDialogGTK::DoSetSize(int x, int y, int width, int height, int sizeFlags )
{
if (!m_wxwindow)
return;
wxGenericDirDialog::DoSetSize( x, y, width, height, sizeFlags );
}
-void wxDirDialog::SetPath(const wxString& dir)
+void wxDirDialogGTK::SetPath(const wxString& dir)
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
wxGenericDirDialog::SetPath( dir );
}
-wxString wxDirDialog::GetPath() const
+wxString wxDirDialogGTK::GetPath() const
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
#if wxUSE_DIRDLG
-#if wxUSE_OLE && !defined(__GNUWIN32_OLD__) && (!defined(__WXWINCE__) || (defined(__HANDHELDPC__) && (_WIN32_WCE >= 500)))
+#if wxUSE_OLE && !defined(__GNUWIN32_OLD__) && (!defined(__WXWINCE__) || \
+ (defined(__HANDHELDPC__) && (_WIN32_WCE >= 500)))
#ifndef WX_PRECOMP
#include "wx/utils.h"
m_message = message;
m_parent = parent;
- SetStyle(style);
+ SetWindowStyle(style);
SetPath(defaultPath);
}
m_path = pidl.GetPath();
+ // change current working directory if asked so
+ if (HasFlag(wxDD_CHANGE_DIR))
+ wxSetWorkingDirectory(m_path);
+
return m_path.empty() ? wxID_CANCEL : wxID_OK;
}