+
+ // if we already have a full history, delete the one at the end
+ if ( m_fileMaxFiles == m_fileHistoryN )
+ {
+ 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();
+ while (node)
+ {
+ wxMenu* menu = (wxMenu*) node->Data();
+ if (m_fileHistoryN == 0)
+ menu->AppendSeparator();
+ menu->Append(wxID_FILE1+m_fileHistoryN, _("[EMPTY]"));
+ node = node->Next();
+ }
+ m_fileHistoryN ++;
+ }
+ // Shuffle filenames down
+ for (i = (m_fileHistoryN-1); i > 0; i--)
+ {
+ m_fileHistory[i] = m_fileHistory[i-1];
+ }
+ 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 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, pathInMenu.c_str());
+ wxNode* node = m_fileMenus.First();
+ while (node)
+ {
+ wxMenu* menu = (wxMenu*) node->Data();
+ menu->SetLabel(wxID_FILE1 + i, buf);
+ node = node->Next();
+ }
+ }
+ }
+}
+
+void wxFileHistory::RemoveFileFromHistory(int i)
+{
+ wxCHECK_RET( i < m_fileHistoryN,
+ wxT("invalid index in wxFileHistory::RemoveFileFromHistory") );
+
+ // delete the element from the array (could use memmove() too...)
+ delete [] m_fileHistory[i];
+
+ int j;
+ for ( j = i; j < m_fileHistoryN - 1; j++ )
+ {
+ 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++ )
+ {
+ buf.Printf(s_MRUEntryFormat, j + 1, m_fileHistory[j]);
+ menu->SetLabel(wxID_FILE1 + j, buf);
+ }
+
+ 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
+ if ( m_fileHistoryN == 1 )
+ {
+ wxMenuItemList::Node *node = menu->GetMenuItems().GetLast();
+ if ( node )
+ {
+ wxMenuItem *menuItem = node->GetData();
+ if ( menuItem->IsSeparator() )
+ {
+ menu->Delete(menuItem);
+ }
+ //else: should we search backwards for the last separator?
+ }
+ //else: menu is empty somehow
+ }
+ }
+
+ m_fileHistoryN--;