01: /*
02: * AllBufferSet.java - All buffer matcher
03: * :tabSize=8:indentSize=8:noTabs=false:
04: * :folding=explicit:collapseFolds=1:
05: *
06: * Copyright (C) 1999, 2000, 2001 Slava Pestov
07: *
08: * This program is free software; you can redistribute it and/or
09: * 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:
23: package org.gjt.sp.jedit.search;
24:
25: //{{{ Imports
26: import java.awt.Component;
27: import java.util.ArrayList;
28: import java.util.regex.Pattern;
29: import org.gjt.sp.jedit.*;
30: import org.gjt.sp.util.Log;
31: import org.gjt.sp.util.StandardUtilities;
32:
33: //}}}
34:
35: /**
36: * A file set for searching all open buffers.
37: * @author Slava Pestov
38: * @version $Id: AllBufferSet.java 6808 2006-08-26 23:22:57Z vanza $
39: */
40: public class AllBufferSet extends BufferListSet {
41: //{{{ AllBufferSet constructor
42: /**
43: * Creates a new all buffer set.
44: * @param glob The filename glob
45: * @since jEdit 2.7pre3
46: */
47: public AllBufferSet(String glob) {
48: this .glob = glob;
49: } //}}}
50:
51: //{{{ getFileFilter() method
52: /**
53: * Returns the filename filter.
54: * @since jEdit 2.7pre3
55: */
56: public String getFileFilter() {
57: return glob;
58: } //}}}
59:
60: //{{{ getCode() method
61: /**
62: * Returns the BeanShell code that will recreate this file set.
63: * @since jEdit 2.7pre3
64: */
65: public String getCode() {
66: return "new AllBufferSet(\""
67: + MiscUtilities.charsToEscapes(glob) + "\")";
68: } //}}}
69:
70: //{{{ Instance variables
71: private String glob;
72:
73: //}}}
74:
75: //{{{ _getFiles() method
76: protected String[] _getFiles(Component comp) {
77: Buffer[] buffers = jEdit.getBuffers();
78: ArrayList returnValue = new ArrayList(buffers.length);
79:
80: Pattern filter;
81: try {
82: filter = Pattern.compile(StandardUtilities.globToRE(glob));
83: } catch (Exception e) {
84: Log.log(Log.ERROR, this , e);
85: return null;
86: }
87:
88: for (int i = 0; i < buffers.length; i++) {
89: Buffer buffer = buffers[i];
90: if (filter.matcher(buffer.getName()).matches())
91: returnValue.add(buffer.getPath());
92: }
93:
94: return (String[]) returnValue.toArray(new String[returnValue
95: .size()]);
96: } //}}}
97: }
|