Example #1
0
 @Override
 public String convertValueToText(
     Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
   String s = super.convertValueToText(value, selected, expanded, leaf, row, hasFocus);
   String newProp = jEdit.getProperty(HIGHLIGHT_PROP);
   if (newProp == null || newProp.isEmpty()) return s;
   DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
   while (node != null && !(node.getUserObject() instanceof HyperSearchOperationNode)) {
     node = (DefaultMutableTreeNode) node.getParent();
   }
   if (node == null) return s;
   if (!newProp.equals(prop)) {
     prop = newProp;
     Font f = (resultTree != null) ? resultTree.getFont() : UIManager.getFont("Tree.font");
     styleTag = HtmlUtilities.style2html(prop, f);
   }
   SearchMatcher matcher = ((HyperSearchOperationNode) node.getUserObject()).getSearchMatcher();
   int i = s.indexOf(": ");
   if (i > 0) i += 2;
   else i = 0;
   Match m;
   List<Integer> matches = new ArrayList<Integer>();
   while ((m = matcher.nextMatch(s.substring(i), true, true, true, false)) != null) {
     matches.add(i + m.start);
     matches.add(i + m.end);
     i += m.end;
   }
   return HtmlUtilities.highlightString(s, styleTag, matches);
 }
Example #2
0
    @Override
    public void actionPerformed(ActionEvent evt) {
      JCheckBoxMenuItem menuItem = (JCheckBoxMenuItem) evt.getSource();
      boolean curState = menuItem.isSelected();

      TreePath path = resultTree.getSelectionPath();
      DefaultMutableTreeNode operNode = (DefaultMutableTreeNode) path.getLastPathComponent();

      HyperSearchOperationNode operNodeObj = (HyperSearchOperationNode) operNode.getUserObject();
      if (curState) operNodeObj.cacheResultNodes(operNode);
      operNode.removeAllChildren();
      if (curState) {
        Exception excp = null;
        try {
          operNodeObj.insertTreeNodes(resultTree, operNode);
        } catch (Exception ex) {
          operNodeObj.restoreFlatNodes(resultTree, operNode);
          menuItem.setSelected(false);
          excp = ex;
        } finally {
          ((DefaultTreeModel) resultTree.getModel()).nodeStructureChanged(operNode);
          expandAllNodes(operNode);
          resultTree.scrollPathToVisible(new TreePath(operNode.getPath()));
        }
        if (excp != null) throw new RuntimeException(excp);
      } else operNodeObj.restoreFlatNodes(resultTree, operNode);

      operNodeObj.setTreeViewDisplayed(menuItem.isSelected());
    }
Example #3
0
  private void goToSelectedNode(int mode) {
    TreePath path = resultTree.getSelectionPath();
    if (path == null) return;

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
    Object value = node.getUserObject();

    // do nothing if clicked "foo (showing n occurrences in m files)"
    if (node.getParent() != resultTreeRoot && value instanceof HyperSearchNode) {
      HyperSearchNode n = (HyperSearchNode) value;
      Buffer buffer = n.getBuffer(view);
      if (buffer == null) return;

      EditPane pane;

      switch (mode) {
        case M_OPEN:
          pane = view.goToBuffer(buffer);
          break;
        case M_OPEN_NEW_VIEW:
          pane = jEdit.newView(view, buffer, false).getEditPane();
          break;
        case M_OPEN_NEW_PLAIN_VIEW:
          pane = jEdit.newView(view, buffer, true).getEditPane();
          break;
        case M_OPEN_NEW_SPLIT:
          pane = view.splitHorizontally();
          break;
        default:
          throw new IllegalArgumentException("Bad mode: " + mode);
      }

      n.goTo(pane);
    }
  } // }}}
Example #4
0
 @Override
 public void actionPerformed(ActionEvent evt) {
   TreePath path = resultTree.getSelectionPath();
   DefaultMutableTreeNode operNode = (DefaultMutableTreeNode) path.getLastPathComponent();
   for (Enumeration e = operNode.children(); e.hasMoreElements(); ) {
     DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
     resultTree.collapsePath(new TreePath(node.getPath()));
   }
   resultTree.scrollPathToVisible(new TreePath(operNode.getPath()));
 }
Example #5
0
    @Override
    public void actionPerformed(ActionEvent evt) {
      TreePath path = resultTree.getSelectionPath();
      DefaultMutableTreeNode operNode = (DefaultMutableTreeNode) path.getLastPathComponent();
      HyperSearchFolderNode nodeObj = (HyperSearchFolderNode) operNode.getUserObject();

      String glob = "*";
      SearchFileSet dirList = SearchAndReplace.getSearchFileSet();
      if (dirList instanceof DirectoryListSet) glob = ((DirectoryListSet) dirList).getFileFilter();
      SearchAndReplace.setSearchFileSet(
          new DirectoryListSet(nodeObj.getNodeFile().getAbsolutePath(), glob, true));
      SearchDialog.showSearchDialog(view, null, SearchDialog.DIRECTORY);
    }
Example #6
0
  // {{{ removeSelectedNode() method
  private void removeSelectedNode() {
    TreePath path = resultTree.getSelectionPath();
    if (path == null) return;

    MutableTreeNode value = (MutableTreeNode) path.getLastPathComponent();

    if (path.getPathCount() > 1) {
      // Adjust selection so that repeating some removals
      // behave naturally.
      TreePath parentPath = path.getParentPath();
      MutableTreeNode parent = (MutableTreeNode) parentPath.getLastPathComponent();
      int removingIndex = parent.getIndex(value);
      int nextIndex = removingIndex + 1;
      if (nextIndex < parent.getChildCount()) {
        TreeNode next = parent.getChildAt(nextIndex);
        resultTree.setSelectionPath(parentPath.pathByAddingChild(next));
      } else {
        resultTree.setSelectionPath(parentPath);
      }

      resultTreeModel.removeNodeFromParent(value);
    }

    HyperSearchOperationNode.removeNodeFromCache(value);
    if (resultTreeRoot.getChildCount() == 0) {
      hideDockable();
    }
  } // }}}
Example #7
0
 @Override
 public boolean processNode(DefaultMutableTreeNode node) {
   Object userObject = node.getUserObject();
   if (userObject instanceof HyperSearchFileNode) {
     resultCount += ((HyperSearchFileNode) userObject).getCount();
     bufferCount++;
   }
   return true;
 }
Example #8
0
 // {{{ traverseNodes() method
 public static boolean traverseNodes(
     DefaultMutableTreeNode node, HyperSearchTreeNodeCallback callbackInterface) {
   if (!callbackInterface.processNode(node)) return false;
   for (Enumeration e = node.children(); e.hasMoreElements(); ) {
     DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) e.nextElement();
     if (!traverseNodes(childNode, callbackInterface)) return false;
   }
   return true;
 } // }}}
Example #9
0
    // {{{ getTreeCellRendererComponent() method
    @Override
    protected void configureTreeCellRendererComponent(
        JTree tree,
        Object value,
        boolean sel,
        boolean expanded,
        boolean leaf,
        int row,
        boolean hasFocus) {
      setIcon(null);
      DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;

      if (node.getUserObject() instanceof HyperSearchOperationNode) {
        setFont(boldFont);

        CountNodes countNodes = new CountNodes();
        traverseNodes(node, countNodes);

        setText(
            jEdit.getProperty(
                "hypersearch-results.result-caption",
                new Object[] {
                  node.toString(),
                  Integer.valueOf(countNodes.resultCount),
                  Integer.valueOf(countNodes.bufferCount)
                }));
      } else if (node.getUserObject() instanceof HyperSearchFolderNode) {
        setFont(plainFont);
        setText(node.toString() + " (" + node.getChildCount() + " files/folders)");
      } else if (node.getUserObject() instanceof HyperSearchFileNode) {
        // file name
        setFont(boldFont);
        HyperSearchFileNode hyperSearchFileNode = (HyperSearchFileNode) node.getUserObject();
        setText(
            jEdit.getProperty(
                "hypersearch-results.file-caption",
                new Object[] {
                  hyperSearchFileNode,
                  Integer.valueOf(hyperSearchFileNode.getCount()),
                  Integer.valueOf(node.getChildCount())
                }));
      } else {
        setFont(plainFont);
      }
    } // }}}
Example #10
0
 @Override
 public boolean processNode(DefaultMutableTreeNode node) {
   Object userObject = node.getUserObject();
   if (userObject instanceof HyperSearchFileNode)
     nodesString.append(((HyperSearchFileNode) userObject).path);
   else if (userObject instanceof HyperSearchResult) {
     HyperSearchResult hsr = (HyperSearchResult) userObject;
     // Copy the ORIGINAL line from the buffer!
     nodesString.append(hsr.buffer == null ? hsr.toString() : hsr.buffer.getLineText(hsr.line));
   } else nodesString.append(userObject.toString());
   nodesString.append('\n');
   return true;
 }
Example #11
0
    // {{{ showPopupMenu method
    private void showPopupMenu(MouseEvent evt) {
      TreePath path = resultTree.getSelectionPath();
      DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();

      popupMenu = new JPopupMenu();
      Object userObj = node.getUserObject();
      if (userObj instanceof HyperSearchFileNode || userObj instanceof HyperSearchResult) {
        popupMenu.add(new GoToNodeAction("hypersearch-results.open", M_OPEN));
        popupMenu.add(new GoToNodeAction("hypersearch-results.open-view", M_OPEN_NEW_VIEW));
        popupMenu.add(
            new GoToNodeAction("hypersearch-results.open-plain-view", M_OPEN_NEW_PLAIN_VIEW));
        popupMenu.add(new GoToNodeAction("hypersearch-results.open-split", M_OPEN_NEW_SPLIT));
      }
      if (!(userObj instanceof HyperSearchFolderNode)) popupMenu.add(new RemoveTreeNodeAction());
      popupMenu.add(new ExpandChildTreeNodesAction());
      if (userObj instanceof HyperSearchFolderNode || userObj instanceof HyperSearchOperationNode) {
        popupMenu.add(new CollapseChildTreeNodesAction());
        if (userObj instanceof HyperSearchFolderNode) popupMenu.add(new NewSearchAction());
      }
      if (userObj instanceof HyperSearchOperationNode) {
        popupMenu.add(new JPopupMenu.Separator());
        HyperSearchOperationNode resultNode = (HyperSearchOperationNode) userObj;
        JCheckBoxMenuItem chkItem =
            new JCheckBoxMenuItem(
                jEdit.getProperty("hypersearch-results.tree-view"),
                resultNode.isTreeViewDisplayed());
        chkItem.addActionListener(new TreeDisplayAction());
        popupMenu.add(chkItem);

        popupMenu.add(new RedoSearchAction((HyperSearchOperationNode) userObj));
      }
      popupMenu.add(new CopyToClipboardAction());

      GUIUtilities.showPopupMenu(popupMenu, evt.getComponent(), evt.getX(), evt.getY());
      evt.consume();
    } // }}}
Example #12
0
  /**
   * @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);
          }
        });
  } // }}}
Example #13
0
 // {{{ removeAllNodes() method
 private void removeAllNodes() {
   resultTreeRoot.removeAllChildren();
   resultTreeModel.reload(resultTreeRoot);
   setSearchStatus(null);
   hideDockable();
 } // }}}