PageRenderTime 370ms CodeModel.GetById 363ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre5/org/gjt/sp/jedit/search/AllBufferSet.java

#
Java | 103 lines | 46 code | 10 blank | 47 comment | 2 complexity | 9a20ff682eec83d3498ce9042fa20ba8 MD5 | raw file
  1/*
  2 * AllBufferSet.java - All buffer 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
 23package org.gjt.sp.jedit.search;
 24
 25//{{{ Imports
 26import gnu.regexp.*;
 27import java.util.Vector;
 28import org.gjt.sp.jedit.*;
 29import org.gjt.sp.util.Log;
 30//}}}
 31
 32/**
 33 * A file set for searching all open buffers.
 34 * @author Slava Pestov
 35 * @version $Id: AllBufferSet.java 3931 2001-12-02 11:40:51Z spestov $
 36 */
 37public class AllBufferSet extends BufferListSet
 38{
 39	//{{{ AllBufferSet constructor
 40	/**
 41	 * Creates a new all buffer set.
 42	 * @param glob The filename glob
 43	 * @since jEdit 2.7pre3
 44	 */
 45	public AllBufferSet(String glob)
 46	{
 47		this.glob = glob;
 48	} //}}}
 49
 50	//{{{ getFileFilter() method
 51	/**
 52	 * Returns the filename filter.
 53	 * @since jEdit 2.7pre3
 54	 */
 55	public String getFileFilter()
 56	{
 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	{
 67		return "new AllBufferSet(\"" + MiscUtilities.charsToEscapes(glob)
 68			+ "\")";
 69	} //}}}
 70
 71	//{{{ Instance variables
 72	private String glob;
 73	//}}}
 74
 75	//{{{ _getFiles() method
 76	protected String[] _getFiles()
 77	{
 78		Buffer[] buffers = jEdit.getBuffers();
 79		Vector vector = new Vector(buffers.length);
 80
 81		RE filter;
 82		try
 83		{
 84			filter = new RE(MiscUtilities.globToRE(glob));
 85		}
 86		catch(Exception e)
 87		{
 88			Log.log(Log.ERROR,DirectoryListSet.class,e);
 89			return null;
 90		}
 91
 92		for(int i = 0; i < buffers.length; i++)
 93		{
 94			Buffer buffer = buffers[i];
 95			if(filter.isMatch(buffer.getName()))
 96				vector.addElement(buffer.getPath());
 97		}
 98
 99		String[] retVal = new String[vector.size()];
100		vector.copyInto(retVal);
101		return retVal;
102	} //}}}
103}