PageRenderTime 38ms CodeModel.GetById 34ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 1/*
 2 * HyperSearch_Results_to_Buffer.bsh - a Beanshell macro
 3 * for jEdit text that writes HyperSearch results
 4 * matches to a new buffer in the format:
 5 *
 6 * <filename> :<linenum>: <line text>
 7 *
 8 * Copyright (C) 2002, 2003 Ollie Rutherfurd <oliver@rutherfurd.net>
 9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23 *
24 * $Id: HyperSearch_Results_to_Buffer.bsh 5228 2005-07-13 03:24:43Z copy_paste $
25 */
26
27
28traverseTree(javax.swing.tree.DefaultMutableTreeNode node, StringBuffer results){
29	if (node.getUserObject() instanceof org.gjt.sp.jedit.search.HyperSearchFileNode)
30	{
31		path = node.getUserObject().path;
32		match = node.getFirstChild();
33		while(match != null)
34		{
35			text = match.getUserObject().str;
36			results.append(path + " :" + text + "\n");
37			match = match.getNextSibling();
38		}
39	}
40	else
41	{
42		for (Enumeration e = node.children(); e.hasMoreElements();)
43			traverseTree(e.nextElement(), results);
44	}
45}
46
47writeHypersearchResultsToBuffer(View view){
48	hs = view.getDockableWindowManager().getDockableWindow("hypersearch-results");
49	if (hs == null)
50	{
51		Macros.error(view, "The 'HyperSearch Results' window is not open.");
52		return;
53	}
54
55	root = hs.getTreeModel().getRoot();
56	if(root == null || root.getDepth() == 0)
57	{
58		Macros.error(view, "No HyperSearch matches.");
59		return;
60	}
61
62	node = root.getFirstChild();
63	while(node.getNextSibling() != null)
64	{
65		node = node.getNextSibling();
66	}
67
68	results = new StringBuffer();
69	traverseTree(node, results);
70
71	text = results.toString();
72	if(text.length() > 0)
73	{
74		jEdit.newFile(view);
75		view.getTextArea().setText(text);
76	}
77}
78
79writeHypersearchResultsToBuffer(view);
80
81/*
82	Macro index data (in DocBook format)
83
84<listitem>
85	<para><filename>HyperSearch_Results_to_Buffer.bsh</filename></para>
86	<abstract><para>
87	Writes HyperSeach results to a new buffer.
88	</para></abstract>
89</listitem>
90
91*/
92
93// :wrap=none:collapseFolds=0:noTabs=false:lineSeparator=\n:maxLineLen=80:indentSize=4:deepIndent=false:folding=none: