]> git.saurik.com Git - wxWidgets.git/commitdiff
wxFileDialog changed to use (new) wxCHANGE_DIR flag, docs updated
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 8 Oct 2000 23:35:09 +0000 (23:35 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 8 Oct 2000 23:35:09 +0000 (23:35 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8494 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/filedlg.tex
include/wx/filedlg.h
src/generic/filedlgg.cpp
src/gtk/filedlg.cpp
src/gtk1/filedlg.cpp
src/msw/filedlg.cpp

index 23b6835bf82d07e7b63ccd3099b32a758af954a9..6aa8bc22cd3b591690d0732c59cb70da4bafc5a9 100644 (file)
@@ -67,13 +67,22 @@ Constructor. Use \helpref{wxFileDialog::ShowModal}{wxfiledialogshowmodal} to sho
 \twocolitem{{\bf wxOPEN}}{This is an open dialog.}
 \twocolitem{{\bf wxSAVE}}{This is a save dialog.}
 \twocolitem{{\bf wxHIDE\_READONLY}}{Hide read-only files.}
-\twocolitem{{\bf wxOVERWRITE\_PROMPT}}{Prompt for a conformation if a file will be overridden.}
-\twocolitem{{\bf wxMULTIPLE}}{For open dialog only: allows selecting multiple files}
+\twocolitem{{\bf wxOVERWRITE\_PROMPT}}{For save dialog only: prompt for a conformation if a file will be overridden.}
+\twocolitem{{\bf wxMULTIPLE}}{For open dialog only: allows selecting multiple files.}
+\twocolitem{{\bf wxCHANGE\_DIR}}{Change the current working directory to the
+directory where the file(s) chosen by the user are.}
 \end{twocollist}%
 }
 
 \docparam{pos}{Dialog position. Not implemented.}
 
+{\bf NB:} Previous versions of wxWindows used {\tt wxCHANGE\_DIR} by default
+under MS Windows which allowed the program to simply remember the last
+directory where user selected the files to open/save. This (desired)
+functionality must be implemented in the program itself now (manually remember
+the last path used and pass it to the dialog the next time it is called) or
+by using this flag.
+
 \membersection{wxFileDialog::\destruct{wxFileDialog}}
 
 \func{}{\destruct{wxFileDialog}}{\void}
index b35e63d016e25fe63906365e2953bc90bd754e95..9fb43982bc78760e1b7089b9b97bc5c4e6ff0950 100644 (file)
@@ -3,12 +3,13 @@
 
 enum
 {
-    wxOPEN  = 1,
-    wxSAVE = 2,
-    wxOVERWRITE_PROMPT = 4,
-    wxHIDE_READONLY = 8,
-    wxFILE_MUST_EXIST = 16,
-    wxMULTIPLE = 32
+    wxOPEN              = 0x0001,
+    wxSAVE              = 0x0002,
+    wxOVERWRITE_PROMPT  = 0x0004,
+    wxHIDE_READONLY     = 0x0008,
+    wxFILE_MUST_EXIST   = 0x0010,
+    wxMULTIPLE          = 0x0020,
+    wxCHANGE_DIR        = 0x0040
 };
 
 #if defined(__WXMSW__)
index bc72174e984e57eea0b36f0ae3308898c9551510..24ed3ae470ae35f682e39c649401db9f5dbd920d 100644 (file)
@@ -1097,6 +1097,18 @@ void wxFileDialog::HandleAction( const wxString &fn )
 
     SetPath( filename );
 
+    // change to the directory where the user went if asked
+    if ( style & wxCHANGE_DIR )
+    {
+        wxString cwd;
+        wxSplitPath(filename, &cwd, NULL, NULL);
+
+        if ( cwd != wxGetWorkingDirectory() )
+        {
+            wxSetWorkingDirectory(cwd);
+        }
+    }
+
     wxCommandEvent event;
     wxDialog::OnOK(event);
 }
@@ -1262,19 +1274,17 @@ wxString wxFileSelector( const wxChar *title,
     }
 }
 
-wxString wxLoadFileSelector( const wxChar *what, const wxChar *extension, const wxChar *default_name, wxWindow *parent )
+wxString wxLoadFileSelector( const wxChar *what, const wxChar *ext, const wxChar *default_name, wxWindow *parent )
 {
-    wxChar *ext = (wxChar *)extension;
+    wxString prompt = wxString::Format(_("Load %s file"), what);
 
-    wxChar prompt[50];
-    wxString str = _("Load %s file");
-    wxSprintf(prompt, str, what);
+    if (*ext == wxT('.'))
+        ext++;
 
-    if (*ext == wxT('.')) ext++;
-    wxChar wild[60];
-    wxSprintf(wild, wxT("*.%s"), ext);
+    wxString wild = wxString::Format(_T("*.%s"), ext);
 
-    return wxFileSelector (prompt, (const wxChar *) NULL, default_name, ext, wild, 0, parent);
+    return wxFileSelector(prompt, (const wxChar *) NULL, default_name,
+                          ext, wild, 0, parent);
 }
 
 wxString wxSaveFileSelector(const wxChar *what, const wxChar *extension, const wxChar *default_name,
@@ -1282,15 +1292,15 @@ wxString wxSaveFileSelector(const wxChar *what, const wxChar *extension, const w
 {
     wxChar *ext = (wxChar *)extension;
 
-    wxChar prompt[50];
-    wxString str = _("Save %s file");
-    wxSprintf(prompt, str, what);
+    wxString prompt = wxString::Format(_("Save %s file"), what);
+
+    if (*ext == wxT('.'))
+        ext++;
 
-    if (*ext == wxT('.')) ext++;
-    wxChar wild[60];
-    wxSprintf(wild, wxT("*.%s"), ext);
+    wxString wild = wxString::Format(_T("*.%s"), ext);
 
-    return wxFileSelector (prompt, (const wxChar *) NULL, default_name, ext, wild, 0, parent);
+    return wxFileSelector(prompt, (const wxChar *) NULL, default_name,
+                          ext, wild, 0, parent);
 }
 
 
index 0f9fd4887a033d5a553d0137ce99ec732393e1d9..946ae917c47082900542b2fe9a860f3aa41344f4 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        filedlg.cpp
+// Name:        gtk/filedlg.cpp
 // Purpose:
 // Author:      Robert Roebling
 // Id:          $Id$
@@ -83,6 +83,18 @@ void gtk_filedialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFileDialog *dial
         }
     }
 
+    // change to the directory where the user went if asked
+    if ( style & wxCHANGE_DIR )
+    {
+        wxString cwd;
+        wxSplitPath(filename, &cwd, NULL, NULL);
+
+        if ( cwd != wxGetWorkingDirectory() )
+        {
+            wxSetWorkingDirectory(cwd);
+        }
+    }
+
     dialog->SetPath( filename );
 
     wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
@@ -121,9 +133,9 @@ wxFileDialog::wxFileDialog( wxWindow *parent, const wxString& message,
         !CreateBase( parent, -1, pos, wxDefaultSize, style | wxDIALOG_MODAL, wxDefaultValidator, wxT("filedialog") ))
     {
         wxFAIL_MSG( wxT("wxXX creation failed") );
-       return;
+        return;
     }
-    
+
     m_message = message;
     m_path = wxT("");
     m_fileName = defaultFileName;
@@ -156,10 +168,10 @@ wxFileDialog::wxFileDialog( wxWindow *parent, const wxString& message,
 
     gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked",
       GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback), (gpointer*)this );
-      
+
     // strange way to internationalize
     gtk_label_set( GTK_LABEL( GTK_BUTTON(sel->cancel_button)->child ), wxConvCurrent->cWX2MB(_("Cancel")) );
-    
+
     gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
         GTK_SIGNAL_FUNC(gtk_filedialog_delete_callback), (gpointer)this );
 }
@@ -172,11 +184,11 @@ void wxFileDialog::SetPath(const wxString& path)
     {
         wxString ext;
         wxSplitPath(path, &m_dir, &m_fileName, &ext);
-       if (!ext.IsEmpty())
-       {
-           m_fileName += wxT(".");
+        if (!ext.IsEmpty())
+        {
+            m_fileName += wxT(".");
             m_fileName += ext;
-       }
+        }
     }
 }
 
@@ -234,15 +246,15 @@ wxString wxLoadFileSelector( const wxChar *what, const wxChar *extension, const
 {
     wxChar *ext = (wxChar *)extension;
 
-    wxChar prompt[50];
-    wxString str = _("Load %s file");
-    wxSprintf(prompt, str, what);
+    wxString prompt = wxString::Format(_("Load %s file"), what);
+
+    if (*ext == wxT('.'))
+        ext++;
 
-    if (*ext == wxT('.')) ext++;
-    wxChar wild[60];
-    wxSprintf(wild, wxT("*.%s"), ext);
+    wxString wild = wxString::Format(_T("*.%s"), ext);
 
-    return wxFileSelector (prompt, (const wxChar *) NULL, default_name, ext, wild, 0, parent);
+    return wxFileSelector(prompt, (const wxChar *) NULL, default_name,
+                          ext, wild, 0, parent);
 }
 
 wxString wxSaveFileSelector(const wxChar *what, const wxChar *extension, const wxChar *default_name,
@@ -250,14 +262,14 @@ wxString wxSaveFileSelector(const wxChar *what, const wxChar *extension, const w
 {
     wxChar *ext = (wxChar *)extension;
 
-    wxChar prompt[50];
-    wxString str = _("Save %s file");
-    wxSprintf(prompt, str, what);
+    wxString prompt = wxString::Format(_("Save %s file"), what);
+
+    if (*ext == wxT('.'))
+        ext++;
 
-    if (*ext == wxT('.')) ext++;
-    wxChar wild[60];
-    wxSprintf(wild, wxT("*.%s"), ext);
+    wxString wild = wxString::Format(_T("*.%s"), ext);
 
-    return wxFileSelector (prompt, (const wxChar *) NULL, default_name, ext, wild, 0, parent);
+    return wxFileSelector(prompt, (const wxChar *) NULL, default_name,
+                          ext, wild, 0, parent);
 }
 
index 0f9fd4887a033d5a553d0137ce99ec732393e1d9..946ae917c47082900542b2fe9a860f3aa41344f4 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        filedlg.cpp
+// Name:        gtk/filedlg.cpp
 // Purpose:
 // Author:      Robert Roebling
 // Id:          $Id$
@@ -83,6 +83,18 @@ void gtk_filedialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFileDialog *dial
         }
     }
 
+    // change to the directory where the user went if asked
+    if ( style & wxCHANGE_DIR )
+    {
+        wxString cwd;
+        wxSplitPath(filename, &cwd, NULL, NULL);
+
+        if ( cwd != wxGetWorkingDirectory() )
+        {
+            wxSetWorkingDirectory(cwd);
+        }
+    }
+
     dialog->SetPath( filename );
 
     wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
@@ -121,9 +133,9 @@ wxFileDialog::wxFileDialog( wxWindow *parent, const wxString& message,
         !CreateBase( parent, -1, pos, wxDefaultSize, style | wxDIALOG_MODAL, wxDefaultValidator, wxT("filedialog") ))
     {
         wxFAIL_MSG( wxT("wxXX creation failed") );
-       return;
+        return;
     }
-    
+
     m_message = message;
     m_path = wxT("");
     m_fileName = defaultFileName;
@@ -156,10 +168,10 @@ wxFileDialog::wxFileDialog( wxWindow *parent, const wxString& message,
 
     gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked",
       GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback), (gpointer*)this );
-      
+
     // strange way to internationalize
     gtk_label_set( GTK_LABEL( GTK_BUTTON(sel->cancel_button)->child ), wxConvCurrent->cWX2MB(_("Cancel")) );
-    
+
     gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
         GTK_SIGNAL_FUNC(gtk_filedialog_delete_callback), (gpointer)this );
 }
@@ -172,11 +184,11 @@ void wxFileDialog::SetPath(const wxString& path)
     {
         wxString ext;
         wxSplitPath(path, &m_dir, &m_fileName, &ext);
-       if (!ext.IsEmpty())
-       {
-           m_fileName += wxT(".");
+        if (!ext.IsEmpty())
+        {
+            m_fileName += wxT(".");
             m_fileName += ext;
-       }
+        }
     }
 }
 
@@ -234,15 +246,15 @@ wxString wxLoadFileSelector( const wxChar *what, const wxChar *extension, const
 {
     wxChar *ext = (wxChar *)extension;
 
-    wxChar prompt[50];
-    wxString str = _("Load %s file");
-    wxSprintf(prompt, str, what);
+    wxString prompt = wxString::Format(_("Load %s file"), what);
+
+    if (*ext == wxT('.'))
+        ext++;
 
-    if (*ext == wxT('.')) ext++;
-    wxChar wild[60];
-    wxSprintf(wild, wxT("*.%s"), ext);
+    wxString wild = wxString::Format(_T("*.%s"), ext);
 
-    return wxFileSelector (prompt, (const wxChar *) NULL, default_name, ext, wild, 0, parent);
+    return wxFileSelector(prompt, (const wxChar *) NULL, default_name,
+                          ext, wild, 0, parent);
 }
 
 wxString wxSaveFileSelector(const wxChar *what, const wxChar *extension, const wxChar *default_name,
@@ -250,14 +262,14 @@ wxString wxSaveFileSelector(const wxChar *what, const wxChar *extension, const w
 {
     wxChar *ext = (wxChar *)extension;
 
-    wxChar prompt[50];
-    wxString str = _("Save %s file");
-    wxSprintf(prompt, str, what);
+    wxString prompt = wxString::Format(_("Save %s file"), what);
+
+    if (*ext == wxT('.'))
+        ext++;
 
-    if (*ext == wxT('.')) ext++;
-    wxChar wild[60];
-    wxSprintf(wild, wxT("*.%s"), ext);
+    wxString wild = wxString::Format(_T("*.%s"), ext);
 
-    return wxFileSelector (prompt, (const wxChar *) NULL, default_name, ext, wild, 0, parent);
+    return wxFileSelector(prompt, (const wxChar *) NULL, default_name,
+                          ext, wild, 0, parent);
 }
 
index b64a9f842c9db3e38b5ef0ee402fe65e8cc0e9b3..cc4ffb6e5ea32fac2c7aee586aeddebf098b3d15 100644 (file)
@@ -246,6 +246,8 @@ int wxFileDialog::ShowModal()
         OFN_EXPLORER |
 #endif // OFN_EXPLORER
         OFN_ALLOWMULTISELECT;
+    if ( !(m_dialogStyle & wxCHANGE_DIR) )
+        msw_flags |= OFN_NOCHANGEDIR;
 
     OPENFILENAME of;
     wxZeroMemory(of);
@@ -329,8 +331,8 @@ int wxFileDialog::ShowModal()
 
     //== Execute FileDialog >>=================================================
 
-    bool success = (m_dialogStyle & wxSAVE) ? (GetSaveFileName(&of) != 0)
-                                            : (GetOpenFileName(&of) != 0);
+    bool success = (m_dialogStyle & wxSAVE ? GetSaveFileName(&of)
+                                           : GetOpenFileName(&of)) != 0;
 
     DWORD errCode = CommDlgExtendedError();