]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/docview.cpp
Removed rundant files, updated readme.txt.
[wxWidgets.git] / src / common / docview.cpp
index 95b9f93b460ad1244cd01235811084ab31a175c7..78f6ea18ef1eafd77d21e567566098c5d57f0627 100644 (file)
@@ -40,6 +40,7 @@
     #include "wx/list.h"
     #include "wx/filedlg.h"
     #include "wx/intl.h"
+    #include "wx/log.h"
 #endif
 
 
@@ -164,6 +165,8 @@ bool wxDocument::Close()
 
 bool wxDocument::OnCloseDocument()
 {
+    // Tell all views that we're about to close
+    NotifyClosing();    
     DeleteContents();
     Modify(FALSE);
     return TRUE;
@@ -341,7 +344,8 @@ bool wxDocument::OnOpenDocument(const wxString& file)
         return FALSE;
     }
 #if wxUSE_STD_IOSTREAM
-    if (!LoadObject(store))
+    LoadObject(store);
+    if ( !store && !store.eof() )
 #else
     int res = LoadObject(store).LastError();
     if ((res != wxSTREAM_NOERROR) &&
@@ -507,6 +511,17 @@ void wxDocument::UpdateAllViews(wxView *sender, wxObject *hint)
     }
 }
 
+void wxDocument::NotifyClosing()
+{
+    wxNode *node = m_documentViews.First();
+    while (node)
+    {
+        wxView *view = (wxView *)node->Data();
+        view->OnClosingDocument();
+        node = node->Next();
+    }
+}
+
 void wxDocument::SetFilename(const wxString& filename, bool notifyViews)
 {
     m_documentFile = filename;
@@ -593,7 +608,7 @@ bool wxView::Close(bool deleteWindow)
 
 void wxView::Activate(bool activate)
 {
-    if (GetDocumentManager())
+    if (GetDocument() && GetDocumentManager())
     {
         OnActivateView(activate, this, GetDocumentManager()->GetCurrentView());
         GetDocumentManager()->ActivateView(this, activate);
@@ -698,6 +713,7 @@ bool wxDocTemplate::FileMatchesTemplate(const wxString& path)
 BEGIN_EVENT_TABLE(wxDocManager, wxEvtHandler)
     EVT_MENU(wxID_OPEN, wxDocManager::OnFileOpen)
     EVT_MENU(wxID_CLOSE, wxDocManager::OnFileClose)
+    EVT_MENU(wxID_CLOSE_ALL, wxDocManager::OnFileCloseAll)
     EVT_MENU(wxID_REVERT, wxDocManager::OnFileRevert)
     EVT_MENU(wxID_NEW, wxDocManager::OnFileNew)
     EVT_MENU(wxID_SAVE, wxDocManager::OnFileSave)
@@ -707,6 +723,7 @@ BEGIN_EVENT_TABLE(wxDocManager, wxEvtHandler)
 
     EVT_UPDATE_UI(wxID_OPEN, wxDocManager::OnUpdateFileOpen)
     EVT_UPDATE_UI(wxID_CLOSE, wxDocManager::OnUpdateFileClose)
+    EVT_UPDATE_UI(wxID_CLOSE_ALL, wxDocManager::OnUpdateFileClose)
     EVT_UPDATE_UI(wxID_REVERT, wxDocManager::OnUpdateFileRevert)
     EVT_UPDATE_UI(wxID_NEW, wxDocManager::OnUpdateFileNew)
     EVT_UPDATE_UI(wxID_SAVE, wxDocManager::OnUpdateFileSave)
@@ -747,7 +764,7 @@ wxDocManager::~wxDocManager()
     sm_docManager = (wxDocManager*) NULL;
 }
 
-bool wxDocManager::Clear(bool force)
+bool wxDocManager::CloseDocuments(bool force)
 {
     wxNode *node = m_docs.First();
     while (node)
@@ -771,7 +788,15 @@ bool wxDocManager::Clear(bool force)
         // delete another.
         node = next;
     }
-    node = m_templates.First();
+    return TRUE;
+}
+
+bool wxDocManager::Clear(bool force)
+{
+    if (!CloseDocuments(force))
+        return FALSE;
+
+    wxNode *node = m_templates.First();
     while (node)
     {
         wxDocTemplate *templ = (wxDocTemplate*) node->Data();
@@ -806,6 +831,11 @@ void wxDocManager::OnFileClose(wxCommandEvent& WXUNUSED(event))
     }
 }
 
+void wxDocManager::OnFileCloseAll(wxCommandEvent& WXUNUSED(event))
+{
+    CloseDocuments(FALSE);
+}
+
 void wxDocManager::OnFileNew(wxCommandEvent& WXUNUSED(event))
 {
     CreateDocument(wxString(""), wxDOC_NEW);
@@ -945,7 +975,7 @@ void wxDocManager::OnUpdateFileNew(wxUpdateUIEvent& event)
 void wxDocManager::OnUpdateFileSave(wxUpdateUIEvent& event)
 {
     wxDocument *doc = GetCurrentDocument();
-    event.Enable( (doc != (wxDocument*) NULL) );
+    event.Enable( doc && doc->IsModified() );
 }
 
 void wxDocManager::OnUpdateFileSaveAs(wxUpdateUIEvent& event)
@@ -958,12 +988,16 @@ void wxDocManager::OnUpdateUndo(wxUpdateUIEvent& event)
 {
     wxDocument *doc = GetCurrentDocument();
     event.Enable( (doc && doc->GetCommandProcessor() && doc->GetCommandProcessor()->CanUndo()) );
+    if (doc && doc->GetCommandProcessor())
+        doc->GetCommandProcessor()->SetMenuStrings();
 }
 
 void wxDocManager::OnUpdateRedo(wxUpdateUIEvent& event)
 {
     wxDocument *doc = GetCurrentDocument();
     event.Enable( (doc && doc->GetCommandProcessor() && doc->GetCommandProcessor()->CanRedo()) );
+    if (doc && doc->GetCommandProcessor())
+        doc->GetCommandProcessor()->SetMenuStrings();
 }
 
 void wxDocManager::OnUpdatePrint(wxUpdateUIEvent& event)
@@ -1176,8 +1210,9 @@ bool wxDocManager::FlushDoc(wxDocument *WXUNUSED(doc))
 
 wxDocument *wxDocManager::GetCurrentDocument() const
 {
-    if (m_currentView)
-        return m_currentView->GetDocument();
+    wxView *view = GetCurrentView();
+    if (view)
+        return view->GetDocument();
     else
         return (wxDocument *) NULL;
 }
@@ -1441,13 +1476,26 @@ wxDocTemplate *wxDocManager::SelectDocumentType(wxDocTemplate **templates,
     wxDocTemplate **data = new wxDocTemplate *[noTemplates];
     int i;
     int n = 0;
+        
        for (i = 0; i < noTemplates; i++)
        {
                if (templates[i]->IsVisible())
                {
-                       strings.Add(templates[i]->m_description);
-                       if (!sort)
+               int j;
+            bool want = TRUE;
+                       for (j = 0; j < n; j++)
+                       {
+                //filter out NOT unique documents + view combinations
+                               if ( templates[i]->m_docTypeName == data[j]->m_docTypeName &&
+                     templates[i]->m_viewTypeName == data[j]->m_viewTypeName
+                   )
+                    want = FALSE;
+                       }
+
+            if ( want )
                        {
+                       strings.Add(templates[i]->m_description);
+
                                data[n] = templates[i];
                                n ++;
                        }
@@ -1508,14 +1556,24 @@ wxDocTemplate *wxDocManager::SelectViewType(wxDocTemplate **templates,
     wxDocTemplate **data = new wxDocTemplate *[noTemplates];
     int i;
     int n = 0;
+        
     for (i = 0; i < noTemplates; i++)
     {
         wxDocTemplate *templ = templates[i];
         if ( templ->IsVisible() && !templ->GetViewName().empty() )
         {
-            strings.Add(templ->m_viewTypeName);
-                       if (!sort)
+               int j;
+            bool want = TRUE;
+                       for (j = 0; j < n; j++)
                        {
+                //filter out NOT unique views
+                               if ( templates[i]->m_viewTypeName == data[j]->m_viewTypeName )
+                    want = FALSE;
+                       }
+
+            if ( want )
+            {
+                       strings.Add(templ->m_viewTypeName);
                                data[n] = templ;
                                n ++;
                        }