]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/docview.cpp
All char, char *, and char arrays changed to use wxChar or wxString. 99% backward...
[wxWidgets.git] / src / common / docview.cpp
index 50bd316bea94b5e576e0c1db2394f58df9260215..b745d1fbb1635b499e4f18488653c4bd86e79990 100644 (file)
@@ -1386,7 +1386,7 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
                 msgTitle = wxTheApp->GetAppName();
             else
                 msgTitle = wxString(_("File error"));
-            
+
             (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK | wxICON_EXCLAMATION,
                 parent);
 
@@ -1435,21 +1435,40 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
 }
 
 wxDocTemplate *wxDocManager::SelectDocumentType(wxDocTemplate **templates,
-                                                int noTemplates)
+                                                int noTemplates, bool sort)
 {
-    wxArrayString strings;
+    wxArrayString strings(sort);
     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;
 
@@ -1483,9 +1502,9 @@ wxDocTemplate *wxDocManager::SelectDocumentType(wxDocTemplate **templates,
 }
 
 wxDocTemplate *wxDocManager::SelectViewType(wxDocTemplate **templates,
-                                            int noTemplates)
+                                            int noTemplates, bool sort)
 {
-    wxArrayString strings;
+    wxArrayString strings(sort);
     wxDocTemplate **data = new wxDocTemplate *[noTemplates];
     int i;
     int n = 0;
@@ -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
@@ -2040,22 +2078,29 @@ wxFileHistory::~wxFileHistory()
 void wxFileHistory::AddFileToHistory(const wxString& file)
 {
     int i;
+
     // Check we don't already have this file
     for (i = 0; i < m_fileHistoryN; i++)
     {
-        if (m_fileHistory[i] && wxString(m_fileHistory[i]) == file)
+        if ( m_fileHistory[i] && (file == m_fileHistory[i]) )
+        {
+            // we do have it, move it to the top of the history
+            RemoveFileFromHistory (i);
+            AddFileToHistory (file);
             return;
+        }
     }
 
-    // Add to the project file history:
-    // Move existing files (if any) down so we can insert file at beginning.
-
-    // First delete filename that has popped off the end of the array (if any)
-    if (m_fileHistoryN == m_fileMaxFiles)
+    // if we already have a full history, delete the one at the end
+    if ( m_fileMaxFiles == m_fileHistoryN )
     {
-        delete[] m_fileHistory[m_fileMaxFiles-1];
-        m_fileHistory[m_fileMaxFiles-1] = (wxChar *) NULL;
+        RemoveFileFromHistory (m_fileHistoryN - 1);
+        AddFileToHistory (file);
+        return;
     }
+
+    // Add to the project file history:
+    // Move existing files (if any) down so we can insert file at beginning.
     if (m_fileHistoryN < m_fileMaxFiles)
     {
         wxNode* node = m_fileMenus.First();
@@ -2076,19 +2121,40 @@ void wxFileHistory::AddFileToHistory(const wxString& file)
     }
     m_fileHistory[0] = copystring(file);
 
+    // this is the directory of the last opened file
+    wxString pathCurrent;
+    wxSplitPath( m_fileHistory[0], &pathCurrent, NULL, NULL );
     for (i = 0; i < m_fileHistoryN; i++)
-        if (m_fileHistory[i])
+    {
+        if ( m_fileHistory[i] )
         {
+            // if in same directory just show the filename; otherwise the full
+            // path
+            wxString pathInMenu, path, filename, ext;
+            wxSplitPath( m_fileHistory[i], &path, &filename, &ext );
+            if ( path == pathCurrent )
+            {
+                pathInMenu = filename;
+                if ( !ext.empty() )
+                    pathInMenu = pathInMenu + wxFILE_SEP_EXT + ext;
+            }
+            else
+            {
+                // absolute path; could also set relative path
+                pathInMenu = m_fileHistory[i];
+            }
+
             wxString buf;
-            buf.Printf(s_MRUEntryFormat, i+1, m_fileHistory[i]);
+            buf.Printf(s_MRUEntryFormat, i + 1, pathInMenu.c_str());
             wxNode* node = m_fileMenus.First();
             while (node)
             {
                 wxMenu* menu = (wxMenu*) node->Data();
-                menu->SetLabel(wxID_FILE1+i, buf);
+                menu->SetLabel(wxID_FILE1 + i, buf);
                 node = node->Next();
             }
         }
+    }
 }
 
 void wxFileHistory::RemoveFileFromHistory(int i)