Example usage for com.intellij.openapi.actionSystem ActionPlaces MAIN_MENU

List of usage examples for com.intellij.openapi.actionSystem ActionPlaces MAIN_MENU

Introduction

In this page you can find the example usage for com.intellij.openapi.actionSystem ActionPlaces MAIN_MENU.

Prototype

String MAIN_MENU

To view the source code for com.intellij.openapi.actionSystem ActionPlaces MAIN_MENU.

Click Source Link

Usage

From source file:com.android.tools.idea.actions.MeetAndroidStudioHelpAction.java

License:Apache License

@Override
public void update(AnActionEvent e) {
    if (e.getPlace().equals(ActionPlaces.MAIN_MENU)) {
        // Remove the toolbar icon from the menu to keep all the menu items left aligned:
        Presentation presentation = e.getPresentation();
        presentation.setIcon(null);//w ww  .j ava  2s .  c  o  m
    }
}

From source file:com.intellij.analysis.BaseAnalysisAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    DataContext dataContext = e.getDataContext();
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final Module module = e.getData(LangDataKeys.MODULE);
    if (project == null) {
        return;//from  w w  w.ja va  2s  .c o  m
    }
    AnalysisScope scope = getInspectionScope(dataContext);
    LOG.assertTrue(scope != null);
    final boolean rememberScope = e.getPlace().equals(ActionPlaces.MAIN_MENU);
    final AnalysisUIOptions uiOptions = AnalysisUIOptions.getInstance(project);
    PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
    BaseAnalysisActionDialog dlg = new BaseAnalysisActionDialog(
            AnalysisScopeBundle.message("specify.analysis.scope", myTitle),
            AnalysisScopeBundle.message("analysis.scope.title", myAnalysisNoon), project, scope,
            module != null ? ModuleUtilCore.getModuleNameInReadAction(module) : null, rememberScope,
            AnalysisUIOptions.getInstance(project), element) {
        @Override
        @Nullable
        protected JComponent getAdditionalActionSettings(final Project project) {
            return BaseAnalysisAction.this.getAdditionalActionSettings(project, this);
        }

        @Override
        protected void doHelpAction() {
            HelpManager.getInstance().invokeHelp(getHelpTopic());
        }

        @NotNull
        @Override
        protected Action[] createActions() {
            return new Action[] { getOKAction(), getCancelAction(), getHelpAction() };
        }
    };
    dlg.show();
    if (!dlg.isOK()) {
        canceled();
        return;
    }
    final int oldScopeType = uiOptions.SCOPE_TYPE;
    scope = dlg.getScope(uiOptions, scope, project, module);
    if (!rememberScope) {
        uiOptions.SCOPE_TYPE = oldScopeType;
    }
    uiOptions.ANALYZE_TEST_SOURCES = dlg.isInspectTestSources();
    FileDocumentManager.getInstance().saveAllDocuments();

    analyze(project, scope);
}

From source file:com.intellij.codeInspection.actions.ViewOfflineResultsAction.java

License:Apache License

@Override
public void update(AnActionEvent event) {
    final Presentation presentation = event.getPresentation();
    final Project project = event.getData(CommonDataKeys.PROJECT);
    presentation.setEnabled(project != null);
    presentation.setVisible(ActionPlaces.MAIN_MENU.equals(event.getPlace()));
}

From source file:com.intellij.compiler.actions.CompileAction.java

License:Apache License

public void update(AnActionEvent event) {
    super.update(event);
    Presentation presentation = event.getPresentation();
    if (!presentation.isEnabled()) {
        return;//from w  w  w.j a v a  2s .  com
    }
    DataContext dataContext = event.getDataContext();

    presentation.setText(ActionsBundle.actionText(IdeActions.ACTION_COMPILE));
    presentation.setVisible(true);

    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
        presentation.setEnabled(false);
        return;
    }

    final Module module = LangDataKeys.MODULE_CONTEXT.getData(dataContext);

    final VirtualFile[] files = getCompilableFiles(project,
            PlatformDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext));
    if (module == null && files.length == 0) {
        presentation.setEnabled(false);
        presentation.setVisible(!ActionPlaces.isPopupPlace(event.getPlace()));
        return;
    }

    String elementDescription = null;
    if (module != null) {
        elementDescription = CompilerBundle.message("action.compile.description.module", module.getName());
    } else {
        PsiPackage aPackage = null;
        if (files.length == 1) {
            final PsiDirectory directory = PsiManager.getInstance(project).findDirectory(files[0]);
            if (directory != null) {
                aPackage = PsiPackageManager.getInstance(project).findAnyPackage(directory);
            }
        } else {
            PsiElement element = LangDataKeys.PSI_ELEMENT.getData(dataContext);
            if (element instanceof PsiPackage) {
                aPackage = (PsiPackage) element;
            }
        }

        if (aPackage != null) {
            String name = aPackage.getQualifiedName();
            if (name.length() == 0) {
                //noinspection HardCodedStringLiteral
                name = "<default>";
            }
            elementDescription = "'" + name + "'";
        } else if (files.length == 1) {
            final VirtualFile file = files[0];
            FileType fileType = file.getFileType();
            if (CompilerManager.getInstance(project).isCompilableFileType(fileType)
                    || isCompilableResourceFile(project, file)) {
                elementDescription = "'" + file.getName() + "'";
            } else {
                if (!ActionPlaces.MAIN_MENU.equals(event.getPlace())) {
                    // the action should be invisible in popups for non-java files
                    presentation.setEnabled(false);
                    presentation.setVisible(false);
                    return;
                }
            }
        } else {
            elementDescription = CompilerBundle.message("action.compile.description.selected.files");
        }
    }

    if (elementDescription == null) {
        presentation.setEnabled(false);
        return;
    }

    presentation.setText(createPresentationText(elementDescription), true);
    presentation.setEnabled(true);
}

From source file:com.intellij.compiler.actions.ProcessAnnotationsAction.java

License:Apache License

@Override
public void update(AnActionEvent event) {
    super.update(event);
    Presentation presentation = event.getPresentation();
    if (!presentation.isEnabled()) {
        return;/*from ww  w .  ja v a 2  s  .  com*/
    }
    DataContext dataContext = event.getDataContext();
    presentation.setVisible(false);

    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
        presentation.setEnabled(false);
        return;
    }

    final JavaCompilerConfiguration compilerConfiguration = JavaCompilerConfiguration.getInstance(project);

    final Module module = LangDataKeys.MODULE.getData(dataContext);
    final Module moduleContext = LangDataKeys.MODULE_CONTEXT.getData(dataContext);

    if (module == null) {
        presentation.setEnabled(false);
        return;
    }
    final AnnotationProcessingConfiguration profile = compilerConfiguration
            .getAnnotationProcessingConfiguration(module);
    if (!profile.isEnabled()
            || (!profile.isObtainProcessorsFromClasspath() && profile.getProcessors().isEmpty())) {
        presentation.setEnabled(false);
        return;
    }

    presentation.setVisible(true);
    presentation.setText(createPresentationText(""), true);
    final FileSetCompileScope scope = getCompilableFiles(project,
            PlatformDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext));
    if (moduleContext == null && scope == null) {
        presentation.setEnabled(false);
        return;
    }

    String elementDescription = null;
    if (moduleContext != null) {
        elementDescription = CompilerBundle.message("action.compile.description.module",
                moduleContext.getName());
    } else {
        PsiJavaPackage aPackage = null;
        final Collection<VirtualFile> files = scope.getRootFiles();
        if (files.size() == 1) {
            final PsiDirectory directory = PsiManager.getInstance(project)
                    .findDirectory(files.iterator().next());
            if (directory != null) {
                aPackage = JavaDirectoryService.getInstance().getPackage(directory);
            }
        } else {
            PsiElement element = LangDataKeys.PSI_ELEMENT.getData(dataContext);
            if (element instanceof PsiJavaPackage) {
                aPackage = (PsiJavaPackage) element;
            }
        }

        if (aPackage != null) {
            String name = aPackage.getQualifiedName();
            if (name.length() == 0) {
                //noinspection HardCodedStringLiteral
                name = "<default>";
            }
            elementDescription = "'" + name + "'";
        } else if (files.size() == 1) {
            final VirtualFile file = files.iterator().next();
            FileType fileType = file.getFileType();
            if (CompilerManager.getInstance(project).isCompilableFileType(fileType)) {
                elementDescription = "'" + file.getName() + "'";
            } else {
                if (!ActionPlaces.MAIN_MENU.equals(event.getPlace())) {
                    // the action should be invisible in popups for non-java files
                    presentation.setEnabled(false);
                    presentation.setVisible(false);
                    return;
                }
            }
        } else {
            elementDescription = CompilerBundle.message("action.compile.description.selected.files");
        }
    }

    if (elementDescription == null) {
        presentation.setEnabled(false);
        return;
    }

    presentation.setText(createPresentationText(elementDescription), true);
    presentation.setEnabled(true);
}

From source file:com.intellij.debugger.actions.PopFrameAction.java

License:Apache License

public void update(AnActionEvent e) {
    boolean enable = false;
    StackFrameProxyImpl stackFrameProxy = getStackFrameProxy(e);

    if (stackFrameProxy != null && isAtBreakpoint(e)) {
        VirtualMachineProxyImpl virtualMachineProxy = stackFrameProxy.getVirtualMachine();
        enable = virtualMachineProxy.canPopFrames();
    }//from   www  .  j  a va 2  s.c  om

    if (ActionPlaces.MAIN_MENU.equals(e.getPlace()) || ActionPlaces.DEBUGGER_TOOLBAR.equals(e.getPlace())) {
        e.getPresentation().setEnabled(enable);
    } else {
        e.getPresentation().setVisible(enable);
    }
}

From source file:com.intellij.execution.actions.StopAction.java

License:Apache License

@Override
public void update(final AnActionEvent e) {
    boolean enable = false;
    Icon icon = getTemplatePresentation().getIcon();
    String description = getTemplatePresentation().getDescription();
    final Presentation presentation = e.getPresentation();

    if (ActionPlaces.MAIN_MENU.equals(e.getPlace())) {
        enable = !getCancellableProcesses(e.getProject()).isEmpty()
                || !getActiveDescriptors(e.getDataContext()).isEmpty();
    } else {//from w  w  w  . j a v a 2s  .co m
        final ProcessHandler processHandler = getHandler(e.getDataContext());
        if (processHandler != null && !processHandler.isProcessTerminated()) {
            if (!processHandler.isProcessTerminating()) {
                enable = true;
            } else if (processHandler instanceof KillableProcess
                    && ((KillableProcess) processHandler).canKillProcess()) {
                enable = true;
                icon = AllIcons.Debugger.KillProcess;
                description = "Kill process";
            }
        }
    }

    presentation.setEnabled(enable);
    presentation.setIcon(icon);
    presentation.setDescription(description);
}

From source file:com.intellij.execution.actions.StopAction.java

License:Apache License

@Override
public void actionPerformed(final AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    ProcessHandler activeProcessHandler = getHandler(dataContext);

    List<Pair<TaskInfo, ProgressIndicator>> backgroundTasks = getCancellableProcesses(e.getProject());
    if (ActionPlaces.MAIN_MENU.equals(e.getPlace())) {
        if (activeProcessHandler != null && !activeProcessHandler.isProcessTerminating()
                && !activeProcessHandler.isProcessTerminated() && backgroundTasks.isEmpty()) {
            stopProcess(activeProcessHandler);
            return;
        }/*from   w  w  w  .j a va2  s.c o  m*/

        Pair<List<HandlerItem>, HandlerItem> handlerItems = getItemsList(backgroundTasks,
                getActiveDescriptors(dataContext), activeProcessHandler);
        if (handlerItems.first.isEmpty())
            return;

        final JBList list = new JBList(handlerItems.first);
        if (handlerItems.second != null)
            list.setSelectedValue(handlerItems.second, true);

        list.setCellRenderer(new GroupedItemsListRenderer(new ListItemDescriptor() {
            @Nullable
            @Override
            public String getTextFor(Object value) {
                return value instanceof HandlerItem ? ((HandlerItem) value).displayName : null;
            }

            @Nullable
            @Override
            public String getTooltipFor(Object value) {
                return null;
            }

            @Nullable
            @Override
            public Icon getIconFor(Object value) {
                return value instanceof HandlerItem ? ((HandlerItem) value).icon : null;
            }

            @Override
            public boolean hasSeparatorAboveOf(Object value) {
                return value instanceof HandlerItem && ((HandlerItem) value).hasSeparator;
            }

            @Nullable
            @Override
            public String getCaptionAboveOf(Object value) {
                return null;
            }
        }));

        final PopupChooserBuilder builder = JBPopupFactory.getInstance().createListPopupBuilder(list);
        final JBPopup popup = builder.setMovable(true)
                .setTitle(handlerItems.first.size() == 1 ? "Confirm process stop" : "Stop process")
                .setFilteringEnabled(new Function<Object, String>() {
                    @Override
                    public String fun(Object o) {
                        return ((HandlerItem) o).displayName;
                    }
                }).setItemChoosenCallback(new Runnable() {
                    @Override
                    public void run() {
                        HandlerItem item = (HandlerItem) list.getSelectedValue();
                        if (item != null)
                            item.stop();
                    }
                }).setRequestFocus(true).createPopup();

        popup.showCenteredInCurrentWindow(e.getProject());
    } else {
        if (activeProcessHandler != null) {
            stopProcess(activeProcessHandler);
        }
    }
}

From source file:com.intellij.ide.actions.AssociateFileType.java

License:Apache License

@Override
public void update(AnActionEvent e) {
    Presentation presentation = e.getPresentation();
    DataContext dataContext = e.getDataContext();
    VirtualFile file = PlatformDataKeys.VIRTUAL_FILE.getData(dataContext);
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    boolean haveSmthToDo;
    if (project == null || file == null || file.isDirectory()) {
        haveSmthToDo = false;/* w  w w .  j  a va 2s.c  om*/
    } else {
        // the action should also be available for files which have been auto-detected as text or as a particular language (IDEA-79574)
        haveSmthToDo = FileTypeManager.getInstance()
                .getFileTypeByFileName(file.getName()) == UnknownFileType.INSTANCE;
    }
    presentation.setVisible(haveSmthToDo || ActionPlaces.MAIN_MENU.equals(e.getPlace()));
    presentation.setEnabled(haveSmthToDo);
}

From source file:com.intellij.ide.actions.ContextHelpAction.java

License:Apache License

public void update(AnActionEvent event) {
    Presentation presentation = event.getPresentation();
    if (!ApplicationInfo.contextHelpAvailable()) {
        presentation.setVisible(false);/*from   w ww . j  a va 2s . c  o  m*/
        return;
    }

    if (ActionPlaces.MAIN_MENU.equals(event.getPlace())) {
        DataContext dataContext = event.getDataContext();
        presentation.setEnabled(getHelpId(dataContext) != null);
    } else {
        presentation.setIcon(AllIcons.Actions.Help);
        presentation.setText(CommonBundle.getHelpButtonText());
    }
}