From: Julian Smart <julian@anthemion.co.uk>
Date: Thu, 3 Jun 2004 19:04:16 +0000 (+0000)
Subject: If several doc templates use the same document and view classes, they should
X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/041295149d0db765378978f2f47d8dd8ee82b1ab

If several doc templates use the same document and view classes, they should
share their filters in Save As


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27602 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---

diff --git a/include/wx/docview.h b/include/wx/docview.h
index 08a9a3ce44..0d005d04b6 100644
--- a/include/wx/docview.h
+++ b/include/wx/docview.h
@@ -276,6 +276,9 @@ public:
 
     bool IsVisible() const { return ((m_flags & wxTEMPLATE_VISIBLE) == wxTEMPLATE_VISIBLE); }
 
+    wxClassInfo* GetDocClassInfo() const { return m_docClassInfo; }
+    wxClassInfo* GetViewClassInfo() const { return m_viewClassInfo; }
+
     virtual bool FileMatchesTemplate(const wxString& path);
 
 protected:
diff --git a/src/common/docview.cpp b/src/common/docview.cpp
index f77b00cdbd..d881e212d1 100644
--- a/src/common/docview.cpp
+++ b/src/common/docview.cpp
@@ -253,11 +253,42 @@ bool wxDocument::SaveAs()
     if (!docTemplate)
         return FALSE;
 
+#if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXMAC__)
+    wxString filter = docTemplate->GetDescription() + wxT(" (") + docTemplate->GetFileFilter() + wxT(")|") + docTemplate->GetFileFilter();
+
+    // Now see if there are some other template with identical view and document
+    // classes, whose filters may also be used.
+
+    if (docTemplate->GetViewClassInfo() && docTemplate->GetDocClassInfo())
+    {
+        wxObjectListNode* node = wxDocManager::GetDocumentManager()->GetTemplates().GetFirst();
+        while (node)
+        {
+            wxDocTemplate *t = (wxDocTemplate*) node->GetData();
+            
+            if (t->IsVisible() && t != docTemplate &&
+                t->GetViewClassInfo() == docTemplate->GetViewClassInfo() &&
+                t->GetDocClassInfo() == docTemplate->GetDocClassInfo())
+            {
+                // add a '|' to separate this filter from the previous one
+                if ( !filter.IsEmpty() )
+                    filter << wxT('|');
+                
+                filter << t->GetDescription() << wxT(" (") << t->GetFileFilter() << wxT(") |")
+                       << t->GetFileFilter();
+            }
+
+            node = node->GetNext();
+        }
+    }
+#else
+    wxString filter = docTemplate->GetFileFilter() ;
+#endif
     wxString tmp = wxFileSelector(_("Save as"),
             docTemplate->GetDirectory(),
             wxFileNameFromPath(GetFilename()),
             docTemplate->GetDefaultExtension(),
-            docTemplate->GetFileFilter(),
+            filter,
             wxSAVE | wxOVERWRITE_PROMPT,
             GetDocumentWindow());