Ejemplo n.º 1
0
 private void handle(MouseEvent e) {
   if (e.isPopupTrigger()) {
     ActionManager mgr = getContext().getActions();
     JPopupMenu menu =
         mgr.createPopup(
             getContext().getResources().getStringArray(ElementNavigator.class, "popupActions"));
     menu.show((JComponent) e.getSource(), e.getX(), e.getY());
   }
 }
Ejemplo n.º 2
0
 private void popupInvoked(Component component, int x, int y) {
   final TreePath path = myTree.getLeadSelectionPath();
   if (path == null) return;
   if (!(path.getLastPathComponent() instanceof MessageNode)) return;
   if (getData(DataConstants.NAVIGATABLE_ARRAY) == null) return;
   DefaultActionGroup group = new DefaultActionGroup();
   group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE));
   ActionPopupMenu menu =
       ActionManager.getInstance().createActionPopupMenu(ActionPlaces.ANT_MESSAGES_POPUP, group);
   menu.getComponent().show(component, x, y);
 }
 private JComponent toUsageViewToolbar(final DefaultActionGroup group) {
   ActionToolbar actionToolbar =
       ActionManager.getInstance()
           .createActionToolbar(ActionPlaces.USAGE_VIEW_TOOLBAR, group, false);
   actionToolbar.setTargetComponent(myRootPanel);
   return actionToolbar.getComponent();
 }
  private AnAction[] createActions() {
    final TreeExpander treeExpander =
        new TreeExpander() {
          @Override
          public void expandAll() {
            UsageViewImpl.this.expandAll();
          }

          @Override
          public boolean canExpand() {
            return true;
          }

          @Override
          public void collapseAll() {
            UsageViewImpl.this.collapseAll();
          }

          @Override
          public boolean canCollapse() {
            return true;
          }
        };

    CommonActionsManager actionsManager = CommonActionsManager.getInstance();

    myTextFileExporter = new ExporterToTextFile(this);

    final JComponent component = getComponent();

    final AnAction expandAllAction = actionsManager.createExpandAllAction(treeExpander, component);
    final AnAction collapseAllAction =
        actionsManager.createCollapseAllAction(treeExpander, component);

    scheduleDisposeOnClose(
        new Disposable() {
          @Override
          public void dispose() {
            collapseAllAction.unregisterCustomShortcutSet(component);
            expandAllAction.unregisterCustomShortcutSet(component);
          }
        });

    return new AnAction[] {
      canPerformReRun() ? new ReRunAction() : null,
      new CloseAction(),
      ActionManager.getInstance().getAction("PinToolwindowTab"),
      createRecentFindUsagesAction(),
      expandAllAction,
      collapseAllAction,
      actionsManager.createPrevOccurenceAction(myRootPanel),
      actionsManager.createNextOccurenceAction(myRootPanel),
      actionsManager.installAutoscrollToSourceHandler(
          myProject, myTree, new MyAutoScrollToSourceOptionProvider()),
      actionsManager.createExportToTextFileAction(myTextFileExporter),
      actionsManager.createHelpAction(HELP_ID)
    };
  }
Ejemplo n.º 5
0
 protected void initTree() {
   ((DefaultTreeModel) myTree.getModel()).setRoot(myRoot);
   myTree.setRootVisible(false);
   myTree.setShowsRootHandles(true);
   UIUtil.setLineStyleAngled(myTree);
   TreeUtil.installActions(myTree);
   myTree.setCellRenderer(
       new ColoredTreeCellRenderer() {
         public void customizeCellRenderer(
             JTree tree,
             Object value,
             boolean selected,
             boolean expanded,
             boolean leaf,
             int row,
             boolean hasFocus) {
           if (value instanceof MyNode) {
             final MyNode node = ((MyNode) value);
             setIcon(node.getIcon(expanded));
             final Font font = UIUtil.getTreeFont();
             if (node.isDisplayInBold()) {
               setFont(font.deriveFont(Font.BOLD));
             } else {
               setFont(font.deriveFont(Font.PLAIN));
             }
             append(
                 node.getDisplayName(),
                 node.isDisplayInBold()
                     ? SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES
                     : SimpleTextAttributes.REGULAR_ATTRIBUTES);
           }
         }
       });
   initToolbar();
   ArrayList<AnAction> actions = createActions(true);
   if (actions != null) {
     final DefaultActionGroup group = new DefaultActionGroup();
     for (AnAction action : actions) {
       group.add(action);
     }
     actions = getAdditionalActions();
     if (actions != null) {
       group.addSeparator();
       for (AnAction action : actions) {
         group.add(action);
       }
     }
     PopupHandler.installPopupHandler(
         myTree,
         group,
         ActionPlaces.UNKNOWN,
         ActionManager.getInstance()); // popup should follow the selection
   }
 }
Ejemplo n.º 6
0
 private void initToolbar() {
   if (isNewProjectSettings()) return;
   DefaultActionGroup group = createToolbarActionGroup();
   if (group != null) {
     final JComponent component =
         ActionManager.getInstance()
             .createActionToolbar(ActionPlaces.UNKNOWN, group, true)
             .getComponent();
     myNorthPanel.add(component, BorderLayout.NORTH);
   }
 }
  @Override
  protected JComponent createCenterPanel() {
    JPanel panel = new JPanel(new BorderLayout());

    // Toolbar

    DefaultActionGroup group = new DefaultActionGroup();

    fillToolbarActions(group);

    group.addSeparator();

    ExpandAllAction expandAllAction = new ExpandAllAction();
    expandAllAction.registerCustomShortcutSet(
        new CustomShortcutSet(
            KeymapManager.getInstance()
                .getActiveKeymap()
                .getShortcuts(IdeActions.ACTION_EXPAND_ALL)),
        myTree);
    group.add(expandAllAction);

    CollapseAllAction collapseAllAction = new CollapseAllAction();
    collapseAllAction.registerCustomShortcutSet(
        new CustomShortcutSet(
            KeymapManager.getInstance()
                .getActiveKeymap()
                .getShortcuts(IdeActions.ACTION_COLLAPSE_ALL)),
        myTree);
    group.add(collapseAllAction);

    panel.add(
        ActionManager.getInstance()
            .createActionToolbar(ActionPlaces.UNKNOWN, group, true)
            .getComponent(),
        BorderLayout.NORTH);

    // Tree
    expandFirst();
    defaultExpandTree();
    installSpeedSearch();

    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
    scrollPane.setPreferredSize(new Dimension(350, 450));
    panel.add(scrollPane, BorderLayout.CENTER);

    return panel;
  }
Ejemplo n.º 8
0
  private void reset(
      final Keymap keymap,
      final QuickList[] allQuickLists,
      String filter,
      @Nullable KeyboardShortcut shortcut) {
    myKeymap = keymap;

    final PathsKeeper pathsKeeper = new PathsKeeper();
    pathsKeeper.storePaths();

    myRoot.removeAllChildren();

    ActionManager actionManager = ActionManager.getInstance();
    Project project =
        CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(myComponent));
    Group mainGroup =
        ActionsTreeUtil.createMainGroup(
            project,
            myKeymap,
            allQuickLists,
            filter,
            true,
            ActionsTreeUtil.isActionFiltered(actionManager, myKeymap, shortcut, filter, true));
    if ((filter != null && filter.length() > 0 || shortcut != null)
        && mainGroup.initIds().isEmpty()) {
      mainGroup =
          ActionsTreeUtil.createMainGroup(
              project,
              myKeymap,
              allQuickLists,
              filter,
              false,
              ActionsTreeUtil.isActionFiltered(actionManager, myKeymap, shortcut, filter, false));
    }
    myRoot = ActionsTreeUtil.createNode(mainGroup);
    myMainGroup = mainGroup;
    MyModel model = (MyModel) myTree.getModel();
    model.setRoot(myRoot);
    model.nodeStructureChanged(myRoot);

    pathsKeeper.restorePaths();
  }
 private void updateMenu() {
   PopupHandler.installPopupHandler(
       this, myMenuGroup, ActionPlaces.CHANGES_VIEW_POPUP, ActionManager.getInstance());
 }
Ejemplo n.º 10
0
    // Make sure that the text rendered by this method is 'searchable' via
    // com.intellij.openapi.keymap.impl.ui.ActionsTree.filter method.
    public void customizeCellRenderer(
        JTree tree,
        Object value,
        boolean selected,
        boolean expanded,
        boolean leaf,
        int row,
        boolean hasFocus) {
      final boolean showIcons = UISettings.getInstance().SHOW_ICONS_IN_MENUS;
      Keymap originalKeymap = myKeymap != null ? myKeymap.getParent() : null;
      Icon icon = null;
      String text;
      boolean bound = false;
      setToolTipText(null);

      if (value instanceof DefaultMutableTreeNode) {
        Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
        boolean changed;
        if (userObject instanceof Group) {
          Group group = (Group) userObject;
          text = group.getName();

          changed = originalKeymap != null && isGroupChanged(group, originalKeymap, myKeymap);
          icon = group.getIcon();
          if (icon == null) {
            icon = CLOSE_ICON;
          }
        } else if (userObject instanceof String) {
          String actionId = (String) userObject;
          bound = myShowBoundActions && ((KeymapImpl) myKeymap).isActionBound(actionId);
          AnAction action = ActionManager.getInstance().getAction(actionId);
          if (action != null) {
            text = action.getTemplatePresentation().getText();
            if (text == null || text.length() == 0) { // fill dynamic presentation gaps
              text = actionId;
            }
            Icon actionIcon = action.getTemplatePresentation().getIcon();
            if (actionIcon != null) {
              icon = actionIcon;
            }
            setToolTipText(action.getTemplatePresentation().getDescription());
          } else {
            text = actionId;
          }
          changed = originalKeymap != null && isActionChanged(actionId, originalKeymap, myKeymap);
        } else if (userObject instanceof QuickList) {
          QuickList list = (QuickList) userObject;
          icon = AllIcons.Actions.QuickList;
          text = list.getDisplayName();

          changed =
              originalKeymap != null
                  && isActionChanged(list.getActionId(), originalKeymap, myKeymap);
        } else if (userObject instanceof Separator) {
          // TODO[vova,anton]: beautify
          changed = false;
          text = "-------------";
        } else {
          throw new IllegalArgumentException("unknown userObject: " + userObject);
        }

        if (showIcons) {
          setIcon(ActionsTree.getEvenIcon(icon));
        }

        Color foreground;
        if (selected) {
          foreground = UIUtil.getTreeSelectionForeground();
        } else {
          if (changed) {
            foreground = PlatformColors.BLUE;
          } else {
            foreground = UIUtil.getTreeForeground();
          }

          if (bound) {
            foreground = JBColor.MAGENTA;
          }
        }
        SearchUtil.appendFragments(
            myFilter,
            text,
            Font.PLAIN,
            foreground,
            selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground(),
            this);
      }
    }
  public StructureViewComponent(
      final FileEditor editor,
      final StructureViewModel structureViewModel,
      final Project project,
      final boolean showRootNode) {
    super(true, true);

    myProject = project;
    myFileEditor = editor;
    myTreeModel = structureViewModel;
    myTreeModelWrapper = new TreeModelWrapper(myTreeModel, this);

    SmartTreeStructure treeStructure =
        new SmartTreeStructure(project, myTreeModelWrapper) {
          public void rebuildTree() {
            if (!isDisposed()) {
              super.rebuildTree();
            }
          }

          public boolean isToBuildChildrenInBackground(final Object element) {
            return getRootElement() == element;
          }

          protected TreeElementWrapper createTree() {
            return new StructureViewTreeElementWrapper(myProject, myModel.getRoot(), myModel);
          }

          @Override
          public String toString() {
            return "structure view tree structure(model=" + myTreeModel + ")";
          }
        };

    final DefaultTreeModel model =
        new DefaultTreeModel(new DefaultMutableTreeNode(treeStructure.getRootElement()));
    myTree = new Tree(model);
    myTree.setRootVisible(showRootNode);
    myTree.setShowsRootHandles(true);

    myAbstractTreeBuilder =
        new StructureTreeBuilder(
            project,
            myTree,
            (DefaultTreeModel) myTree.getModel(),
            treeStructure,
            myTreeModelWrapper) {
          @Override
          protected boolean validateNode(Object child) {
            return isValid(child);
          }
        };
    Disposer.register(this, myAbstractTreeBuilder);
    Disposer.register(
        myAbstractTreeBuilder,
        new Disposable() {
          public void dispose() {
            storeState();
          }
        });

    setContent(ScrollPaneFactory.createScrollPane(myAbstractTreeBuilder.getTree()));

    myAbstractTreeBuilder.getTree().setCellRenderer(new NodeRenderer());

    myAutoScrollToSourceHandler = new MyAutoScrollToSourceHandler();
    myAutoScrollFromSourceHandler = new MyAutoScrollFromSourceHandler(myProject, this);

    JComponent toolbarComponent =
        ActionManager.getInstance()
            .createActionToolbar(ActionPlaces.STRUCTURE_VIEW_TOOLBAR, createActionGroup(), true)
            .getComponent();
    setToolbar(toolbarComponent);

    installTree();

    myCopyPasteDelegator =
        new CopyPasteDelegator(myProject, getTree()) {
          @NotNull
          protected PsiElement[] getSelectedElements() {
            return getSelectedPsiElements();
          }
        };
  }
 private AnAction createRecentFindUsagesAction() {
   AnAction action = ActionManager.getInstance().getAction(SHOW_RECENT_FIND_USAGES_ACTION_ID);
   action.registerCustomShortcutSet(action.getShortcutSet(), getComponent());
   return action;
 }