PageRenderTime 63ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/menu/FavoritesProvider.java

#
Java | 107 lines | 71 code | 8 blank | 28 comment | 4 complexity | f24363138795b6317b16d5ccba6e9a5a 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. * FavoritesProvider.java - Favorites list menu
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 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 javax.swing.event.*;
  25. import javax.swing.*;
  26. import java.awt.event.*;
  27. import org.gjt.sp.jedit.browser.*;
  28. import org.gjt.sp.jedit.io.*;
  29. import org.gjt.sp.jedit.*;
  30. //}}}
  31. public class FavoritesProvider 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. //{{{ ActionListeners
  43. ActionListener fileListener = new ActionListener()
  44. {
  45. public void actionPerformed(ActionEvent evt)
  46. {
  47. jEdit.openFile(view,evt.getActionCommand());
  48. }
  49. };
  50. ActionListener dirListener = new ActionListener()
  51. {
  52. public void actionPerformed(ActionEvent evt)
  53. {
  54. VFSBrowser.browseDirectory(view,
  55. evt.getActionCommand());
  56. }
  57. }; //}}}
  58. VFS.DirectoryEntry[] favorites
  59. = FavoritesVFS.getFavorites();
  60. if(favorites.length == 0)
  61. {
  62. JMenuItem mi = new JMenuItem(
  63. jEdit.getProperty(
  64. "vfs.browser.favorites"
  65. + ".no-favorites.label"));
  66. mi.setEnabled(false);
  67. menu.add(mi);
  68. }
  69. else
  70. {
  71. MiscUtilities.quicksort(favorites,
  72. new VFS.DirectoryEntryCompare(
  73. jEdit.getBooleanProperty("vfs.browser.sortMixFilesAndDirs"),
  74. jEdit.getBooleanProperty("vfs.browser.sortIgnoreCase")));
  75. for(int i = 0; i < favorites.length; i++)
  76. {
  77. VFS.DirectoryEntry favorite
  78. = favorites[i];
  79. JMenuItem mi = new JMenuItem(favorite.path);
  80. mi.setIcon(FileCellRenderer
  81. .getIconForFile(
  82. favorite,false));
  83. if(favorite.type ==
  84. VFS.DirectoryEntry.FILE)
  85. {
  86. mi.addActionListener(fileListener);
  87. }
  88. else
  89. {
  90. mi.addActionListener(dirListener);
  91. }
  92. menu.add(mi);
  93. }
  94. }
  95. } //}}}
  96. //{{{ Private members
  97. private String dir;
  98. //}}}
  99. }