001: /*
002: * BufferListSet.java - Buffer list matcher
003: * :tabSize=8:indentSize=8:noTabs=false:
004: * :folding=explicit:collapseFolds=1:
005: *
006: * Copyright (C) 1999, 2004 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 java.awt.Component;
027: import org.gjt.sp.jedit.*;
028: import org.gjt.sp.jedit.io.*;
029: import org.gjt.sp.util.StandardUtilities;
030:
031: //}}}
032:
033: /**
034: * A file set for searching a user-specified list of buffers.
035: * @author Slava Pestov
036: * @version $Id: BufferListSet.java 5570 2006-07-11 09:27:07Z kpouer $
037: */
038: public abstract class BufferListSet implements SearchFileSet {
039: //{{{ getFirstFile() method
040: public synchronized String getFirstFile(View view) {
041: if (files == null)
042: files = _getFiles(view);
043:
044: if (files == null || files.length == 0)
045: return null;
046: else
047: return files[0];
048: } //}}}
049:
050: //{{{ getNextFile() method
051: public synchronized String getNextFile(View view, String path) {
052: if (files == null)
053: files = _getFiles(view);
054:
055: if (files == null || files.length == 0)
056: return null;
057:
058: if (path == null) {
059: path = view.getBuffer().getSymlinkPath();
060: VFS vfs = VFSManager.getVFSForPath(path);
061: boolean ignoreCase = ((vfs.getCapabilities() & VFS.CASE_INSENSITIVE_CAP) != 0);
062:
063: for (int i = 0; i < files.length; i++) {
064: if (StandardUtilities.compareStrings(files[i], path,
065: ignoreCase) == 0) {
066: return path;
067: }
068: }
069:
070: return getFirstFile(view);
071: } else {
072: // -1 so that the last isn't checked
073: VFS vfs = VFSManager.getVFSForPath(path);
074: boolean ignoreCase = ((vfs.getCapabilities() & VFS.CASE_INSENSITIVE_CAP) != 0);
075:
076: for (int i = 0; i < files.length - 1; i++) {
077: if (StandardUtilities.compareStrings(files[i], path,
078: ignoreCase) == 0) {
079: return files[i + 1];
080: }
081: }
082:
083: return null;
084: }
085: } //}}}
086:
087: //{{{ getFiles() method
088: public synchronized String[] getFiles(View view) {
089: if (files == null)
090: files = _getFiles(view);
091:
092: if (files == null || files.length == 0)
093: return null;
094: else
095: return files;
096: } //}}}
097:
098: //{{{ getFileCount() method
099: public synchronized int getFileCount(View view) {
100: if (files == null)
101: files = _getFiles(view);
102:
103: if (files == null)
104: return 0;
105: else
106: return files.length;
107: } //}}}
108:
109: //{{{ getCode() method
110: public String getCode() {
111: // not supported for arbitriary filesets
112: return null;
113: } //}}}
114:
115: //{{{ invalidateCachedList() method
116: public void invalidateCachedList() {
117: files = null;
118: } //}}}
119:
120: /**
121: * Note that the paths in the returned list must be
122: * fully canonicalized.
123: */
124: protected abstract String[] _getFiles(Component comp);
125:
126: private String[] files;
127: }
|