PageRenderTime 249ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 152 lines | 99 code | 22 blank | 31 comment | 21 complexity | 509672eff97ea99e59a06ff030eafb04 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. * CurrentDirectoryMenu.java - 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. import javax.swing.*;
  24. import java.awt.event.*;
  25. import java.io.File;
  26. import org.gjt.sp.jedit.browser.*;
  27. import org.gjt.sp.jedit.io.VFSManager;
  28. import org.gjt.sp.jedit.*;
  29. public class CurrentDirectoryMenu extends EnhancedMenu
  30. {
  31. //{{{ CurrentDirectoryMenu constructor
  32. public CurrentDirectoryMenu()
  33. {
  34. super("current-directory");
  35. } //}}}
  36. //{{{ setPopupMenuVisible() method
  37. public void setPopupMenuVisible(boolean b)
  38. {
  39. if(b)
  40. {
  41. final View view = GUIUtilities.getView(this);
  42. if(getMenuComponentCount() != 0)
  43. removeAll();
  44. final String path = MiscUtilities.getParentOfPath(
  45. view.getBuffer().getPath());
  46. JMenuItem mi = new JMenuItem(path);
  47. mi.setIcon(FileCellRenderer.openDirIcon);
  48. //{{{ Directory action listener...
  49. mi.addActionListener(new ActionListener()
  50. {
  51. public void actionPerformed(ActionEvent evt)
  52. {
  53. VFSBrowser.browseDirectory(view,path);
  54. }
  55. }); //}}}
  56. add(mi);
  57. addSeparator();
  58. if(view.getBuffer().getFile() == null)
  59. {
  60. mi = new JMenuItem(jEdit.getProperty(
  61. "current-directory.not-local"));
  62. mi.setEnabled(false);
  63. add(mi);
  64. super.setPopupMenuVisible(b);
  65. return;
  66. }
  67. File dir = new File(path);
  68. JMenu current = this;
  69. //{{{ ActionListener class
  70. ActionListener listener = new ActionListener()
  71. {
  72. public void actionPerformed(ActionEvent evt)
  73. {
  74. jEdit.openFile(view,evt.getActionCommand());
  75. }
  76. }; //}}}
  77. // for filtering out backups
  78. String backupPrefix = jEdit.getProperty("backup.prefix");
  79. String backupSuffix = jEdit.getProperty("backup.suffix");
  80. String[] list = dir.list();
  81. if(list == null || list.length == 0)
  82. {
  83. mi = new JMenuItem(jEdit.getProperty(
  84. "current-directory.no-files"));
  85. mi.setEnabled(false);
  86. add(mi);
  87. }
  88. else
  89. {
  90. MiscUtilities.quicksort(list,
  91. new MiscUtilities.StringICaseCompare());
  92. for(int i = 0; i < list.length; i++)
  93. {
  94. String name = list[i];
  95. // skip marker files
  96. if(name.endsWith(".marks"))
  97. continue;
  98. // skip autosave files
  99. if(name.startsWith("#") && name.endsWith("#"))
  100. continue;
  101. // skip backup files
  102. if((backupPrefix.length() != 0
  103. && name.startsWith(backupPrefix))
  104. || (backupSuffix.length() != 0
  105. && name.endsWith(backupSuffix)))
  106. continue;
  107. // skip directories
  108. File file = new File(path,name);
  109. if(file.isDirectory())
  110. continue;
  111. mi = new JMenuItem(name);
  112. mi.setActionCommand(file.getPath());
  113. mi.addActionListener(listener);
  114. mi.setIcon(FileCellRenderer.fileIcon);
  115. if(current.getItemCount() >= 20)
  116. {
  117. //current.addSeparator();
  118. JMenu newCurrent = new JMenu(
  119. jEdit.getProperty(
  120. "common.more"));
  121. current.add(newCurrent);
  122. current = newCurrent;
  123. }
  124. current.add(mi);
  125. }
  126. }
  127. }
  128. super.setPopupMenuVisible(b);
  129. } //}}}
  130. }