Search in sources :

Example 21 with CustomShortcutSet

use of com.intellij.openapi.actionSystem.CustomShortcutSet 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 22 with CustomShortcutSet

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

the class SvnConfigureProxiesComponent method createActions.

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

        {
            registerCustomShortcutSet(CommonShortcuts.INSERT, myTree);
        }

        public void actionPerformed(AnActionEvent event) {
            addGroup(null);
        }
    });
    result.add(new MyDeleteAction(forAll(o -> {
        if (o instanceof MyNode) {
            final MyNode node = (MyNode) o;
            if (node.getConfigurable() instanceof GroupConfigurable) {
                final ProxyGroup group = ((GroupConfigurable) node.getConfigurable()).getEditableObject();
                return !group.isDefault();
            }
        }
        return false;
    })) {

        public void actionPerformed(final AnActionEvent e) {
            final TreePath path = myTree.getSelectionPath();
            final MyNode node = (MyNode) path.getLastPathComponent();
            final MyNode parentNode = (MyNode) node.getParent();
            int idx = parentNode.getIndex(node);
            super.actionPerformed(e);
            idx = (idx == parentNode.getChildCount()) ? idx - 1 : idx;
            if (parentNode.getChildCount() > 0) {
                final TreePath newSelectedPath = new TreePath(parentNode.getPath()).pathByAddingChild(parentNode.getChildAt(idx));
                myTree.setSelectionPath(newSelectedPath);
            }
        }
    });
    result.add(new AnAction("Copy", "Copy", PlatformIcons.COPY_ICON) {

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

        public void actionPerformed(AnActionEvent event) {
            // apply - for update of editable object
            try {
                getSelectedConfigurable().apply();
            } catch (ConfigurationException e) {
            // suppress & wait for OK
            }
            final ProxyGroup selectedGroup = (ProxyGroup) getSelectedObject();
            if (selectedGroup != null) {
                addGroup(selectedGroup);
            }
        }

        public void update(AnActionEvent event) {
            super.update(event);
            event.getPresentation().setEnabled(getSelectedObject() != null);
        }
    });
    return result;
}
Also used : CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) TreePath(javax.swing.tree.TreePath) ConfigurationException(com.intellij.openapi.options.ConfigurationException) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 23 with CustomShortcutSet

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

the class IpnbFileEditor method registerHeadingActions.

private void registerHeadingActions() {
    new IpnbHeading1CellAction().registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("ctrl shift 1")), myIpnbFilePanel);
    new IpnbHeading2CellAction().registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("ctrl shift 2")), myIpnbFilePanel);
    new IpnbHeading3CellAction().registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("ctrl shift 3")), myIpnbFilePanel);
    new IpnbHeading4CellAction().registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("ctrl shift 4")), myIpnbFilePanel);
    new IpnbHeading5CellAction().registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("ctrl shift 5")), myIpnbFilePanel);
    new IpnbHeading6CellAction().registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("ctrl shift 6")), myIpnbFilePanel);
}
Also used : CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet)

Aggregations

CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)23 AnAction (com.intellij.openapi.actionSystem.AnAction)13 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)13 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)4 ConfigurationException (com.intellij.openapi.options.ConfigurationException)3 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)3 KeyEvent (java.awt.event.KeyEvent)3 Disposable (com.intellij.openapi.Disposable)2 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)2 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)2 FileChooser (com.intellij.openapi.fileChooser.FileChooser)2 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)2 StdFileTypes (com.intellij.openapi.fileTypes.StdFileTypes)2 SearchableConfigurable (com.intellij.openapi.options.SearchableConfigurable)2 Project (com.intellij.openapi.project.Project)2 DialogBuilder (com.intellij.openapi.ui.DialogBuilder)2 FrameWrapper (com.intellij.openapi.ui.FrameWrapper)2 Messages (com.intellij.openapi.ui.Messages)2 TreePath (javax.swing.tree.TreePath)2