]> git.saurik.com Git - wxWidgets.git/commitdiff
misc fixes for wxDirDialog; new wxDD_CHANGE_DIR flag (patch 1478051)
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 6 May 2006 20:10:11 +0000 (20:10 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 6 May 2006 20:10:11 +0000 (20:10 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39079 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

12 files changed:
docs/latex/wx/dirdlg.tex
include/wx/cocoa/dirdlg.h
include/wx/defs.h
include/wx/dirdlg.h
include/wx/generic/dirdlgg.h
include/wx/gtk/dirdlg.h
include/wx/mac/carbon/dirdlg.h
include/wx/mac/classic/dirdlg.h
include/wx/os2/dirdlg.h
src/generic/dirdlgg.cpp
src/gtk/dirdlg.cpp
src/msw/dirdlg.cpp

index 5ac906af222f2840f577e935fa0ef9f095f98ae1..ec61a15c83ea94fceae8a818fae7c799814fe463 100644 (file)
@@ -12,17 +12,16 @@ This class represents the directory chooser dialog.
 \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}.
@@ -78,12 +77,6 @@ Returns the default or user-selected path.
 
 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}}
@@ -96,12 +89,6 @@ Sets the message that will be displayed on the dialog.
 
 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}
index 6b74ed026f24c9433d2e95774677988991c34b5f..b221050d99bdc9a6e0f056b446a9cf025f2f7e27 100644 (file)
@@ -33,15 +33,12 @@ public:
                 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;
index 8bfbee8cc236d3a30953494c77971ba625ce5280..fa9403a04a6df6788f562c51ae853f6f98ae1048 100644 (file)
@@ -1711,6 +1711,8 @@ enum wxBorder
  */
 
 #define wxDD_NEW_DIR_BUTTON     0x0080
+#define wxDD_CHANGE_DIR         0x0100
+
 
 /*
  * extended dialog specifiers. these values are stored in a different
index 401eeda50f531366e6253692addb46806d2e8f26..e8c7e441001099a45bcd4943b0f871da71d06806 100644 (file)
@@ -40,6 +40,7 @@ extern WXDLLEXPORT_DATA(const wxChar) wxDirSelectorPromptStr[];
 class WXDLLEXPORT wxDirDialogBase : public wxDialog
 {
 public:
+    wxDirDialogBase() {}
     wxDirDialogBase(wxWindow *parent,
                     const wxString& title = wxDirSelectorPromptStr,
                     const wxString& defaultPath = wxEmptyString,
@@ -47,20 +48,34 @@ public:
                     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;
index 93dcac9bec3548ed486fe0d61e400e773b4f3ffd..1c48740479d39fd25962442dcffa84e9d748aa0f 100644 (file)
@@ -22,8 +22,8 @@ class WXDLLEXPORT wxTreeEvent;
 // 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)
@@ -62,13 +62,11 @@ public:
 
     //// 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; }
@@ -83,7 +81,6 @@ protected:
     void OnGoHome(wxCommandEvent& event);
     void OnShowHidden(wxCommandEvent& event);
 
-    long              m_dialogStyle;
     wxGenericDirCtrl* m_dirCtrl;
     wxTextCtrl*       m_input;
 
index d044dee8731d76ca222b85f0c0074a23553c25d9..ea078fd2ab480444d014541009e36bcf247aea18 100644 (file)
@@ -23,7 +23,7 @@ public:
 
     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,
index 1017750ea3d38d23a27107aeb4356b517afbbf55..5db3edc6bb002d292642ac4475ade05610b21a99 100644 (file)
@@ -23,13 +23,9 @@ public:
                 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)
index 1017750ea3d38d23a27107aeb4356b517afbbf55..5db3edc6bb002d292642ac4475ade05610b21a99 100644 (file)
@@ -23,13 +23,9 @@ public:
                 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)
index 9f8d900ae3e2a1f732a34da4165a99eb6a3d995a..250da8c5bbc3f7aa4ccf96094b897aa98e9e9d8b 100644 (file)
@@ -18,19 +18,15 @@ WXDLLEXPORT_DATA(extern const wxChar) wxFileSelectorPromptStr[];
 
 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;
 };
 
index 2c50f0ec39d926f3f25430774390bc122c1d4cd2..078123f9833df03e05ffc6568c00df325c53492e 100644 (file)
@@ -78,21 +78,23 @@ END_EVENT_TABLE()
 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);
@@ -211,6 +213,15 @@ bool wxGenericDirDialog::Create(wxWindow* WXUNUSED(parent),
     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);
@@ -219,12 +230,15 @@ void wxGenericDirDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
 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?"),
@@ -232,15 +246,18 @@ void wxGenericDirDialog::OnOK(wxCommandEvent& WXUNUSED(event))
     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());
index 56ad5ae8592b4a5aa506da252192db8b868681a6..bfd86d0b3956ae3815e8ca0f32e42410d1ada2bc 100644 (file)
@@ -1,6 +1,6 @@
 /////////////////////////////////////////////////////////////////////////////
 // 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
@@ -13,7 +13,7 @@
 
 
 /*
-  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
@@ -52,43 +48,13 @@ extern void wxapp_install_idle_handler();
 //-----------------------------------------------------------------------------
 
 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);
 
@@ -104,7 +70,7 @@ static void gtk_filedialog_ok_callback(GtkWidget *widget, wxDirDialog *dialog)
 
 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);
@@ -115,7 +81,7 @@ static void gtk_filedialog_cancel_callback(GtkWidget *WXUNUSED(w),
 extern "C" {
 static void gtk_filedialog_response_callback(GtkWidget *w,
                                              gint response,
-                                             wxDirDialog *dialog)
+                                             wxDirDialogGTK *dialog)
 {
     wxapp_install_idle_handler();
 
@@ -134,16 +100,16 @@ static void gtk_filedialog_response_callback(GtkWidget *w,
 #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)
@@ -159,7 +125,7 @@ wxDirDialog::wxDirDialog(wxWindow* parent, const wxString& title,
             !CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style,
                     wxDefaultValidator, wxT("filedialog")))
         {
-            wxFAIL_MSG( wxT("wxDirDialog creation failed") );
+            wxFAIL_MSG( wxT("wxDirDialogGTK creation failed") );
             return;
         }
 
@@ -199,7 +165,7 @@ wxDirDialog::wxDirDialog(wxWindow* parent, const wxString& title,
         wxGenericDirDialog::Create(parent, title, defaultPath, style, pos, sz, name);
 }
 
-wxDirDialog::~wxDirDialog()
+wxDirDialogGTK::~wxDirDialogGTK()
 {
 #ifdef __WXGTK24__
     if (!gtk_check_version(2,4,0))
@@ -210,7 +176,7 @@ wxDirDialog::~wxDirDialog()
 #endif
 }
 
-void wxDirDialog::OnFakeOk( wxCommandEvent &event )
+void wxDirDialogGTK::OnFakeOk( wxCommandEvent &event )
 {
 #ifdef __WXGTK24__
     if (!gtk_check_version(2,4,0))
@@ -220,7 +186,7 @@ void wxDirDialog::OnFakeOk( wxCommandEvent &event )
         wxGenericDirDialog::OnOK( event );
 }
 
-int wxDirDialog::ShowModal()
+int wxDirDialogGTK::ShowModal()
 {
 #ifdef __WXGTK24__
     if (!gtk_check_version(2,4,0))
@@ -230,7 +196,7 @@ int wxDirDialog::ShowModal()
         return wxGenericDirDialog::ShowModal();
 }
 
-bool wxDirDialog::Show( bool show )
+bool wxDirDialogGTK::Show( bool show )
 {
 #ifdef __WXGTK24__
     if (!gtk_check_version(2,4,0))
@@ -240,7 +206,7 @@ bool wxDirDialog::Show( bool show )
         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;
@@ -248,7 +214,7 @@ void wxDirDialog::DoSetSize(int x, int y, int width, int height, int sizeFlags )
         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))
@@ -263,7 +229,7 @@ void wxDirDialog::SetPath(const wxString& dir)
         wxGenericDirDialog::SetPath( dir );
 }
 
-wxString wxDirDialog::GetPath() const
+wxString wxDirDialogGTK::GetPath() const
 {
 #ifdef __WXGTK24__
     if (!gtk_check_version(2,4,0))
index 5f2f111abb6ebd1edf5c4e869b810fcee9ec9740..018f4e13239fdc33c8e9c4037c604a9ae68cb35c 100644 (file)
@@ -26,7 +26,8 @@
 
 #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"
@@ -89,7 +90,7 @@ wxDirDialog::wxDirDialog(wxWindow *parent,
     m_message = message;
     m_parent = parent;
 
-    SetStyle(style);
+    SetWindowStyle(style);
     SetPath(defaultPath);
 }
 
@@ -181,6 +182,10 @@ int wxDirDialog::ShowModal()
 
     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;
 }