PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/menu/RecentFilesProvider.java

#
Java | 153 lines | 88 code | 19 blank | 46 comment | 9 complexity | debe5349ea09e15c1ccd7bde0cfac548 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. * RecentFilesProvider.java - Recent file list menu
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2000, 2003 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.menu;
  23. //{{{ Imports
  24. import java.awt.event.*;
  25. import javax.swing.*;
  26. import javax.swing.event.*;
  27. import java.util.*;
  28. import org.gjt.sp.jedit.browser.FileCellRenderer;
  29. import org.gjt.sp.jedit.*;
  30. //}}}
  31. public class RecentFilesProvider implements DynamicMenuProvider
  32. {
  33. //{{{ updateEveryTime() method
  34. public boolean updateEveryTime()
  35. {
  36. return false;
  37. } //}}}
  38. //{{{ update() method
  39. public void update(JMenu menu)
  40. {
  41. final View view = GUIUtilities.getView(menu);
  42. //{{{ ActionListener...
  43. ActionListener actionListener = new ActionListener()
  44. {
  45. public void actionPerformed(ActionEvent evt)
  46. {
  47. jEdit.openFile(view,evt.getActionCommand());
  48. view.getStatus().setMessage(null);
  49. }
  50. }; //}}}
  51. //{{{ MouseListener...
  52. /*
  53. MouseListener mouseListener = new MouseAdapter()
  54. {
  55. public void mouseEntered(MouseEvent evt)
  56. {
  57. view.getStatus().setMessage(
  58. ((JMenuItem)evt.getSource())
  59. .getActionCommand());
  60. }
  61. public void mouseExited(MouseEvent evt)
  62. {
  63. view.getStatus().setMessage(null);
  64. }
  65. };
  66. */
  67. //}}}
  68. //{{{ ChangeListener...
  69. ChangeListener changeListener = new ChangeListener()
  70. {
  71. public void stateChanged(ChangeEvent e)
  72. {
  73. JMenuItem menuItem = (JMenuItem) e.getSource();
  74. view.getStatus().setMessage(menuItem.isArmed()?menuItem.getActionCommand():null);
  75. }
  76. }; //}}}
  77. List recentVector = BufferHistory.getHistory();
  78. if(recentVector.isEmpty())
  79. {
  80. JMenuItem menuItem = new JMenuItem(
  81. jEdit.getProperty("no-recent-files.label"));
  82. menuItem.setEnabled(false);
  83. menu.add(menuItem);
  84. return;
  85. }
  86. Vector menuItems = new Vector();
  87. boolean sort = jEdit.getBooleanProperty("sortRecent");
  88. int maxItems = jEdit.getIntegerProperty("menu.spillover",20);
  89. Iterator iter = recentVector.iterator();
  90. while(iter.hasNext())
  91. {
  92. String path = ((BufferHistory.Entry)iter.next()).path;
  93. JMenuItem menuItem = new JMenuItem(MiscUtilities
  94. .getFileName(path));
  95. menuItem.setActionCommand(path);
  96. menuItem.addActionListener(actionListener);
  97. // menuItem.addMouseListener(mouseListener);
  98. menuItem.addChangeListener(changeListener);
  99. menuItem.setIcon(FileCellRenderer.fileIcon);
  100. if(sort)
  101. menuItems.addElement(menuItem);
  102. else
  103. {
  104. if(menu.getMenuComponentCount() >= maxItems
  105. && iter.hasNext())
  106. {
  107. JMenu newMenu = new JMenu(
  108. jEdit.getProperty("common.more"));
  109. menu.add(newMenu);
  110. menu = newMenu;
  111. }
  112. menu.add(menuItem);
  113. }
  114. }
  115. if(sort)
  116. {
  117. Collections.sort(menuItems,
  118. new MiscUtilities.MenuItemCompare());
  119. for(int i = 0; i < menuItems.size(); i++)
  120. {
  121. if(menu.getMenuComponentCount() >= maxItems
  122. && i != 0)
  123. {
  124. JMenu newMenu = new JMenu(
  125. jEdit.getProperty("common.more"));
  126. menu.add(newMenu);
  127. menu = newMenu;
  128. }
  129. menu.add((JMenuItem)menuItems.elementAt(i));
  130. }
  131. }
  132. } //}}}
  133. }