extracted common code into a single wxfileDialogBase class (patch 758901)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22113 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -18,8 +18,10 @@
|
|||||||
#pragma interface "filedlg.h"
|
#pragma interface "filedlg.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "wx/dialog.h"
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
// wxFileDialog data and generic functions
|
// wxFileDialog data
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
enum
|
enum
|
||||||
@@ -36,15 +38,74 @@ enum
|
|||||||
WXDLLEXPORT_DATA(extern const wxChar*) wxFileSelectorPromptStr;
|
WXDLLEXPORT_DATA(extern const wxChar*) wxFileSelectorPromptStr;
|
||||||
WXDLLEXPORT_DATA(extern const wxChar*) wxFileSelectorDefaultWildcardStr;
|
WXDLLEXPORT_DATA(extern const wxChar*) wxFileSelectorDefaultWildcardStr;
|
||||||
|
|
||||||
// Parses the filterStr, returning the number of filters.
|
//----------------------------------------------------------------------------
|
||||||
// Returns 0 if none or if there's a problem, they arrays will contain an equal
|
// wxFileDialogBase
|
||||||
// number of items found before the error.
|
//----------------------------------------------------------------------------
|
||||||
// filterStr is in the form:
|
|
||||||
// "All files (*.*)|*.*|Image Files (*.jpeg *.png)|*.jpg;*.png"
|
class WXDLLEXPORT wxFileDialogBase: public wxDialog
|
||||||
extern int wxParseFileFilter(const wxString& filterStr,
|
{
|
||||||
|
public:
|
||||||
|
wxFileDialogBase () {}
|
||||||
|
|
||||||
|
wxFileDialogBase(wxWindow *parent,
|
||||||
|
const wxString& message = wxFileSelectorPromptStr,
|
||||||
|
const wxString& defaultDir = wxEmptyString,
|
||||||
|
const wxString& defaultFile = wxEmptyString,
|
||||||
|
const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
|
||||||
|
long style = 0,
|
||||||
|
const wxPoint& pos = wxDefaultPosition);
|
||||||
|
|
||||||
|
virtual void SetMessage(const wxString& message) { m_message = message; }
|
||||||
|
virtual void SetPath(const wxString& path) { m_path = path; }
|
||||||
|
virtual void SetDirectory(const wxString& dir) { m_dir = dir; }
|
||||||
|
virtual void SetFilename(const wxString& name) { m_fileName = name; }
|
||||||
|
virtual void SetWildcard(const wxString& wildCard) { m_wildCard = wildCard; }
|
||||||
|
virtual void SetStyle(long style) { m_dialogStyle = style; }
|
||||||
|
virtual void SetFilterIndex(int filterIndex) { m_filterIndex = filterIndex; }
|
||||||
|
|
||||||
|
virtual wxString GetMessage() const { return m_message; }
|
||||||
|
virtual wxString GetPath() const { return m_path; }
|
||||||
|
virtual void GetPaths(wxArrayString& paths) const { paths.Empty(); paths.Add(m_path); }
|
||||||
|
virtual wxString GetDirectory() const { return m_dir; }
|
||||||
|
virtual wxString GetFilename() const { return m_fileName; }
|
||||||
|
virtual void GetFilenames(wxArrayString& files) const { files.Empty(); files.Add(m_fileName); }
|
||||||
|
virtual wxString GetWildcard() const { return m_wildCard; }
|
||||||
|
virtual long GetStyle() const { return m_dialogStyle; }
|
||||||
|
virtual int GetFilterIndex() const { return m_filterIndex; }
|
||||||
|
|
||||||
|
// Utility functions
|
||||||
|
|
||||||
|
// Parses the wildCard, returning the number of filters.
|
||||||
|
// Returns 0 if none or if there's a problem,
|
||||||
|
// The arrays will contain an equal number of items found before the error.
|
||||||
|
// wildCard is in the form:
|
||||||
|
// "All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png"
|
||||||
|
static int ParseWildcard(const wxString& wildCard,
|
||||||
wxArrayString& descriptions,
|
wxArrayString& descriptions,
|
||||||
wxArrayString& filters);
|
wxArrayString& filters);
|
||||||
|
|
||||||
|
// Append first extension to filePath from a ';' separated extensionList
|
||||||
|
// if filePath = "path/foo.bar" just return it as is
|
||||||
|
// if filePath = "foo[.]" and extensionList = "*.jpg;*.png" return "foo.jpg"
|
||||||
|
// if the extension is "*.j?g" (has wildcards) or "jpg" then return filePath
|
||||||
|
static wxString AppendExtension(const wxString &filePath,
|
||||||
|
const wxString &extensionList);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
wxString m_message;
|
||||||
|
long m_dialogStyle;
|
||||||
|
wxWindow *m_parent;
|
||||||
|
wxString m_dir;
|
||||||
|
wxString m_path; // Full path
|
||||||
|
wxString m_fileName;
|
||||||
|
wxString m_wildCard;
|
||||||
|
int m_filterIndex;
|
||||||
|
|
||||||
|
private:
|
||||||
|
DECLARE_DYNAMIC_CLASS(wxFileDialogBase)
|
||||||
|
DECLARE_NO_COPY_CLASS(wxFileDialogBase)
|
||||||
|
};
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
// wxFileDialog convenience functions
|
// wxFileDialog convenience functions
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
@@ -16,7 +16,6 @@
|
|||||||
#pragma interface "filedlgg.h"
|
#pragma interface "filedlgg.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/dialog.h"
|
|
||||||
#include "wx/listctrl.h"
|
#include "wx/listctrl.h"
|
||||||
#include "wx/datetime.h"
|
#include "wx/datetime.h"
|
||||||
|
|
||||||
@@ -43,39 +42,27 @@ class WXDLLEXPORT wxTextCtrl;
|
|||||||
// wxGenericFileDialog
|
// wxGenericFileDialog
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
class WXDLLEXPORT wxGenericFileDialog: public wxDialog
|
class WXDLLEXPORT wxGenericFileDialog: public wxFileDialogBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxGenericFileDialog() { }
|
wxGenericFileDialog() { }
|
||||||
|
|
||||||
wxGenericFileDialog(wxWindow *parent,
|
wxGenericFileDialog(wxWindow *parent,
|
||||||
const wxString& message = wxFileSelectorPromptStr,
|
const wxString& message = wxFileSelectorPromptStr,
|
||||||
const wxString& defaultDir = _T(""),
|
const wxString& defaultDir = wxEmptyString,
|
||||||
const wxString& defaultFile = _T(""),
|
const wxString& defaultFile = wxEmptyString,
|
||||||
const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
|
const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
|
||||||
long style = 0,
|
long style = 0,
|
||||||
const wxPoint& pos = wxDefaultPosition);
|
const wxPoint& pos = wxDefaultPosition);
|
||||||
virtual ~wxGenericFileDialog();
|
virtual ~wxGenericFileDialog();
|
||||||
|
|
||||||
void SetMessage(const wxString& message) { SetTitle(message); }
|
virtual void SetMessage(const wxString& message) { SetTitle(message); }
|
||||||
void SetPath(const wxString& path);
|
virtual void SetPath(const wxString& path);
|
||||||
void SetDirectory(const wxString& dir) { m_dir = dir; }
|
virtual void SetFilterIndex(int filterIndex);
|
||||||
void SetFilename(const wxString& name) { m_fileName = name; }
|
|
||||||
void SetWildcard(const wxString& wildCard) { m_wildCard = wildCard; }
|
|
||||||
void SetStyle(long style) { m_dialogStyle = style; }
|
|
||||||
void SetFilterIndex(int filterIndex);
|
|
||||||
|
|
||||||
wxString GetMessage() const { return m_message; }
|
|
||||||
wxString GetPath() const { return m_path; }
|
|
||||||
wxString GetDirectory() const { return m_dir; }
|
|
||||||
wxString GetFilename() const { return m_fileName; }
|
|
||||||
wxString GetWildcard() const { return m_wildCard; }
|
|
||||||
long GetStyle() const { return m_dialogStyle; }
|
|
||||||
int GetFilterIndex() const { return m_filterIndex; }
|
|
||||||
|
|
||||||
// for multiple file selection
|
// for multiple file selection
|
||||||
void GetPaths(wxArrayString& paths) const;
|
virtual void GetPaths(wxArrayString& paths) const;
|
||||||
void GetFilenames(wxArrayString& files) const;
|
virtual void GetFilenames(wxArrayString& files) const;
|
||||||
|
|
||||||
// implementation only from now on
|
// implementation only from now on
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
@@ -103,13 +90,6 @@ protected:
|
|||||||
// use the filter with the given index
|
// use the filter with the given index
|
||||||
void DoSetFilterIndex(int filterindex);
|
void DoSetFilterIndex(int filterindex);
|
||||||
|
|
||||||
wxString m_message;
|
|
||||||
long m_dialogStyle;
|
|
||||||
wxString m_dir;
|
|
||||||
wxString m_path; // Full path
|
|
||||||
wxString m_fileName;
|
|
||||||
wxString m_wildCard;
|
|
||||||
int m_filterIndex;
|
|
||||||
wxString m_filterExtension;
|
wxString m_filterExtension;
|
||||||
wxChoice *m_choice;
|
wxChoice *m_choice;
|
||||||
wxTextCtrl *m_text;
|
wxTextCtrl *m_text;
|
||||||
|
@@ -15,50 +15,24 @@
|
|||||||
#pragma interface
|
#pragma interface
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/dialog.h"
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
// File selector
|
// wxFileDialog
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
class wxFileDialog: public wxDialog
|
class wxFileDialog: public wxFileDialogBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxFileDialog() { }
|
wxFileDialog() { }
|
||||||
|
|
||||||
wxFileDialog(wxWindow *parent,
|
wxFileDialog(wxWindow *parent,
|
||||||
const wxString& message = wxFileSelectorPromptStr,
|
const wxString& message = wxFileSelectorPromptStr,
|
||||||
const wxString& defaultDir = "",
|
const wxString& defaultDir = wxEmptyString,
|
||||||
const wxString& defaultFile = "",
|
const wxString& defaultFile = wxEmptyString,
|
||||||
const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
|
const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
|
||||||
long style = 0,
|
long style = 0,
|
||||||
const wxPoint& pos = wxDefaultPosition);
|
const wxPoint& pos = wxDefaultPosition);
|
||||||
|
|
||||||
void SetMessage(const wxString& message) { m_message = message; }
|
|
||||||
void SetPath(const wxString& path);
|
|
||||||
void SetDirectory(const wxString& dir) { m_dir = dir; }
|
|
||||||
void SetFilename(const wxString& name) { m_fileName = name; }
|
|
||||||
void SetWildcard(const wxString& wildCard) { m_wildCard = wildCard; }
|
|
||||||
void SetStyle(long style) { m_dialogStyle = style; }
|
|
||||||
void SetFilterIndex(int filterIndex) { m_filterIndex = filterIndex; }
|
|
||||||
|
|
||||||
wxString GetMessage() const { return m_message; }
|
|
||||||
wxString GetPath() const { return m_path; }
|
|
||||||
wxString GetDirectory() const { return m_dir; }
|
|
||||||
wxString GetFilename() const { return m_fileName; }
|
|
||||||
wxString GetWildcard() const { return m_wildCard; }
|
|
||||||
long GetStyle() const { return m_dialogStyle; }
|
|
||||||
int GetFilterIndex() const { return m_filterIndex ; }
|
|
||||||
|
|
||||||
protected:
|
virtual void SetPath(const wxString& path);
|
||||||
wxString m_message;
|
|
||||||
long m_dialogStyle;
|
|
||||||
wxWindow * m_parent;
|
|
||||||
wxString m_dir;
|
|
||||||
wxString m_path; // Full path
|
|
||||||
wxString m_fileName;
|
|
||||||
wxString m_wildCard;
|
|
||||||
int m_filterIndex;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_DYNAMIC_CLASS(wxFileDialog)
|
DECLARE_DYNAMIC_CLASS(wxFileDialog)
|
||||||
|
@@ -15,50 +15,24 @@
|
|||||||
#pragma interface
|
#pragma interface
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/dialog.h"
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
// File selector
|
// wxFileDialog
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
class wxFileDialog: public wxDialog
|
class wxFileDialog: public wxFileDialogBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxFileDialog() { }
|
wxFileDialog() { }
|
||||||
|
|
||||||
wxFileDialog(wxWindow *parent,
|
wxFileDialog(wxWindow *parent,
|
||||||
const wxString& message = wxFileSelectorPromptStr,
|
const wxString& message = wxFileSelectorPromptStr,
|
||||||
const wxString& defaultDir = "",
|
const wxString& defaultDir = wxEmptyString,
|
||||||
const wxString& defaultFile = "",
|
const wxString& defaultFile = wxEmptyString,
|
||||||
const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
|
const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
|
||||||
long style = 0,
|
long style = 0,
|
||||||
const wxPoint& pos = wxDefaultPosition);
|
const wxPoint& pos = wxDefaultPosition);
|
||||||
|
|
||||||
void SetMessage(const wxString& message) { m_message = message; }
|
|
||||||
void SetPath(const wxString& path);
|
|
||||||
void SetDirectory(const wxString& dir) { m_dir = dir; }
|
|
||||||
void SetFilename(const wxString& name) { m_fileName = name; }
|
|
||||||
void SetWildcard(const wxString& wildCard) { m_wildCard = wildCard; }
|
|
||||||
void SetStyle(long style) { m_dialogStyle = style; }
|
|
||||||
void SetFilterIndex(int filterIndex) { m_filterIndex = filterIndex; }
|
|
||||||
|
|
||||||
wxString GetMessage() const { return m_message; }
|
|
||||||
wxString GetPath() const { return m_path; }
|
|
||||||
wxString GetDirectory() const { return m_dir; }
|
|
||||||
wxString GetFilename() const { return m_fileName; }
|
|
||||||
wxString GetWildcard() const { return m_wildCard; }
|
|
||||||
long GetStyle() const { return m_dialogStyle; }
|
|
||||||
int GetFilterIndex() const { return m_filterIndex ; }
|
|
||||||
|
|
||||||
protected:
|
virtual void SetPath(const wxString& path);
|
||||||
wxString m_message;
|
|
||||||
long m_dialogStyle;
|
|
||||||
wxWindow * m_parent;
|
|
||||||
wxString m_dir;
|
|
||||||
wxString m_path; // Full path
|
|
||||||
wxString m_fileName;
|
|
||||||
wxString m_wildCard;
|
|
||||||
int m_filterIndex;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_DYNAMIC_CLASS(wxFileDialog)
|
DECLARE_DYNAMIC_CLASS(wxFileDialog)
|
||||||
|
@@ -16,56 +16,34 @@
|
|||||||
#pragma interface "filedlg.h"
|
#pragma interface "filedlg.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/dialog.h"
|
//-------------------------------------------------------------------------
|
||||||
|
// wxFileDialog
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
/*
|
class WXDLLEXPORT wxFileDialog: public wxFileDialogBase
|
||||||
* File selector
|
|
||||||
*/
|
|
||||||
|
|
||||||
class WXDLLEXPORT wxFileDialog: public wxDialog
|
|
||||||
{
|
{
|
||||||
DECLARE_DYNAMIC_CLASS(wxFileDialog)
|
DECLARE_DYNAMIC_CLASS(wxFileDialog)
|
||||||
protected:
|
protected:
|
||||||
wxString m_message;
|
|
||||||
long m_dialogStyle;
|
|
||||||
wxWindow * m_parent;
|
|
||||||
wxString m_dir;
|
|
||||||
wxString m_path; // Full path
|
|
||||||
wxString m_fileName;
|
|
||||||
wxArrayString m_fileNames;
|
wxArrayString m_fileNames;
|
||||||
wxArrayString m_paths;
|
wxArrayString m_paths;
|
||||||
wxString m_wildCard;
|
|
||||||
int m_filterIndex;
|
|
||||||
public:
|
public:
|
||||||
wxFileDialog(wxWindow *parent, const wxString& message = wxFileSelectorPromptStr,
|
wxFileDialog(wxWindow *parent,
|
||||||
const wxString& defaultDir = wxEmptyString, const wxString& defaultFile = wxEmptyString, const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
|
const wxString& message = wxFileSelectorPromptStr,
|
||||||
long style = 0, const wxPoint& pos = wxDefaultPosition);
|
const wxString& defaultDir = wxEmptyString,
|
||||||
|
const wxString& defaultFile = wxEmptyString,
|
||||||
|
const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
|
||||||
|
long style = 0,
|
||||||
|
const wxPoint& pos = wxDefaultPosition);
|
||||||
|
|
||||||
inline void SetMessage(const wxString& message) { m_message = message; }
|
virtual void GetPaths(wxArrayString& paths) const { paths = m_paths; }
|
||||||
inline void SetPath(const wxString& path) { m_path = path; }
|
|
||||||
inline void SetDirectory(const wxString& dir) { m_dir = dir; }
|
|
||||||
inline void SetFilename(const wxString& name) { m_fileName = name; }
|
|
||||||
inline void SetWildcard(const wxString& wildCard) { m_wildCard = wildCard; }
|
|
||||||
inline void SetStyle(long style) { m_dialogStyle = style; }
|
|
||||||
inline void SetFilterIndex(int filterIndex) { m_filterIndex = filterIndex; }
|
|
||||||
|
|
||||||
inline wxString GetMessage() const { return m_message; }
|
virtual int ShowModal();
|
||||||
inline wxString GetPath() const { return m_path; }
|
|
||||||
inline wxString GetDirectory() const { return m_dir; }
|
|
||||||
inline wxString GetFilename() const { return m_fileName; }
|
|
||||||
void GetPaths(wxArrayString& paths) const { paths = m_paths; }
|
|
||||||
void GetFilenames(wxArrayString& files) const { files = m_fileNames; }
|
|
||||||
inline wxString GetWildcard() const { return m_wildCard; }
|
|
||||||
inline long GetStyle() const { return m_dialogStyle; }
|
|
||||||
inline int GetFilterIndex() const { return m_filterIndex ; }
|
|
||||||
|
|
||||||
int ShowModal();
|
|
||||||
|
|
||||||
// not supported for file dialog, RR
|
// not supported for file dialog, RR
|
||||||
virtual void DoSetSize(int WXUNUSED(x), int WXUNUSED(y),
|
virtual void DoSetSize(int WXUNUSED(x), int WXUNUSED(y),
|
||||||
int WXUNUSED(width), int WXUNUSED(height),
|
int WXUNUSED(width), int WXUNUSED(height),
|
||||||
int WXUNUSED(sizeFlags) = wxSIZE_AUTO) {}
|
int WXUNUSED(sizeFlags) = wxSIZE_AUTO) {}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _WX_FILEDLG_H_
|
#endif // _WX_FILEDLG_H_
|
||||||
|
@@ -16,55 +16,29 @@
|
|||||||
#pragma interface "filedlg.h"
|
#pragma interface "filedlg.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/dialog.h"
|
//-------------------------------------------------------------------------
|
||||||
|
// wxFileDialog
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
/*
|
class WXDLLEXPORT wxFileDialog: public wxFileDialogBase
|
||||||
* File selector
|
|
||||||
*/
|
|
||||||
|
|
||||||
class WXDLLEXPORT wxFileDialog: public wxDialog
|
|
||||||
{
|
{
|
||||||
DECLARE_DYNAMIC_CLASS(wxFileDialog)
|
DECLARE_DYNAMIC_CLASS(wxFileDialog)
|
||||||
public:
|
public:
|
||||||
wxString m_message;
|
|
||||||
long m_dialogStyle;
|
|
||||||
wxWindow * m_parent;
|
|
||||||
wxString m_dir;
|
|
||||||
wxString m_path; // Full path
|
|
||||||
wxString m_fileName;
|
|
||||||
wxString m_wildCard;
|
|
||||||
int m_filterIndex;
|
|
||||||
|
|
||||||
// For Motif
|
// For Motif
|
||||||
wxPoint m_pos;
|
|
||||||
static wxString m_fileSelectorAnswer;
|
static wxString m_fileSelectorAnswer;
|
||||||
static bool m_fileSelectorReturned;
|
static bool m_fileSelectorReturned;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
wxFileDialog(wxWindow *parent, const wxString& message = wxFileSelectorPromptStr,
|
wxFileDialog(wxWindow *parent,
|
||||||
const wxString& defaultDir = "", const wxString& defaultFile = "", const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
|
const wxString& message = wxFileSelectorPromptStr,
|
||||||
long style = 0, const wxPoint& pos = wxDefaultPosition);
|
const wxString& defaultDir = wxEmptyString,
|
||||||
|
const wxString& defaultFile = wxEmptyString,
|
||||||
|
const wxString& wildCard = wxFileSelectorDefaultWildcardStr,
|
||||||
|
long style = 0,
|
||||||
|
const wxPoint& pos = wxDefaultPosition);
|
||||||
|
|
||||||
inline void SetMessage(const wxString& message) { m_message = message; }
|
virtual int ShowModal();
|
||||||
inline void SetPath(const wxString& path) { m_path = path; }
|
|
||||||
inline void SetDirectory(const wxString& dir) { m_dir = dir; }
|
|
||||||
inline void SetFilename(const wxString& name) { m_fileName = name; }
|
|
||||||
inline void SetWildcard(const wxString& wildCard) { m_wildCard = wildCard; }
|
|
||||||
inline void SetStyle(long style) { m_dialogStyle = style; }
|
|
||||||
inline void SetFilterIndex(int filterIndex) { m_filterIndex = filterIndex; }
|
|
||||||
|
|
||||||
inline wxString GetMessage() const { return m_message; }
|
|
||||||
inline wxString GetPath() const { return m_path; }
|
|
||||||
inline void GetPaths(wxArrayString& a) { a.Empty(); a.Add(m_path); }
|
|
||||||
inline wxString GetDirectory() const { return m_dir; }
|
|
||||||
inline wxString GetFilename() const { return m_fileName; }
|
|
||||||
inline void GetFilenames(wxArrayString& a) { a.Empty();
|
|
||||||
a.Add( m_fileName); }
|
|
||||||
inline wxString GetWildcard() const { return m_wildCard; }
|
|
||||||
inline long GetStyle() const { return m_dialogStyle; }
|
|
||||||
inline int GetFilterIndex() const { return m_filterIndex ; }
|
|
||||||
|
|
||||||
int ShowModal();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _WX_FILEDLG_H_
|
#endif // _WX_FILEDLG_H_
|
||||||
|
@@ -16,13 +16,11 @@
|
|||||||
#pragma interface "filedlg.h"
|
#pragma interface "filedlg.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/dialog.h"
|
//-------------------------------------------------------------------------
|
||||||
|
// wxFileDialog
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
/*
|
class WXDLLEXPORT wxFileDialog: public wxFileDialogBase
|
||||||
* File selector
|
|
||||||
*/
|
|
||||||
|
|
||||||
class WXDLLEXPORT wxFileDialog: public wxDialog
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxFileDialog(wxWindow *parent,
|
wxFileDialog(wxWindow *parent,
|
||||||
@@ -33,38 +31,14 @@ public:
|
|||||||
long style = 0,
|
long style = 0,
|
||||||
const wxPoint& pos = wxDefaultPosition);
|
const wxPoint& pos = wxDefaultPosition);
|
||||||
|
|
||||||
void SetMessage(const wxString& message) { m_message = message; }
|
virtual void SetPath(const wxString& path);
|
||||||
void SetPath(const wxString& path);
|
virtual void GetPaths(wxArrayString& paths) const;
|
||||||
void SetDirectory(const wxString& dir) { m_dir = dir; }
|
|
||||||
void SetFilename(const wxString& name) { m_fileName = name; }
|
|
||||||
void SetWildcard(const wxString& wildCard) { m_wildCard = wildCard; }
|
|
||||||
void SetStyle(long style) { m_dialogStyle = style; }
|
|
||||||
void SetFilterIndex(int filterIndex) { m_filterIndex = filterIndex; }
|
|
||||||
|
|
||||||
wxString GetMessage() const { return m_message; }
|
|
||||||
wxString GetPath() const { return m_path; }
|
|
||||||
void GetPaths(wxArrayString& paths) const;
|
|
||||||
wxString GetDirectory() const { return m_dir; }
|
|
||||||
wxString GetFilename() const { return m_fileName; }
|
|
||||||
void GetFilenames(wxArrayString& files) const { files = m_fileNames; }
|
|
||||||
wxString GetWildcard() const { return m_wildCard; }
|
|
||||||
long GetStyle() const { return m_dialogStyle; }
|
|
||||||
int GetFilterIndex() const { return m_filterIndex ; }
|
|
||||||
|
|
||||||
virtual int ShowModal();
|
virtual int ShowModal();
|
||||||
|
|
||||||
protected:
|
|
||||||
wxString m_message;
|
|
||||||
long m_dialogStyle;
|
|
||||||
wxWindow * m_parent;
|
|
||||||
wxString m_dir;
|
|
||||||
wxString m_path; // Full path
|
|
||||||
wxString m_fileName;
|
|
||||||
wxArrayString m_fileNames;
|
|
||||||
wxString m_wildCard;
|
|
||||||
int m_filterIndex;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
wxArrayString m_fileNames;
|
||||||
|
|
||||||
DECLARE_DYNAMIC_CLASS(wxFileDialog)
|
DECLARE_DYNAMIC_CLASS(wxFileDialog)
|
||||||
DECLARE_NO_COPY_CLASS(wxFileDialog)
|
DECLARE_NO_COPY_CLASS(wxFileDialog)
|
||||||
};
|
};
|
||||||
|
@@ -12,56 +12,29 @@
|
|||||||
#ifndef _WX_FILEDLG_H_
|
#ifndef _WX_FILEDLG_H_
|
||||||
#define _WX_FILEDLG_H_
|
#define _WX_FILEDLG_H_
|
||||||
|
|
||||||
#include "wx/dialog.h"
|
//-------------------------------------------------------------------------
|
||||||
|
// wxFileDialog
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
/*
|
class WXDLLEXPORT wxFileDialog: public wxFileDialogBase
|
||||||
* File selector
|
|
||||||
*/
|
|
||||||
|
|
||||||
class WXDLLEXPORT wxFileDialog: public wxDialog
|
|
||||||
{
|
{
|
||||||
DECLARE_DYNAMIC_CLASS(wxFileDialog)
|
DECLARE_DYNAMIC_CLASS(wxFileDialog)
|
||||||
public:
|
public:
|
||||||
wxFileDialog( wxWindow* pParent
|
wxFileDialog( wxWindow* pParent
|
||||||
,const wxString& rsMessage = wxFileSelectorPromptStr
|
,const wxString& rsMessage = wxFileSelectorPromptStr
|
||||||
,const wxString& rsDefaultDir = ""
|
,const wxString& rsDefaultDir = wxEmptyString
|
||||||
,const wxString& rsDefaultFile = ""
|
,const wxString& rsDefaultFile = wxEmptyString
|
||||||
,const wxString& rsWildCard = wxFileSelectorDefaultWildcardStr
|
,const wxString& rsWildCard = wxFileSelectorDefaultWildcardStr
|
||||||
,long lStyle = 0
|
,long lStyle = 0
|
||||||
,const wxPoint& rPos = wxDefaultPosition
|
,const wxPoint& rPos = wxDefaultPosition
|
||||||
);
|
);
|
||||||
|
|
||||||
inline void SetMessage(const wxString& rsMessage) { m_sMessage = rsMessage; }
|
virtual void GetPaths(wxArrayString& rasPath) const;
|
||||||
inline void SetPath(const wxString& rsPath) { m_sPath = rsPath; }
|
|
||||||
inline void SetDirectory(const wxString& rsDir) { m_sDir = rsDir; }
|
|
||||||
inline void SetFilename(const wxString& rsName) { m_sFileName = rsName; }
|
|
||||||
inline void SetWildcard(const wxString& rsWildCard) { m_sWildCard = rsWildCard; }
|
|
||||||
inline void SetStyle(long lStyle) { m_lDialogStyle = lStyle; }
|
|
||||||
inline void SetFilterIndex(int nFilterIndex) { m_nFilterIndex = nFilterIndex; }
|
|
||||||
|
|
||||||
inline wxString GetMessage(void) const { return m_sMessage; }
|
|
||||||
inline wxString GetPath(void) const { return m_sPath; }
|
|
||||||
void GetPaths(wxArrayString& rasPath) const;
|
|
||||||
inline wxString GetDirectory(void) const { return m_sDir; }
|
|
||||||
inline wxString GetFilename(void) const { return m_sFileName; }
|
|
||||||
inline void GetFilenames(wxArrayString& rasFilenames) { rasFilenames = m_asFileNames; }
|
|
||||||
inline wxString GetWildcard(void) const { return m_sWildCard; }
|
|
||||||
inline long GetStyle(void) const { return m_lDialogStyle; }
|
|
||||||
inline int GetFilterIndex() const { return m_nFilterIndex ; }
|
|
||||||
|
|
||||||
int ShowModal();
|
int ShowModal();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxString m_sMessage;
|
wxArrayString m_fileNames;
|
||||||
long m_lDialogStyle;
|
|
||||||
wxWindow* m_pParent;
|
|
||||||
wxString m_sDir;
|
|
||||||
wxString m_sPath; // Full path
|
|
||||||
wxString m_sFileName;
|
|
||||||
wxArrayString m_asFileNames;
|
|
||||||
wxString m_sWildCard;
|
|
||||||
int m_nFilterIndex;
|
|
||||||
wxPoint m_vPos;
|
|
||||||
}; // end of CLASS wxFileDialog
|
}; // end of CLASS wxFileDialog
|
||||||
|
|
||||||
#endif // _WX_FILEDLG_H_
|
#endif // _WX_FILEDLG_H_
|
||||||
|
@@ -30,219 +30,47 @@
|
|||||||
|
|
||||||
#if wxUSE_FILEDLG
|
#if wxUSE_FILEDLG
|
||||||
|
|
||||||
wxString wxFileSelector(const wxChar *title,
|
//----------------------------------------------------------------------------
|
||||||
const wxChar *defaultDir,
|
// wxFileDialogBase
|
||||||
const wxChar *defaultFileName,
|
//----------------------------------------------------------------------------
|
||||||
const wxChar *defaultExtension,
|
|
||||||
const wxChar *filter,
|
IMPLEMENT_DYNAMIC_CLASS(wxFileDialogBase, wxDialog)
|
||||||
int flags,
|
|
||||||
wxWindow *parent,
|
wxFileDialogBase::wxFileDialogBase(wxWindow *parent,
|
||||||
int x, int y)
|
const wxString& message,
|
||||||
|
const wxString& defaultDir,
|
||||||
|
const wxString& defaultFile,
|
||||||
|
const wxString& wildCard,
|
||||||
|
long style,
|
||||||
|
const wxPoint& pos)
|
||||||
{
|
{
|
||||||
// The defaultExtension, if non-NULL, is
|
m_parent = parent;
|
||||||
// appended to the filename if the user fails to type an extension. The new
|
m_message = message;
|
||||||
// implementation (taken from wxFileSelectorEx) appends the extension
|
m_dir = defaultDir;
|
||||||
// automatically, by looking at the filter specification. In fact this
|
m_fileName = defaultFile;
|
||||||
// should be better than the native Microsoft implementation because
|
m_wildCard = wildCard;
|
||||||
// Windows only allows *one* default extension, whereas here we do the
|
m_dialogStyle = style;
|
||||||
// right thing depending on the filter the user has chosen.
|
m_path = wxT("");
|
||||||
|
m_filterIndex = 0;
|
||||||
|
|
||||||
// If there's a default extension specified but no filter, we create a
|
if (m_wildCard.IsEmpty())
|
||||||
// suitable filter.
|
m_wildCard = wxFileSelectorDefaultWildcardStr;
|
||||||
|
|
||||||
wxString filter2;
|
// convert m_wildCard from "*.bar" to "Files (*.bar)|*.bar"
|
||||||
if ( defaultExtension && !filter )
|
if ( m_wildCard.Find(wxT('|')) == wxNOT_FOUND )
|
||||||
filter2 = wxString(wxT("*.")) + defaultExtension;
|
|
||||||
else if ( filter )
|
|
||||||
filter2 = filter;
|
|
||||||
|
|
||||||
wxString defaultDirString;
|
|
||||||
if (defaultDir)
|
|
||||||
defaultDirString = defaultDir;
|
|
||||||
|
|
||||||
wxString defaultFilenameString;
|
|
||||||
if (defaultFileName)
|
|
||||||
defaultFilenameString = defaultFileName;
|
|
||||||
|
|
||||||
wxFileDialog fileDialog(parent, title, defaultDirString,
|
|
||||||
defaultFilenameString, filter2,
|
|
||||||
flags, wxPoint(x, y));
|
|
||||||
if( wxStrlen(defaultExtension) != 0 )
|
|
||||||
{
|
{
|
||||||
int filterFind = 0,
|
m_wildCard.Printf(_("Files (%s)|%s"),
|
||||||
filterIndex = 0;
|
m_wildCard.c_str(), m_wildCard.c_str());
|
||||||
|
|
||||||
for( unsigned int i = 0; i < filter2.Len(); i++ )
|
|
||||||
{
|
|
||||||
if( filter2.GetChar(i) == wxT('|') )
|
|
||||||
{
|
|
||||||
// save the start index of the new filter
|
|
||||||
unsigned int is = i++;
|
|
||||||
|
|
||||||
// find the end of the filter
|
|
||||||
for( ; i < filter2.Len(); i++ )
|
|
||||||
{
|
|
||||||
if(filter2[i] == wxT('|'))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( i-is-1 > 0 && is+1 < filter2.Len() )
|
|
||||||
{
|
|
||||||
if( filter2.Mid(is+1,i-is-1).Contains(defaultExtension) )
|
|
||||||
{
|
|
||||||
filterFind = filterIndex;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
filterIndex++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fileDialog.SetFilterIndex(filterFind);
|
|
||||||
}
|
|
||||||
|
|
||||||
wxString filename;
|
|
||||||
if ( fileDialog.ShowModal() == wxID_OK )
|
|
||||||
{
|
|
||||||
filename = fileDialog.GetPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
return filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
wxString wxFileSelector( const wxChar *title,
|
|
||||||
const wxChar *defaultDir,
|
|
||||||
const wxChar *defaultFileName,
|
|
||||||
const wxChar *defaultExtension,
|
|
||||||
const wxChar *filter,
|
|
||||||
int flags,
|
|
||||||
wxWindow *parent,
|
|
||||||
int x,
|
|
||||||
int y )
|
|
||||||
{
|
|
||||||
wxString filter2;
|
|
||||||
if ( defaultExtension && !filter )
|
|
||||||
filter2 = wxString(wxT("*.")) + wxString(defaultExtension) ;
|
|
||||||
else if ( filter )
|
|
||||||
filter2 = filter;
|
|
||||||
|
|
||||||
wxString defaultDirString;
|
|
||||||
if (defaultDir)
|
|
||||||
defaultDirString = defaultDir;
|
|
||||||
|
|
||||||
wxString defaultFilenameString;
|
|
||||||
if (defaultFileName)
|
|
||||||
defaultFilenameString = defaultFileName;
|
|
||||||
|
|
||||||
wxFileDialog fileDialog( parent, title, defaultDirString, defaultFilenameString, filter2, flags, wxPoint(x, y) );
|
|
||||||
|
|
||||||
if ( fileDialog.ShowModal() == wxID_OK )
|
|
||||||
{
|
|
||||||
return fileDialog.GetPath();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return wxEmptyString;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
wxString wxFileSelectorEx(const wxChar *title,
|
|
||||||
const wxChar *defaultDir,
|
|
||||||
const wxChar *defaultFileName,
|
|
||||||
int* defaultFilterIndex,
|
|
||||||
const wxChar *filter,
|
|
||||||
int flags,
|
|
||||||
wxWindow* parent,
|
|
||||||
int x,
|
|
||||||
int y)
|
|
||||||
|
|
||||||
{
|
|
||||||
wxFileDialog fileDialog(parent,
|
|
||||||
title ? title : wxT(""),
|
|
||||||
defaultDir ? defaultDir : wxT(""),
|
|
||||||
defaultFileName ? defaultFileName : wxT(""),
|
|
||||||
filter ? filter : wxT(""),
|
|
||||||
flags, wxPoint(x, y));
|
|
||||||
|
|
||||||
wxString filename;
|
|
||||||
if ( fileDialog.ShowModal() == wxID_OK )
|
|
||||||
{
|
|
||||||
if ( defaultFilterIndex )
|
|
||||||
*defaultFilterIndex = fileDialog.GetFilterIndex();
|
|
||||||
|
|
||||||
filename = fileDialog.GetPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
return filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Generic file load/save dialog (for internal use only)
|
|
||||||
// see wx[Load/Save]FileSelector
|
|
||||||
static wxString wxDefaultFileSelector(bool load,
|
|
||||||
const wxChar *what,
|
|
||||||
const wxChar *extension,
|
|
||||||
const wxChar *default_name,
|
|
||||||
wxWindow *parent)
|
|
||||||
{
|
|
||||||
wxString prompt;
|
|
||||||
wxString str;
|
|
||||||
if (load)
|
|
||||||
str = _("Load %s file");
|
|
||||||
else
|
|
||||||
str = _("Save %s file");
|
|
||||||
prompt.Printf(str, what);
|
|
||||||
|
|
||||||
wxString wild;
|
|
||||||
const wxChar *ext = extension;
|
|
||||||
if ( ext )
|
|
||||||
{
|
|
||||||
if ( *ext == wxT('.') )
|
|
||||||
ext++;
|
|
||||||
|
|
||||||
wild.Printf(wxT("*.%s"), ext);
|
|
||||||
}
|
|
||||||
else // no extension specified
|
|
||||||
{
|
|
||||||
wild = wxFileSelectorDefaultWildcardStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return wxFileSelector(prompt, NULL, default_name, ext, wild,
|
|
||||||
load ? wxOPEN : wxSAVE, parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generic file load dialog
|
|
||||||
WXDLLEXPORT wxString wxLoadFileSelector(const wxChar *what,
|
|
||||||
const wxChar *extension,
|
|
||||||
const wxChar *default_name,
|
|
||||||
wxWindow *parent)
|
|
||||||
{
|
|
||||||
return wxDefaultFileSelector(TRUE, what, extension, default_name, parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generic file save dialog
|
|
||||||
WXDLLEXPORT wxString wxSaveFileSelector(const wxChar *what,
|
|
||||||
const wxChar *extension,
|
|
||||||
const wxChar *default_name,
|
|
||||||
wxWindow *parent)
|
|
||||||
{
|
|
||||||
return wxDefaultFileSelector(FALSE, what, extension, default_name, parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Parses the filterStr, returning the number of filters.
|
// Parses the filterStr, returning the number of filters.
|
||||||
// Returns 0 if none or if there's a problem.
|
// Returns 0 if none or if there's a problem.
|
||||||
// filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg"
|
// filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg"
|
||||||
|
|
||||||
int wxParseFileFilter(const wxString& filterStr,
|
int wxFileDialogBase::ParseWildcard(const wxString& filterStr,
|
||||||
wxArrayString& descriptions,
|
wxArrayString& descriptions,
|
||||||
wxArrayString& filters)
|
wxArrayString& filters)
|
||||||
{
|
{
|
||||||
descriptions.Clear();
|
descriptions.Clear();
|
||||||
filters.Clear();
|
filters.Clear();
|
||||||
@@ -290,5 +118,205 @@ int wxParseFileFilter(const wxString& filterStr,
|
|||||||
return filters.GetCount();
|
return filters.GetCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxString wxFileDialogBase::AppendExtension(const wxString &filePath,
|
||||||
|
const wxString &extensionList)
|
||||||
|
{
|
||||||
|
// strip off path, to avoid problems with "path.bar/foo"
|
||||||
|
wxString fileName = filePath.AfterLast(wxFILE_SEP_PATH);
|
||||||
|
|
||||||
|
// if fileName is of form "foo.bar" it's ok, return it
|
||||||
|
int idx_dot = fileName.Find(wxT('.'), TRUE);
|
||||||
|
if ((idx_dot != wxNOT_FOUND) && (idx_dot < (int)fileName.Len() - 1))
|
||||||
|
return filePath;
|
||||||
|
|
||||||
|
// get the first extension from extensionList, or all of it
|
||||||
|
wxString ext = extensionList.BeforeFirst(wxT(';'));
|
||||||
|
|
||||||
|
// if ext == "foo" or "foo." there's no extension
|
||||||
|
int idx_ext_dot = ext.Find(wxT('.'), TRUE);
|
||||||
|
if ((idx_ext_dot == wxNOT_FOUND) || (idx_ext_dot == (int)ext.Len() - 1))
|
||||||
|
return filePath;
|
||||||
|
else
|
||||||
|
ext = ext.AfterLast(wxT('.'));
|
||||||
|
|
||||||
|
// if ext == "*" or "bar*" or "b?r" or " " then its not valid
|
||||||
|
if ((ext.Find(wxT('*')) != wxNOT_FOUND) ||
|
||||||
|
(ext.Find(wxT('?')) != wxNOT_FOUND) ||
|
||||||
|
(ext.Strip(wxString::both).IsEmpty()))
|
||||||
|
return filePath;
|
||||||
|
|
||||||
|
// if fileName doesn't have a '.' then add one
|
||||||
|
if (filePath.Last() != wxT('.'))
|
||||||
|
ext = wxT(".") + ext;
|
||||||
|
|
||||||
|
return filePath + ext;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
// wxFileDialog convenience functions
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxString wxFileSelector(const wxChar *title,
|
||||||
|
const wxChar *defaultDir,
|
||||||
|
const wxChar *defaultFileName,
|
||||||
|
const wxChar *defaultExtension,
|
||||||
|
const wxChar *filter,
|
||||||
|
int flags,
|
||||||
|
wxWindow *parent,
|
||||||
|
int x, int y)
|
||||||
|
{
|
||||||
|
// The defaultExtension, if non-NULL, is
|
||||||
|
// appended to the filename if the user fails to type an extension. The new
|
||||||
|
// implementation (taken from wxFileSelectorEx) appends the extension
|
||||||
|
// automatically, by looking at the filter specification. In fact this
|
||||||
|
// should be better than the native Microsoft implementation because
|
||||||
|
// Windows only allows *one* default extension, whereas here we do the
|
||||||
|
// right thing depending on the filter the user has chosen.
|
||||||
|
|
||||||
|
// If there's a default extension specified but no filter, we create a
|
||||||
|
// suitable filter.
|
||||||
|
|
||||||
|
wxString filter2;
|
||||||
|
if ( defaultExtension && !filter )
|
||||||
|
filter2 = wxString(wxT("*.")) + defaultExtension;
|
||||||
|
else if ( filter )
|
||||||
|
filter2 = filter;
|
||||||
|
|
||||||
|
wxString defaultDirString;
|
||||||
|
if (defaultDir)
|
||||||
|
defaultDirString = defaultDir;
|
||||||
|
|
||||||
|
wxString defaultFilenameString;
|
||||||
|
if (defaultFileName)
|
||||||
|
defaultFilenameString = defaultFileName;
|
||||||
|
|
||||||
|
wxFileDialog fileDialog(parent, title, defaultDirString,
|
||||||
|
defaultFilenameString, filter2,
|
||||||
|
flags, wxPoint(x, y));
|
||||||
|
|
||||||
|
// if filter is of form "All files (*)|*|..." set correct filter index
|
||||||
|
if((wxStrlen(defaultExtension) != 0) && (filter2.Find(wxT('|')) != wxNOT_FOUND))
|
||||||
|
{
|
||||||
|
int filterIndex = 0;
|
||||||
|
|
||||||
|
wxArrayString descriptions, filters;
|
||||||
|
// don't care about errors, handled already by wxFileDialog
|
||||||
|
(void)wxFileDialogBase::ParseWildcard(filter2, descriptions, filters);
|
||||||
|
for (size_t n=0; n<filters.GetCount(); n++)
|
||||||
|
{
|
||||||
|
if (filters[n].Contains(defaultExtension))
|
||||||
|
{
|
||||||
|
filterIndex = n;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filterIndex > 0)
|
||||||
|
fileDialog.SetFilterIndex(filterIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString filename;
|
||||||
|
if ( fileDialog.ShowModal() == wxID_OK )
|
||||||
|
{
|
||||||
|
filename = fileDialog.GetPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
// wxFileSelectorEx
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxString wxFileSelectorEx(const wxChar *title,
|
||||||
|
const wxChar *defaultDir,
|
||||||
|
const wxChar *defaultFileName,
|
||||||
|
int* defaultFilterIndex,
|
||||||
|
const wxChar *filter,
|
||||||
|
int flags,
|
||||||
|
wxWindow* parent,
|
||||||
|
int x,
|
||||||
|
int y)
|
||||||
|
|
||||||
|
{
|
||||||
|
wxFileDialog fileDialog(parent,
|
||||||
|
title ? title : wxT(""),
|
||||||
|
defaultDir ? defaultDir : wxT(""),
|
||||||
|
defaultFileName ? defaultFileName : wxT(""),
|
||||||
|
filter ? filter : wxT(""),
|
||||||
|
flags, wxPoint(x, y));
|
||||||
|
|
||||||
|
wxString filename;
|
||||||
|
if ( fileDialog.ShowModal() == wxID_OK )
|
||||||
|
{
|
||||||
|
if ( defaultFilterIndex )
|
||||||
|
*defaultFilterIndex = fileDialog.GetFilterIndex();
|
||||||
|
|
||||||
|
filename = fileDialog.GetPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
// wxDefaultFileSelector - Generic load/save dialog (for internal use only)
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static wxString wxDefaultFileSelector(bool load,
|
||||||
|
const wxChar *what,
|
||||||
|
const wxChar *extension,
|
||||||
|
const wxChar *default_name,
|
||||||
|
wxWindow *parent)
|
||||||
|
{
|
||||||
|
wxString prompt;
|
||||||
|
wxString str;
|
||||||
|
if (load)
|
||||||
|
str = _("Load %s file");
|
||||||
|
else
|
||||||
|
str = _("Save %s file");
|
||||||
|
prompt.Printf(str, what);
|
||||||
|
|
||||||
|
wxString wild;
|
||||||
|
const wxChar *ext = extension;
|
||||||
|
if ( ext )
|
||||||
|
{
|
||||||
|
if ( *ext == wxT('.') )
|
||||||
|
ext++;
|
||||||
|
|
||||||
|
wild.Printf(wxT("*.%s"), ext);
|
||||||
|
}
|
||||||
|
else // no extension specified
|
||||||
|
{
|
||||||
|
wild = wxFileSelectorDefaultWildcardStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return wxFileSelector(prompt, NULL, default_name, ext, wild,
|
||||||
|
load ? wxOPEN : wxSAVE, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
// wxLoadFileSelector
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
WXDLLEXPORT wxString wxLoadFileSelector(const wxChar *what,
|
||||||
|
const wxChar *extension,
|
||||||
|
const wxChar *default_name,
|
||||||
|
wxWindow *parent)
|
||||||
|
{
|
||||||
|
return wxDefaultFileSelector(TRUE, what, extension, default_name, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
// wxSaveFileSelector
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
WXDLLEXPORT wxString wxSaveFileSelector(const wxChar *what,
|
||||||
|
const wxChar *extension,
|
||||||
|
const wxChar *default_name,
|
||||||
|
wxWindow *parent)
|
||||||
|
{
|
||||||
|
return wxDefaultFileSelector(FALSE, what, extension, default_name, parent);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // wxUSE_FILEDLG
|
#endif // wxUSE_FILEDLG
|
||||||
|
|
||||||
|
@@ -47,6 +47,7 @@
|
|||||||
#include "wx/mimetype.h"
|
#include "wx/mimetype.h"
|
||||||
#include "wx/image.h"
|
#include "wx/image.h"
|
||||||
#include "wx/choice.h"
|
#include "wx/choice.h"
|
||||||
|
#include "wx/filedlg.h" // for wxFileDialogBase::ParseWildcard
|
||||||
|
|
||||||
#if wxUSE_STATLINE
|
#if wxUSE_STATLINE
|
||||||
#include "wx/statline.h"
|
#include "wx/statline.h"
|
||||||
@@ -101,9 +102,6 @@ extern bool wxIsDriveAvailable(const wxString& dirName);
|
|||||||
#undef GetFirstChild
|
#undef GetFirstChild
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// declared in filedlg.h, defined in fldlgcmn.cpp
|
|
||||||
extern int wxParseFileFilter(const wxString& filterStr, wxArrayString& descriptions, wxArrayString& filters);
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxGetAvailableDrives, for WINDOWS, DOS, WXPM, MAC, UNIX (returns "/")
|
// wxGetAvailableDrives, for WINDOWS, DOS, WXPM, MAC, UNIX (returns "/")
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -1046,7 +1044,7 @@ bool wxGenericDirCtrl::ExtractWildcard(const wxString& filterStr, int n, wxStrin
|
|||||||
|
|
||||||
int wxGenericDirCtrl::ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions)
|
int wxGenericDirCtrl::ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions)
|
||||||
{
|
{
|
||||||
return wxParseFileFilter(filterStr, descriptions, filters );
|
return wxFileDialogBase::ParseWildcard(filterStr, descriptions, filters );
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGenericDirCtrl::DoResize()
|
void wxGenericDirCtrl::DoResize()
|
||||||
|
@@ -810,7 +810,7 @@ wxFileCtrl::~wxFileCtrl()
|
|||||||
#define ID_ACTIVATED (wxID_FILEDLGG + 11)
|
#define ID_ACTIVATED (wxID_FILEDLGG + 11)
|
||||||
#define ID_CHECK (wxID_FILEDLGG + 12)
|
#define ID_CHECK (wxID_FILEDLGG + 12)
|
||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxGenericFileDialog,wxDialog)
|
IMPLEMENT_DYNAMIC_CLASS(wxGenericFileDialog, wxFileDialogBase)
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(wxGenericFileDialog,wxDialog)
|
BEGIN_EVENT_TABLE(wxGenericFileDialog,wxDialog)
|
||||||
EVT_BUTTON(ID_LIST_MODE, wxGenericFileDialog::OnList)
|
EVT_BUTTON(ID_LIST_MODE, wxGenericFileDialog::OnList)
|
||||||
@@ -837,9 +837,11 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent,
|
|||||||
const wxString& wildCard,
|
const wxString& wildCard,
|
||||||
long style,
|
long style,
|
||||||
const wxPoint& pos )
|
const wxPoint& pos )
|
||||||
: wxDialog( parent, -1, message, pos, wxDefaultSize,
|
:wxFileDialogBase(parent, message, defaultDir, defaultFile, wildCard, style, pos)
|
||||||
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
|
|
||||||
{
|
{
|
||||||
|
wxDialog::Create( parent, -1, message, pos, wxDefaultSize,
|
||||||
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER );
|
||||||
|
|
||||||
if (wxConfig::Get(FALSE))
|
if (wxConfig::Get(FALSE))
|
||||||
{
|
{
|
||||||
wxConfig::Get()->Read(wxT("/wxWindows/wxFileDialog/ViewStyle"),
|
wxConfig::Get()->Read(wxT("/wxWindows/wxFileDialog/ViewStyle"),
|
||||||
@@ -848,15 +850,11 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent,
|
|||||||
&ms_lastShowHidden);
|
&ms_lastShowHidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_message = message;
|
|
||||||
m_dialogStyle = style;
|
|
||||||
|
|
||||||
if (m_dialogStyle == 0)
|
if (m_dialogStyle == 0)
|
||||||
m_dialogStyle = wxOPEN;
|
m_dialogStyle = wxOPEN;
|
||||||
if ((m_dialogStyle & wxMULTIPLE ) && !(m_dialogStyle & wxOPEN))
|
if ((m_dialogStyle & wxMULTIPLE ) && !(m_dialogStyle & wxOPEN))
|
||||||
m_dialogStyle |= wxOPEN;
|
m_dialogStyle |= wxOPEN;
|
||||||
|
|
||||||
m_dir = defaultDir;
|
|
||||||
if ((m_dir.empty()) || (m_dir == wxT(".")))
|
if ((m_dir.empty()) || (m_dir == wxT(".")))
|
||||||
{
|
{
|
||||||
m_dir = wxGetCwd();
|
m_dir = wxGetCwd();
|
||||||
@@ -869,30 +867,13 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent,
|
|||||||
m_path = m_dir;
|
m_path = m_dir;
|
||||||
m_path += wxFILE_SEP_PATH;
|
m_path += wxFILE_SEP_PATH;
|
||||||
m_path += defaultFile;
|
m_path += defaultFile;
|
||||||
m_fileName = defaultFile;
|
|
||||||
m_wildCard = wildCard;
|
|
||||||
m_filterIndex = 0;
|
|
||||||
m_filterExtension = wxEmptyString;
|
m_filterExtension = wxEmptyString;
|
||||||
|
|
||||||
// interpret wildcards
|
// interpret wildcards
|
||||||
|
|
||||||
if (m_wildCard.IsEmpty())
|
|
||||||
m_wildCard = _("All files (*)|*");
|
|
||||||
|
|
||||||
wxArrayString wildDescriptions, wildFilters;
|
wxArrayString wildDescriptions, wildFilters;
|
||||||
int wild_count = wxParseFileFilter(m_wildCard, wildDescriptions, wildFilters);
|
int wild_count = ParseWildcard(m_wildCard, wildDescriptions, wildFilters);
|
||||||
|
|
||||||
wxASSERT_MSG(wild_count > 0, wxT("Wrong file type descripition") );
|
wxASSERT_MSG(wild_count > 0, wxT("Wrong file type descripition") );
|
||||||
|
|
||||||
// if error parsing, add default back
|
|
||||||
if (wildFilters.GetCount() < 1u)
|
|
||||||
{
|
|
||||||
wild_count = 1;
|
|
||||||
m_wildCard = _("All files (*)|*");
|
|
||||||
wildDescriptions.Add(_("All files (*)"));
|
|
||||||
wildFilters.Add(wxT("*"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// layout
|
// layout
|
||||||
|
|
||||||
bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
|
bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
|
||||||
@@ -1212,13 +1193,7 @@ void wxGenericFileDialog::HandleAction( const wxString &fn )
|
|||||||
// file without extension as well?
|
// file without extension as well?
|
||||||
if ( !(m_dialogStyle & wxOPEN) || !wxFileExists(filename) )
|
if ( !(m_dialogStyle & wxOPEN) || !wxFileExists(filename) )
|
||||||
{
|
{
|
||||||
wxString ext;
|
filename = AppendExtension(filename, m_filterExtension);
|
||||||
wxSplitPath(filename, NULL, NULL, &ext);
|
|
||||||
if ( ext.empty() )
|
|
||||||
{
|
|
||||||
// append the first extension of the filter string
|
|
||||||
filename += m_filterExtension.BeforeFirst(_T(';'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check that the file [doesn't] exist if necessary
|
// check that the file [doesn't] exist if necessary
|
||||||
|
@@ -16,7 +16,6 @@
|
|||||||
#include "wx/intl.h"
|
#include "wx/intl.h"
|
||||||
#include "wx/generic/msgdlgg.h"
|
#include "wx/generic/msgdlgg.h"
|
||||||
|
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -120,12 +119,13 @@ void gtk_filedialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFileDialog *dialo
|
|||||||
// wxFileDialog
|
// wxFileDialog
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxDialog)
|
IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxFileDialogBase)
|
||||||
|
|
||||||
wxFileDialog::wxFileDialog( wxWindow *parent, const wxString& message,
|
wxFileDialog::wxFileDialog( wxWindow *parent, const wxString& message,
|
||||||
const wxString& defaultDir, const wxString& defaultFileName,
|
const wxString& defaultDir, const wxString& defaultFileName,
|
||||||
const wxString& wildCard,
|
const wxString& wildCard,
|
||||||
long style, const wxPoint& pos )
|
long style, const wxPoint& pos )
|
||||||
|
:wxFileDialogBase(parent, message, defaultDir, defaultFileName, wildCard, style, pos)
|
||||||
{
|
{
|
||||||
m_needParent = FALSE;
|
m_needParent = FALSE;
|
||||||
|
|
||||||
@@ -136,14 +136,6 @@ wxFileDialog::wxFileDialog( wxWindow *parent, const wxString& message,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_message = message;
|
|
||||||
m_path = wxT("");
|
|
||||||
m_fileName = defaultFileName;
|
|
||||||
m_dir = defaultDir;
|
|
||||||
m_wildCard = wildCard;
|
|
||||||
m_dialogStyle = style;
|
|
||||||
m_filterIndex = 1;
|
|
||||||
|
|
||||||
m_widget = gtk_file_selection_new( m_message.mbc_str() );
|
m_widget = gtk_file_selection_new( m_message.mbc_str() );
|
||||||
|
|
||||||
int x = (gdk_screen_width () - 400) / 2;
|
int x = (gdk_screen_width () - 400) / 2;
|
||||||
|
@@ -16,7 +16,6 @@
|
|||||||
#include "wx/intl.h"
|
#include "wx/intl.h"
|
||||||
#include "wx/generic/msgdlgg.h"
|
#include "wx/generic/msgdlgg.h"
|
||||||
|
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -120,12 +119,13 @@ void gtk_filedialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFileDialog *dialo
|
|||||||
// wxFileDialog
|
// wxFileDialog
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxDialog)
|
IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxFileDialogBase)
|
||||||
|
|
||||||
wxFileDialog::wxFileDialog( wxWindow *parent, const wxString& message,
|
wxFileDialog::wxFileDialog( wxWindow *parent, const wxString& message,
|
||||||
const wxString& defaultDir, const wxString& defaultFileName,
|
const wxString& defaultDir, const wxString& defaultFileName,
|
||||||
const wxString& wildCard,
|
const wxString& wildCard,
|
||||||
long style, const wxPoint& pos )
|
long style, const wxPoint& pos )
|
||||||
|
:wxFileDialogBase(parent, message, defaultDir, defaultFileName, wildCard, style, pos)
|
||||||
{
|
{
|
||||||
m_needParent = FALSE;
|
m_needParent = FALSE;
|
||||||
|
|
||||||
@@ -136,14 +136,6 @@ wxFileDialog::wxFileDialog( wxWindow *parent, const wxString& message,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_message = message;
|
|
||||||
m_path = wxT("");
|
|
||||||
m_fileName = defaultFileName;
|
|
||||||
m_dir = defaultDir;
|
|
||||||
m_wildCard = wildCard;
|
|
||||||
m_dialogStyle = style;
|
|
||||||
m_filterIndex = 1;
|
|
||||||
|
|
||||||
m_widget = gtk_file_selection_new( m_message.mbc_str() );
|
m_widget = gtk_file_selection_new( m_message.mbc_str() );
|
||||||
|
|
||||||
int x = (gdk_screen_width () - 400) / 2;
|
int x = (gdk_screen_width () - 400) / 2;
|
||||||
|
@@ -26,7 +26,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !USE_SHARED_LIBRARY
|
#if !USE_SHARED_LIBRARY
|
||||||
IMPLEMENT_CLASS(wxFileDialog, wxDialog)
|
IMPLEMENT_CLASS(wxFileDialog, wxFileDialogBase)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// begin wxmac
|
// begin wxmac
|
||||||
@@ -277,16 +277,9 @@ static pascal Boolean CrossPlatformFileFilter(CInfoPBPtr myCInfoPBPtr, void *dat
|
|||||||
wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
|
wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
|
||||||
const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard,
|
const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard,
|
||||||
long style, const wxPoint& pos)
|
long style, const wxPoint& pos)
|
||||||
|
:wxFileDialogBase(parent, message, defaultDir, defaultFileName, wildCard, style, pos)
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
|
wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
|
||||||
m_message = message;
|
|
||||||
m_dialogStyle = style;
|
|
||||||
m_parent = parent;
|
|
||||||
m_path = wxT("");
|
|
||||||
m_fileName = defaultFileName;
|
|
||||||
m_dir = defaultDir;
|
|
||||||
m_wildCard = wildCard;
|
|
||||||
m_filterIndex = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pascal Boolean CrossPlatformFilterCallback (
|
pascal Boolean CrossPlatformFilterCallback (
|
||||||
|
@@ -26,7 +26,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !USE_SHARED_LIBRARY
|
#if !USE_SHARED_LIBRARY
|
||||||
IMPLEMENT_CLASS(wxFileDialog, wxDialog)
|
IMPLEMENT_CLASS(wxFileDialog, wxFileDialogBase)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// begin wxmac
|
// begin wxmac
|
||||||
@@ -277,16 +277,9 @@ static pascal Boolean CrossPlatformFileFilter(CInfoPBPtr myCInfoPBPtr, void *dat
|
|||||||
wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
|
wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
|
||||||
const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard,
|
const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard,
|
||||||
long style, const wxPoint& pos)
|
long style, const wxPoint& pos)
|
||||||
|
:wxFileDialogBase(parent, message, defaultDir, defaultFileName, wildCard, style, pos)
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
|
wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
|
||||||
m_message = message;
|
|
||||||
m_dialogStyle = style;
|
|
||||||
m_parent = parent;
|
|
||||||
m_path = wxT("");
|
|
||||||
m_fileName = defaultFileName;
|
|
||||||
m_dir = defaultDir;
|
|
||||||
m_wildCard = wildCard;
|
|
||||||
m_filterIndex = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pascal Boolean CrossPlatformFilterCallback (
|
pascal Boolean CrossPlatformFilterCallback (
|
||||||
|
@@ -21,7 +21,6 @@
|
|||||||
|
|
||||||
#include "wx/defs.h"
|
#include "wx/defs.h"
|
||||||
#include "wx/utils.h"
|
#include "wx/utils.h"
|
||||||
#include "wx/dialog.h"
|
|
||||||
#include "wx/filedlg.h"
|
#include "wx/filedlg.h"
|
||||||
#include "wx/intl.h"
|
#include "wx/intl.h"
|
||||||
#include "wx/app.h"
|
#include "wx/app.h"
|
||||||
@@ -47,7 +46,7 @@
|
|||||||
|
|
||||||
#include "wx/motif/private.h"
|
#include "wx/motif/private.h"
|
||||||
|
|
||||||
IMPLEMENT_CLASS(wxFileDialog, wxDialog)
|
IMPLEMENT_CLASS(wxFileDialog, wxFileDialogBase)
|
||||||
|
|
||||||
#define DEFAULT_FILE_SELECTOR_SIZE 0
|
#define DEFAULT_FILE_SELECTOR_SIZE 0
|
||||||
// Let Motif defines the size of File
|
// Let Motif defines the size of File
|
||||||
@@ -115,16 +114,9 @@ static wxString ParseWildCard( const wxString& wild )
|
|||||||
wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
|
wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
|
||||||
const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard,
|
const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard,
|
||||||
long style, const wxPoint& pos)
|
long style, const wxPoint& pos)
|
||||||
|
:wxFileDialogBase(parent, message, defaultDir, defaultFileName, wildCard, style, pos)
|
||||||
{
|
{
|
||||||
m_message = message;
|
|
||||||
m_dialogStyle = style;
|
|
||||||
m_parent = parent;
|
|
||||||
m_path = "";
|
|
||||||
m_fileName = defaultFileName;
|
|
||||||
m_dir = defaultDir;
|
|
||||||
m_wildCard = wildCard;
|
|
||||||
m_filterIndex = 1;
|
m_filterIndex = 1;
|
||||||
m_pos = pos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wxChangeListBoxColours(wxWindow* WXUNUSED(win), Widget widget)
|
static void wxChangeListBoxColours(wxWindow* WXUNUSED(win), Widget widget)
|
||||||
|
@@ -33,7 +33,6 @@
|
|||||||
#ifndef WX_PRECOMP
|
#ifndef WX_PRECOMP
|
||||||
#include "wx/utils.h"
|
#include "wx/utils.h"
|
||||||
#include "wx/msgdlg.h"
|
#include "wx/msgdlg.h"
|
||||||
#include "wx/dialog.h"
|
|
||||||
#include "wx/filedlg.h"
|
#include "wx/filedlg.h"
|
||||||
#include "wx/filefn.h"
|
#include "wx/filefn.h"
|
||||||
#include "wx/intl.h"
|
#include "wx/intl.h"
|
||||||
@@ -76,11 +75,7 @@
|
|||||||
// implementation
|
// implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
IMPLEMENT_CLASS(wxFileDialog, wxFileDialogBase)
|
||||||
// wxWin macros
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
IMPLEMENT_CLASS(wxFileDialog, wxDialog)
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxFileDialog
|
// wxFileDialog
|
||||||
@@ -92,18 +87,12 @@ wxFileDialog::wxFileDialog(wxWindow *parent,
|
|||||||
const wxString& defaultFileName,
|
const wxString& defaultFileName,
|
||||||
const wxString& wildCard,
|
const wxString& wildCard,
|
||||||
long style,
|
long style,
|
||||||
const wxPoint& WXUNUSED(pos))
|
const wxPoint& pos)
|
||||||
|
:wxFileDialogBase(parent, message, defaultDir, defaultFileName, wildCard, style, pos)
|
||||||
|
|
||||||
{
|
{
|
||||||
m_message = message;
|
|
||||||
m_dialogStyle = style;
|
|
||||||
if ( ( m_dialogStyle & wxMULTIPLE ) && ( m_dialogStyle & wxSAVE ) )
|
if ( ( m_dialogStyle & wxMULTIPLE ) && ( m_dialogStyle & wxSAVE ) )
|
||||||
m_dialogStyle &= ~wxMULTIPLE;
|
m_dialogStyle &= ~wxMULTIPLE;
|
||||||
m_parent = parent;
|
|
||||||
m_path = wxEmptyString;
|
|
||||||
m_fileName = defaultFileName;
|
|
||||||
m_dir = defaultDir;
|
|
||||||
m_wildCard = wildCard;
|
|
||||||
m_filterIndex = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFileDialog::GetPaths(wxArrayString& paths) const
|
void wxFileDialog::GetPaths(wxArrayString& paths) const
|
||||||
@@ -350,8 +339,6 @@ int wxFileDialog::ShowModal()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const wxChar* extension = NULL;
|
|
||||||
|
|
||||||
//=== Adding the correct extension >>=================================
|
//=== Adding the correct extension >>=================================
|
||||||
|
|
||||||
m_filterIndex = (int)of.nFilterIndex - 1;
|
m_filterIndex = (int)of.nFilterIndex - 1;
|
||||||
@@ -360,39 +347,15 @@ int wxFileDialog::ShowModal()
|
|||||||
(of.nFileExtension && fileNameBuffer[of.nFileExtension] == wxT('\0')) )
|
(of.nFileExtension && fileNameBuffer[of.nFileExtension] == wxT('\0')) )
|
||||||
{
|
{
|
||||||
// User has typed a filename without an extension:
|
// User has typed a filename without an extension:
|
||||||
|
const wxChar* extension = filterBuffer;
|
||||||
|
int maxFilter = (int)(of.nFilterIndex*2L) - 1;
|
||||||
|
|
||||||
// A filename can end in a "." here ("abc."), this means it
|
for( int i = 0; i < maxFilter; i++ ) // get extension
|
||||||
// does not have an extension. Because later on a "." with
|
extension = extension + wxStrlen( extension ) + 1;
|
||||||
// the default extension is appended we remove the "." if
|
|
||||||
// filename ends with one (We don't want files called
|
|
||||||
// "abc..ext")
|
|
||||||
int idx = wxStrlen(fileNameBuffer) - 1;
|
|
||||||
if ( fileNameBuffer[idx] == wxT('.') )
|
|
||||||
{
|
|
||||||
fileNameBuffer[idx] = wxT('\0');
|
|
||||||
}
|
|
||||||
|
|
||||||
int maxFilter = (int)(of.nFilterIndex*2L-1L);
|
m_fileName = AppendExtension(fileNameBuffer, extension);
|
||||||
extension = filterBuffer;
|
wxStrncpy(fileNameBuffer, m_fileName.c_str(), wxMin(m_fileName.Len(), wxMAXPATH-1));
|
||||||
|
fileNameBuffer[wxMin(m_fileName.Len(), wxMAXPATH-1)] = wxT('\0');
|
||||||
for( int i = 0; i < maxFilter; i++ ) { // get extension
|
|
||||||
extension = extension + wxStrlen( extension ) +1;
|
|
||||||
}
|
|
||||||
|
|
||||||
extension = wxStrrchr( extension, wxT('.') );
|
|
||||||
if ( extension // != "blabla"
|
|
||||||
&& !wxStrrchr( extension, wxT('*') ) // != "blabla.*"
|
|
||||||
&& !wxStrrchr( extension, wxT('?') ) // != "blabla.?"
|
|
||||||
&& extension[1] // != "blabla."
|
|
||||||
&& extension[1] != wxT(' ') ) // != "blabla. "
|
|
||||||
{
|
|
||||||
// now concat extension to the fileName:
|
|
||||||
m_fileName = wxString(fileNameBuffer) + extension;
|
|
||||||
|
|
||||||
int len = wxStrlen( fileNameBuffer );
|
|
||||||
wxStrncpy( fileNameBuffer + len, extension, wxMAXPATH - len );
|
|
||||||
fileNameBuffer[ wxMAXPATH -1 ] = wxT('\0');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_path = fileNameBuffer;
|
m_path = fileNameBuffer;
|
||||||
|
@@ -19,7 +19,6 @@
|
|||||||
#ifndef WX_PRECOMP
|
#ifndef WX_PRECOMP
|
||||||
#include "wx/utils.h"
|
#include "wx/utils.h"
|
||||||
#include "wx/msgdlg.h"
|
#include "wx/msgdlg.h"
|
||||||
#include "wx/dialog.h"
|
|
||||||
#include "wx/filedlg.h"
|
#include "wx/filedlg.h"
|
||||||
#include "wx/intl.h"
|
#include "wx/intl.h"
|
||||||
#include "wx/log.h"
|
#include "wx/log.h"
|
||||||
@@ -56,7 +55,7 @@
|
|||||||
#ifndef MAXEXT
|
#ifndef MAXEXT
|
||||||
# define MAXEXT 5
|
# define MAXEXT 5
|
||||||
#endif
|
#endif
|
||||||
IMPLEMENT_CLASS(wxFileDialog, wxDialog)
|
IMPLEMENT_CLASS(wxFileDialog, wxFileDialogBase)
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// CLASS wxFileDialog
|
// CLASS wxFileDialog
|
||||||
@@ -71,34 +70,29 @@ wxFileDialog::wxFileDialog (
|
|||||||
, long lStyle
|
, long lStyle
|
||||||
, const wxPoint& rPos
|
, const wxPoint& rPos
|
||||||
)
|
)
|
||||||
|
:wxFileDialogBase(pParent, rsMessage, rsDefaultDir, rsDefaultFileName, rsWildCard, lStyle, rPos)
|
||||||
|
|
||||||
{
|
{
|
||||||
m_sMessage = rsMessage;
|
if ((m_dialogStyle & wxMULTIPLE) && (m_dialogStyle & wxSAVE))
|
||||||
m_lDialogStyle = lStyle;
|
m_dialogStyle &= ~wxMULTIPLE;
|
||||||
if ((m_lDialogStyle & wxMULTIPLE) && (m_lDialogStyle & wxSAVE))
|
|
||||||
m_lDialogStyle &= ~wxMULTIPLE;
|
m_filterIndex = 1;
|
||||||
m_pParent = pParent;
|
|
||||||
m_sPath = "";
|
|
||||||
m_sFileName = rsDefaultFileName;
|
|
||||||
m_sDir = rsDefaultDir;
|
|
||||||
m_sWildCard = rsWildCard;
|
|
||||||
m_nFilterIndex = 1;
|
|
||||||
m_vPos = rPos;
|
|
||||||
} // end of wxFileDialog::wxFileDialog
|
} // end of wxFileDialog::wxFileDialog
|
||||||
|
|
||||||
void wxFileDialog::GetPaths (
|
void wxFileDialog::GetPaths (
|
||||||
wxArrayString& rasPaths
|
wxArrayString& rasPaths
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
wxString sDir(m_sDir);
|
wxString sDir(m_dir);
|
||||||
size_t nCount = m_asFileNames.GetCount();
|
size_t nCount = m_fileNames.GetCount();
|
||||||
|
|
||||||
rasPaths.Empty();
|
rasPaths.Empty();
|
||||||
if (m_sDir.Last() != _T('\\'))
|
if (m_dir.Last() != _T('\\'))
|
||||||
sDir += _T('\\');
|
sDir += _T('\\');
|
||||||
|
|
||||||
for ( size_t n = 0; n < nCount; n++ )
|
for ( size_t n = 0; n < nCount; n++ )
|
||||||
{
|
{
|
||||||
rasPaths.Add(sDir + m_asFileNames[n]);
|
rasPaths.Add(sDir + m_fileNames[n]);
|
||||||
}
|
}
|
||||||
} // end of wxFileDialog::GetPaths
|
} // end of wxFileDialog::GetPaths
|
||||||
|
|
||||||
@@ -112,14 +106,14 @@ int wxFileDialog::ShowModal()
|
|||||||
wxChar zTitleBuffer[wxMAXFILE + 1 + wxMAXEXT]; // the file-name, without path
|
wxChar zTitleBuffer[wxMAXFILE + 1 + wxMAXEXT]; // the file-name, without path
|
||||||
wxString sDir;
|
wxString sDir;
|
||||||
size_t i;
|
size_t i;
|
||||||
size_t nLen = m_sDir.length();
|
size_t nLen = m_dir.length();
|
||||||
int nCount = 0;
|
int nCount = 0;
|
||||||
FILEDLG vFileDlg;
|
FILEDLG vFileDlg;
|
||||||
ULONG lFlags = 0L;
|
ULONG lFlags = 0L;
|
||||||
|
|
||||||
memset(&vFileDlg, '\0', sizeof(FILEDLG));
|
memset(&vFileDlg, '\0', sizeof(FILEDLG));
|
||||||
if (m_pParent)
|
if (m_parent)
|
||||||
hWnd = (HWND) m_pParent->GetHWND();
|
hWnd = (HWND) m_parent->GetHWND();
|
||||||
if (!hWnd && wxTheApp->GetTopWindow())
|
if (!hWnd && wxTheApp->GetTopWindow())
|
||||||
hWnd = (HWND) wxTheApp->GetTopWindow()->GetHWND();
|
hWnd = (HWND) wxTheApp->GetTopWindow()->GetHWND();
|
||||||
|
|
||||||
@@ -127,14 +121,14 @@ int wxFileDialog::ShowModal()
|
|||||||
*zFileNameBuffer = wxT('\0');
|
*zFileNameBuffer = wxT('\0');
|
||||||
*zTitleBuffer = wxT('\0');
|
*zTitleBuffer = wxT('\0');
|
||||||
|
|
||||||
if (m_lDialogStyle & wxSAVE)
|
if (m_dialogStyle & wxSAVE)
|
||||||
lFlags = FDS_SAVEAS_DIALOG;
|
lFlags = FDS_SAVEAS_DIALOG;
|
||||||
else
|
else
|
||||||
lFlags = FDS_OPEN_DIALOG;
|
lFlags = FDS_OPEN_DIALOG;
|
||||||
|
|
||||||
if ((m_lDialogStyle & wxHIDE_READONLY) || (m_lDialogStyle & wxSAVE))
|
if ((m_dialogStyle & wxHIDE_READONLY) || (m_dialogStyle & wxSAVE))
|
||||||
lFlags |= FDS_SAVEAS_DIALOG;
|
lFlags |= FDS_SAVEAS_DIALOG;
|
||||||
if (m_lDialogStyle & wxMULTIPLE )
|
if (m_dialogStyle & wxMULTIPLE )
|
||||||
lFlags |= FDS_OPEN_DIALOG | FDS_MULTIPLESEL;
|
lFlags |= FDS_OPEN_DIALOG | FDS_MULTIPLESEL;
|
||||||
|
|
||||||
vFileDlg.cbSize = sizeof(FILEDLG);
|
vFileDlg.cbSize = sizeof(FILEDLG);
|
||||||
@@ -149,7 +143,7 @@ int wxFileDialog::ShowModal()
|
|||||||
sDir.reserve(nLen);
|
sDir.reserve(nLen);
|
||||||
for ( i = 0; i < nLen; i++ )
|
for ( i = 0; i < nLen; i++ )
|
||||||
{
|
{
|
||||||
wxChar ch = m_sDir[i];
|
wxChar ch = m_dir[i];
|
||||||
|
|
||||||
switch (ch)
|
switch (ch)
|
||||||
{
|
{
|
||||||
@@ -165,7 +159,7 @@ int wxFileDialog::ShowModal()
|
|||||||
case _T('\\'):
|
case _T('\\'):
|
||||||
while (i < nLen - 1)
|
while (i < nLen - 1)
|
||||||
{
|
{
|
||||||
wxChar chNext = m_sDir[i + 1];
|
wxChar chNext = m_dir[i + 1];
|
||||||
|
|
||||||
if (chNext != _T('\\') && chNext != _T('/'))
|
if (chNext != _T('\\') && chNext != _T('/'))
|
||||||
break;
|
break;
|
||||||
@@ -189,10 +183,10 @@ int wxFileDialog::ShowModal()
|
|||||||
sDir += ch;
|
sDir += ch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( wxStrlen(m_sWildCard) == 0 )
|
if ( wxStrlen(m_wildCard) == 0 )
|
||||||
sTheFilter = "";
|
sTheFilter = "";
|
||||||
else
|
else
|
||||||
sTheFilter = m_sWildCard;
|
sTheFilter = m_wildCard;
|
||||||
|
|
||||||
pzFilterBuffer = strtok((char*)sTheFilter.c_str(), "|");
|
pzFilterBuffer = strtok((char*)sTheFilter.c_str(), "|");
|
||||||
while(pzFilterBuffer != NULL)
|
while(pzFilterBuffer != NULL)
|
||||||
@@ -207,38 +201,38 @@ int wxFileDialog::ShowModal()
|
|||||||
nCount++;
|
nCount++;
|
||||||
}
|
}
|
||||||
if (nCount == 0)
|
if (nCount == 0)
|
||||||
sDir += m_sFileName;
|
sDir += m_fileName;
|
||||||
if (sDir.IsEmpty())
|
if (sDir.IsEmpty())
|
||||||
sDir = "*.*";
|
sDir = "*.*";
|
||||||
wxStrcpy(vFileDlg.szFullFile, sDir.c_str());
|
wxStrcpy(vFileDlg.szFullFile, sDir.c_str());
|
||||||
sFilterBuffer = sDir;
|
sFilterBuffer = sDir;
|
||||||
|
|
||||||
hWnd = ::WinFileDlg( HWND_DESKTOP
|
hWnd = ::WinFileDlg( HWND_DESKTOP
|
||||||
,GetHwndOf(m_pParent)
|
,GetHwndOf(m_parent)
|
||||||
,&vFileDlg
|
,&vFileDlg
|
||||||
);
|
);
|
||||||
if (hWnd && vFileDlg.lReturn == DID_OK)
|
if (hWnd && vFileDlg.lReturn == DID_OK)
|
||||||
{
|
{
|
||||||
m_asFileNames.Empty();
|
m_fileNames.Empty();
|
||||||
if ((m_lDialogStyle & wxMULTIPLE ) && vFileDlg.ulFQFCount > 1)
|
if ((m_dialogStyle & wxMULTIPLE ) && vFileDlg.ulFQFCount > 1)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < vFileDlg.ulFQFCount; i++)
|
for (int i = 0; i < vFileDlg.ulFQFCount; i++)
|
||||||
{
|
{
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
m_sDir = wxPathOnly(wxString((const char*)*vFileDlg.papszFQFilename[0]));
|
m_dir = wxPathOnly(wxString((const char*)*vFileDlg.papszFQFilename[0]));
|
||||||
m_sPath = (const char*)*vFileDlg.papszFQFilename[0];
|
m_path = (const char*)*vFileDlg.papszFQFilename[0];
|
||||||
}
|
}
|
||||||
m_sFileName = wxFileNameFromPath(wxString((const char*)*vFileDlg.papszFQFilename[i]));
|
m_fileName = wxFileNameFromPath(wxString((const char*)*vFileDlg.papszFQFilename[i]));
|
||||||
m_asFileNames.Add(m_sFileName);
|
m_fileNames.Add(m_fileName);
|
||||||
}
|
}
|
||||||
::WinFreeFileDlgList(vFileDlg.papszFQFilename);
|
::WinFreeFileDlgList(vFileDlg.papszFQFilename);
|
||||||
}
|
}
|
||||||
else if (!(m_lDialogStyle & wxSAVE))
|
else if (!(m_dialogStyle & wxSAVE))
|
||||||
{
|
{
|
||||||
m_sPath = vFileDlg.szFullFile;
|
m_path = vFileDlg.szFullFile;
|
||||||
m_sFileName = wxFileNameFromPath(vFileDlg.szFullFile);
|
m_fileName = wxFileNameFromPath(vFileDlg.szFullFile);
|
||||||
m_sDir = wxPathOnly(vFileDlg.szFullFile);
|
m_dir = wxPathOnly(vFileDlg.szFullFile);
|
||||||
}
|
}
|
||||||
else // save file
|
else // save file
|
||||||
{
|
{
|
||||||
@@ -250,8 +244,8 @@ int wxFileDialog::ShowModal()
|
|||||||
wxString sExt;
|
wxString sExt;
|
||||||
|
|
||||||
wxSplitPath( zFileNameBuffer
|
wxSplitPath( zFileNameBuffer
|
||||||
,&m_sPath
|
,&m_path
|
||||||
,&m_sFileName
|
,&m_fileName
|
||||||
,&sExt
|
,&sExt
|
||||||
);
|
);
|
||||||
if (zFileNameBuffer[nIdx] == wxT('.') || sExt.IsEmpty())
|
if (zFileNameBuffer[nIdx] == wxT('.') || sExt.IsEmpty())
|
||||||
@@ -285,28 +279,28 @@ int wxFileDialog::ShowModal()
|
|||||||
//
|
//
|
||||||
// Now concat extension to the fileName:
|
// Now concat extension to the fileName:
|
||||||
//
|
//
|
||||||
m_sPath = wxString(zFileNameBuffer) + pzExtension;
|
m_path = wxString(zFileNameBuffer) + pzExtension;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_sPath = vFileDlg.szFullFile;
|
m_path = vFileDlg.szFullFile;
|
||||||
}
|
}
|
||||||
m_sFileName = wxFileNameFromPath(vFileDlg.szFullFile);
|
m_fileName = wxFileNameFromPath(vFileDlg.szFullFile);
|
||||||
m_sDir = wxPathOnly(vFileDlg.szFullFile);
|
m_dir = wxPathOnly(vFileDlg.szFullFile);
|
||||||
|
|
||||||
//
|
//
|
||||||
// === Simulating the wxOVERWRITE_PROMPT >>============================
|
// === Simulating the wxOVERWRITE_PROMPT >>============================
|
||||||
//
|
//
|
||||||
if ((m_lDialogStyle & wxOVERWRITE_PROMPT) &&
|
if ((m_dialogStyle & wxOVERWRITE_PROMPT) &&
|
||||||
(m_lDialogStyle & wxSAVE) &&
|
(m_dialogStyle & wxSAVE) &&
|
||||||
(wxFileExists(m_sPath.c_str())))
|
(wxFileExists(m_path.c_str())))
|
||||||
{
|
{
|
||||||
wxString sMessageText;
|
wxString sMessageText;
|
||||||
|
|
||||||
sMessageText.Printf( _("File '%s' already exists.\nDo you want to replace it?")
|
sMessageText.Printf( _("File '%s' already exists.\nDo you want to replace it?")
|
||||||
,m_sPath.c_str()
|
,m_path.c_str()
|
||||||
);
|
);
|
||||||
if (wxMessageBox( sMessageText
|
if (wxMessageBox( sMessageText
|
||||||
,wxT("Save File As")
|
,wxT("Save File As")
|
||||||
|
Reference in New Issue
Block a user