PageRenderTime 245ms CodeModel.GetById 6ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre3/org/gjt/sp/jedit/io/FavoritesVFS.java

#
Java | 166 lines | 98 code | 18 blank | 50 comment | 4 complexity | 815357d754ed6b889a13393780534142 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. * FavoritesVFS.java - Stores frequently-visited directory locations
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2000 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.io;
  23. //{{{ Imports
  24. import java.awt.Component;
  25. import java.util.Vector;
  26. import org.gjt.sp.jedit.jEdit;
  27. //}}}
  28. /**
  29. * A VFS used for remembering frequently-visited directories. Listing it
  30. * returns the favorites list. The deletePath of each entry is the
  31. * directory prefixed with "favorites:" so that right-clicking on a
  32. * favorite and clicking 'delete' in the browser just deletes the
  33. * favorite, and not the directory itself.
  34. * @author Slava Pestov
  35. * @version $Id: FavoritesVFS.java 3905 2001-11-23 09:08:49Z spestov $
  36. */
  37. public class FavoritesVFS extends VFS
  38. {
  39. public static final String PROTOCOL = "favorites";
  40. //{{{ FavoritesVFS constructor
  41. public FavoritesVFS()
  42. {
  43. super("favorites");
  44. /* addToFavorites(), which is a static method
  45. * (for convinience) needs an instance of the
  46. * VFS to pass to VFSManager.sendVFSUpdate(),
  47. * hence this hack. */
  48. instance = this;
  49. } //}}}
  50. //{{{ getCapabilities() method
  51. public int getCapabilities()
  52. {
  53. // BROWSE_CAP not set because we don't want the VFS browser
  54. // to create the default 'favorites' button on the tool bar
  55. return /* BROWSE_CAP | */ DELETE_CAP;
  56. } //}}}
  57. //{{{ getParentOfPath() method
  58. public String getParentOfPath(String path)
  59. {
  60. return PROTOCOL + ":";
  61. } //}}}
  62. //{{{ _listDirectory() method
  63. public VFS.DirectoryEntry[] _listDirectory(Object session, String url,
  64. Component comp)
  65. {
  66. synchronized(lock)
  67. {
  68. VFS.DirectoryEntry[] retVal = new VFS.DirectoryEntry[favorites.size()];
  69. for(int i = 0; i < retVal.length; i++)
  70. {
  71. String favorite = (String)favorites.elementAt(i);
  72. retVal[i] = _getDirectoryEntry(session,favorite,comp);
  73. }
  74. return retVal;
  75. }
  76. } //}}}
  77. //{{{ _getDirectoryEntry() method
  78. public DirectoryEntry _getDirectoryEntry(Object session, String path,
  79. Component comp)
  80. {
  81. return new VFS.DirectoryEntry(path,path,"favorites:" + path,
  82. VFS.DirectoryEntry.DIRECTORY,
  83. 0L,false);
  84. } //}}}
  85. //{{{ _delete() method
  86. public boolean _delete(Object session, String path, Component comp)
  87. {
  88. synchronized(lock)
  89. {
  90. path = path.substring(PROTOCOL.length() + 1);
  91. favorites.removeElement(path);
  92. VFSManager.sendVFSUpdate(this,PROTOCOL + ":",false);
  93. }
  94. return true;
  95. } //}}}
  96. //{{{ loadFavorites() method
  97. public static void loadFavorites()
  98. {
  99. synchronized(lock)
  100. {
  101. String favorite;
  102. int i = 0;
  103. while((favorite = jEdit.getProperty("vfs.favorite." + i)) != null)
  104. {
  105. favorites.addElement(favorite);
  106. i++;
  107. }
  108. }
  109. } //}}}
  110. //{{{ addToFavorites() method
  111. public static void addToFavorites(String path)
  112. {
  113. synchronized(lock)
  114. {
  115. if(!favorites.contains(path))
  116. favorites.addElement(path);
  117. VFSManager.sendVFSUpdate(instance,PROTOCOL + ":",false);
  118. }
  119. } //}}}
  120. //{{{ saveFavorites() method
  121. public static void saveFavorites()
  122. {
  123. synchronized(lock)
  124. {
  125. for(int i = 0; i < favorites.size(); i++)
  126. {
  127. jEdit.setProperty("vfs.favorite." + i,
  128. (String)favorites.elementAt(i));
  129. }
  130. jEdit.unsetProperty("vfs.favorite." + favorites.size());
  131. }
  132. } //}}}
  133. //{{{ getFavorites() method
  134. public static String[] getFavorites()
  135. {
  136. synchronized(lock)
  137. {
  138. String[] retVal = new String[favorites.size()];
  139. favorites.copyInto(retVal);
  140. return retVal;
  141. }
  142. } //}}}
  143. //{{{ Private members
  144. private static FavoritesVFS instance;
  145. private static Object lock = new Object();
  146. private static Vector favorites = new Vector();
  147. //}}}
  148. }