Search in sources :

Example 26 with BaseListPopupStep

use of com.intellij.openapi.ui.popup.util.BaseListPopupStep in project intellij-community by JetBrains.

the class GitPushTargetPanel method showRemoteSelector.

private void showRemoteSelector(@NotNull Component component, @NotNull Point point) {
    List<PopupItem> remotes = getPopupItems();
    if (remotes.size() <= 1) {
        return;
    }
    ListPopup popup = new ListPopupImpl(new BaseListPopupStep<PopupItem>(null, remotes) {

        @Override
        public PopupStep onChosen(@NotNull PopupItem selectedValue, boolean finalChoice) {
            return doFinalStep(() -> {
                if (selectedValue.isDefineRemote()) {
                    showDefineRemoteDialog();
                } else {
                    myRemoteRenderer.updateLinkText(selectedValue.getPresentable());
                    if (myFireOnChangeAction != null && !myTargetEditor.isShowing()) {
                        //fireOnChange only when editing completed
                        myFireOnChangeAction.run();
                    }
                }
            });
        }

        @Nullable
        @Override
        public ListSeparator getSeparatorAbove(PopupItem value) {
            return value.isDefineRemote() ? new ListSeparator() : null;
        }
    }) {

        @Override
        public void cancel(InputEvent e) {
            super.cancel(e);
            if (myTargetEditor.isShowing()) {
                //repaint and force move focus to target editor component
                GitPushTargetPanel.this.repaint();
                IdeFocusManager.getInstance(myProject).requestFocus(myTargetEditor, true);
            }
        }
    };
    popup.show(new RelativePoint(component, point));
}
Also used : ListSeparator(com.intellij.openapi.ui.popup.ListSeparator) ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) ListPopup(com.intellij.openapi.ui.popup.ListPopup) RelativePoint(com.intellij.ui.awt.RelativePoint) Nullable(org.jetbrains.annotations.Nullable) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep)

Example 27 with BaseListPopupStep

use of com.intellij.openapi.ui.popup.util.BaseListPopupStep in project intellij-community by JetBrains.

the class FindUsagesInProjectStructureActionBase method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final ProjectStructureElement selected = getSelectedElement();
    if (selected == null)
        return;
    final Collection<ProjectStructureElementUsage> usages = getContext().getDaemonAnalyzer().getUsages(selected);
    if (usages.isEmpty()) {
        Messages.showInfoMessage(myParentComponent, FindBundle.message("find.usage.view.no.usages.text"), FindBundle.message("find.pointcut.applications.not.found.title"));
        return;
    }
    RelativePoint point = getPointToShowResults();
    final ProjectStructureElementUsage[] usagesArray = usages.toArray(new ProjectStructureElementUsage[usages.size()]);
    Arrays.sort(usagesArray, (o1, o2) -> o1.getPresentableName().compareToIgnoreCase(o2.getPresentableName()));
    BaseListPopupStep<ProjectStructureElementUsage> step = new BaseListPopupStep<ProjectStructureElementUsage>(ProjectBundle.message("dependencies.used.in.popup.title"), usagesArray) {

        @Override
        public PopupStep onChosen(final ProjectStructureElementUsage selected, final boolean finalChoice) {
            selected.getPlace().navigate();
            return FINAL_CHOICE;
        }

        @NotNull
        @Override
        public String getTextFor(ProjectStructureElementUsage value) {
            return value.getPresentableName();
        }

        @Override
        public Icon getIconFor(ProjectStructureElementUsage selection) {
            return selection.getIcon();
        }
    };
    new ListPopupImpl(step) {

        @Override
        protected ListCellRenderer getListElementRenderer() {
            return new ListCellRendererWithRightAlignedComponent<ProjectStructureElementUsage>() {

                @Override
                protected void customize(ProjectStructureElementUsage value) {
                    setLeftText(value.getPresentableName());
                    setIcon(value.getIcon());
                    setRightForeground(Color.GRAY);
                    setRightText(value.getPresentableLocationInElement());
                }
            };
        }
    }.show(point);
}
Also used : ProjectStructureElementUsage(com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElementUsage) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) ProjectStructureElement(com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 28 with BaseListPopupStep

use of com.intellij.openapi.ui.popup.util.BaseListPopupStep in project intellij-community by JetBrains.

the class ClasspathPanelImpl method createTableWithButtons.

private JComponent createTableWithButtons() {
    final boolean isAnalyzeShown = false;
    final ClasspathPanelAction removeAction = new ClasspathPanelAction(this) {

        @Override
        public void run() {
            removeSelectedItems(TableUtil.removeSelectedItems(myEntryTable));
        }
    };
    final AnActionButton analyzeButton = new AnActionButton(ProjectBundle.message("classpath.panel.analyze"), null, IconUtil.getAnalyzeIcon()) {

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            AnalyzeDependenciesDialog.show(getRootModel().getModule());
        }
    };
    //addButton.setShortcut(CustomShortcutSet.fromString("alt A", "INSERT"));
    //removeButton.setShortcut(CustomShortcutSet.fromString("alt DELETE"));
    //upButton.setShortcut(CustomShortcutSet.fromString("alt UP"));
    //downButton.setShortcut(CustomShortcutSet.fromString("alt DOWN"));
    final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myEntryTable);
    AnActionButtonUpdater moveUpDownUpdater = new AnActionButtonUpdater() {

        @Override
        public boolean isEnabled(AnActionEvent e) {
            for (RowSorter.SortKey key : myEntryTable.getRowSorter().getSortKeys()) {
                if (key.getSortOrder() != SortOrder.UNSORTED) {
                    return false;
                }
            }
            return true;
        }
    };
    decorator.setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            initPopupActions();
            final JBPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<AddItemPopupAction<?>>(null, myPopupActions) {

                @Override
                public Icon getIconFor(AddItemPopupAction<?> aValue) {
                    return aValue.getIcon();
                }

                @Override
                public boolean hasSubstep(AddItemPopupAction<?> selectedValue) {
                    return selectedValue.hasSubStep();
                }

                @Override
                public boolean isMnemonicsNavigationEnabled() {
                    return true;
                }

                @Override
                public PopupStep onChosen(final AddItemPopupAction<?> selectedValue, final boolean finalChoice) {
                    if (selectedValue.hasSubStep()) {
                        return selectedValue.createSubStep();
                    }
                    return doFinalStep(() -> selectedValue.execute());
                }

                @Override
                @NotNull
                public String getTextFor(AddItemPopupAction<?> value) {
                    return "&" + value.getIndex() + "  " + value.getTitle();
                }
            });
            popup.show(button.getPreferredPopupPoint());
        }
    }).setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            removeAction.actionPerformed(null);
        }
    }).setRemoveActionUpdater(new AnActionButtonUpdater() {

        @Override
        public boolean isEnabled(AnActionEvent e) {
            final int[] selectedRows = myEntryTable.getSelectedRows();
            for (final int selectedRow : selectedRows) {
                if (!getItemAt(selectedRow).isRemovable()) {
                    return false;
                }
            }
            return selectedRows.length > 0;
        }
    }).setMoveUpAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            moveSelectedRows(-1);
        }
    }).setMoveUpActionUpdater(moveUpDownUpdater).setMoveUpActionName("Move Up (disabled if items are shown in sorted order)").setMoveDownAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            moveSelectedRows(+1);
        }
    }).setMoveDownActionUpdater(moveUpDownUpdater).setMoveDownActionName("Move Down (disabled if items are shown in sorted order)").addExtraAction(myEditButton);
    if (isAnalyzeShown) {
        decorator.addExtraAction(analyzeButton);
    }
    final JPanel panel = decorator.createPanel();
    myRemoveButton = ToolbarDecorator.findRemoveButton(panel);
    return panel;
}
Also used : TableRowSorter(javax.swing.table.TableRowSorter) NotNull(org.jetbrains.annotations.NotNull) RelativePoint(com.intellij.ui.awt.RelativePoint) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 29 with BaseListPopupStep

use of com.intellij.openapi.ui.popup.util.BaseListPopupStep in project intellij-community by JetBrains.

the class ShowRecentFindUsagesAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    UsageView usageView = e.getData(UsageView.USAGE_VIEW_KEY);
    Project project = e.getData(CommonDataKeys.PROJECT);
    final FindUsagesManager findUsagesManager = ((FindManagerImpl) FindManager.getInstance(project)).getFindUsagesManager();
    List<ConfigurableUsageTarget> history = new ArrayList<>(findUsagesManager.getHistory().getAll());
    if (!history.isEmpty()) {
        // skip most recent find usage, it's under your nose
        history.remove(history.size() - 1);
        Collections.reverse(history);
    }
    if (history.isEmpty()) {
        // to fill the popup
        history.add(null);
    }
    BaseListPopupStep<ConfigurableUsageTarget> step = new BaseListPopupStep<ConfigurableUsageTarget>(FindBundle.message("recent.find.usages.action.title"), history) {

        @Override
        public Icon getIconFor(final ConfigurableUsageTarget data) {
            ItemPresentation presentation = data == null ? null : data.getPresentation();
            return presentation == null ? null : presentation.getIcon(false);
        }

        @Override
        @NotNull
        public String getTextFor(final ConfigurableUsageTarget data) {
            if (data == null) {
                return FindBundle.message("recent.find.usages.action.nothing");
            }
            return data.getLongDescriptiveName();
        }

        @Override
        public PopupStep onChosen(final ConfigurableUsageTarget selectedValue, final boolean finalChoice) {
            return doFinalStep(() -> {
                if (selectedValue != null) {
                    TransactionGuard.getInstance().submitTransactionAndWait(() -> findUsagesManager.rerunAndRecallFromHistory(selectedValue));
                }
            });
        }
    };
    RelativePoint point;
    if (e.getInputEvent() instanceof MouseEvent) {
        point = new RelativePoint((MouseEvent) e.getInputEvent());
    } else {
        point = new RelativePoint(usageView.getComponent(), new Point(4, 4));
    }
    JBPopupFactory.getInstance().createListPopup(step).show(point);
}
Also used : MouseEvent(java.awt.event.MouseEvent) ArrayList(java.util.ArrayList) ItemPresentation(com.intellij.navigation.ItemPresentation) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) UsageView(com.intellij.usages.UsageView) Project(com.intellij.openapi.project.Project) ConfigurableUsageTarget(com.intellij.usages.ConfigurableUsageTarget) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) FindUsagesManager(com.intellij.find.findUsages.FindUsagesManager)

Example 30 with BaseListPopupStep

use of com.intellij.openapi.ui.popup.util.BaseListPopupStep in project intellij-community by JetBrains.

the class ExpressionEditorWithHistory method showHistory.

private void showHistory() {
    List<XExpression> expressions = getRecentExpressions();
    if (!expressions.isEmpty()) {
        ListPopupImpl historyPopup = new ListPopupImpl(new BaseListPopupStep<XExpression>(null, expressions) {

            @Override
            public PopupStep onChosen(XExpression selectedValue, boolean finalChoice) {
                setExpression(selectedValue);
                requestFocusInEditor();
                return FINAL_CHOICE;
            }
        }) {

            @Override
            protected ListCellRenderer getListElementRenderer() {
                return new ColoredListCellRenderer<XExpression>() {

                    @Override
                    protected void customizeCellRenderer(@NotNull JList list, XExpression value, int index, boolean selected, boolean hasFocus) {
                        append(value.getExpression(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
                    }
                };
            }
        };
        historyPopup.getList().setFont(EditorUtil.getEditorFont());
        historyPopup.showUnderneathOf(getEditorComponent());
    }
}
Also used : ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) XExpression(com.intellij.xdebugger.XExpression) ColoredListCellRenderer(com.intellij.ui.ColoredListCellRenderer) NotNull(org.jetbrains.annotations.NotNull) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep)

Aggregations

BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)33 PopupStep (com.intellij.openapi.ui.popup.PopupStep)18 NotNull (org.jetbrains.annotations.NotNull)15 ListPopup (com.intellij.openapi.ui.popup.ListPopup)10 ListPopupImpl (com.intellij.ui.popup.list.ListPopupImpl)10 RelativePoint (com.intellij.ui.awt.RelativePoint)8 Project (com.intellij.openapi.project.Project)7 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)5 JBPopup (com.intellij.openapi.ui.popup.JBPopup)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 PsiFile (com.intellij.psi.PsiFile)4 Nullable (org.jetbrains.annotations.Nullable)3 AllIcons (com.intellij.icons.AllIcons)2 DefaultPsiElementCellRenderer (com.intellij.ide.util.DefaultPsiElementCellRenderer)2 Result (com.intellij.openapi.application.Result)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 Editor (com.intellij.openapi.editor.Editor)2 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)2 FileChooser (com.intellij.openapi.fileChooser.FileChooser)2 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)2