]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/docview.cpp
fingers crossed..
[wxWidgets.git] / src / common / docview.cpp
index 02fdca8fe46e8164b25e0fd330ad1bd7c6855ae3..18e348c044006a7b7a0c563b8c793a7368159807 100644 (file)
@@ -230,7 +230,7 @@ bool wxDocument::Save()
 {
     bool ret = FALSE;
 
-    if (!IsModified()) return TRUE;
+    if (!IsModified() && m_savedYet) return TRUE;
     if (m_documentFile == wxT("") || !m_savedYet)
         ret = SaveAs();
     else
@@ -248,7 +248,7 @@ bool wxDocument::SaveAs()
 
     wxString tmp = wxFileSelector(_("Save as"),
             docTemplate->GetDirectory(),
-            GetFilename(),
+            wxFileNameFromPath(GetFilename()),
             docTemplate->GetDefaultExtension(),
             docTemplate->GetFileFilter(),
             wxSAVE | wxOVERWRITE_PROMPT,
@@ -296,7 +296,7 @@ bool wxDocument::OnSaveDocument(const wxString& file)
         msgTitle = wxString(_("File error"));
 
 #if wxUSE_STD_IOSTREAM
-    ofstream store(wxString(file.fn_str()).mb_str());
+    wxSTD ofstream store(wxString(file.fn_str()).mb_str());
     if (store.fail() || store.bad())
 #else
     wxFileOutputStream store(wxString(file.fn_str()));
@@ -332,7 +332,7 @@ bool wxDocument::OnOpenDocument(const wxString& file)
         msgTitle = wxString(_("File error"));
 
 #if wxUSE_STD_IOSTREAM
-    ifstream store(wxString(file.fn_str()).mb_str());
+    wxSTD ifstream store(wxString(file.fn_str()).mb_str());
     if (store.fail() || store.bad())
 #else
     wxFileInputStream store(wxString(file.fn_str()));
@@ -365,7 +365,7 @@ bool wxDocument::OnOpenDocument(const wxString& file)
 }
 
 #if wxUSE_STD_IOSTREAM
-istream& wxDocument::LoadObject(istream& stream)
+wxSTD istream& wxDocument::LoadObject(wxSTD istream& stream)
 #else
 wxInputStream& wxDocument::LoadObject(wxInputStream& stream)
 #endif
@@ -374,7 +374,7 @@ wxInputStream& wxDocument::LoadObject(wxInputStream& stream)
 }
 
 #if wxUSE_STD_IOSTREAM
-ostream& wxDocument::SaveObject(ostream& stream)
+wxSTD ostream& wxDocument::SaveObject(wxSTD ostream& stream)
 #else
 wxOutputStream& wxDocument::SaveObject(wxOutputStream& stream)
 #endif
@@ -1441,15 +1441,34 @@ 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);
-            data[n] = templates[i];
-            n ++;
-        }
-    }
+       for (i = 0; i < noTemplates; i++)
+       {
+               if (templates[i]->IsVisible())
+               {
+                       strings.Add(templates[i]->m_description);
+                       if (!sort)
+                       {
+                               data[n] = templates[i];
+                               n ++;
+                       }
+               }
+       }  // for
+
+       if (sort)
+       {
+               // Yes, this will be slow, but template lists
+               // are typically short.
+               int j;
+               n = strings.Count();
+               for (i = 0; i < n; i++)
+               {
+                       for (j = 0; j < noTemplates; j++)
+                       {
+                               if (strings[i] == templates[j]->m_description)
+                                       data[i] = templates[j];
+                       }
+               }
+       }
 
     wxDocTemplate *theTemplate;
 
@@ -1495,11 +1514,30 @@ wxDocTemplate *wxDocManager::SelectViewType(wxDocTemplate **templates,
         if ( templ->IsVisible() && !templ->GetViewName().empty() )
         {
             strings.Add(templ->m_viewTypeName);
-            data[n] = templ;
-            n ++;
+                       if (!sort)
+                       {
+                               data[n] = templ;
+                               n ++;
+                       }
         }
     }
 
+       if (sort)
+       {
+               // Yes, this will be slow, but template lists
+               // are typically short.
+               int j;
+               n = strings.Count();
+               for (i = 0; i < n; i++)
+               {
+                       for (j = 0; j < noTemplates; j++)
+                       {
+                               if (strings[i] == templates[j]->m_viewTypeName)
+                                       data[i] = templates[j];
+                       }
+               }
+       }
+
     wxDocTemplate *theTemplate;
 
     // the same logic as above
@@ -2124,11 +2162,6 @@ void wxFileHistory::RemoveFileFromHistory(int i)
     wxCHECK_RET( i < m_fileHistoryN,
                  wxT("invalid index in wxFileHistory::RemoveFileFromHistory") );
 
-    wxNode* node = m_fileMenus.First();
-    while ( node )
-    {
-        wxMenu* menu = (wxMenu*) node->Data();
-
         // delete the element from the array (could use memmove() too...)
         delete [] m_fileHistory[i];
 
@@ -2138,6 +2171,12 @@ void wxFileHistory::RemoveFileFromHistory(int i)
             m_fileHistory[j] = m_fileHistory[j + 1];
         }
 
+    wxNode* node = m_fileMenus.First();
+    while ( node )
+    {
+        wxMenu* menu = (wxMenu*) node->Data();
+
+
         // shuffle filenames up
         wxString buf;
         for ( j = i; j < m_fileHistoryN - 1; j++ )
@@ -2149,6 +2188,7 @@ void wxFileHistory::RemoveFileFromHistory(int i)
         node = node->Next();
 
         // delete the last menu item which is unused now
+        if (menu->FindItem(wxID_FILE1 + m_fileHistoryN - 1))
         menu->Delete(wxID_FILE1 + m_fileHistoryN - 1);
 
         // delete the last separator too if no more files are left
@@ -2274,7 +2314,7 @@ void wxFileHistory::AddFilesToMenu(wxMenu* menu)
 // ----------------------------------------------------------------------------
 
 #if wxUSE_STD_IOSTREAM
-bool wxTransferFileToStream(const wxString& filename, ostream& stream)
+bool wxTransferFileToStream(const wxString& filename, wxSTD ostream& stream)
 {
     FILE *fd1;
     int ch;
@@ -2289,7 +2329,7 @@ bool wxTransferFileToStream(const wxString& filename, ostream& stream)
     return TRUE;
 }
 
-bool wxTransferStreamToFile(istream& stream, const wxString& filename)
+bool wxTransferStreamToFile(wxSTD istream& stream, const wxString& filename)
 {
     FILE *fd1;
     int ch;