/** * Performs a HyperSearch. * * @param view The view * @param selection If true, will only search in the current selection. Note that the file set * must be the current buffer file set for this to work. * @since jEdit 4.0pre1 */ public static boolean hyperSearch(View view, boolean selection) { // component that will parent any dialog boxes Component comp = SearchDialog.getSearchDialog(view); if (comp == null) comp = view; record(view, "hyperSearch(view," + selection + ')', false, !selection); view.getDockableWindowManager().addDockableWindow(HyperSearchResults.NAME); HyperSearchResults results = (HyperSearchResults) view.getDockableWindowManager().getDockable(HyperSearchResults.NAME); results.searchStarted(); try { SearchMatcher matcher = getSearchMatcher(); if (matcher == null) { view.getToolkit().beep(); results.searchFailed(); return false; } Selection[] s; if (selection) { s = view.getTextArea().getSelection(); if (s == null) { results.searchFailed(); return false; } } else s = null; ThreadUtilities.runInBackground(new HyperSearchRequest(view, matcher, results, s)); return true; } catch (Exception e) { results.searchFailed(); handleError(comp, e); return false; } } // }}}
/** * @param searchNode the result node * @param selectNode the node that must be selected, or null * @since jEdit 4.3pre12 */ public void searchDone( final DefaultMutableTreeNode searchNode, final DefaultMutableTreeNode selectNode) { stop.setEnabled(false); final int nodeCount = searchNode.getChildCount(); if (nodeCount < 1) { searchFailed(); return; } caption.setText( jEdit.getProperty("hypersearch-results.done", new String[] {trimSearchString()})); EventQueue.invokeLater( new Runnable() { @Override public void run() { if (!multiStatus) { for (int i = 0; i < resultTreeRoot.getChildCount(); i++) { resultTreeRoot.remove(0); } } resultTreeRoot.add(searchNode); resultTreeModel.reload(resultTreeRoot); for (int i = 0; i < nodeCount; i++) { TreePath lastNode = new TreePath(((DefaultMutableTreeNode) searchNode.getChildAt(i)).getPath()); resultTree.expandPath(lastNode); } TreePath treePath; if (selectNode == null) { treePath = new TreePath(new Object[] {resultTreeRoot, searchNode}); } else { treePath = new TreePath(selectNode.getPath()); } resultTree.setSelectionPath(treePath); resultTree.scrollPathToVisible(treePath); } }); } // }}}