From 3f6638b82b01d7691b321dbcfb08765d559e4c59 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 8 Oct 2000 23:35:09 +0000 Subject: [PATCH] wxFileDialog changed to use (new) wxCHANGE_DIR flag, docs updated git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8494 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/filedlg.tex | 13 +++++++-- include/wx/filedlg.h | 13 +++++---- src/generic/filedlgg.cpp | 42 +++++++++++++++++----------- src/gtk/filedlg.cpp | 58 +++++++++++++++++++++++---------------- src/gtk1/filedlg.cpp | 58 +++++++++++++++++++++++---------------- src/msw/filedlg.cpp | 6 ++-- 6 files changed, 118 insertions(+), 72 deletions(-) diff --git a/docs/latex/wx/filedlg.tex b/docs/latex/wx/filedlg.tex index 23b6835bf8..6aa8bc22cd 100644 --- a/docs/latex/wx/filedlg.tex +++ b/docs/latex/wx/filedlg.tex @@ -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} diff --git a/include/wx/filedlg.h b/include/wx/filedlg.h index b35e63d016..9fb43982bc 100644 --- a/include/wx/filedlg.h +++ b/include/wx/filedlg.h @@ -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__) diff --git a/src/generic/filedlgg.cpp b/src/generic/filedlgg.cpp index bc72174e98..24ed3ae470 100644 --- a/src/generic/filedlgg.cpp +++ b/src/generic/filedlgg.cpp @@ -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); } diff --git a/src/gtk/filedlg.cpp b/src/gtk/filedlg.cpp index 0f9fd4887a..946ae917c4 100644 --- a/src/gtk/filedlg.cpp +++ b/src/gtk/filedlg.cpp @@ -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); } diff --git a/src/gtk1/filedlg.cpp b/src/gtk1/filedlg.cpp index 0f9fd4887a..946ae917c4 100644 --- a/src/gtk1/filedlg.cpp +++ b/src/gtk1/filedlg.cpp @@ -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); } diff --git a/src/msw/filedlg.cpp b/src/msw/filedlg.cpp index b64a9f842c..cc4ffb6e5e 100644 --- a/src/msw/filedlg.cpp +++ b/src/msw/filedlg.cpp @@ -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(); -- 2.45.2