PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. traverseTree(javax.swing.tree.DefaultMutableTreeNode node, StringBuffer results){
  27. if (node.getUserObject() instanceof org.gjt.sp.jedit.search.HyperSearchFileNode)
  28. {
  29. path = node.getUserObject().path;
  30. match = node.getFirstChild();
  31. while(match != null)
  32. {
  33. text = match.getUserObject().str;
  34. results.append(path + " :" + text + "\n");
  35. match = match.getNextSibling();
  36. }
  37. }
  38. else
  39. {
  40. for (Enumeration e = node.children(); e.hasMoreElements();)
  41. traverseTree(e.nextElement(), results);
  42. }
  43. }
  44. writeHypersearchResultsToBuffer(View view){
  45. hs = view.getDockableWindowManager().getDockableWindow("hypersearch-results");
  46. if (hs == null)
  47. {
  48. Macros.error(view, "The 'HyperSearch Results' window is not open.");
  49. return;
  50. }
  51. root = hs.getTreeModel().getRoot();
  52. if(root == null || root.getDepth() == 0)
  53. {
  54. Macros.error(view, "No HyperSearch matches.");
  55. return;
  56. }
  57. node = root.getFirstChild();
  58. while(node.getNextSibling() != null)
  59. {
  60. node = node.getNextSibling();
  61. }
  62. results = new StringBuffer();
  63. traverseTree(node, results);
  64. text = results.toString();
  65. if(text.length() > 0)
  66. {
  67. jEdit.newFile(view);
  68. view.getTextArea().setText(text);
  69. }
  70. }
  71. writeHypersearchResultsToBuffer(view);
  72. /*
  73. Macro index data (in DocBook format)
  74. <listitem>
  75. <para><filename>HyperSearch_Results_to_Buffer.bsh</filename></para>
  76. <abstract><para>
  77. Writes HyperSeach results to a new buffer.
  78. </para></abstract>
  79. </listitem>
  80. */
  81. // :wrap=none:collapseFolds=0:noTabs=false:lineSeparator=\n:maxLineLen=80:indentSize=4:deepIndent=false:folding=none: