예제 #1
1
        @Override
        protected Transferable createTransferable(JComponent c) {
          if (!(c instanceof XDebuggerTree)) {
            return null;
          }
          XDebuggerTree tree = (XDebuggerTree) c;
          //noinspection deprecation
          TreePath[] selectedPaths = tree.getSelectionPaths();
          if (selectedPaths == null || selectedPaths.length == 0) {
            return null;
          }

          StringBuilder plainBuf = new StringBuilder();
          StringBuilder htmlBuf = new StringBuilder();
          htmlBuf.append("<html>\n<body>\n<ul>\n");
          TextTransferable.ColoredStringBuilder coloredTextContainer =
              new TextTransferable.ColoredStringBuilder();
          for (TreePath path : selectedPaths) {
            htmlBuf.append("  <li>");
            Object node = path.getLastPathComponent();
            if (node != null) {
              if (node instanceof XDebuggerTreeNode) {
                ((XDebuggerTreeNode) node).appendToComponent(coloredTextContainer);
                coloredTextContainer.appendTo(plainBuf, htmlBuf);
              } else {
                String text = node.toString();
                plainBuf.append(text);
                htmlBuf.append(text);
              }
            }
            plainBuf.append('\n');
            htmlBuf.append("</li>\n");
          }

          // remove the last newline
          plainBuf.setLength(plainBuf.length() - 1);
          htmlBuf.append("</ul>\n</body>\n</html>");
          return new TextTransferable(htmlBuf.toString(), plainBuf.toString());
        }
  @Override
  public void processSessionEvent(@NotNull final SessionEvent event) {
    XStackFrame stackFrame = mySession.getCurrentStackFrame();
    XDebuggerTree tree = myTreePanel.getTree();

    if (event == SessionEvent.BEFORE_RESUME || event == SessionEvent.SETTINGS_CHANGED) {
      if (myTreeRestorer != null) {
        myTreeRestorer.dispose();
      }
      myTreeState = XDebuggerTreeState.saveState(tree);
      if (event == SessionEvent.BEFORE_RESUME) {
        return;
      }
    }

    if (stackFrame != null) {
      tree.setSourcePosition(stackFrame.getSourcePosition());
      myRootNode.updateWatches(stackFrame.getEvaluator());
      if (myTreeState != null) {
        myTreeRestorer = myTreeState.restoreState(tree);
      }
    } else {
      tree.setSourcePosition(null);
      myRootNode.updateWatches(null);
    }
  }
  @Nullable
  public static XValueNodeImpl getSelectedNode(final DataContext dataContext) {
    XDebuggerTree tree = XDebuggerTree.getTree(dataContext);
    if (tree == null) return null;

    TreePath path = tree.getSelectionPath();
    if (path == null) return null;

    Object node = path.getLastPathComponent();
    return node instanceof XValueNodeImpl ? (XValueNodeImpl) node : null;
  }
예제 #4
0
 private void showTree(final XValue value, final String name) {
   XDebuggerTree tree =
       new XDebuggerTree(
           myDebugSession,
           myDebugSession.getDebugProcess().getEditorsProvider(),
           myDebugSession.getCurrentPosition(),
           XDebuggerActions.VALUE_HINT_TREE_POPUP_GROUP);
   tree.getModel().addTreeModelListener(createTreeListener(tree));
   XValueHintTreeComponent component =
       new XValueHintTreeComponent(this, tree, Pair.create(value, name));
   showTreePopup(component, tree, name);
 }
예제 #5
0
  public void actionPerformed(final AnActionEvent e) {
    XDebuggerTree tree = XDebuggerTree.getTree(e);
    if (tree == null) return;

    List<? extends WatchNode> watchNodes = getSelectedNodes(tree, WatchNode.class);
    if (watchNodes.size() != 1) return;

    WatchNode node = watchNodes.get(0);
    XDebuggerTreeNode root = tree.getRoot();
    if (root instanceof WatchesRootNode) {
      ((WatchesRootNode) root).editWatch(node);
    }
  }
예제 #6
0
 @Override
 public void update(final AnActionEvent e) {
   XDebuggerTree tree = XDebuggerTree.getTree(e);
   e.getPresentation()
       .setVisible(tree != null && getSelectedNodes(tree, WatchNode.class).size() == 1);
   super.update(e);
 }
 private void disposeIfFinished() {
   if (myNode2ParentState.isEmpty() && myNode2State.isEmpty()) {
     if (myLastVisibleNodeRect != null) {
       myTree.scrollRectToVisible(myLastVisibleNodeRect);
     }
     dispose();
   }
 }
  private XDebuggerTreeState(@NotNull XDebuggerTree tree) {
    myRootInfo = new NodeInfo("", "", false);
    ApplicationManager.getApplication().assertIsDispatchThread();

    final XDebuggerTreeNode root = (XDebuggerTreeNode) tree.getTreeModel().getRoot();
    if (root != null) {
      addChildren(tree, myRootInfo, root);
    }
  }
 private void addChildren(
     final XDebuggerTree tree, final NodeInfo nodeInfo, final XDebuggerTreeNode treeNode) {
   if (tree.isExpanded(treeNode.getPath())) {
     List<? extends XDebuggerTreeNode> children = treeNode.getLoadedChildren();
     if (children != null) {
       nodeInfo.myExpanded = true;
       for (XDebuggerTreeNode child : children) {
         final TreePath path = child.getPath();
         final Rectangle bounds = tree.getPathBounds(path);
         if (bounds != null && tree.getVisibleRect().contains(bounds)) {
           myLastVisibleNodeRect = bounds;
         }
         NodeInfo childInfo = createNode(child, tree.isPathSelected(path));
         if (childInfo != null) {
           nodeInfo.addChild(childInfo);
           addChildren(tree, childInfo, child);
         }
       }
     }
   }
 }
 private void restoreChildren(
     final XDebuggerTreeNode treeNode, final XDebuggerTreeState.NodeInfo nodeInfo) {
   if (nodeInfo.isExpanded()) {
     myTree.expandPath(treeNode.getPath());
     List<? extends XDebuggerTreeNode> children = treeNode.getLoadedChildren();
     if (children != null) {
       for (XDebuggerTreeNode child : children) {
         restoreNode(child, nodeInfo);
       }
     }
     myNode2State.put(treeNode, nodeInfo);
   }
 }
  private void doRestoreNode(
      final RestorableStateNode treeNode, final XDebuggerTreeState.NodeInfo nodeInfo) {
    if (nodeInfo != null) {
      if (!checkExtendedModified(treeNode)
          && !(Comparing.equal(nodeInfo.getValue(), treeNode.getRawValue()))) {
        treeNode.markChanged();
      }
      if (!myStopRestoringSelection && nodeInfo.isSelected()) {
        try {
          myInsideRestoring = true;
          myTree.addSelectionPath(treeNode.getPath());
        } finally {
          myInsideRestoring = false;
        }
      }

      restoreChildren((XDebuggerTreeNode) treeNode, nodeInfo);
    } else if (!checkExtendedModified(treeNode)) {
      treeNode.markChanged();
    }
  }
  public XWatchesViewImpl(
      @NotNull final XDebugSession session, final @NotNull XDebugSessionData sessionData) {
    mySession = session;
    mySessionData = sessionData;
    myTreePanel =
        new XDebuggerTreePanel(
            session.getProject(),
            session.getDebugProcess().getEditorsProvider(),
            this,
            null,
            XDebuggerActions.WATCHES_TREE_POPUP_GROUP,
            ((XDebugSessionImpl) session).getValueMarkers());

    ActionManager actionManager = ActionManager.getInstance();

    XDebuggerTree tree = myTreePanel.getTree();
    actionManager
        .getAction(XDebuggerActions.XNEW_WATCH)
        .registerCustomShortcutSet(CommonShortcuts.INSERT, tree);
    actionManager
        .getAction(XDebuggerActions.XREMOVE_WATCH)
        .registerCustomShortcutSet(CommonShortcuts.DELETE, tree);

    CustomShortcutSet f2Shortcut = new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0));
    actionManager
        .getAction(XDebuggerActions.XEDIT_WATCH)
        .registerCustomShortcutSet(f2Shortcut, tree);

    DnDManager.getInstance().registerTarget(this, tree);
    myRootNode = new WatchesRootNode(tree, session, this, sessionData.getWatchExpressions());
    tree.setRoot(myRootNode, false);

    final ToolbarDecorator decorator =
        ToolbarDecorator.createDecorator(myTreePanel.getTree()).disableUpDownActions();
    decorator.setAddAction(
        new AnActionButtonRunnable() {
          @Override
          public void run(AnActionButton button) {
            executeAction(XDebuggerActions.XNEW_WATCH);
          }
        });
    decorator.setRemoveAction(
        new AnActionButtonRunnable() {
          @Override
          public void run(AnActionButton button) {
            executeAction(XDebuggerActions.XREMOVE_WATCH);
          }
        });
    CustomLineBorder border =
        new CustomLineBorder(
            CaptionPanel.CNT_ACTIVE_BORDER_COLOR,
            SystemInfo.isMac ? 1 : 0,
            0,
            SystemInfo.isMac ? 0 : 1,
            0);
    decorator.setToolbarBorder(border);
    myDecoratedPanel = decorator.createPanel();
    myDecoratedPanel.setBorder(null);

    myTreePanel.getTree().getEmptyText().setText(XDebuggerBundle.message("debugger.no.watches"));
  }
 public XDebuggerTreeRestorer(final XDebuggerTree tree, Rectangle lastVisibleNodeRect) {
   myTree = tree;
   myLastVisibleNodeRect = lastVisibleNodeRect;
   tree.addTreeListener(this);
   tree.addTreeSelectionListener(this);
 }
 public void dispose() {
   myNode2ParentState.clear();
   myNode2State.clear();
   myTree.removeTreeListener(this);
   myTree.removeTreeSelectionListener(this);
 }
 public XDebuggerTreeRestorer restoreState(@NotNull XDebuggerTree tree) {
   ApplicationManager.getApplication().assertIsDispatchThread();
   XDebuggerTreeRestorer restorer = new XDebuggerTreeRestorer(tree, myLastVisibleNodeRect);
   restorer.restoreChildren(((XDebuggerTreeNode) tree.getTreeModel().getRoot()), myRootInfo);
   return restorer;
 }