]> git.saurik.com Git - wxWidgets.git/commitdiff
replace wxDocument::GetPrintableName(wxString&) and wxDocManager::MakeDefaultName...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 16 Jun 2007 12:49:56 +0000 (12:49 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 16 Jun 2007 12:49:56 +0000 (12:49 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46488 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
docs/latex/wx/docmanag.tex
docs/latex/wx/document.tex
include/wx/docview.h
src/common/docview.cpp

index 7bbd2f16c0bec8a7a15180bfd1571276711d5572..f7b6796f78c5dd0613a7b6d874c7d3973600c42c 100644 (file)
@@ -79,6 +79,9 @@ Deprecated methods and their replacements
   or wxStringBufferLength instead.
 - wxDIRCTRL_SHOW_FILTERS style is deprecated, filters are alwsys shown if
   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
index d8516852f05a20f5d8520d595a79fff332e4a24d..4437a110783c0d7455ae16e7db75dae16d7d1663 100644 (file)
@@ -320,16 +320,14 @@ The bottom line: if you're not deriving from Initialize, forget it and
 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
-appending an integer counter to the string {\bf unnamed} and incrementing
-the counter.
-
-\perlnote{In wxPerl this function must return the modified name rather
-than just modifying the argument.}
+Return a string containing a suitable default name for a new document. By
+default this is implemented by appending an integer counter to the string
+{\bf unnamed} but can be overridden in the derived classes to do something more
+appropriate.
 
 
 \membersection{wxDocManager::OnCreateFileHistory}\label{wxdocmanageroncreatefilehistory}
index 413dc2e7e551f0abcfd94571edd0c0b7a4451b19..a6dc7c39e6fba9fbd7993492c5090e266b811ced 100644 (file)
@@ -153,16 +153,13 @@ in many cases a document will only have a single view.
 
 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
-function uses the title, or if there is no title, uses the filename; or if no
-filename, the string {\bf unnamed}. 
-
-\perlnote{In wxPerl this function must return the modified name rather
-than just modifying the argument.}
+Return the document name suitable to be shown to the user. The default
+implementation uses the document title, if any, of the name part of the
+document filename if it was set or, otherwise, the string {\bf unnamed}.
 
 \membersection{wxDocument::GetTitle}\label{wxdocumentgettitle}
 
index 8da6fd723374f52451e73e80fd9d1741303b73e2..92b7509823da82ecd90f2c4eb9bb4d48dec29310 100644 (file)
@@ -140,8 +140,17 @@ public:
     virtual wxDocTemplate *GetDocumentTemplate() const { return m_documentTemplate; }
     virtual void SetDocumentTemplate(wxDocTemplate *temp) { m_documentTemplate = temp; }
 
-    // Get title, or filename if no title, else [unnamed]
-    virtual bool GetPrintableName(wxString& buf) const;
+    // Get the document name to be shown to the user: the title if there is
+    // 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
     // dialogs. Override if necessary.
@@ -164,6 +173,9 @@ protected:
     virtual bool DoSaveDocument(const wxString& file);
     virtual bool DoOpenDocument(const wxString& file);
 
+    // the default implementation of GetUserReadableName()
+    wxString DoGetUserReadableName() const;
+
 private:
     DECLARE_ABSTRACT_CLASS(wxDocument)
     DECLARE_NO_COPY_CLASS(wxDocument)
@@ -393,8 +405,9 @@ public:
     wxList& GetDocuments() { return m_docs; }
     wxList& GetTemplates() { return m_templates; }
 
-    // Make a default document name
-    virtual bool MakeDefaultName(wxString& buf);
+    // Return the default name for a new document (by default returns strings
+    // in the form "unnamed <counter>" but can be overridden)
+    virtual wxString MakeNewDocumentName();
 
     // Make a frame title (override this to do something different)
     virtual wxString MakeFrameTitle(wxDocument* doc);
@@ -423,6 +436,13 @@ public:
     // Get the current document manager
     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
     // deprecated, use GetHistoryFilesCount() instead
     wxDEPRECATED( size_t GetNoHistoryFiles() const );
index 1ebad15e2ba009c72649967b880edeaa1955a502..34cbdbadafcfdd590bd0b174790329b2d40fb71c 100644 (file)
@@ -241,8 +241,7 @@ bool wxDocument::OnNewDocument()
     Modify(false);
     SetDocumentSaved(false);
 
-    wxString name;
-    GetDocumentManager()->MakeDefaultName(name);
+    const wxString name = GetDocumentManager()->MakeNewDocumentName();
     SetTitle(name);
     SetFilename(name, true);
 
@@ -408,23 +407,41 @@ bool wxDocument::Revert()
 
 
 // Get title, or filename if no title, else unnamed
+#if WXWIN_COMPATIBILITY_2_8
 bool wxDocument::GetPrintableName(wxString& buf) const
 {
-    if (!m_documentTitle.empty())
-    {
-        buf = m_documentTitle;
-        return true;
-    }
-    else if (!m_documentFile.empty())
-    {
-        buf = wxFileNameFromPath(m_documentFile);
-        return true;
-    }
-    else
-    {
-        buf = _("unnamed");
-        return true;
-    }
+    // 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
+    // GetUserReadableName() but we can't call it because this would result in
+    // an infinite recursion, hence we use the helper DoGetUserReadableName()
+    buf = DoGetUserReadableName();
+
+    return true;
+}
+#endif // WXWIN_COMPATIBILITY_2_8
+
+wxString wxDocument::GetUserReadableName() const
+{
+#if WXWIN_COMPATIBILITY_2_8
+    // 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
@@ -446,8 +463,7 @@ bool wxDocument::OnSaveModified()
 {
     if (IsModified())
     {
-        wxString title;
-        GetPrintableName(title);
+        wxString title = GetUserReadableName();
 
         wxString msgTitle;
         if (!wxTheApp->GetAppName().empty())
@@ -663,9 +679,7 @@ void wxView::OnChangeFilename()
     wxDocument *doc = GetDocument();
     if (!doc) return;
 
-    wxString name;
-    doc->GetPrintableName(name);
-    win->SetLabel(name);
+    win->SetLabel(doc->GetUserReadableName());
 }
 
 void wxView::SetDocument(wxDocument *doc)
@@ -1404,13 +1418,30 @@ wxDocument *wxDocManager::GetCurrentDocument() const
         return (wxDocument *) NULL;
 }
 
-// Make a default document name
-bool wxDocManager::MakeDefaultName(wxString& name)
+// Make a default name for a new document
+#if WXWIN_COMPATIBILITY_2_8
+bool wxDocManager::MakeDefaultName(wxString& WXUNUSED(name))
+{
+    // we consider that this function can only be overridden by the user code,
+    // 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
+
+wxString wxDocManager::MakeNewDocumentName()
 {
-    name.Printf(_("unnamed%d"), m_defaultDocumentNameCounter);
-    m_defaultDocumentNameCounter++;
+    wxString name;
 
-    return true;
+#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)
@@ -1423,8 +1454,7 @@ wxString wxDocManager::MakeFrameTitle(wxDocument* doc)
         title = appName;
     else
     {
-        wxString docName;
-        doc->GetPrintableName(docName);
+        wxString docName = doc->GetUserReadableName();
         title = docName + wxString(_(" - ")) + appName;
     }
     return title;