Example usage for com.intellij.openapi.actionSystem DefaultActionGroup remove

List of usage examples for com.intellij.openapi.actionSystem DefaultActionGroup remove

Introduction

In this page you can find the example usage for com.intellij.openapi.actionSystem DefaultActionGroup remove.

Prototype

public final void remove(@NotNull AnAction action) 

Source Link

Document

Removes specified action from group.

Usage

From source file:be.cegeka.intellij.plugin.configurablefilename.settings.PluginSettings.java

License:Open Source License

public void removeActions() {
    ActionManager am = ActionManager.getInstance();
    DefaultActionGroup newGroup = (DefaultActionGroup) am.getAction("NewGroup");
    for (ConfigurableFilename filename : filenames) {
        AnAction action = am.getAction("ConfigurableFileName." + filename.getType());
        am.unregisterAction("ConfigurableFileName." + filename.getType());
        newGroup.remove(action);
    }/*from  w  w w .  j a va  2s .  c  o  m*/
}

From source file:com.android.tools.idea.startup.GradleSpecificInitializer.java

License:Apache License

private static void replaceProjectPopupActions() {
    Deque<Pair<DefaultActionGroup, AnAction>> stack = new ArrayDeque<>();
    stack.add(Pair.of(null, ActionManager.getInstance().getAction("ProjectViewPopupMenu")));
    while (!stack.isEmpty()) {
        Pair<DefaultActionGroup, AnAction> entry = stack.pop();
        DefaultActionGroup parent = entry.getFirst();
        AnAction action = entry.getSecond();
        if (action instanceof DefaultActionGroup) {
            DefaultActionGroup actionGroup = (DefaultActionGroup) action;
            for (AnAction child : actionGroup.getChildActionsOrStubs()) {
                stack.push(Pair.of(actionGroup, child));
            }/*from w  w  w .  j  a va 2  s .  c o m*/
        }

        if (action instanceof MoveModuleToGroupTopLevel) {
            parent.remove(action);
            parent.add(new AndroidActionGroupRemover((ActionGroup) action, "Move Module to Group"),
                    new Constraints(AFTER, "OpenModuleSettings"));
        } else if (action instanceof MarkRootGroup) {
            parent.remove(action);
            parent.add(new AndroidActionGroupRemover((ActionGroup) action, "Mark Directory As"),
                    new Constraints(AFTER, "OpenModuleSettings"));
        }
    }
}

From source file:com.google.cloud.tools.intellij.debugger.CloudDebugProcess.java

License:Apache License

@Override
public void registerAdditionalActions(@NotNull DefaultActionGroup leftToolbar,
        @NotNull DefaultActionGroup topToolbar, @NotNull DefaultActionGroup settings) {
    ActionManager manager = ActionManager.getInstance();
    leftToolbar.add(new SaveAndExitAction(), new Constraints(Anchor.AFTER, IdeActions.ACTION_STOP_PROGRAM));

    leftToolbar.remove(manager.getAction(IdeActions.ACTION_RERUN));
    leftToolbar.remove(manager.getAction(IdeActions.ACTION_STOP_PROGRAM));

    // XDebugSessionTab puts this action second from end.
    AnAction[] actions = leftToolbar.getChildActionsOrStubs();
    for (AnAction action : actions) {
        String text = action.getTemplatePresentation().getText();
        if (ExecutionBundle.message("close.tab.action.name").equals(text)) {
            leftToolbar.remove(action);//  w  w  w.jav  a  2 s .  com
            break;
        }
    }

    // remove help button since it points to the IntelliJ help by default and we don't have
    // a help page yet.
    // for some reason, the help button's key in leftToolbar is null, so we need to remove it
    // by class name.
    // https://github.com/GoogleCloudPlatform/gcloud-intellij/issues/149
    for (AnAction child : leftToolbar.getChildActionsOrStubs()) {
        if (child.getClass().getCanonicalName()
                .equalsIgnoreCase("com.intellij.ide.actions.ContextHelpAction")) {
            // we never want to show IDEA's help.
            leftToolbar.remove(child);

            // show our help if we have it.
            String helpUrl = GctBundle.getString("clouddebug.helpurl");
            if (!"".equals(helpUrl)) {
                leftToolbar.add(new CloudDebugHelpAction(helpUrl));
            }
            break;
        }
    }

    leftToolbar.remove(manager.getAction(XDebuggerActions.RESUME));
    leftToolbar.remove(manager.getAction(XDebuggerActions.PAUSE));
    leftToolbar.remove(manager.getAction(XDebuggerActions.MUTE_BREAKPOINTS));

    topToolbar.remove(manager.getAction(XDebuggerActions.STEP_OVER));
    topToolbar.remove(manager.getAction(XDebuggerActions.STEP_INTO));
    topToolbar.remove(manager.getAction(XDebuggerActions.FORCE_STEP_INTO));
    topToolbar.remove(manager.getAction(XDebuggerActions.STEP_OUT));
    topToolbar.remove(manager.getAction(XDebuggerActions.RUN_TO_CURSOR));
    topToolbar.remove(manager.getAction(XDebuggerActions.EVALUATE_EXPRESSION));
    topToolbar.remove(manager.getAction(DebuggerActions.POP_FRAME));
}

From source file:com.google.gct.idea.debugger.CloudDebugProcess.java

License:Apache License

@Override
public void registerAdditionalActions(@NotNull DefaultActionGroup leftToolbar,
        @NotNull DefaultActionGroup topToolbar, @NotNull DefaultActionGroup settings) {
    ActionManager manager = ActionManager.getInstance();
    leftToolbar.add(new SaveAndExitAction(), new Constraints(Anchor.AFTER, IdeActions.ACTION_STOP_PROGRAM));

    leftToolbar.remove(manager.getAction(IdeActions.ACTION_RERUN));
    leftToolbar.remove(manager.getAction(IdeActions.ACTION_STOP_PROGRAM));
    leftToolbar.remove(manager.getAction(XDebuggerActions.RESUME));
    leftToolbar.remove(manager.getAction(XDebuggerActions.PAUSE));
    leftToolbar.remove(manager.getAction(XDebuggerActions.MUTE_BREAKPOINTS));

    topToolbar.remove(manager.getAction(XDebuggerActions.STEP_OVER));
    topToolbar.remove(manager.getAction(XDebuggerActions.STEP_INTO));
    topToolbar.remove(manager.getAction(XDebuggerActions.FORCE_STEP_INTO));
    topToolbar.remove(manager.getAction(XDebuggerActions.STEP_OUT));
    topToolbar.remove(manager.getAction(XDebuggerActions.RUN_TO_CURSOR));
    topToolbar.remove(manager.getAction(XDebuggerActions.EVALUATE_EXPRESSION));
}

From source file:com.intellij.execution.ExecutorRegistryImpl.java

License:Apache License

private void unregisterAction(@NotNull final String actionId, @NotNull final String groupId,
        @NotNull final Map<String, AnAction> map) {
    final DefaultActionGroup group = (DefaultActionGroup) myActionManager.getAction(groupId);
    if (group != null) {
        group.remove(myActionManager.getAction(actionId));
        final AnAction action = map.get(actionId);
        if (action != null) {
            myActionManager.unregisterAction(actionId);
            map.remove(actionId);/*from  w w w. ja v a2  s  .c om*/
        }
    }
}

From source file:com.microsoft.alm.plugin.idea.common.ui.controls.WorkItemQueryDropDown.java

License:Open Source License

private void addQueriesFromServer(final DefaultActionGroup group) {
    final AtomicBoolean isContextFound = new AtomicBoolean(true);
    WorkItemQueriesLookupOperation operation = new WorkItemQueriesLookupOperation(repositoryContext);
    operation.addListener(new Operation.Listener() {
        @Override//from ww  w  .  ja va2  s.  co  m
        public void notifyLookupStarted() {
            // nothing to do
            logger.info("WorkItemQueriesLookupOperation started.");
        }

        @Override
        public void notifyLookupCompleted() {
            logger.info("WorkItemQueriesLookupOperation completed and context found: " + isContextFound.get());
            // only remove loading when we have actually gotten a context and made a successful call to get the queries
            if (isContextFound.get()) {
                IdeaHelper.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        group.remove(loadingAction);
                    }
                });
            }
        }

        @Override
        public void notifyLookupResults(final Operation.Results results) {
            final WorkItemQueriesLookupOperation.QueryResults wiResults = (WorkItemQueriesLookupOperation.QueryResults) results;

            if (wiResults.isCancelled()) {
                // Do nothing
                logger.info("WorkItemQueriesLookupOperation was cancelled");
            } else {
                final ServerContext newContext;
                if (wiResults.hasError() && AuthHelper.isNotAuthorizedError(wiResults.getError())) {
                    isContextFound.set(false);
                    //401 or 403 - token is not valid, prompt user for credentials and retry
                    newContext = ServerContextManager.getInstance()
                            .createContextFromGitRemoteUrl(repositoryContext.getUrl(), false);
                } else {
                    newContext = null;
                }
                // Update table model on UI thread
                IdeaHelper.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        if (wiResults.hasError()) {
                            if (AuthHelper.isNotAuthorizedError(wiResults.getError())) {
                                logger.warn("WorkItemQueriesLookupOperation failed due to auth error");
                                if (newContext != null) {
                                    isContextFound.set(true);
                                    //retry loading workitems with new context and authentication info
                                    addQueriesFromServer(group);
                                } else {
                                    //user cancelled login, don't retry
                                    logger.info("WorkItemQueriesLookupOperation was cancelled");
                                }
                            } else {
                                IdeaHelper.showErrorDialog(project, wiResults.getError());
                            }
                        }

                        // add results to the menu
                        for (final QueryHierarchyItem item : wiResults.getQueries()) {
                            //TODO check for folder items here and handle appropriately
                            group.add(new QueryAction(item.getName(), item.getWiql()));
                        }
                    }
                });
            }
        }
    });
    operation.doWorkAsync(queryOperationInput);
}

From source file:com.twitter.intellij.pants.ui.PantsCompileActionGroup.java

License:Apache License

@NotNull
@Override/*ww w .j a  v a 2s.  c o m*/
public AnAction[] getChildren(@Nullable AnActionEvent event) {
    //  Deletes existing make and compile options.
    ActionManager actionManager = ActionManager.getInstance();
    DefaultActionGroup actionGroup = (DefaultActionGroup) actionManager.getAction("ProjectViewCompileGroup");
    actionGroup.remove(actionManager.getAction("MakeModule"));
    actionGroup.remove(actionManager.getAction("Compile"));

    final AnAction[] emptyAction = new AnAction[0];

    if (event == null) {
        return emptyAction;
    }

    Project project = event.getProject();
    VirtualFile file = event.getData(CommonDataKeys.VIRTUAL_FILE);

    if (project == null || file == null) {
        return emptyAction;
    }

    Module module = ModuleUtil.findModuleForFile(file, project);
    List<String> targetAddresses = PantsUtil.getTargetAddressesFromModule(module).stream()
            .map(PantsTargetAddress::toString).collect(Collectors.toList());

    if (targetAddresses.isEmpty()) {
        return emptyAction;
    }

    LinkedList<AnAction> actions = new LinkedList<AnAction>();

    //  Adds compile all option for modules with multiple targets.
    if (targetAddresses.size() > 1) {
        actions.push(new PantsCompileTargetAction(targetAddresses));
    }

    for (String targetAddress : targetAddresses) {
        actions.push(new PantsCompileTargetAction(targetAddress));
    }

    return actions.toArray(emptyAction);
}

From source file:generate.tostring.psi.PsiAdapter.java

License:Apache License

/**
 * Removes the action from the menu./* w  ww.ja  v  a2s. c  o  m*/
 * <p/>
 * The group must be of a DefaultActionGroup instance, if not this method returns false.
 *
 * @param actionId group id of the action to remove.
 * @param menuId   id of the menu that contains the action. See ActionManager.xml in the IDEA openapi folder.
 * @return true if the action was remove, false if not (action could not be found)
 */
public boolean removeActionFromMenu(String actionId, String menuId) {
    ActionManager am = ActionManager.getInstance();
    AnAction group = am.getAction(menuId);

    // must be default action group
    if (group instanceof DefaultActionGroup) {
        DefaultActionGroup defGroup = (DefaultActionGroup) group;

        // loop children (actions) and remove the matching id
        AnAction[] actions = defGroup.getChildren(null);
        for (AnAction action : actions) {
            String id = am.getId(action);

            // if match id then remove action from menu
            if (actionId.equals(id)) {
                defGroup.remove(action);
                return true;
            }

        }

    }

    // action to remove not found
    return false;
}

From source file:io.ballerina.plugins.idea.debugger.BallerinaDebugProcess.java

License:Open Source License

@Override
public void registerAdditionalActions(@NotNull DefaultActionGroup leftToolbar,
        @NotNull DefaultActionGroup topToolbar, @NotNull DefaultActionGroup settings) {
    super.registerAdditionalActions(leftToolbar, topToolbar, settings);
    topToolbar.remove(ActionManager.getInstance().getAction(XDebuggerActions.RUN_TO_CURSOR));
}

From source file:io.flutter.run.FlutterDebugProcess.java

License:Open Source License

@Override
public void registerAdditionalActions(@NotNull final DefaultActionGroup leftToolbar,
        @NotNull final DefaultActionGroup topToolbar, @NotNull final DefaultActionGroup settings) {

    if (app.getMode() != RunMode.DEBUG) {
        // Remove the debug-specific actions that aren't needed when we're not debugging.

        // Remove all but specified actions.
        final AnAction[] leftActions = leftToolbar.getChildActionsOrStubs();
        // Not all on the classpath so we resort to Strings.
        final List<String> actionClassNames = Arrays.asList("com.intellij.execution.actions.StopAction",
                "com.intellij.ui.content.tabs.PinToolwindowTabAction",
                "com.intellij.execution.ui.actions.CloseAction", "com.intellij.ide.actions.ContextHelpAction");
        for (AnAction a : leftActions) {
            if (!actionClassNames.contains(a.getClass().getName())) {
                leftToolbar.remove(a);
            }/*  w  ww .j ava  2  s  .  c o m*/
        }

        // Remove all top actions.
        final AnAction[] topActions = topToolbar.getChildActionsOrStubs();
        for (AnAction action : topActions) {
            topToolbar.remove(action);
        }

        // Remove all settings actions.
        final AnAction[] settingsActions = settings.getChildActionsOrStubs();
        for (AnAction a : settingsActions) {
            settings.remove(a);
        }
    }

    // Add actions common to run and debug windows.

    final Computable<Boolean> isSessionActive = () -> app.isStarted() && getVmConnected()
            && !getSession().isStopped();
    final Computable<Boolean> canReload = () -> app.getMode().isReloadEnabled() && isSessionActive.compute();

    topToolbar.addSeparator();
    topToolbar.addAction(new OpenObservatoryAction(app.getConnector(), isSessionActive));
    topToolbar.addSeparator();
    topToolbar.addAction(new ReloadFlutterApp(app, canReload));
    topToolbar.addAction(new RestartFlutterApp(app, canReload));

    // Don't call super since we have our own observatory action.
}