Search in sources :

Example 36 with DumbAwareAction

use of com.intellij.openapi.project.DumbAwareAction in project intellij-community by JetBrains.

the class ChangesBrowserBase method buildToolBar.

protected void buildToolBar(final DefaultActionGroup toolBarGroup) {
    myDiffAction = new DumbAwareAction() {

        public void update(AnActionEvent e) {
            e.getPresentation().setEnabled(canShowDiff());
        }

        public void actionPerformed(AnActionEvent e) {
            showDiff();
        }
    };
    ActionUtil.copyFrom(myDiffAction, "ChangesView.Diff");
    myDiffAction.registerCustomShortcutSet(myViewer, null);
    toolBarGroup.add(myDiffAction);
}
Also used : DumbAwareAction(com.intellij.openapi.project.DumbAwareAction)

Example 37 with DumbAwareAction

use of com.intellij.openapi.project.DumbAwareAction in project intellij-community by JetBrains.

the class CopyrightProfilesPanel method createActions.

@Override
@Nullable
protected ArrayList<AnAction> createActions(boolean fromPopup) {
    ArrayList<AnAction> result = new ArrayList<>();
    result.add(new DumbAwareAction("Add", "Add", IconUtil.getAddIcon()) {

        {
            registerCustomShortcutSet(CommonShortcuts.INSERT, myTree);
        }

        @Override
        public void actionPerformed(AnActionEvent event) {
            String name = askForProfileName("Create Copyright Profile", "");
            if (name != null) {
                addProfileNode(new CopyrightProfile(name));
            }
        }
    });
    result.add(new MyDeleteAction());
    result.add(new DumbAwareAction("Copy", "Copy", PlatformIcons.COPY_ICON) {

        {
            registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_MASK)), myTree);
        }

        @Override
        public void actionPerformed(AnActionEvent event) {
            String profileName = askForProfileName("Copy Copyright Profile", "");
            if (profileName == null) {
                return;
            }
            CopyrightProfile clone = new CopyrightProfile();
            clone.copyFrom((CopyrightProfile) getSelectedObject());
            clone.setName(profileName);
            addProfileNode(clone);
        }

        @Override
        public void update(AnActionEvent event) {
            super.update(event);
            event.getPresentation().setEnabled(getSelectedObject() != null);
        }
    });
    result.add(new DumbAwareAction("Import", "Import", PlatformIcons.IMPORT_ICON) {

        @Override
        public void actionPerformed(AnActionEvent event) {
            FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor().withFileFilter(file -> {
                final FileType fileType = file.getFileType();
                return fileType != PlainTextFileType.INSTANCE && (fileType == StdFileTypes.IDEA_MODULE || fileType == StdFileTypes.XML);
            }).withTitle("Choose File Containing Copyright Notice");
            FileChooser.chooseFile(descriptor, myProject, null, file -> {
                final List<CopyrightProfile> profiles = ExternalOptionHelper.loadOptions(VfsUtilCore.virtualToIoFile(file));
                if (profiles == null)
                    return;
                if (!profiles.isEmpty()) {
                    if (profiles.size() == 1) {
                        importProfile(profiles.get(0));
                    } else {
                        JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<CopyrightProfile>("Choose profile to import", profiles) {

                            @Override
                            public PopupStep onChosen(final CopyrightProfile selectedValue, boolean finalChoice) {
                                return doFinalStep(() -> importProfile(selectedValue));
                            }

                            @NotNull
                            @Override
                            public String getTextFor(CopyrightProfile value) {
                                return value.getName();
                            }
                        }).showUnderneathOf(myNorthPanel);
                    }
                } else {
                    Messages.showWarningDialog(myProject, "The selected file does not contain any copyright settings.", "Import Failure");
                }
            });
        }

        private void importProfile(CopyrightProfile copyrightProfile) {
            final String profileName = askForProfileName("Import copyright profile", copyrightProfile.getName());
            if (profileName == null)
                return;
            copyrightProfile.setName(profileName);
            addProfileNode(copyrightProfile);
            Messages.showInfoMessage(myProject, "The copyright settings have been successfully imported.", "Import Complete");
        }
    });
    return result;
}
Also used : InputEvent(java.awt.event.InputEvent) FileChooserDescriptorFactory(com.intellij.openapi.fileChooser.FileChooserDescriptorFactory) java.util(java.util) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) HashMap(com.intellij.util.containers.HashMap) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) NonNls(org.jetbrains.annotations.NonNls) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CopyrightManager(com.intellij.copyright.CopyrightManager) Nls(org.jetbrains.annotations.Nls) Project(com.intellij.openapi.project.Project) MasterDetailsComponent(com.intellij.openapi.ui.MasterDetailsComponent) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Messages(com.intellij.openapi.ui.Messages) PlatformIcons(com.intellij.util.PlatformIcons) StdFileTypes(com.intellij.openapi.fileTypes.StdFileTypes) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) TreePath(javax.swing.tree.TreePath) CopyrightProfile(com.maddyhome.idea.copyright.CopyrightProfile) AnAction(com.intellij.openapi.actionSystem.AnAction) PlainTextFileType(com.intellij.openapi.fileTypes.PlainTextFileType) ExternalOptionHelper(com.maddyhome.idea.copyright.options.ExternalOptionHelper) FileType(com.intellij.openapi.fileTypes.FileType) KeyEvent(java.awt.event.KeyEvent) MasterDetailsStateService(com.intellij.openapi.ui.MasterDetailsStateService) Nullable(org.jetbrains.annotations.Nullable) CommonShortcuts(com.intellij.openapi.actionSystem.CommonShortcuts) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) InputValidator(com.intellij.openapi.ui.InputValidator) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) PopupStep(com.intellij.openapi.ui.popup.PopupStep) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) FileChooser(com.intellij.openapi.fileChooser.FileChooser) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) IconUtil(com.intellij.util.IconUtil) javax.swing(javax.swing) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) NotNull(org.jetbrains.annotations.NotNull) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) PlainTextFileType(com.intellij.openapi.fileTypes.PlainTextFileType) FileType(com.intellij.openapi.fileTypes.FileType) CopyrightProfile(com.maddyhome.idea.copyright.CopyrightProfile) Nullable(org.jetbrains.annotations.Nullable)

Example 38 with DumbAwareAction

use of com.intellij.openapi.project.DumbAwareAction in project intellij-community by JetBrains.

the class MultilinePopupBuilder method createPopup.

@NotNull
JBPopup createPopup() {
    JPanel panel = new JPanel(new BorderLayout());
    panel.add(myTextField, BorderLayout.CENTER);
    ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, myTextField).setCancelOnClickOutside(true).setAdText(KeymapUtil.getShortcutsText(CommonShortcuts.CTRL_ENTER.getShortcuts()) + " to finish").setRequestFocus(true).setResizable(true).setMayBeParent(true);
    final JBPopup popup = builder.createPopup();
    popup.setMinimumSize(new JBDimension(200, 90));
    AnAction okAction = new DumbAwareAction() {

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            unregisterCustomShortcutSet(popup.getContent());
            popup.closeOk(e.getInputEvent());
        }
    };
    okAction.registerCustomShortcutSet(CommonShortcuts.CTRL_ENTER, popup.getContent());
    return popup;
}
Also used : ComponentPopupBuilder(com.intellij.openapi.ui.popup.ComponentPopupBuilder) JBDimension(com.intellij.util.ui.JBDimension) JBPopup(com.intellij.openapi.ui.popup.JBPopup) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 39 with DumbAwareAction

use of com.intellij.openapi.project.DumbAwareAction in project intellij-community by JetBrains.

the class DeepCompareAction method selectBranchAndPerformAction.

private static void selectBranchAndPerformAction(@NotNull VcsLogDataPack dataPack, @NotNull AnActionEvent event, @NotNull final Consumer<String> consumer, @NotNull Collection<VirtualFile> visibleRoots) {
    ActionGroup actionGroup = new BranchPopupBuilder(dataPack, visibleRoots, null) {

        @NotNull
        @Override
        protected AnAction createAction(@NotNull final String name) {
            return new DumbAwareAction(name) {

                @Override
                public void actionPerformed(AnActionEvent e) {
                    consumer.consume(name);
                }
            };
        }
    }.build();
    ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup("Select branch to compare", actionGroup, event.getDataContext(), false, false, false, null, -1, null);
    InputEvent inputEvent = event.getInputEvent();
    if (inputEvent instanceof MouseEvent) {
        popup.show(new RelativePoint((MouseEvent) inputEvent));
    } else {
        popup.showInBestPositionFor(event.getDataContext());
    }
}
Also used : BranchPopupBuilder(com.intellij.vcs.log.ui.filter.BranchPopupBuilder) MouseEvent(java.awt.event.MouseEvent) ListPopup(com.intellij.openapi.ui.popup.ListPopup) InputEvent(java.awt.event.InputEvent) RelativePoint(com.intellij.ui.awt.RelativePoint) NotNull(org.jetbrains.annotations.NotNull) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction)

Example 40 with DumbAwareAction

use of com.intellij.openapi.project.DumbAwareAction in project android by JetBrains.

the class GradleBuildTreeViewPanel method fillRightToolbarGroup.

@Override
protected void fillRightToolbarGroup(DefaultActionGroup group) {
    super.fillRightToolbarGroup(group);
    group.add(new DumbAwareAction("Show Console Output", null, AndroidIcons.GradleConsole) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            ToolWindow window = ToolWindowManager.getInstance(myProject).getToolWindow(GradleConsoleToolWindowFactory.ID);
            if (window != null) {
                window.activate(null, false);
            }
        }

        @Override
        public void update(AnActionEvent e) {
            e.getPresentation().setEnabledAndVisible(true);
        }
    });
    DefaultActionGroup filterGroup = new DefaultActionGroup("GradleBuildMessagesFilter", true) {

        @Override
        public void update(AnActionEvent e) {
            Presentation presentation = e.getPresentation();
            presentation.setDescription("Filter messages to display");
            presentation.setIcon(AllIcons.General.Filter);
        }

        @Override
        public boolean isDumbAware() {
            return true;
        }
    };
    // We could have iterated through ErrorTreeElementKind.values() and have less code, but we want to keep this order:
    filterGroup.add(new FilterMessagesByKindAction(ErrorTreeElementKind.ERROR));
    filterGroup.add(new FilterMessagesByKindAction(ErrorTreeElementKind.WARNING));
    filterGroup.add(new FilterMessagesByKindAction(ErrorTreeElementKind.INFO));
    filterGroup.add(new FilterMessagesByKindAction(ErrorTreeElementKind.NOTE));
    filterGroup.add(new FilterMessagesByKindAction(ErrorTreeElementKind.GENERIC));
    group.add(filterGroup);
}
Also used : ToolWindow(com.intellij.openapi.wm.ToolWindow) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Presentation(com.intellij.openapi.actionSystem.Presentation) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup)

Aggregations

DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)41 NotNull (org.jetbrains.annotations.NotNull)19 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)18 AnAction (com.intellij.openapi.actionSystem.AnAction)8 Nullable (org.jetbrains.annotations.Nullable)8 List (java.util.List)6 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)4 FileChooser (com.intellij.openapi.fileChooser.FileChooser)4 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)4 SearchableConfigurable (com.intellij.openapi.options.SearchableConfigurable)4 Project (com.intellij.openapi.project.Project)4 Messages (com.intellij.openapi.ui.Messages)4 JBPopup (com.intellij.openapi.ui.popup.JBPopup)4 RelativePoint (com.intellij.ui.awt.RelativePoint)4 JBTable (com.intellij.ui.table.JBTable)4 MouseEvent (java.awt.event.MouseEvent)4 StdFileTypes (com.intellij.openapi.fileTypes.StdFileTypes)3 ConfigurationException (com.intellij.openapi.options.ConfigurationException)3 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)3 StringUtil (com.intellij.openapi.util.text.StringUtil)3