PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/bundles/plugins-trunk/SideKick/macros/SearchAsset.bsh

#
Unknown | 93 lines | 88 code | 5 blank | 0 comment | 0 complexity | 958a152f7dafce897db9bad7e50188fd 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. // This is a recorded macro. First, check over the
  2. // commands to make sure this is what you intended. Then,
  3. // save this buffer, and the macro should appear in the
  4. // Macros menu.
  5. import javax.swing.tree.*;
  6. import javax.swing.Timer;
  7. DefaultMutableTreeNode findNodeOfLine(DefaultMutableTreeNode node, int line)
  8. {
  9. if (node.getUserObject() instanceof org.gjt.sp.jedit.search.HyperSearchFileNode)
  10. {
  11. DefaultMutableTreeNode match = node.getFirstChild();
  12. while(match != null)
  13. {
  14. String text = match.getUserObject().str;
  15. if (text.startsWith(String.valueOf(line + 1) + ":"))
  16. return match;
  17. match = match.getNextSibling();
  18. }
  19. }
  20. else
  21. {
  22. for (Enumeration e = node.children(); e.hasMoreElements();)
  23. {
  24. DefaultMutableTreeNode n = findNodeOfLine(e.nextElement(), line);
  25. if (n != null)
  26. return n;
  27. }
  28. }
  29. return null;
  30. }
  31. void selectNodeOfLine(View view, int line)
  32. {
  33. HyperSearchResults hs = view.getDockableWindowManager().getDockableWindow(
  34. "hypersearch-results");
  35. if (hs == null)
  36. return;
  37. DefaultMutableTreeNode root = hs.getTreeModel().getRoot();
  38. if (root == null || root.getDepth() == 0)
  39. return;
  40. // Check only the results of the last search
  41. DefaultMutableTreeNode node = root.getLastChild();
  42. if (node == null)
  43. return;
  44. Object object = node.getUserObject();
  45. if (! (object instanceof org.gjt.sp.jedit.search.HyperSearchOperationNode))
  46. continue;
  47. DefaultMutableTreeNode n = findNodeOfLine(node, line);
  48. if (n != null)
  49. {
  50. hs.getTree().setSelectionPath(new TreePath(n.getPath()));
  51. return;
  52. }
  53. }
  54. void SearchAsset(JEditTextArea textArea, boolean exact)
  55. {
  56. int position = textArea.getCaretPosition();
  57. int line = textArea.getCaretLine();
  58. Selection[] selection = textArea.getSelection();
  59. String s = null;
  60. if (selection == null || selection.length == 0) {
  61. s = Macros.input(view, "Enter text to search for:");
  62. if (s == null)
  63. return;
  64. } else {
  65. s = textArea.getSelectedText(selection[0]);
  66. }
  67. sidekick.SideKickActions.selectAsset(view);
  68. if (exact)
  69. SearchAndReplace.setSearchString("\\b" + s + "\\b");
  70. else
  71. SearchAndReplace.setSearchString(s);
  72. SearchAndReplace.setAutoWrapAround(false);
  73. SearchAndReplace.setReverseSearch(false);
  74. SearchAndReplace.setIgnoreCase(false);
  75. SearchAndReplace.setRegexp(exact);
  76. SearchAndReplace.hyperSearch(view,true);
  77. textArea.setCaretPosition(position);
  78. textArea.setSelection(selection);
  79. Timer timer = new Timer(1000, new ActionListener() {
  80. public void actionPerformed(ActionEvent ae) {
  81. setAccessibility(true);
  82. selectNodeOfLine(view, line);
  83. setAccessibility(false);
  84. }
  85. });
  86. timer.setRepeats(false);
  87. timer.start();
  88. }