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

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/search/DirectoryListSet.java

#
Java | 164 lines | 98 code | 18 blank | 48 comment | 3 complexity | d4c09b9eedb50a14da01a8d7c4c01bce 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. * DirectoryListSet.java - Directory list matcher
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 1999, 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.search;
  23. //{{{ Imports
  24. import javax.swing.SwingUtilities;
  25. import java.awt.Component;
  26. import java.io.*;
  27. import org.gjt.sp.jedit.io.*;
  28. import org.gjt.sp.jedit.*;
  29. import org.gjt.sp.util.Log;
  30. //}}}
  31. /**
  32. * Recursive directory search.
  33. * @author Slava Pestov
  34. * @version $Id: DirectoryListSet.java 5427 2006-05-27 08:14:07Z kpouer $
  35. */
  36. public class DirectoryListSet extends BufferListSet
  37. {
  38. //{{{ DirectoryListSet constructor
  39. public DirectoryListSet(String directory, String glob, boolean recurse)
  40. {
  41. this.directory = directory;
  42. this.glob = glob;
  43. this.recurse = recurse;
  44. this.skipBinary = jEdit.getBooleanProperty("search.skipBinary.toggle");
  45. this.skipHidden = jEdit.getBooleanProperty("search.skipHidden.toggle");
  46. } //}}}
  47. //{{{ getDirectory() method
  48. public String getDirectory()
  49. {
  50. return directory;
  51. } //}}}
  52. //{{{ setDirectory() method
  53. /**
  54. * @since jEdit 4.2pre1
  55. */
  56. public void setDirectory(String directory)
  57. {
  58. this.directory = directory;
  59. invalidateCachedList();
  60. } //}}}
  61. //{{{ getFileFilter() method
  62. public String getFileFilter()
  63. {
  64. return glob;
  65. } //}}}
  66. //{{{ setFileFilter() method
  67. /**
  68. * @since jEdit 4.2pre1
  69. */
  70. public void setFileFilter(String glob)
  71. {
  72. this.glob = glob;
  73. invalidateCachedList();
  74. } //}}}
  75. //{{{ isRecursive() method
  76. public boolean isRecursive()
  77. {
  78. return recurse;
  79. } //}}}
  80. //{{{ setRecursive() method
  81. /**
  82. * @since jEdit 4.2pre1
  83. */
  84. public void setRecursive(boolean recurse)
  85. {
  86. this.recurse = recurse;
  87. invalidateCachedList();
  88. } //}}}
  89. //{{{ getCode() method
  90. public String getCode()
  91. {
  92. return "new DirectoryListSet(\"" + MiscUtilities.charsToEscapes(directory)
  93. + "\",\"" + MiscUtilities.charsToEscapes(glob) + "\","
  94. + recurse + ")";
  95. } //}}}
  96. //{{{ _getFiles() method
  97. protected String[] _getFiles(final Component comp)
  98. {
  99. this.skipBinary = jEdit.getBooleanProperty("search.skipBinary.toggle");
  100. this.skipHidden = jEdit.getBooleanProperty("search.skipHidden.toggle");
  101. final VFS vfs = VFSManager.getVFSForPath(directory);
  102. Object session;
  103. if(SwingUtilities.isEventDispatchThread())
  104. {
  105. session = vfs.createVFSSession(directory,comp);
  106. }
  107. else
  108. {
  109. final Object[] returnValue = new Object[1];
  110. try
  111. {
  112. SwingUtilities.invokeAndWait(new Runnable()
  113. {
  114. public void run()
  115. {
  116. returnValue[0] = vfs.createVFSSession(directory,comp);
  117. }
  118. });
  119. }
  120. catch(Exception e)
  121. {
  122. Log.log(Log.ERROR,this,e);
  123. }
  124. session = returnValue[0];
  125. }
  126. if(session == null)
  127. return null;
  128. try
  129. {
  130. return vfs._listDirectory(session,directory,glob,recurse,comp, skipBinary, skipHidden);
  131. }
  132. catch(IOException io)
  133. {
  134. VFSManager.error(comp,directory,"ioerror",new String[]
  135. { io.toString() });
  136. return null;
  137. }
  138. } //}}}
  139. //{{{ Private members
  140. private String directory;
  141. private String glob;
  142. private boolean recurse;
  143. private boolean skipHidden;
  144. private boolean skipBinary;
  145. //}}}
  146. }