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
This commit is contained in:
@@ -67,13 +67,22 @@ Constructor. Use \helpref{wxFileDialog::ShowModal}{wxfiledialogshowmodal} to sho
|
|||||||
\twocolitem{{\bf wxOPEN}}{This is an open dialog.}
|
\twocolitem{{\bf wxOPEN}}{This is an open dialog.}
|
||||||
\twocolitem{{\bf wxSAVE}}{This is a save dialog.}
|
\twocolitem{{\bf wxSAVE}}{This is a save dialog.}
|
||||||
\twocolitem{{\bf wxHIDE\_READONLY}}{Hide read-only files.}
|
\twocolitem{{\bf wxHIDE\_READONLY}}{Hide read-only files.}
|
||||||
\twocolitem{{\bf wxOVERWRITE\_PROMPT}}{Prompt for a conformation if a file will be overridden.}
|
\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 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}%
|
\end{twocollist}%
|
||||||
}
|
}
|
||||||
|
|
||||||
\docparam{pos}{Dialog position. Not implemented.}
|
\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}}
|
\membersection{wxFileDialog::\destruct{wxFileDialog}}
|
||||||
|
|
||||||
\func{}{\destruct{wxFileDialog}}{\void}
|
\func{}{\destruct{wxFileDialog}}{\void}
|
||||||
|
@@ -3,12 +3,13 @@
|
|||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
wxOPEN = 1,
|
wxOPEN = 0x0001,
|
||||||
wxSAVE = 2,
|
wxSAVE = 0x0002,
|
||||||
wxOVERWRITE_PROMPT = 4,
|
wxOVERWRITE_PROMPT = 0x0004,
|
||||||
wxHIDE_READONLY = 8,
|
wxHIDE_READONLY = 0x0008,
|
||||||
wxFILE_MUST_EXIST = 16,
|
wxFILE_MUST_EXIST = 0x0010,
|
||||||
wxMULTIPLE = 32
|
wxMULTIPLE = 0x0020,
|
||||||
|
wxCHANGE_DIR = 0x0040
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(__WXMSW__)
|
#if defined(__WXMSW__)
|
||||||
|
@@ -1097,6 +1097,18 @@ void wxFileDialog::HandleAction( const wxString &fn )
|
|||||||
|
|
||||||
SetPath( filename );
|
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;
|
wxCommandEvent event;
|
||||||
wxDialog::OnOK(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];
|
if (*ext == wxT('.'))
|
||||||
wxString str = _("Load %s file");
|
ext++;
|
||||||
wxSprintf(prompt, str, what);
|
|
||||||
|
|
||||||
if (*ext == wxT('.')) ext++;
|
wxString wild = wxString::Format(_T("*.%s"), ext);
|
||||||
wxChar wild[60];
|
|
||||||
wxSprintf(wild, wxT("*.%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,
|
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 *ext = (wxChar *)extension;
|
||||||
|
|
||||||
wxChar prompt[50];
|
wxString prompt = wxString::Format(_("Save %s file"), what);
|
||||||
wxString str = _("Save %s file");
|
|
||||||
wxSprintf(prompt, str, what);
|
|
||||||
|
|
||||||
if (*ext == wxT('.')) ext++;
|
if (*ext == wxT('.'))
|
||||||
wxChar wild[60];
|
ext++;
|
||||||
wxSprintf(wild, wxT("*.%s"), ext);
|
|
||||||
|
|
||||||
return wxFileSelector (prompt, (const wxChar *) NULL, default_name, ext, wild, 0, parent);
|
wxString wild = wxString::Format(_T("*.%s"), ext);
|
||||||
|
|
||||||
|
return wxFileSelector(prompt, (const wxChar *) NULL, default_name,
|
||||||
|
ext, wild, 0, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: filedlg.cpp
|
// Name: gtk/filedlg.cpp
|
||||||
// Purpose:
|
// Purpose:
|
||||||
// Author: Robert Roebling
|
// Author: Robert Roebling
|
||||||
// Id: $Id$
|
// 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 );
|
dialog->SetPath( filename );
|
||||||
|
|
||||||
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
|
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") ))
|
!CreateBase( parent, -1, pos, wxDefaultSize, style | wxDIALOG_MODAL, wxDefaultValidator, wxT("filedialog") ))
|
||||||
{
|
{
|
||||||
wxFAIL_MSG( wxT("wxXX creation failed") );
|
wxFAIL_MSG( wxT("wxXX creation failed") );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_message = message;
|
m_message = message;
|
||||||
m_path = wxT("");
|
m_path = wxT("");
|
||||||
m_fileName = defaultFileName;
|
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_connect( GTK_OBJECT(sel->cancel_button), "clicked",
|
||||||
GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback), (gpointer*)this );
|
GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback), (gpointer*)this );
|
||||||
|
|
||||||
// strange way to internationalize
|
// strange way to internationalize
|
||||||
gtk_label_set( GTK_LABEL( GTK_BUTTON(sel->cancel_button)->child ), wxConvCurrent->cWX2MB(_("Cancel")) );
|
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_connect( GTK_OBJECT(m_widget), "delete_event",
|
||||||
GTK_SIGNAL_FUNC(gtk_filedialog_delete_callback), (gpointer)this );
|
GTK_SIGNAL_FUNC(gtk_filedialog_delete_callback), (gpointer)this );
|
||||||
}
|
}
|
||||||
@@ -172,11 +184,11 @@ void wxFileDialog::SetPath(const wxString& path)
|
|||||||
{
|
{
|
||||||
wxString ext;
|
wxString ext;
|
||||||
wxSplitPath(path, &m_dir, &m_fileName, &ext);
|
wxSplitPath(path, &m_dir, &m_fileName, &ext);
|
||||||
if (!ext.IsEmpty())
|
if (!ext.IsEmpty())
|
||||||
{
|
{
|
||||||
m_fileName += wxT(".");
|
m_fileName += wxT(".");
|
||||||
m_fileName += ext;
|
m_fileName += ext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,15 +246,15 @@ wxString wxLoadFileSelector( const wxChar *what, const wxChar *extension, const
|
|||||||
{
|
{
|
||||||
wxChar *ext = (wxChar *)extension;
|
wxChar *ext = (wxChar *)extension;
|
||||||
|
|
||||||
wxChar prompt[50];
|
wxString prompt = wxString::Format(_("Load %s file"), what);
|
||||||
wxString str = _("Load %s file");
|
|
||||||
wxSprintf(prompt, str, what);
|
|
||||||
|
|
||||||
if (*ext == wxT('.')) ext++;
|
if (*ext == wxT('.'))
|
||||||
wxChar wild[60];
|
ext++;
|
||||||
wxSprintf(wild, wxT("*.%s"), ext);
|
|
||||||
|
|
||||||
return wxFileSelector (prompt, (const wxChar *) NULL, default_name, ext, wild, 0, parent);
|
wxString wild = wxString::Format(_T("*.%s"), ext);
|
||||||
|
|
||||||
|
return wxFileSelector(prompt, (const wxChar *) NULL, default_name,
|
||||||
|
ext, wild, 0, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxSaveFileSelector(const wxChar *what, const wxChar *extension, const wxChar *default_name,
|
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 *ext = (wxChar *)extension;
|
||||||
|
|
||||||
wxChar prompt[50];
|
wxString prompt = wxString::Format(_("Save %s file"), what);
|
||||||
wxString str = _("Save %s file");
|
|
||||||
wxSprintf(prompt, str, what);
|
|
||||||
|
|
||||||
if (*ext == wxT('.')) ext++;
|
if (*ext == wxT('.'))
|
||||||
wxChar wild[60];
|
ext++;
|
||||||
wxSprintf(wild, wxT("*.%s"), ext);
|
|
||||||
|
|
||||||
return wxFileSelector (prompt, (const wxChar *) NULL, default_name, ext, wild, 0, parent);
|
wxString wild = wxString::Format(_T("*.%s"), ext);
|
||||||
|
|
||||||
|
return wxFileSelector(prompt, (const wxChar *) NULL, default_name,
|
||||||
|
ext, wild, 0, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: filedlg.cpp
|
// Name: gtk/filedlg.cpp
|
||||||
// Purpose:
|
// Purpose:
|
||||||
// Author: Robert Roebling
|
// Author: Robert Roebling
|
||||||
// Id: $Id$
|
// 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 );
|
dialog->SetPath( filename );
|
||||||
|
|
||||||
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
|
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") ))
|
!CreateBase( parent, -1, pos, wxDefaultSize, style | wxDIALOG_MODAL, wxDefaultValidator, wxT("filedialog") ))
|
||||||
{
|
{
|
||||||
wxFAIL_MSG( wxT("wxXX creation failed") );
|
wxFAIL_MSG( wxT("wxXX creation failed") );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_message = message;
|
m_message = message;
|
||||||
m_path = wxT("");
|
m_path = wxT("");
|
||||||
m_fileName = defaultFileName;
|
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_connect( GTK_OBJECT(sel->cancel_button), "clicked",
|
||||||
GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback), (gpointer*)this );
|
GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback), (gpointer*)this );
|
||||||
|
|
||||||
// strange way to internationalize
|
// strange way to internationalize
|
||||||
gtk_label_set( GTK_LABEL( GTK_BUTTON(sel->cancel_button)->child ), wxConvCurrent->cWX2MB(_("Cancel")) );
|
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_connect( GTK_OBJECT(m_widget), "delete_event",
|
||||||
GTK_SIGNAL_FUNC(gtk_filedialog_delete_callback), (gpointer)this );
|
GTK_SIGNAL_FUNC(gtk_filedialog_delete_callback), (gpointer)this );
|
||||||
}
|
}
|
||||||
@@ -172,11 +184,11 @@ void wxFileDialog::SetPath(const wxString& path)
|
|||||||
{
|
{
|
||||||
wxString ext;
|
wxString ext;
|
||||||
wxSplitPath(path, &m_dir, &m_fileName, &ext);
|
wxSplitPath(path, &m_dir, &m_fileName, &ext);
|
||||||
if (!ext.IsEmpty())
|
if (!ext.IsEmpty())
|
||||||
{
|
{
|
||||||
m_fileName += wxT(".");
|
m_fileName += wxT(".");
|
||||||
m_fileName += ext;
|
m_fileName += ext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,15 +246,15 @@ wxString wxLoadFileSelector( const wxChar *what, const wxChar *extension, const
|
|||||||
{
|
{
|
||||||
wxChar *ext = (wxChar *)extension;
|
wxChar *ext = (wxChar *)extension;
|
||||||
|
|
||||||
wxChar prompt[50];
|
wxString prompt = wxString::Format(_("Load %s file"), what);
|
||||||
wxString str = _("Load %s file");
|
|
||||||
wxSprintf(prompt, str, what);
|
|
||||||
|
|
||||||
if (*ext == wxT('.')) ext++;
|
if (*ext == wxT('.'))
|
||||||
wxChar wild[60];
|
ext++;
|
||||||
wxSprintf(wild, wxT("*.%s"), ext);
|
|
||||||
|
|
||||||
return wxFileSelector (prompt, (const wxChar *) NULL, default_name, ext, wild, 0, parent);
|
wxString wild = wxString::Format(_T("*.%s"), ext);
|
||||||
|
|
||||||
|
return wxFileSelector(prompt, (const wxChar *) NULL, default_name,
|
||||||
|
ext, wild, 0, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxSaveFileSelector(const wxChar *what, const wxChar *extension, const wxChar *default_name,
|
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 *ext = (wxChar *)extension;
|
||||||
|
|
||||||
wxChar prompt[50];
|
wxString prompt = wxString::Format(_("Save %s file"), what);
|
||||||
wxString str = _("Save %s file");
|
|
||||||
wxSprintf(prompt, str, what);
|
|
||||||
|
|
||||||
if (*ext == wxT('.')) ext++;
|
if (*ext == wxT('.'))
|
||||||
wxChar wild[60];
|
ext++;
|
||||||
wxSprintf(wild, wxT("*.%s"), ext);
|
|
||||||
|
|
||||||
return wxFileSelector (prompt, (const wxChar *) NULL, default_name, ext, wild, 0, parent);
|
wxString wild = wxString::Format(_T("*.%s"), ext);
|
||||||
|
|
||||||
|
return wxFileSelector(prompt, (const wxChar *) NULL, default_name,
|
||||||
|
ext, wild, 0, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -246,6 +246,8 @@ int wxFileDialog::ShowModal()
|
|||||||
OFN_EXPLORER |
|
OFN_EXPLORER |
|
||||||
#endif // OFN_EXPLORER
|
#endif // OFN_EXPLORER
|
||||||
OFN_ALLOWMULTISELECT;
|
OFN_ALLOWMULTISELECT;
|
||||||
|
if ( !(m_dialogStyle & wxCHANGE_DIR) )
|
||||||
|
msw_flags |= OFN_NOCHANGEDIR;
|
||||||
|
|
||||||
OPENFILENAME of;
|
OPENFILENAME of;
|
||||||
wxZeroMemory(of);
|
wxZeroMemory(of);
|
||||||
@@ -329,8 +331,8 @@ int wxFileDialog::ShowModal()
|
|||||||
|
|
||||||
//== Execute FileDialog >>=================================================
|
//== Execute FileDialog >>=================================================
|
||||||
|
|
||||||
bool success = (m_dialogStyle & wxSAVE) ? (GetSaveFileName(&of) != 0)
|
bool success = (m_dialogStyle & wxSAVE ? GetSaveFileName(&of)
|
||||||
: (GetOpenFileName(&of) != 0);
|
: GetOpenFileName(&of)) != 0;
|
||||||
|
|
||||||
DWORD errCode = CommDlgExtendedError();
|
DWORD errCode = CommDlgExtendedError();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user