/jEdit/tags/jedit-4-3-pre5/macros/Misc/HyperSearch_Results_to_Buffer.bsh
# · Unknown · 93 lines · 81 code · 12 blank · 0 comment · 0 complexity · 3f1f8dfb747335c6685c02bad2807743 MD5 · raw file
- /*
- * HyperSearch_Results_to_Buffer.bsh - a Beanshell macro
- * for jEdit text that writes HyperSearch results
- * matches to a new buffer in the format:
- *
- * <filename> :<linenum>: <line text>
- *
- * Copyright (C) 2002, 2003 Ollie Rutherfurd <oliver@rutherfurd.net>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Id: HyperSearch_Results_to_Buffer.bsh 5228 2005-07-13 03:24:43Z copy_paste $
- */
- traverseTree(javax.swing.tree.DefaultMutableTreeNode node, StringBuffer results){
- if (node.getUserObject() instanceof org.gjt.sp.jedit.search.HyperSearchFileNode)
- {
- path = node.getUserObject().path;
- match = node.getFirstChild();
- while(match != null)
- {
- text = match.getUserObject().str;
- results.append(path + " :" + text + "\n");
- match = match.getNextSibling();
- }
- }
- else
- {
- for (Enumeration e = node.children(); e.hasMoreElements();)
- traverseTree(e.nextElement(), results);
- }
- }
- writeHypersearchResultsToBuffer(View view){
- hs = view.getDockableWindowManager().getDockableWindow("hypersearch-results");
- if (hs == null)
- {
- Macros.error(view, "The 'HyperSearch Results' window is not open.");
- return;
- }
- root = hs.getTreeModel().getRoot();
- if(root == null || root.getDepth() == 0)
- {
- Macros.error(view, "No HyperSearch matches.");
- return;
- }
- node = root.getFirstChild();
- while(node.getNextSibling() != null)
- {
- node = node.getNextSibling();
- }
- results = new StringBuffer();
- traverseTree(node, results);
- text = results.toString();
- if(text.length() > 0)
- {
- jEdit.newFile(view);
- view.getTextArea().setText(text);
- }
- }
- writeHypersearchResultsToBuffer(view);
- /*
- Macro index data (in DocBook format)
- <listitem>
- <para><filename>HyperSearch_Results_to_Buffer.bsh</filename></para>
- <abstract><para>
- Writes HyperSeach results to a new buffer.
- </para></abstract>
- </listitem>
- */
- // :wrap=none:collapseFolds=0:noTabs=false:lineSeparator=\n:maxLineLen=80:indentSize=4:deepIndent=false:folding=none: