replace wxDocument::GetPrintableName(wxString&) and wxDocManager::MakeDefaultName(wxString&) with GetUserReadableName() and MakeNewDocumentName() which return wxStrings directly
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46488 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -79,6 +79,9 @@ Deprecated methods and their replacements
|
|||||||
or wxStringBufferLength instead.
|
or wxStringBufferLength instead.
|
||||||
- wxDIRCTRL_SHOW_FILTERS style is deprecated, filters are alwsys shown if
|
- wxDIRCTRL_SHOW_FILTERS style is deprecated, filters are alwsys shown if
|
||||||
specified so this style should simply be removed
|
specified so this style should simply be removed
|
||||||
|
- wxDocManager::MakeDefaultName() replaced by MakeNewDocumentName() and
|
||||||
|
wxDocument::GetPrintableName() with GetUserReadableName() which are simpler
|
||||||
|
to use
|
||||||
|
|
||||||
|
|
||||||
Major new features in this release
|
Major new features in this release
|
||||||
|
@@ -320,16 +320,14 @@ The bottom line: if you're not deriving from Initialize, forget it and
|
|||||||
construct wxDocManager with no arguments.
|
construct wxDocManager with no arguments.
|
||||||
|
|
||||||
|
|
||||||
\membersection{wxDocManager::MakeDefaultName}\label{wxdocmanagermakedefaultname}
|
\membersection{wxDocManager::MakeNewDocumentName}\label{wxdocmanagermakenewdocumentname}
|
||||||
|
|
||||||
\func{bool}{MakeDefaultName}{\param{const wxString\& }{buf}}
|
\func{wxString}{MakeNewDocumentName}{\void}
|
||||||
|
|
||||||
Copies a suitable default name into {\it buf}. This is implemented by
|
Return a string containing a suitable default name for a new document. By
|
||||||
appending an integer counter to the string {\bf unnamed} and incrementing
|
default this is implemented by appending an integer counter to the string
|
||||||
the counter.
|
{\bf unnamed} but can be overridden in the derived classes to do something more
|
||||||
|
appropriate.
|
||||||
\perlnote{In wxPerl this function must return the modified name rather
|
|
||||||
than just modifying the argument.}
|
|
||||||
|
|
||||||
|
|
||||||
\membersection{wxDocManager::OnCreateFileHistory}\label{wxdocmanageroncreatefilehistory}
|
\membersection{wxDocManager::OnCreateFileHistory}\label{wxdocmanageroncreatefilehistory}
|
||||||
|
@@ -153,16 +153,13 @@ in many cases a document will only have a single view.
|
|||||||
|
|
||||||
See also: \helpref{GetViews}{wxdocumentgetviews}
|
See also: \helpref{GetViews}{wxdocumentgetviews}
|
||||||
|
|
||||||
\membersection{wxDocument::GetPrintableName}\label{wxdocumentgetprintablename}
|
\membersection{wxDocument::GetUserReadableName}\label{wxdocumentgetuserreadablentablename}
|
||||||
|
|
||||||
\constfunc{virtual void}{GetPrintableName}{\param{wxString\& }{name}}
|
\constfunc{virtual wxString}{GetUserReadableName}{\void}
|
||||||
|
|
||||||
Copies a suitable document name into the supplied {\it name} buffer. The default
|
Return the document name suitable to be shown to the user. The default
|
||||||
function uses the title, or if there is no title, uses the filename; or if no
|
implementation uses the document title, if any, of the name part of the
|
||||||
filename, the string {\bf unnamed}.
|
document filename if it was set or, otherwise, the string {\bf unnamed}.
|
||||||
|
|
||||||
\perlnote{In wxPerl this function must return the modified name rather
|
|
||||||
than just modifying the argument.}
|
|
||||||
|
|
||||||
\membersection{wxDocument::GetTitle}\label{wxdocumentgettitle}
|
\membersection{wxDocument::GetTitle}\label{wxdocumentgettitle}
|
||||||
|
|
||||||
|
@@ -140,8 +140,17 @@ public:
|
|||||||
virtual wxDocTemplate *GetDocumentTemplate() const { return m_documentTemplate; }
|
virtual wxDocTemplate *GetDocumentTemplate() const { return m_documentTemplate; }
|
||||||
virtual void SetDocumentTemplate(wxDocTemplate *temp) { m_documentTemplate = temp; }
|
virtual void SetDocumentTemplate(wxDocTemplate *temp) { m_documentTemplate = temp; }
|
||||||
|
|
||||||
// Get title, or filename if no title, else [unnamed]
|
// Get the document name to be shown to the user: the title if there is
|
||||||
virtual bool GetPrintableName(wxString& buf) const;
|
// any, otherwise the filename if the document was saved and, finally,
|
||||||
|
// "unnamed" otherwise
|
||||||
|
virtual wxString GetUserReadableName() const;
|
||||||
|
|
||||||
|
#if WXWIN_COMPATIBILITY_2_8
|
||||||
|
// use GetUserReadableName() instead
|
||||||
|
wxDEPRECATED_BUT_USED_INTERNALLY(
|
||||||
|
virtual bool GetPrintableName(wxString& buf) const
|
||||||
|
);
|
||||||
|
#endif // WXWIN_COMPATIBILITY_2_8
|
||||||
|
|
||||||
// Returns a window that can be used as a parent for document-related
|
// Returns a window that can be used as a parent for document-related
|
||||||
// dialogs. Override if necessary.
|
// dialogs. Override if necessary.
|
||||||
@@ -164,6 +173,9 @@ protected:
|
|||||||
virtual bool DoSaveDocument(const wxString& file);
|
virtual bool DoSaveDocument(const wxString& file);
|
||||||
virtual bool DoOpenDocument(const wxString& file);
|
virtual bool DoOpenDocument(const wxString& file);
|
||||||
|
|
||||||
|
// the default implementation of GetUserReadableName()
|
||||||
|
wxString DoGetUserReadableName() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_ABSTRACT_CLASS(wxDocument)
|
DECLARE_ABSTRACT_CLASS(wxDocument)
|
||||||
DECLARE_NO_COPY_CLASS(wxDocument)
|
DECLARE_NO_COPY_CLASS(wxDocument)
|
||||||
@@ -393,8 +405,9 @@ public:
|
|||||||
wxList& GetDocuments() { return m_docs; }
|
wxList& GetDocuments() { return m_docs; }
|
||||||
wxList& GetTemplates() { return m_templates; }
|
wxList& GetTemplates() { return m_templates; }
|
||||||
|
|
||||||
// Make a default document name
|
// Return the default name for a new document (by default returns strings
|
||||||
virtual bool MakeDefaultName(wxString& buf);
|
// in the form "unnamed <counter>" but can be overridden)
|
||||||
|
virtual wxString MakeNewDocumentName();
|
||||||
|
|
||||||
// Make a frame title (override this to do something different)
|
// Make a frame title (override this to do something different)
|
||||||
virtual wxString MakeFrameTitle(wxDocument* doc);
|
virtual wxString MakeFrameTitle(wxDocument* doc);
|
||||||
@@ -423,6 +436,13 @@ public:
|
|||||||
// Get the current document manager
|
// Get the current document manager
|
||||||
static wxDocManager* GetDocumentManager() { return sm_docManager; }
|
static wxDocManager* GetDocumentManager() { return sm_docManager; }
|
||||||
|
|
||||||
|
#if WXWIN_COMPATIBILITY_2_8
|
||||||
|
// deprecated, override GetDefaultName() instead
|
||||||
|
wxDEPRECATED_BUT_USED_INTERNALLY(
|
||||||
|
virtual bool MakeDefaultName(wxString& buf)
|
||||||
|
);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if WXWIN_COMPATIBILITY_2_6
|
#if WXWIN_COMPATIBILITY_2_6
|
||||||
// deprecated, use GetHistoryFilesCount() instead
|
// deprecated, use GetHistoryFilesCount() instead
|
||||||
wxDEPRECATED( size_t GetNoHistoryFiles() const );
|
wxDEPRECATED( size_t GetNoHistoryFiles() const );
|
||||||
|
@@ -241,8 +241,7 @@ bool wxDocument::OnNewDocument()
|
|||||||
Modify(false);
|
Modify(false);
|
||||||
SetDocumentSaved(false);
|
SetDocumentSaved(false);
|
||||||
|
|
||||||
wxString name;
|
const wxString name = GetDocumentManager()->MakeNewDocumentName();
|
||||||
GetDocumentManager()->MakeDefaultName(name);
|
|
||||||
SetTitle(name);
|
SetTitle(name);
|
||||||
SetFilename(name, true);
|
SetFilename(name, true);
|
||||||
|
|
||||||
@@ -408,23 +407,41 @@ bool wxDocument::Revert()
|
|||||||
|
|
||||||
|
|
||||||
// Get title, or filename if no title, else unnamed
|
// Get title, or filename if no title, else unnamed
|
||||||
|
#if WXWIN_COMPATIBILITY_2_8
|
||||||
bool wxDocument::GetPrintableName(wxString& buf) const
|
bool wxDocument::GetPrintableName(wxString& buf) const
|
||||||
{
|
{
|
||||||
if (!m_documentTitle.empty())
|
// this function can not only be overridden by the user code but also
|
||||||
{
|
// called by it so we need to ensure that we return the same thing as
|
||||||
buf = m_documentTitle;
|
// GetUserReadableName() but we can't call it because this would result in
|
||||||
return true;
|
// an infinite recursion, hence we use the helper DoGetUserReadableName()
|
||||||
}
|
buf = DoGetUserReadableName();
|
||||||
else if (!m_documentFile.empty())
|
|
||||||
{
|
return true;
|
||||||
buf = wxFileNameFromPath(m_documentFile);
|
}
|
||||||
return true;
|
#endif // WXWIN_COMPATIBILITY_2_8
|
||||||
}
|
|
||||||
else
|
wxString wxDocument::GetUserReadableName() const
|
||||||
{
|
{
|
||||||
buf = _("unnamed");
|
#if WXWIN_COMPATIBILITY_2_8
|
||||||
return true;
|
// we need to call the old virtual function to ensure that the overridden
|
||||||
}
|
// version of it is still called
|
||||||
|
wxString name;
|
||||||
|
if ( GetPrintableName(name) )
|
||||||
|
return name;
|
||||||
|
#endif // WXWIN_COMPATIBILITY_2_8
|
||||||
|
|
||||||
|
return DoGetUserReadableName();
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString wxDocument::DoGetUserReadableName() const
|
||||||
|
{
|
||||||
|
if ( !m_documentTitle.empty() )
|
||||||
|
return m_documentTitle;
|
||||||
|
|
||||||
|
if ( !m_documentFile.empty() )
|
||||||
|
return wxFileNameFromPath(m_documentFile);
|
||||||
|
|
||||||
|
return _("unnamed");
|
||||||
}
|
}
|
||||||
|
|
||||||
wxWindow *wxDocument::GetDocumentWindow() const
|
wxWindow *wxDocument::GetDocumentWindow() const
|
||||||
@@ -446,8 +463,7 @@ bool wxDocument::OnSaveModified()
|
|||||||
{
|
{
|
||||||
if (IsModified())
|
if (IsModified())
|
||||||
{
|
{
|
||||||
wxString title;
|
wxString title = GetUserReadableName();
|
||||||
GetPrintableName(title);
|
|
||||||
|
|
||||||
wxString msgTitle;
|
wxString msgTitle;
|
||||||
if (!wxTheApp->GetAppName().empty())
|
if (!wxTheApp->GetAppName().empty())
|
||||||
@@ -663,9 +679,7 @@ void wxView::OnChangeFilename()
|
|||||||
wxDocument *doc = GetDocument();
|
wxDocument *doc = GetDocument();
|
||||||
if (!doc) return;
|
if (!doc) return;
|
||||||
|
|
||||||
wxString name;
|
win->SetLabel(doc->GetUserReadableName());
|
||||||
doc->GetPrintableName(name);
|
|
||||||
win->SetLabel(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxView::SetDocument(wxDocument *doc)
|
void wxView::SetDocument(wxDocument *doc)
|
||||||
@@ -1404,13 +1418,30 @@ wxDocument *wxDocManager::GetCurrentDocument() const
|
|||||||
return (wxDocument *) NULL;
|
return (wxDocument *) NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a default document name
|
// Make a default name for a new document
|
||||||
bool wxDocManager::MakeDefaultName(wxString& name)
|
#if WXWIN_COMPATIBILITY_2_8
|
||||||
|
bool wxDocManager::MakeDefaultName(wxString& WXUNUSED(name))
|
||||||
{
|
{
|
||||||
name.Printf(_("unnamed%d"), m_defaultDocumentNameCounter);
|
// we consider that this function can only be overridden by the user code,
|
||||||
m_defaultDocumentNameCounter++;
|
// not called by it as it only makes sense to call it internally, so we
|
||||||
|
// don't bother to return anything from here
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif // WXWIN_COMPATIBILITY_2_8
|
||||||
|
|
||||||
return true;
|
wxString wxDocManager::MakeNewDocumentName()
|
||||||
|
{
|
||||||
|
wxString name;
|
||||||
|
|
||||||
|
#if WXWIN_COMPATIBILITY_2_8
|
||||||
|
if ( !MakeDefaultName(name) )
|
||||||
|
#endif // WXWIN_COMPATIBILITY_2_8
|
||||||
|
{
|
||||||
|
name.Printf(_("unnamed%d"), m_defaultDocumentNameCounter);
|
||||||
|
m_defaultDocumentNameCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a frame title (override this to do something different)
|
// Make a frame title (override this to do something different)
|
||||||
@@ -1423,8 +1454,7 @@ wxString wxDocManager::MakeFrameTitle(wxDocument* doc)
|
|||||||
title = appName;
|
title = appName;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wxString docName;
|
wxString docName = doc->GetUserReadableName();
|
||||||
doc->GetPrintableName(docName);
|
|
||||||
title = docName + wxString(_(" - ")) + appName;
|
title = docName + wxString(_(" - ")) + appName;
|
||||||
}
|
}
|
||||||
return title;
|
return title;
|
||||||
|
Reference in New Issue
Block a user