]> git.saurik.com Git - wxWidgets.git/commitdiff
minor cleanup; add wxDocument::OnChangeFilename for coherence with wxView::OnChangefi...
authorFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Fri, 9 Jan 2009 16:13:49 +0000 (16:13 +0000)
committerFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Fri, 9 Jan 2009 16:13:49 +0000 (16:13 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57950 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/docview.h
interface/wx/docview.h
src/common/docview.cpp

index 0eaf23b8ba1eeab80351e356cadee3d1f6063c5d..6568e7654a34860ed96f68c2a7a4ac7dfe9f1b5f 100644 (file)
@@ -107,6 +107,10 @@ public:
     // modified to false)
     virtual bool OnSaveModified();
 
+    // if you override, remember to call the default 
+    // implementation (wxDocument::OnChangeFilename)
+    virtual void OnChangeFilename(bool notifyViews);
+
     // Called by framework if created automatically by the default document
     // manager: gives document a chance to initialise and (usually) create a
     // view
index 7255d81cb401fb119f8d1ec290826512637da17f..7a2fb033cbdfb443f4f90fbdec69059345b13a23 100644 (file)
@@ -740,8 +740,7 @@ public:
 
     /**
         Called when the filename has changed. The default implementation
-        constructs a suitable title and sets the title of the view frame (if
-        any).
+        constructs a suitable title and sets the title of the view frame (if any).
     */
     virtual void OnChangeFilename();
 
@@ -1296,10 +1295,18 @@ public:
     /**
         Sets the filename for this document. Usually called by the framework.
 
+        Calls OnChangeFilename() which in turn calls wxView::OnChangeFilename() for
+        all views if @a notifyViews is @true,
+    */
+    void SetFilename(const wxString& filename, bool notifyViews = false);
+
+    /**
         If @a notifyViews is @true, wxView::OnChangeFilename() is called for
         all views.
+
+        @since 2.9.0
     */
-    void SetFilename(const wxString& filename, bool notifyViews = false);
+    virtual void OnChangeFilename(bool notifyViews);
 
     /**
         Sets the title for this document. The document title is used for an
index 5de605d0100288b307f15d4cb2aa0116cc0f316b..b9eac572333fd83a0d4bcc23ab264b13f63db156 100644 (file)
@@ -310,7 +310,7 @@ bool wxDocument::SaveAs()
     if (defaultDir.IsEmpty())
         defaultDir = wxPathOnly(GetFilename());
 
-    wxString tmp = wxFileSelector(_("Save As"),
+    wxString fileName = wxFileSelector(_("Save As"),
             defaultDir,
             wxFileNameFromPath(GetFilename()),
             docTemplate->GetDefaultExtension(),
@@ -318,12 +318,11 @@ bool wxDocument::SaveAs()
             wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
             GetDocumentWindow());
 
-    if (tmp.empty())
+    if (fileName.empty())
         return false;
 
-    wxString fileName(tmp);
-    wxString path, name, ext;
-    wxFileName::SplitPath(fileName, & path, & name, & ext);
+    wxString ext;
+    wxFileName::SplitPath(fileName, NULL, NULL, &ext);
 
     if (ext.empty())
     {
@@ -331,22 +330,13 @@ bool wxDocument::SaveAs()
         fileName += docTemplate->GetDefaultExtension();
     }
 
-    SetFilename(fileName);
-    SetTitle(wxFileNameFromPath(fileName));
-
-    // Notify the views that the filename has changed
-    wxList::compatibility_iterator node = m_documentViews.GetFirst();
-    while (node)
-    {
-        wxView *view = (wxView *)node->GetData();
-        view->OnChangeFilename();
-        node = node->GetNext();
-    }
-
     // Files that were not saved correctly are not added to the FileHistory.
-    if (!OnSaveDocument(m_documentFile))
+    if (!OnSaveDocument(fileName))
         return false;
 
+    SetTitle(wxFileNameFromPath(fileName));
+    SetFilename(fileName, true);    // will call OnChangeFileName automatically
+
    // A file that doesn't use the default extension of its document template cannot be opened
    // via the FileHistory, so we do not add it.
    if (docTemplate->FileMatchesTemplate(fileName))
@@ -485,8 +475,8 @@ bool wxDocument::OnSaveModified()
                      GetUserReadableName()
                     ),
                     wxTheApp->GetAppDisplayName(),
-                    wxYES_NO | wxCANCEL | wxICON_QUESTION,
-                    GetDocumentWindow()
+                    wxYES_NO | wxCANCEL | wxICON_QUESTION | wxCENTRE,
+                    wxFindSuitableParent()
                  ) )
         {
             case wxNO:
@@ -566,6 +556,11 @@ void wxDocument::NotifyClosing()
 void wxDocument::SetFilename(const wxString& filename, bool notifyViews)
 {
     m_documentFile = filename;
+    OnChangeFilename(notifyViews);
+}
+
+void wxDocument::OnChangeFilename(bool notifyViews)
+{
     if ( notifyViews )
     {
         // Notify the views that the filename has changed
@@ -1509,7 +1504,7 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
             else
                 msgTitle = wxString(_("File error"));
 
-            (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK | wxICON_EXCLAMATION,
+            (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK | wxICON_EXCLAMATION | wxCENTRE,
                 parent);
 
             path = wxEmptyString;
@@ -1531,7 +1526,7 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
             // can only happen if the application changes the allowed templates in runtime.
             (void)wxMessageBox(_("Sorry, the format for this file is unknown."),
                                 _("Open File"),
-                                wxOK | wxICON_EXCLAMATION, wxFindSuitableParent());
+                                wxOK | wxICON_EXCLAMATION | wxCENTRE, wxFindSuitableParent());
         }
     }
     else