Search in sources :

Example 31 with DumbAwareAction

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

the class ChooseFileEncodingAction method createCharsetsActionGroup.

@NotNull
protected DefaultActionGroup createCharsetsActionGroup(@Nullable String clearItemText, @Nullable Charset alreadySelected, @NotNull Function<Charset, String> charsetFilter) {
    DefaultActionGroup group = new DefaultActionGroup();
    List<Charset> favorites = new ArrayList<>(EncodingManager.getInstance().getFavorites());
    Collections.sort(favorites);
    Charset current = myVirtualFile == null ? null : myVirtualFile.getCharset();
    favorites.remove(current);
    favorites.remove(alreadySelected);
    if (clearItemText != null) {
        String description = "Clear " + (myVirtualFile == null ? "default" : "file '" + myVirtualFile.getName() + "'") + " encoding.";
        group.add(new DumbAwareAction(clearItemText, description, null) {

            @Override
            public void actionPerformed(AnActionEvent e) {
                chosen(myVirtualFile, NO_ENCODING);
            }
        });
    }
    if (favorites.isEmpty() && clearItemText == null) {
        fillCharsetActions(group, myVirtualFile, Arrays.asList(CharsetToolkit.getAvailableCharsets()), charsetFilter);
    } else {
        fillCharsetActions(group, myVirtualFile, favorites, charsetFilter);
        DefaultActionGroup more = new DefaultActionGroup("more", true);
        group.add(more);
        fillCharsetActions(more, myVirtualFile, Arrays.asList(CharsetToolkit.getAvailableCharsets()), charsetFilter);
    }
    return group;
}
Also used : ArrayList(java.util.ArrayList) Charset(java.nio.charset.Charset) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with DumbAwareAction

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

the class ProjectStartupConfigurable method createComponent.

@Nullable
@Override
public JComponent createComponent() {
    myModel = new ProjectStartupTasksTableModel(RunManagerEx.getInstanceEx(myProject));
    myTable = new JBTable(myModel);
    myTable.getEmptyText().setText("Add run configurations with the + button");
    new TableSpeedSearch(myTable);
    DefaultCellEditor defaultEditor = (DefaultCellEditor) myTable.getDefaultEditor(Object.class);
    defaultEditor.setClickCountToStart(1);
    myTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    new DumbAwareAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            final int row = myTable.getSelectedRow();
            if (row >= 0 && myModel.isCellEditable(row, ProjectStartupTasksTableModel.IS_SHARED_COLUMN)) {
                myModel.setValueAt(!Boolean.TRUE.equals(myTable.getValueAt(row, ProjectStartupTasksTableModel.IS_SHARED_COLUMN)), row, ProjectStartupTasksTableModel.IS_SHARED_COLUMN);
            }
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(KeyEvent.VK_SPACE), myTable);
    myTable.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() >= 2) {
                editRunConfiguration();
            }
        }
    });
    installRenderers();
    myDecorator = ToolbarDecorator.createDecorator(myTable).setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            selectAndAddConfiguration(button);
        }
    }).setEditAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            editRunConfiguration();
        }
    }).setEditActionUpdater(new AnActionButtonUpdater() {

        @Override
        public boolean isEnabled(AnActionEvent e) {
            return myTable.getSelectedRow() >= 0;
        }
    }).disableUpAction().disableDownAction();
    final JPanel tasksPanel = myDecorator.createPanel();
    final JLabel label = new JLabel("Run tasks and tools via run configurations");
    label.setForeground(UIUtil.getInactiveTextColor());
    label.setHorizontalAlignment(SwingConstants.RIGHT);
    final JPanel wrapper = new JPanel(new BorderLayout());
    wrapper.add(new JLabel("To be started on project opening:"), BorderLayout.WEST);
    wrapper.add(label, BorderLayout.EAST);
    wrapper.setBorder(BorderFactory.createEmptyBorder(0, 0, UIUtil.DEFAULT_VGAP, 0));
    final JPanel main = new JPanel(new BorderLayout());
    main.add(wrapper, BorderLayout.NORTH);
    main.add(tasksPanel, BorderLayout.CENTER);
    return main;
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) JBTable(com.intellij.ui.table.JBTable) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) Nullable(org.jetbrains.annotations.Nullable)

Example 33 with DumbAwareAction

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

the class QuickEditHandler method showBalloon.

public static void showBalloon(Editor editor, PsiFile newFile, JComponent component) {
    final Balloon balloon = JBPopupFactory.getInstance().createBalloonBuilder(component).setShadow(true).setAnimationCycle(0).setHideOnClickOutside(true).setHideOnKeyOutside(true).setHideOnAction(false).setFillColor(UIUtil.getControlColor()).createBalloon();
    new DumbAwareAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            balloon.hide();
        }
    }.registerCustomShortcutSet(CommonShortcuts.ESCAPE, component);
    Disposer.register(newFile.getProject(), balloon);
    final Balloon.Position position = QuickEditAction.getBalloonPosition(editor);
    RelativePoint point = JBPopupFactory.getInstance().guessBestPopupLocation(editor);
    if (position == Balloon.Position.above) {
        final Point p = point.getPoint();
        point = new RelativePoint(point.getComponent(), new Point(p.x, p.y - editor.getLineHeight()));
    }
    balloon.show(point, position);
}
Also used : Balloon(com.intellij.openapi.ui.popup.Balloon) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction)

Example 34 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 35 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)

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