001: /*
002: * DirectoryListSet.java - Directory list matcher
003: * :tabSize=8:indentSize=8:noTabs=false:
004: * :folding=explicit:collapseFolds=1:
005: *
006: * Copyright (C) 1999, 2000, 2001 Slava Pestov
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022:
023: package org.gjt.sp.jedit.search;
024:
025: //{{{ Imports
026: import javax.swing.SwingUtilities;
027: import java.awt.Component;
028: import java.io.*;
029: import org.gjt.sp.jedit.io.*;
030: import org.gjt.sp.jedit.*;
031: import org.gjt.sp.util.Log;
032:
033: //}}}
034:
035: /**
036: * Recursive directory search.
037: * @author Slava Pestov
038: * @version $Id: DirectoryListSet.java 5427 2006-05-27 08:14:07Z kpouer $
039: */
040: public class DirectoryListSet extends BufferListSet {
041: //{{{ DirectoryListSet constructor
042: public DirectoryListSet(String directory, String glob,
043: boolean recurse) {
044: this .directory = directory;
045: this .glob = glob;
046: this .recurse = recurse;
047: this .skipBinary = jEdit
048: .getBooleanProperty("search.skipBinary.toggle");
049: this .skipHidden = jEdit
050: .getBooleanProperty("search.skipHidden.toggle");
051: } //}}}
052:
053: //{{{ getDirectory() method
054: public String getDirectory() {
055: return directory;
056: } //}}}
057:
058: //{{{ setDirectory() method
059: /**
060: * @since jEdit 4.2pre1
061: */
062: public void setDirectory(String directory) {
063: this .directory = directory;
064: invalidateCachedList();
065: } //}}}
066:
067: //{{{ getFileFilter() method
068: public String getFileFilter() {
069: return glob;
070: } //}}}
071:
072: //{{{ setFileFilter() method
073: /**
074: * @since jEdit 4.2pre1
075: */
076: public void setFileFilter(String glob) {
077: this .glob = glob;
078: invalidateCachedList();
079: } //}}}
080:
081: //{{{ isRecursive() method
082: public boolean isRecursive() {
083: return recurse;
084: } //}}}
085:
086: //{{{ setRecursive() method
087: /**
088: * @since jEdit 4.2pre1
089: */
090: public void setRecursive(boolean recurse) {
091: this .recurse = recurse;
092: invalidateCachedList();
093: } //}}}
094:
095: //{{{ getCode() method
096: public String getCode() {
097: return "new DirectoryListSet(\""
098: + MiscUtilities.charsToEscapes(directory) + "\",\""
099: + MiscUtilities.charsToEscapes(glob) + "\"," + recurse
100: + ")";
101: } //}}}
102:
103: //{{{ _getFiles() method
104: protected String[] _getFiles(final Component comp) {
105: this .skipBinary = jEdit
106: .getBooleanProperty("search.skipBinary.toggle");
107: this .skipHidden = jEdit
108: .getBooleanProperty("search.skipHidden.toggle");
109: final VFS vfs = VFSManager.getVFSForPath(directory);
110: Object session;
111: if (SwingUtilities.isEventDispatchThread()) {
112: session = vfs.createVFSSession(directory, comp);
113: } else {
114: final Object[] returnValue = new Object[1];
115:
116: try {
117: SwingUtilities.invokeAndWait(new Runnable() {
118: public void run() {
119: returnValue[0] = vfs.createVFSSession(
120: directory, comp);
121: }
122: });
123: } catch (Exception e) {
124: Log.log(Log.ERROR, this , e);
125: }
126:
127: session = returnValue[0];
128: }
129:
130: if (session == null)
131: return null;
132:
133: try {
134: return vfs._listDirectory(session, directory, glob,
135: recurse, comp, skipBinary, skipHidden);
136: } catch (IOException io) {
137: VFSManager.error(comp, directory, "ioerror",
138: new String[] { io.toString() });
139: return null;
140: }
141: } //}}}
142:
143: //{{{ Private members
144: private String directory;
145: private String glob;
146: private boolean recurse;
147: private boolean skipHidden;
148: private boolean skipBinary;
149: //}}}
150: }
|