PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre3/org/gjt/sp/jedit/gui/RecentFilesMenu.java

#
Java | 131 lines | 83 code | 16 blank | 32 comment | 9 complexity | fbde589b86e1a89523de03132cdd7143 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * RecentFilesMenu.java - Recent file list menu
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2000, 2001 Slava Pestov
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. package org.gjt.sp.jedit.gui;
  23. //{{{ Imports
  24. import javax.swing.*;
  25. import java.awt.event.*;
  26. import java.util.Vector;
  27. import org.gjt.sp.jedit.browser.FileCellRenderer;
  28. import org.gjt.sp.jedit.io.VFSManager;
  29. import org.gjt.sp.jedit.io.VFS;
  30. import org.gjt.sp.jedit.*;
  31. //}}}
  32. public class RecentFilesMenu extends EnhancedMenu
  33. {
  34. //{{{ RecentFilesMenu constructor
  35. public RecentFilesMenu()
  36. {
  37. super("recent-files");
  38. } //}}}
  39. //{{{ setPopupMenuVisible() method
  40. public void setPopupMenuVisible(boolean b)
  41. {
  42. if(b)
  43. {
  44. final View view = GUIUtilities.getView(this);
  45. if(getMenuComponentCount() != 0)
  46. removeAll();
  47. //{{{ ActionListener...
  48. ActionListener actionListener = new ActionListener()
  49. {
  50. public void actionPerformed(ActionEvent evt)
  51. {
  52. jEdit.openFile(view,evt.getActionCommand());
  53. view.getStatus().setMessage(null);
  54. }
  55. }; //}}}
  56. //{{{ MouseListener...
  57. MouseListener mouseListener = new MouseAdapter()
  58. {
  59. public void mouseEntered(MouseEvent evt)
  60. {
  61. view.getStatus().setMessage(
  62. ((JMenuItem)evt.getSource())
  63. .getActionCommand());
  64. }
  65. public void mouseExited(MouseEvent evt)
  66. {
  67. view.getStatus().setMessage(null);
  68. }
  69. }; //}}}
  70. Vector recentVector = BufferHistory.getBufferHistory();
  71. if(recentVector.size() == 0)
  72. {
  73. add(GUIUtilities.loadMenuItem("no-recent-files"));
  74. super.setPopupMenuVisible(b);
  75. return;
  76. }
  77. Vector menuItems = new Vector();
  78. boolean sort = jEdit.getBooleanProperty("sortRecent");
  79. /*
  80. * While recentVector has 50 entries or so, we only display
  81. * a few of those in the menu (otherwise it will be way too
  82. * long)
  83. */
  84. int recentFileCount = Math.min(recentVector.size(),
  85. jEdit.getIntegerProperty("history",25));
  86. for(int i = recentVector.size() - 1;
  87. i >= recentVector.size() - recentFileCount;
  88. i--)
  89. {
  90. String path = ((BufferHistory.Entry)recentVector
  91. .elementAt(i)).path;
  92. VFS vfs = VFSManager.getVFSForPath(path);
  93. JMenuItem menuItem = new JMenuItem(vfs.getFileName(path));
  94. menuItem.setActionCommand(path);
  95. menuItem.addActionListener(actionListener);
  96. menuItem.addMouseListener(mouseListener);
  97. menuItem.setIcon(FileCellRenderer.fileIcon);
  98. if(sort)
  99. menuItems.addElement(menuItem);
  100. else
  101. add(menuItem);
  102. }
  103. if(sort)
  104. {
  105. MiscUtilities.quicksort(menuItems,
  106. new MiscUtilities.MenuItemCompare());
  107. for(int i = 0; i < menuItems.size(); i++)
  108. {
  109. add((JMenuItem)menuItems.elementAt(i));
  110. }
  111. }
  112. }
  113. super.setPopupMenuVisible(b);
  114. } //}}}
  115. }