Search in sources :

Example 16 with PopupStep

use of com.intellij.openapi.ui.popup.PopupStep 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 17 with PopupStep

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

the class StudyNewProjectPanel method setupBrowseButton.

private void setupBrowseButton() {
    if (SystemInfo.isMac && !UIUtil.isUnderDarcula())
        myBrowseButton.putClientProperty("JButton.buttonType", null);
    myBrowseButton.setIcon(InteractiveLearningIcons.InterpreterGear);
    final FileChooserDescriptor fileChooser = new FileChooserDescriptor(true, false, false, true, false, false) {

        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            return file.isDirectory() || StudyUtils.isZip(file.getName());
        }

        @Override
        public boolean isFileSelectable(VirtualFile file) {
            return StudyUtils.isZip(file.getName());
        }
    };
    myBrowseButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            final BaseListPopupStep<String> popupStep = new BaseListPopupStep<String>("", "Add local course", LOGIN_TO_STEPIC) {

                @Override
                public PopupStep onChosen(final String selectedValue, boolean finalChoice) {
                    return doFinalStep(() -> {
                        if ("Add local course".equals(selectedValue)) {
                            Project[] projects = ProjectManager.getInstance().getOpenProjects();
                            FileChooser.chooseFile(fileChooser, null, projects.length == 0 ? null : projects[0].getBaseDir(), file -> {
                                String fileName = file.getPath();
                                int oldSize = myAvailableCourses.size();
                                CourseInfo courseInfo = myGenerator.addLocalCourse(fileName);
                                if (courseInfo != null) {
                                    if (oldSize != myAvailableCourses.size()) {
                                        myCoursesComboBox.addItem(courseInfo);
                                    }
                                    myCoursesComboBox.setSelectedItem(courseInfo);
                                    setOK();
                                } else {
                                    setError(INVALID_COURSE);
                                    myCoursesComboBox.removeAllItems();
                                    myCoursesComboBox.addItem(CourseInfo.INVALID_COURSE);
                                    for (CourseInfo course : myAvailableCourses) {
                                        myCoursesComboBox.addItem(course);
                                    }
                                    myCoursesComboBox.setSelectedItem(CourseInfo.INVALID_COURSE);
                                }
                            });
                        } else if (LOGIN_TO_STEPIC.equals(selectedValue)) {
                            showLoginDialog(true, "Signing In And Getting Stepik Course List");
                        }
                    });
                }
            };
            final ListPopup popup = JBPopupFactory.getInstance().createListPopup(popupStep);
            popup.showInScreenCoordinates(myBrowseButton, myBrowseButton.getLocationOnScreen());
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) UIUtil(com.intellij.util.ui.UIUtil) AllIcons(com.intellij.icons.AllIcons) ActionListener(java.awt.event.ActionListener) VirtualFile(com.intellij.openapi.vfs.VirtualFile) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) StudyUtils(com.jetbrains.edu.learning.StudyUtils) DefaultProjectFactory(com.intellij.openapi.project.DefaultProjectFactory) ArrayList(java.util.ArrayList) FacetValidatorsManager(com.intellij.facet.ui.FacetValidatorsManager) DefaultProjectFactoryImpl(com.intellij.openapi.project.DefaultProjectFactoryImpl) ProjectManager(com.intellij.openapi.project.ProjectManager) StudyProjectGenerator(com.jetbrains.edu.learning.courseGeneration.StudyProjectGenerator) Project(com.intellij.openapi.project.Project) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) AncestorEvent(javax.swing.event.AncestorEvent) ComboBox(com.intellij.openapi.ui.ComboBox) ProgressManager(com.intellij.openapi.progress.ProgressManager) InteractiveLearningIcons(icons.InteractiveLearningIcons) com.jetbrains.edu.learning.stepic(com.jetbrains.edu.learning.stepic) StringUtil(com.intellij.openapi.util.text.StringUtil) ValidationResult(com.intellij.facet.ui.ValidationResult) FixedSizeButton(com.intellij.openapi.ui.FixedSizeButton) ActionEvent(java.awt.event.ActionEvent) SystemInfo(com.intellij.openapi.util.SystemInfo) JBScrollPane(com.intellij.ui.components.JBScrollPane) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout) java.awt(java.awt) ListPopup(com.intellij.openapi.ui.popup.ListPopup) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) AncestorListenerAdapter(com.intellij.ui.AncestorListenerAdapter) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) CourseInfo(com.jetbrains.edu.learning.courseFormat.CourseInfo) PopupStep(com.intellij.openapi.ui.popup.PopupStep) ApplicationManager(com.intellij.openapi.application.ApplicationManager) PanelWithAnchor(com.intellij.ui.PanelWithAnchor) LabeledComponent(com.intellij.openapi.ui.LabeledComponent) NotNull(org.jetbrains.annotations.NotNull) FileChooser(com.intellij.openapi.fileChooser.FileChooser) Course(com.jetbrains.edu.learning.courseFormat.Course) javax.swing(javax.swing) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ActionEvent(java.awt.event.ActionEvent) ListPopup(com.intellij.openapi.ui.popup.ListPopup) CourseInfo(com.jetbrains.edu.learning.courseFormat.CourseInfo) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep) ActionListener(java.awt.event.ActionListener) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep)

Example 18 with PopupStep

use of com.intellij.openapi.ui.popup.PopupStep in project intellij-plugins by JetBrains.

the class DependenciesConfigurable method addItem.

private void addItem(AnActionButton button) {
    initPopupActions();
    final JBPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<AddItemPopupAction>(FlexBundle.message("add.dependency.popup.title"), myPopupActions) {

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

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

        public boolean isMnemonicsNavigationEnabled() {
            return true;
        }

        public PopupStep onChosen(final AddItemPopupAction selectedValue, final boolean finalChoice) {
            if (selectedValue.hasSubStep()) {
                return selectedValue.createSubStep();
            }
            return doFinalStep(() -> selectedValue.run());
        }

        @NotNull
        public String getTextFor(AddItemPopupAction value) {
            return "&" + value.getIndex() + "  " + value.getTitle();
        }
    });
    popup.show(button.getPreferredPopupPoint());
}
Also used : JBPopup(com.intellij.openapi.ui.popup.JBPopup) NotNull(org.jetbrains.annotations.NotNull) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep)

Example 19 with PopupStep

use of com.intellij.openapi.ui.popup.PopupStep in project intellij-plugins by JetBrains.

the class CucumberCreateStepFixBase method applyFix.

public void applyFix(@NotNull final Project project, @NotNull ProblemDescriptor descriptor) {
    final GherkinStep step = (GherkinStep) descriptor.getPsiElement();
    final GherkinFile featureFile = (GherkinFile) step.getContainingFile();
    // TODO + step defs pairs from other content roots
    final List<Pair<PsiFile, BDDFrameworkType>> pairs = ContainerUtil.newArrayList(getStepDefinitionContainers(featureFile));
    if (!pairs.isEmpty()) {
        pairs.add(0, null);
        final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
        final ListPopup popupStep = popupFactory.createListPopup(new BaseListPopupStep<Pair<PsiFile, BDDFrameworkType>>(CucumberBundle.message("choose.step.definition.file"), ContainerUtil.newArrayList(pairs)) {

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

            @NotNull
            @Override
            public String getTextFor(Pair<PsiFile, BDDFrameworkType> value) {
                if (value == null) {
                    return CucumberBundle.message("create.new.file");
                }
                final VirtualFile file = value.getFirst().getVirtualFile();
                assert file != null;
                CucumberStepsIndex stepsIndex = CucumberStepsIndex.getInstance(value.getFirst().getProject());
                StepDefinitionCreator stepDefinitionCreator = stepsIndex.getExtensionMap().get(value.getSecond()).getStepDefinitionCreator();
                return stepDefinitionCreator.getStepDefinitionFilePath(value.getFirst());
            }

            @Override
            public Icon getIconFor(Pair<PsiFile, BDDFrameworkType> value) {
                return value == null ? AllIcons.Actions.CreateFromUsage : value.getFirst().getIcon(0);
            }

            @Override
            public PopupStep onChosen(final Pair<PsiFile, BDDFrameworkType> selectedValue, boolean finalChoice) {
                return doFinalStep(() -> createStepOrSteps(step, selectedValue));
            }
        });
        if (!ApplicationManager.getApplication().isUnitTestMode()) {
            popupStep.showCenteredInCurrentWindow(step.getProject());
        } else {
            createStepOrSteps(step, pairs.get(1));
        }
    } else {
        createFileOrStepDefinition(step, null);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GherkinStep(org.jetbrains.plugins.cucumber.psi.GherkinStep) ListPopup(com.intellij.openapi.ui.popup.ListPopup) NotNull(org.jetbrains.annotations.NotNull) CucumberStepsIndex(org.jetbrains.plugins.cucumber.steps.CucumberStepsIndex) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) PsiFile(com.intellij.psi.PsiFile) GherkinFile(org.jetbrains.plugins.cucumber.psi.GherkinFile) Pair(com.intellij.openapi.util.Pair)

Aggregations

PopupStep (com.intellij.openapi.ui.popup.PopupStep)19 BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)18 NotNull (org.jetbrains.annotations.NotNull)14 ListPopup (com.intellij.openapi.ui.popup.ListPopup)7 RelativePoint (com.intellij.ui.awt.RelativePoint)6 ListPopupImpl (com.intellij.ui.popup.list.ListPopupImpl)5 Project (com.intellij.openapi.project.Project)4 JBPopup (com.intellij.openapi.ui.popup.JBPopup)4 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 PsiFile (com.intellij.psi.PsiFile)3 ColoredListCellRenderer (com.intellij.ui.ColoredListCellRenderer)3 Nullable (org.jetbrains.annotations.Nullable)3 AllIcons (com.intellij.icons.AllIcons)2 Editor (com.intellij.openapi.editor.Editor)2 FileChooser (com.intellij.openapi.fileChooser.FileChooser)2 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)2 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)2 javax.swing (javax.swing)2 HintManager (com.intellij.codeInsight.hint.HintManager)1