added wxStandardPaths::GetAppDocumentsDir() and use it by default for loading/saving documents in wxDocManager
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58259 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -328,6 +328,7 @@ All:
|
|||||||
- Added wxSHUTDOWN_LOGOFF and wxSHUTDOWN_FORCE wxShutdown() flags (troelsk).
|
- Added wxSHUTDOWN_LOGOFF and wxSHUTDOWN_FORCE wxShutdown() flags (troelsk).
|
||||||
- Added wxSocket::ShutdownOutput().
|
- Added wxSocket::ShutdownOutput().
|
||||||
- Handle exceptions thrown from overridden wxView::OnCreate() gracefully.
|
- Handle exceptions thrown from overridden wxView::OnCreate() gracefully.
|
||||||
|
- Added wxStandardPaths::GetAppDocumentsDir().
|
||||||
|
|
||||||
All (Unix):
|
All (Unix):
|
||||||
|
|
||||||
|
@@ -436,7 +436,7 @@ public:
|
|||||||
virtual void FileHistoryAddFilesToMenu();
|
virtual void FileHistoryAddFilesToMenu();
|
||||||
virtual void FileHistoryAddFilesToMenu(wxMenu* menu);
|
virtual void FileHistoryAddFilesToMenu(wxMenu* menu);
|
||||||
|
|
||||||
wxString GetLastDirectory() const { return m_lastDirectory; }
|
wxString GetLastDirectory() const;
|
||||||
void SetLastDirectory(const wxString& dir) { m_lastDirectory = dir; }
|
void SetLastDirectory(const wxString& dir) { m_lastDirectory = dir; }
|
||||||
|
|
||||||
// Get the current document manager
|
// Get the current document manager
|
||||||
|
@@ -131,6 +131,11 @@ public:
|
|||||||
// $HOME under Unix and ~/Documents under Mac
|
// $HOME under Unix and ~/Documents under Mac
|
||||||
virtual wxString GetDocumentsDir() const;
|
virtual wxString GetDocumentsDir() const;
|
||||||
|
|
||||||
|
// return the directory for the documents files used by this application:
|
||||||
|
// it's a subdirectory of GetDocumentsDir() constructed using the
|
||||||
|
// application name/vendor if it exists or just GetDocumentsDir() otherwise
|
||||||
|
virtual wxString GetAppDocumentsDir() const;
|
||||||
|
|
||||||
// return the temporary directory for the current user
|
// return the temporary directory for the current user
|
||||||
virtual wxString GetTempDir() const;
|
virtual wxString GetTempDir() const;
|
||||||
|
|
||||||
@@ -151,8 +156,8 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// append the path component, with a leading path seperator if a
|
// append the path component, with a leading path separator if a
|
||||||
// path seperator or dot (.) is not already at the end of dir
|
// path separator or dot (.) is not already at the end of dir
|
||||||
static wxString AppendPathComponent(const wxString& dir, const wxString& component);
|
static wxString AppendPathComponent(const wxString& dir, const wxString& component);
|
||||||
|
|
||||||
// append application information determined by m_usedAppInfo to dir
|
// append application information determined by m_usedAppInfo to dir
|
||||||
|
@@ -53,6 +53,23 @@ public:
|
|||||||
*/
|
*/
|
||||||
static wxStandardPathsBase& Get();
|
static wxStandardPathsBase& Get();
|
||||||
|
|
||||||
|
/**
|
||||||
|
Return the directory for the document files used by this application.
|
||||||
|
|
||||||
|
If the application-specific directory doesn't exist, this function
|
||||||
|
returns GetDocumentsDir().
|
||||||
|
|
||||||
|
Example return values:
|
||||||
|
- Unix: @c ~/appname
|
||||||
|
- Windows: @c "C:\Documents and Settings\username\My Documents\appname"
|
||||||
|
- Mac: @c ~/Documents/appname
|
||||||
|
|
||||||
|
@since 2.9.0
|
||||||
|
|
||||||
|
@see GetAppDocumentsDir()
|
||||||
|
*/
|
||||||
|
virtual wxString GetAppDocumentsDir() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Return the directory containing the system config files.
|
Return the directory containing the system config files.
|
||||||
Example return values:
|
Example return values:
|
||||||
@@ -78,12 +95,15 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Return the directory containing the current user's documents.
|
Return the directory containing the current user's documents.
|
||||||
|
|
||||||
Example return values:
|
Example return values:
|
||||||
- Unix: @c ~ (the home directory)
|
- Unix: @c ~ (the home directory)
|
||||||
- Windows: @c "C:\Documents and Settings\username\My Documents"
|
- Windows: @c "C:\Documents and Settings\username\My Documents"
|
||||||
- Mac: @c ~/Documents
|
- Mac: @c ~/Documents
|
||||||
|
|
||||||
@since 2.7.0
|
@since 2.7.0
|
||||||
|
|
||||||
|
@see GetAppDocumentsDir()
|
||||||
*/
|
*/
|
||||||
virtual wxString GetDocumentsDir() const;
|
virtual wxString GetDocumentsDir() const;
|
||||||
|
|
||||||
|
@@ -56,6 +56,7 @@
|
|||||||
#include "wx/cmdproc.h"
|
#include "wx/cmdproc.h"
|
||||||
#include "wx/tokenzr.h"
|
#include "wx/tokenzr.h"
|
||||||
#include "wx/filename.h"
|
#include "wx/filename.h"
|
||||||
|
#include "wx/stdpaths.h"
|
||||||
#include "wx/vector.h"
|
#include "wx/vector.h"
|
||||||
#include "wx/ptr_scpd.h"
|
#include "wx/ptr_scpd.h"
|
||||||
|
|
||||||
@@ -307,8 +308,12 @@ bool wxDocument::SaveAs()
|
|||||||
wxString filter = docTemplate->GetFileFilter() ;
|
wxString filter = docTemplate->GetFileFilter() ;
|
||||||
#endif
|
#endif
|
||||||
wxString defaultDir = docTemplate->GetDirectory();
|
wxString defaultDir = docTemplate->GetDirectory();
|
||||||
if (defaultDir.IsEmpty())
|
if ( defaultDir.empty() )
|
||||||
|
{
|
||||||
defaultDir = wxPathOnly(GetFilename());
|
defaultDir = wxPathOnly(GetFilename());
|
||||||
|
if ( defaultDir.empty() )
|
||||||
|
defaultDir = GetDocumentManager()->GetLastDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
wxString fileName = wxFileSelector(_("Save As"),
|
wxString fileName = wxFileSelector(_("Save As"),
|
||||||
defaultDir,
|
defaultDir,
|
||||||
@@ -938,6 +943,19 @@ bool wxDocManager::Initialize()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxString wxDocManager::GetLastDirectory() const
|
||||||
|
{
|
||||||
|
// use the system-dependent default location for the document files if
|
||||||
|
// we're being opened for the first time
|
||||||
|
if ( m_lastDirectory.empty() )
|
||||||
|
{
|
||||||
|
wxDocManager * const self = const_cast<wxDocManager *>(this);
|
||||||
|
self->m_lastDirectory = wxStandardPaths::Get().GetAppDocumentsDir();
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_lastDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
wxFileHistory *wxDocManager::OnCreateFileHistory()
|
wxFileHistory *wxDocManager::OnCreateFileHistory()
|
||||||
{
|
{
|
||||||
return new wxFileHistory;
|
return new wxFileHistory;
|
||||||
@@ -1490,7 +1508,7 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
|
|||||||
wxWindow* parent = wxFindSuitableParent();
|
wxWindow* parent = wxFindSuitableParent();
|
||||||
|
|
||||||
wxString pathTmp = wxFileSelectorEx(_("Open File"),
|
wxString pathTmp = wxFileSelectorEx(_("Open File"),
|
||||||
m_lastDirectory,
|
GetLastDirectory(),
|
||||||
wxEmptyString,
|
wxEmptyString,
|
||||||
&FilterIndex,
|
&FilterIndex,
|
||||||
descrBuf,
|
descrBuf,
|
||||||
@@ -1514,7 +1532,8 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
|
|||||||
path = wxEmptyString;
|
path = wxEmptyString;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
m_lastDirectory = wxPathOnly(pathTmp);
|
|
||||||
|
SetLastDirectory(wxPathOnly(pathTmp));
|
||||||
|
|
||||||
path = pathTmp;
|
path = pathTmp;
|
||||||
|
|
||||||
|
@@ -106,6 +106,14 @@ wxString wxStandardPathsBase::GetDocumentsDir() const
|
|||||||
return wxFileName::GetHomeDir();
|
return wxFileName::GetHomeDir();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxString wxStandardPathsBase::GetAppDocumentsDir() const
|
||||||
|
{
|
||||||
|
const wxString docsDir = GetDocumentsDir();
|
||||||
|
wxString appDocsDir = AppendAppInfo(docsDir);
|
||||||
|
|
||||||
|
return wxDirExists(appDocsDir) ? appDocsDir : docsDir;
|
||||||
|
}
|
||||||
|
|
||||||
// return the temporary directory for the current user
|
// return the temporary directory for the current user
|
||||||
wxString wxStandardPathsBase::GetTempDir() const
|
wxString wxStandardPathsBase::GetTempDir() const
|
||||||
{
|
{
|
||||||
@@ -113,7 +121,9 @@ wxString wxStandardPathsBase::GetTempDir() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
wxString wxStandardPathsBase::AppendPathComponent(const wxString& dir, const wxString& component)
|
wxString
|
||||||
|
wxStandardPathsBase::AppendPathComponent(const wxString& dir,
|
||||||
|
const wxString& component)
|
||||||
{
|
{
|
||||||
wxString subdir(dir);
|
wxString subdir(dir);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user