/jEdit/tags/before-selection-manager/macros/Misc/HyperSearch_Results_to_Buffer.bsh

# · Unknown · 85 lines · 75 code · 10 blank · 0 comment · 0 complexity · fa3ff397a8663ff5abe17cb7d183ef18 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 4911 2003-11-12 00:24:11Z spestov $
  25. */
  26. writeHypersearchResultsToBuffer(View view){
  27. hs = view.getDockableWindowManager().getDockableWindow("hypersearch-results");
  28. if (hs == null)
  29. {
  30. Macros.error(view, "The 'HyperSearch Results' window is not open.");
  31. return;
  32. }
  33. root = hs.getTreeModel().getRoot();
  34. if(root == null)
  35. {
  36. Macros.error(view, "No HyperSearch matches.");
  37. return;
  38. }
  39. node = root.getFirstChild();
  40. while(node.getNextSibling() != null)
  41. {
  42. node = node.getNextSibling();
  43. }
  44. node = node.getFirstChild();
  45. results = new StringBuffer();
  46. while(node != null)
  47. {
  48. path = node.getUserObject().toString();
  49. match = node.getFirstChild();
  50. while(match != null)
  51. {
  52. text = match.getUserObject().str;
  53. results.append(path + " :" + text + "\n");
  54. match = match.getNextSibling();
  55. }
  56. node = node.getNextSibling();
  57. }
  58. text = results.toString();
  59. if(text.length() > 0)
  60. {
  61. jEdit.newFile(view);
  62. view.getTextArea().setText(text);
  63. }
  64. }
  65. writeHypersearchResultsToBuffer(view);
  66. /*
  67. Macro index data (in DocBook format)
  68. <listitem>
  69. <para><filename>HyperSearch_Results_to_Buffer.bsh</filename></para>
  70. <abstract><para>
  71. Writes HyperSeach results to a new buffer.
  72. </para></abstract>
  73. </listitem>
  74. */
  75. // :wrap=none:collapseFolds=0:noTabs=false:lineSeparator=\n:maxLineLen=80:indentSize=4:deepIndent=false:folding=none: