Example usage for com.intellij.openapi.actionSystem CommonShortcuts DELETE

List of usage examples for com.intellij.openapi.actionSystem CommonShortcuts DELETE

Introduction

In this page you can find the example usage for com.intellij.openapi.actionSystem CommonShortcuts DELETE.

Prototype

ShortcutSet DELETE

To view the source code for com.intellij.openapi.actionSystem CommonShortcuts DELETE.

Click Source Link

Usage

From source file:com.intellij.codeInspection.ui.InspectionResultsView.java

License:Apache License

@SuppressWarnings({ "NonStaticInitializer" })
private JComponent createRightActionsToolbar() {
    myIncludeAction = new AnAction(InspectionsBundle.message("inspections.result.view.include.action.text")) {
        {//from   w  w w.j av  a 2  s. c om
            registerCustomShortcutSet(CommonShortcuts.INSERT, myTree);
        }

        @Override
        public void actionPerformed(AnActionEvent e) {
            ((InspectionTreeNode) myTree.getSelectionPath().getLastPathComponent()).amnesty();
            updateView(false);
        }

        @Override
        public void update(final AnActionEvent e) {
            final TreePath path = myTree.getSelectionPath();
            e.getPresentation().setEnabled(
                    path != null && !myGlobalInspectionContext.getUIOptions().FILTER_RESOLVED_ITEMS);
        }
    };

    myExcludeAction = new AnAction(InspectionsBundle.message("inspections.result.view.exclude.action.text")) {
        {
            registerCustomShortcutSet(CommonShortcuts.DELETE, myTree);
        }

        @Override
        public void actionPerformed(final AnActionEvent e) {
            ((InspectionTreeNode) myTree.getSelectionPath().getLastPathComponent()).ignoreElement();
            updateView(false);
        }

        @Override
        public void update(final AnActionEvent e) {
            final TreePath path = myTree.getSelectionPath();
            e.getPresentation().setEnabled(path != null);
        }
    };

    DefaultActionGroup specialGroup = new DefaultActionGroup();
    specialGroup.add(myGlobalInspectionContext.getUIOptions().createGroupBySeverityAction(this));
    specialGroup.add(myGlobalInspectionContext.getUIOptions().createGroupByDirectoryAction(this));
    specialGroup.add(myGlobalInspectionContext.getUIOptions().createFilterResolvedItemsAction(this));
    specialGroup.add(myGlobalInspectionContext.getUIOptions().createShowOutdatedProblemsAction(this));
    specialGroup.add(myGlobalInspectionContext.getUIOptions().createShowDiffOnlyAction(this));
    specialGroup.add(new EditSettingsAction());
    specialGroup.add(new InvokeQuickFixAction(this));
    specialGroup.add(new InspectionsOptionsToolbarAction(this));
    return createToolbar(specialGroup);
}

From source file:com.intellij.debugger.ui.impl.MainWatchPanel.java

License:Apache License

public MainWatchPanel(Project project, DebuggerStateManager stateManager) {
    super(project, stateManager);
    final WatchDebuggerTree watchTree = getWatchTree();

    final AnAction removeWatchesAction = ActionManager.getInstance().getAction(DebuggerActions.REMOVE_WATCH);
    removeWatchesAction.registerCustomShortcutSet(CommonShortcuts.DELETE, watchTree);

    final AnAction newWatchAction = ActionManager.getInstance().getAction(DebuggerActions.NEW_WATCH);
    newWatchAction.registerCustomShortcutSet(CommonShortcuts.INSERT, watchTree);

    final ClickListener mouseListener = new DoubleClickListener() {
        @Override/*from w ww  . ja v  a2 s  . c  o m*/
        protected boolean onDoubleClick(MouseEvent e) {
            AnAction editWatchAction = ActionManager.getInstance().getAction(DebuggerActions.EDIT_WATCH);
            Presentation presentation = editWatchAction.getTemplatePresentation().clone();
            DataContext context = DataManager.getInstance().getDataContext(watchTree);

            AnActionEvent actionEvent = new AnActionEvent(null, context, "WATCH_TREE", presentation,
                    ActionManager.getInstance(), 0);
            editWatchAction.actionPerformed(actionEvent);
            return true;
        }
    };
    ListenerUtil.addClickListener(watchTree, mouseListener);

    final AnAction editWatchAction = ActionManager.getInstance().getAction(DebuggerActions.EDIT_WATCH);
    editWatchAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0)),
            watchTree);
    registerDisposable(new Disposable() {
        public void dispose() {
            ListenerUtil.removeClickListener(watchTree, mouseListener);
            removeWatchesAction.unregisterCustomShortcutSet(watchTree);
            newWatchAction.unregisterCustomShortcutSet(watchTree);
            editWatchAction.unregisterCustomShortcutSet(watchTree);
        }
    });

    DnDManager.getInstance().registerTarget(new DnDNativeTarget() {
        public boolean update(final DnDEvent aEvent) {
            Object object = aEvent.getAttachedObject();
            if (object == null)
                return true;

            String add = DebuggerBundle.message("watchs.add.text");

            if (object.getClass().isArray()) {
                Class<?> type = object.getClass().getComponentType();
                if (DebuggerTreeNodeImpl.class.isAssignableFrom(type)) {
                    aEvent.setHighlighting(myTree, DnDEvent.DropTargetHighlightingType.RECTANGLE
                            | DnDEvent.DropTargetHighlightingType.TEXT);
                    aEvent.setDropPossible(add, new DropActionHandler() {
                        public void performDrop(final DnDEvent aEvent) {
                            addWatchesFrom((DebuggerTreeNodeImpl[]) aEvent.getAttachedObject());
                        }
                    });
                }
            } else if (object instanceof EventInfo) {
                EventInfo info = (EventInfo) object;
                final String text = info.getTextForFlavor(DataFlavor.stringFlavor);
                if (text != null) {
                    aEvent.setHighlighting(myTree, DnDEvent.DropTargetHighlightingType.RECTANGLE
                            | DnDEvent.DropTargetHighlightingType.TEXT);
                    aEvent.setDropPossible(add, new DropActionHandler() {
                        public void performDrop(final DnDEvent aEvent) {
                            addWatchesFrom(text);
                        }
                    });
                }
            }

            return true;
        }

        public void drop(final DnDEvent aEvent) {
        }

        public void cleanUpOnLeave() {
        }

        public void updateDraggedImage(final Image image, final Point dropPoint, final Point imageOffset) {
        }
    }, myTree);
}

From source file:com.intellij.ide.fileTemplates.impl.AllFileTemplatesConfigurable.java

License:Apache License

@Override
public JComponent createComponent() {
    myUIDisposable = Disposer.newDisposable();
    myTemplatesList = new FileTemplateTabAsList(TEMPLATES_TITLE) {
        @Override/*from  w  w w. j av  a2s  .co  m*/
        public void onTemplateSelected() {
            onListSelectionChanged();
        }
    };
    myIncludesList = new FileTemplateTabAsList(INCLUDES_TITLE) {
        @Override
        public void onTemplateSelected() {
            onListSelectionChanged();
        }
    };
    myCurrentTab = myTemplatesList;

    final List<FileTemplateTab> allTabs = new ArrayList<FileTemplateTab>(
            Arrays.asList(myTemplatesList, myIncludesList));
    if (FileTemplateManager.getInstance().getAllCodeTemplates().length > 0) {
        myCodeTemplatesList = new FileTemplateTabAsList(CODE_TITLE) {
            @Override
            public void onTemplateSelected() {
                onListSelectionChanged();
            }
        };
        allTabs.add(myCodeTemplatesList);
    }

    final Set<FileTemplateGroupDescriptorFactory> factories = new THashSet<FileTemplateGroupDescriptorFactory>();
    ContainerUtil.addAll(factories,
            ApplicationManager.getApplication().getComponents(FileTemplateGroupDescriptorFactory.class));
    ContainerUtil.addAll(factories,
            Extensions.getExtensions(FileTemplateGroupDescriptorFactory.EXTENSION_POINT_NAME));

    if (!factories.isEmpty()) {
        myJ2eeTemplatesList = new FileTemplateTabAsTree(J2EE_TITLE) {
            @Override
            public void onTemplateSelected() {
                onListSelectionChanged();
            }

            @Override
            protected FileTemplateNode initModel() {
                SortedSet<FileTemplateGroupDescriptor> categories = new TreeSet<FileTemplateGroupDescriptor>(
                        new Comparator<FileTemplateGroupDescriptor>() {
                            @Override
                            public int compare(FileTemplateGroupDescriptor o1, FileTemplateGroupDescriptor o2) {
                                return o1.getTitle().compareTo(o2.getTitle());
                            }
                        });

                for (FileTemplateGroupDescriptorFactory templateGroupFactory : factories) {
                    ContainerUtil.addIfNotNull(templateGroupFactory.getFileTemplatesDescriptor(), categories);
                }

                //noinspection HardCodedStringLiteral
                return new FileTemplateNode("ROOT", null, ContainerUtil.map2List(categories,
                        new Function<FileTemplateGroupDescriptor, FileTemplateNode>() {
                            @Override
                            public FileTemplateNode fun(FileTemplateGroupDescriptor s) {
                                return new FileTemplateNode(s);
                            }
                        }));
            }
        };
        allTabs.add(myJ2eeTemplatesList);
    }
    myTabs = allTabs.toArray(new FileTemplateTab[allTabs.size()]);
    myTabbedPane = new TabbedPaneWrapper(myUIDisposable);
    myTabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    for (FileTemplateTab tab : myTabs) {
        myTabbedPane.addTab(tab.getTitle(), ScrollPaneFactory.createScrollPane(tab.getComponent()));
    }

    myTabbedPane.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            onTabChanged();
        }
    });

    DefaultActionGroup group = new DefaultActionGroup();
    AnAction removeAction = new AnAction(IdeBundle.message("action.remove.template"), null,
            AllIcons.General.Remove) {
        @Override
        public void actionPerformed(AnActionEvent e) {
            onRemove();
        }

        @Override
        public void update(AnActionEvent e) {
            super.update(e);
            FileTemplate selectedItem = myCurrentTab.getSelectedTemplate();
            e.getPresentation().setEnabled(selectedItem != null
                    && !isInternalTemplate(selectedItem.getName(), myCurrentTab.getTitle()));
        }
    };
    AnAction addAction = new AnAction(IdeBundle.message("action.create.template"), null, AllIcons.General.Add) {
        @Override
        public void actionPerformed(AnActionEvent e) {
            onAdd();
        }

        @Override
        public void update(AnActionEvent e) {
            super.update(e);
            e.getPresentation()
                    .setEnabled(!(myCurrentTab == myCodeTemplatesList || myCurrentTab == myJ2eeTemplatesList));
        }
    };
    AnAction cloneAction = new AnAction(IdeBundle.message("action.copy.template"), null,
            AllIcons.Actions.Copy) {
        @Override
        public void actionPerformed(AnActionEvent e) {
            onClone();
        }

        @Override
        public void update(AnActionEvent e) {
            super.update(e);
            e.getPresentation().setEnabled(myCurrentTab != myCodeTemplatesList
                    && myCurrentTab != myJ2eeTemplatesList && myCurrentTab.getSelectedTemplate() != null);
        }
    };
    AnAction resetAction = new AnAction(IdeBundle.message("action.reset.to.default"), null,
            AllIcons.Actions.Reset) {
        @Override
        public void actionPerformed(AnActionEvent e) {
            onReset();
        }

        @Override
        public void update(AnActionEvent e) {
            super.update(e);
            final FileTemplate selectedItem = myCurrentTab.getSelectedTemplate();
            e.getPresentation()
                    .setEnabled(selectedItem instanceof BundledFileTemplate && !selectedItem.isDefault());
        }
    };
    group.add(addAction);
    group.add(removeAction);
    group.add(cloneAction);
    group.add(resetAction);
    addAction.registerCustomShortcutSet(CommonShortcuts.INSERT, myCurrentTab.getComponent());
    removeAction.registerCustomShortcutSet(CommonShortcuts.DELETE, myCurrentTab.getComponent());

    myToolBar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true)
            .getComponent();

    myEditor = new FileTemplateConfigurable();

    myEditor.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            onEditorChanged();
        }
    });

    myMainPanel = new JPanel(new BorderLayout());
    Splitter splitter = new OnePixelSplitter();
    JPanel leftPanel = new JPanel(new BorderLayout());
    leftPanel.add(myToolBar, BorderLayout.NORTH);
    leftPanel.add(myTabbedPane.getComponent(), BorderLayout.CENTER);
    splitter.setFirstComponent(leftPanel);
    myEditorComponent = myEditor.createComponent();
    splitter.setSecondComponent(myEditorComponent);
    myMainPanel.add(splitter, BorderLayout.CENTER);
    return myMainPanel;
}

From source file:com.intellij.profile.codeInspection.ui.actions.DeleteScopeAction.java

License:Apache License

public DeleteScopeAction(Tree tree) {
    super("Delete Scope", "Delete Scope", IconUtil.getRemoveIcon());
    myTree = tree;//  ww w  .j  av  a2  s .  c o m
    registerCustomShortcutSet(CommonShortcuts.DELETE, myTree);
}

From source file:org.intellij.plugins.intelliLang.InjectionsSettingsUI.java

License:Apache License

private DefaultActionGroup createActions() {
    final Consumer<BaseInjection> consumer = new Consumer<BaseInjection>() {
        @Override//from   w  w w. j ava2 s. co m
        public void consume(final BaseInjection injection) {
            addInjection(injection);
        }
    };
    final Factory<BaseInjection> producer = new NullableFactory<BaseInjection>() {
        @Override
        public BaseInjection create() {
            final InjInfo info = getSelectedInjection();
            return info == null ? null : info.injection;
        }
    };
    for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) {
        ContainerUtil.addAll(myAddActions, support.createAddActions(myProject, consumer));
        final AnAction action = support.createEditAction(myProject, producer);
        myEditActions.put(support.getId(),
                action == null ? AbstractLanguageInjectionSupport.createDefaultEditAction(myProject, producer)
                        : action);
        mySupports.put(support.getId(), support);
    }
    Collections.sort(myAddActions, new Comparator<AnAction>() {
        @Override
        public int compare(final AnAction o1, final AnAction o2) {
            return Comparing.compare(o1.getTemplatePresentation().getText(),
                    o2.getTemplatePresentation().getText());
        }
    });

    final DefaultActionGroup group = new DefaultActionGroup();
    final AnAction addAction = new AnAction("Add", "Add", IconUtil.getAddIcon()) {
        @Override
        public void update(final AnActionEvent e) {
            e.getPresentation().setEnabled(!myAddActions.isEmpty());
        }

        @Override
        public void actionPerformed(final AnActionEvent e) {
            performAdd(e);
        }
    };
    final AnAction removeAction = new AnAction("Remove", "Remove", PlatformIcons.DELETE_ICON) {
        @Override
        public void update(final AnActionEvent e) {
            boolean enabled = false;
            for (InjInfo info : getSelectedInjections()) {
                if (!info.bundled) {
                    enabled = true;
                    break;
                }
            }
            e.getPresentation().setEnabled(enabled);
        }

        @Override
        public void actionPerformed(final AnActionEvent e) {
            performRemove();
        }
    };

    final AnAction editAction = new AnAction("Edit", "Edit", PlatformIcons.PROPERTIES_ICON) {
        @Override
        public void update(final AnActionEvent e) {
            final AnAction action = getEditAction();
            e.getPresentation().setEnabled(action != null);
            if (action != null) {
                action.update(e);
            }
        }

        @Override
        public void actionPerformed(final AnActionEvent e) {
            performEditAction(e);
        }
    };
    final AnAction copyAction = new AnAction("Duplicate", "Duplicate", PlatformIcons.COPY_ICON) {
        @Override
        public void update(final AnActionEvent e) {
            final AnAction action = getEditAction();
            e.getPresentation().setEnabled(action != null);
            if (action != null) {
                action.update(e);
            }
        }

        @Override
        public void actionPerformed(final AnActionEvent e) {
            final InjInfo injection = getSelectedInjection();
            if (injection != null) {
                addInjection(injection.injection.copy());
                //performEditAction(e);
            }
        }
    };
    group.add(addAction);
    group.add(removeAction);
    group.add(copyAction);
    group.add(editAction);

    addAction.registerCustomShortcutSet(CommonShortcuts.INSERT, myInjectionsTable);
    removeAction.registerCustomShortcutSet(CommonShortcuts.DELETE, myInjectionsTable);
    editAction.registerCustomShortcutSet(CommonShortcuts.ENTER, myInjectionsTable);

    group.addSeparator();
    group.add(new AnAction("Enable Selected Injections", "Enable Selected Injections",
            PlatformIcons.SELECT_ALL_ICON) {
        @Override
        public void actionPerformed(final AnActionEvent e) {
            performSelectedInjectionsEnabled(true);
        }
    });
    group.add(new AnAction("Disable Selected Injections", "Disable Selected Injections",
            PlatformIcons.UNSELECT_ALL_ICON) {
        @Override
        public void actionPerformed(final AnActionEvent e) {
            performSelectedInjectionsEnabled(false);
        }
    });

    new AnAction("Toggle") {
        @Override
        public void actionPerformed(final AnActionEvent e) {
            performToggleAction();
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0)),
            myInjectionsTable);

    if (myInfos.length > 1) {
        group.addSeparator();
        final AnAction shareAction = new AnAction("Make Global", null, PlatformIcons.IMPORT_ICON) {
            @Override
            public void actionPerformed(final AnActionEvent e) {
                final List<InjInfo> injections = getSelectedInjections();
                final CfgInfo cfg = getTargetCfgInfo(injections);
                if (cfg == null) {
                    return;
                }
                for (InjInfo info : injections) {
                    if (info.cfgInfo == cfg) {
                        continue;
                    }
                    if (info.bundled) {
                        continue;
                    }
                    info.cfgInfo.injectionInfos.remove(info);
                    cfg.addInjection(info.injection);
                }
                final int[] selectedRows = myInjectionsTable.getSelectedRows();
                myInjectionsTable.getListTableModel().setItems(getInjInfoList(myInfos));
                TableUtil.selectRows(myInjectionsTable, selectedRows);
            }

            @Override
            public void update(final AnActionEvent e) {
                final CfgInfo cfg = getTargetCfgInfo(getSelectedInjections());
                e.getPresentation().setEnabled(cfg != null);
                e.getPresentation().setText(cfg == getDefaultCfgInfo() ? "Make Global" : "Move to Project");
                super.update(e);
            }

            @Nullable
            private CfgInfo getTargetCfgInfo(final List<InjInfo> injections) {
                CfgInfo cfg = null;
                for (InjInfo info : injections) {
                    if (info.bundled) {
                        continue;
                    }
                    if (cfg == null) {
                        cfg = info.cfgInfo;
                    } else if (cfg != info.cfgInfo) {
                        return info.cfgInfo;
                    }
                }
                if (cfg == null) {
                    return cfg;
                }
                for (CfgInfo info : myInfos) {
                    if (info != cfg) {
                        return info;
                    }
                }
                throw new AssertionError();
            }
        };
        shareAction.registerCustomShortcutSet(
                new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.SHIFT_DOWN_MASK)),
                myInjectionsTable);
        group.add(shareAction);
    }
    group.addSeparator();
    group.add(new AnAction("Import", "Import", AllIcons.Actions.Install) {
        @Override
        public void actionPerformed(final AnActionEvent e) {
            doImportAction(e.getDataContext());
            updateCountLabel();
        }
    });
    group.add(new AnAction("Export", "Export", AllIcons.Actions.Export) {
        @Override
        public void actionPerformed(final AnActionEvent e) {
            final List<BaseInjection> injections = getInjectionList(getSelectedInjections());
            final VirtualFileWrapper wrapper = FileChooserFactory.getInstance()
                    .createSaveFileDialog(
                            new FileSaverDescriptor("Export Selected " + "Injections to File...", "", "xml"),
                            myProject)
                    .save(null, null);
            if (wrapper == null) {
                return;
            }
            final Configuration configuration = new Configuration();
            configuration.setInjections(injections);
            final Document document = new Document(configuration.getState());
            try {
                JDOMUtil.writeDocument(document, wrapper.getFile(), "\n");
            } catch (IOException ex) {
                final String msg = ex.getLocalizedMessage();
                Messages.showErrorDialog(myProject, msg != null && msg.length() > 0 ? msg : ex.toString(),
                        "Export Failed");
            }
        }

        @Override
        public void update(final AnActionEvent e) {
            e.getPresentation().setEnabled(!getSelectedInjections().isEmpty());
        }
    });

    return group;
}