trackeditor: keep recently opened files and menu items in sync

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@8289 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 8915ee0fef8bcac19d8170b92bc83537d0b8e85d
Former-commit-id: 85676231cde25b068d7b68c6ff0c5f762cbe1f8a
This commit is contained in:
iobyte 2022-07-01 20:22:53 +00:00
parent bd56bcd310
commit 88241deaa4

View file

@ -136,7 +136,7 @@ public class EditorFrame extends JFrame
private JToolBar jToolBar = null;
private JMenuItem newMenuItem = null;
private JMenuItem openMenuItem = null;
private JMenu recentFilesMenu = null;
private JMenu recentFilesMenu = null;
private JButton saveButton = null;
private JButton openButton = null;
private JButton helpButton = null;
@ -250,6 +250,34 @@ public class EditorFrame extends JFrame
preferences.remove(RECENT_FILES_STRING+i);
}
}
for (int i = 0; i < recentFiles.size(); i++)
{
if (recentFilesMenu.getItem(i) != null)
{
if (recentFilesMenu.getItem(i).getText() != recentFiles.get(i))
{
recentFilesMenu.getItem(i).setText(recentFiles.get(i));
}
}
else
{
addRecentFilesMenuItem(recentFiles.get(i));
}
}
}
private void addRecentFilesMenuItem(String filename)
{
JMenuItem recentFileMenuItem = new JMenuItem(filename);
recentFileMenuItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
openProject(((JMenuItem) e.getSource()).getText());
}
});
recentFilesMenu.add(recentFileMenuItem);
}
/**
@ -625,15 +653,7 @@ public class EditorFrame extends JFrame
if (!file.equals(""))
{
recentFiles.add(file);
JMenuItem recentFileMenuItem = new JMenuItem(file);
recentFileMenuItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
openProject(((JMenuItem) e.getSource()).getText());
}
});
recentFilesMenu.add(recentFileMenuItem);
addRecentFilesMenuItem(file);
}
else
{