Search in sources :

Example 31 with DialogWrapper

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

the class CreateFormAction method invokeDialog.

@NotNull
protected PsiElement[] invokeDialog(Project project, PsiDirectory directory) {
    final MyInputValidator validator = new JavaNameValidator(project, directory);
    final DialogWrapper dialog = new MyDialog(project, validator);
    dialog.show();
    return validator.getCreatedElements();
}
Also used : DialogWrapper(com.intellij.openapi.ui.DialogWrapper) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with DialogWrapper

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

the class DarculaTitlePane method createHelpButton.

private JButton createHelpButton() {
    Ref<WindowButton> button = Ref.create();
    button.set(new WindowButton("Help", AllIcons.Windows.HelpButton, AllIcons.Windows.HelpButton, new AbstractAction("Help") {

        @Override
        public void actionPerformed(ActionEvent e) {
            final DialogWrapper dialog = DialogWrapper.findInstance(button.get());
            if (dialog != null) {
                try {
                    final Method getHelpAction = DialogWrapper.class.getDeclaredMethod("getHelpAction");
                    getHelpAction.setAccessible(true);
                    final Object helpAction = getHelpAction.invoke(dialog);
                    if (helpAction instanceof Action && ((Action) helpAction).isEnabled()) {
                        ((Action) helpAction).actionPerformed(e);
                    }
                } catch (Exception ex) {
                }
            }
        }
    }, BUTTON_HOVER_BG) {

        {
            setFont(new Font("Segoe UI Regular", Font.PLAIN, JBUI.scale(15)));
        }

        @Override
        public void paint(Graphics g) {
            if (isHelpAvailable()) {
                super.paint(g);
            } else {
                g.setColor(getBackground());
                g.fillRect(0, 0, getWidth(), getHeight());
            }
        }

        private boolean isHelpAvailable() {
            final DialogWrapper dialog = DialogWrapper.findInstance(this);
            if (dialog != null) {
                try {
                    final Method getHelpAction = DialogWrapper.class.getDeclaredMethod("getHelpAction");
                    getHelpAction.setAccessible(true);
                    final Object helpAction = getHelpAction.invoke(dialog);
                    if (helpAction instanceof Action && ((Action) helpAction).isEnabled()) {
                        return true;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return false;
        }
    });
    return button.get();
}
Also used : Method(java.lang.reflect.Method) DialogWrapper(com.intellij.openapi.ui.DialogWrapper)

Example 33 with DialogWrapper

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

the class PsiDocumentManagerImplTest method testCommitDocumentInModalDialog.

public void testCommitDocumentInModalDialog() throws IOException {
    VirtualFile vFile = getVirtualFile(createTempFile("a.txt", "abc"));
    PsiFile psiFile = findFile(vFile);
    final Document document = getDocument(psiFile);
    final DialogWrapper dialog = new DialogWrapper(getProject()) {

        @Nullable
        @Override
        protected JComponent createCenterPanel() {
            return null;
        }
    };
    disposeOnTearDown(() -> dialog.close(DialogWrapper.OK_EXIT_CODE));
    ApplicationManager.getApplication().runWriteAction(() -> {
        // commit thread is paused
        document.setText("xx");
        LaterInvocator.enterModal(dialog);
    });
    assertNotSame(ModalityState.NON_MODAL, ApplicationManager.getApplication().getCurrentModalityState());
    // may or may not be committed until exit modal dialog
    waitTenSecondsForCommit(document);
    LaterInvocator.leaveModal(dialog);
    assertEquals(ModalityState.NON_MODAL, ApplicationManager.getApplication().getCurrentModalityState());
    // must commit
    waitTenSecondsForCommit(document);
    assertTrue(getPsiDocumentManager().isCommitted(document));
    // check that inside modal dialog commit is possible
    ApplicationManager.getApplication().runWriteAction(() -> {
        // commit thread is paused
        LaterInvocator.enterModal(dialog);
        document.setText("yyy");
    });
    assertNotSame(ModalityState.NON_MODAL, ApplicationManager.getApplication().getCurrentModalityState());
    // must commit
    waitTenSecondsForCommit(document);
    assertTrue(getPsiDocumentManager().isCommitted(document));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) MockPsiFile(com.intellij.mock.MockPsiFile) Document(com.intellij.openapi.editor.Document) MockDocument(com.intellij.mock.MockDocument) DialogWrapper(com.intellij.openapi.ui.DialogWrapper)

Example 34 with DialogWrapper

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

the class NavBarListener method focusLost.

@Override
public void focusLost(final FocusEvent e) {
    if (myPanel.getProject().isDisposed()) {
        myPanel.setContextComponent(null);
        myPanel.hideHint();
        return;
    }
    final DialogWrapper dialog = DialogWrapper.findInstance(e.getOppositeComponent());
    shouldFocusEditor = dialog != null;
    if (dialog != null) {
        Disposer.register(dialog.getDisposable(), new Disposable() {

            @Override
            public void dispose() {
                if (dialog.getExitCode() == DialogWrapper.CANCEL_EXIT_CODE) {
                    shouldFocusEditor = false;
                }
            }
        });
    }
    // required invokeLater since in current call sequence KeyboardFocusManager is not initialized yet
    // but future focused component
    //noinspection SSBasedInspection
    SwingUtilities.invokeLater(() -> processFocusLost(e));
}
Also used : Disposable(com.intellij.openapi.Disposable) DialogWrapper(com.intellij.openapi.ui.DialogWrapper)

Example 35 with DialogWrapper

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

the class JavaChangeSignatureHandler method invoke.

private static void invoke(final PsiMethod method, final Project project, @Nullable final Editor editor) {
    PsiMethod newMethod = SuperMethodWarningUtil.checkSuperMethod(method, RefactoringBundle.message("to.refactor"));
    if (newMethod == null)
        return;
    if (!newMethod.equals(method)) {
        ChangeSignatureUtil.invokeChangeSignatureOn(newMethod, project);
        return;
    }
    if (!CommonRefactoringUtil.checkReadOnlyStatus(project, method))
        return;
    final PsiClass containingClass = method.getContainingClass();
    final PsiReferenceExpression refExpr = editor != null ? JavaTargetElementEvaluator.findReferenceExpression(editor) : null;
    final boolean allowDelegation = containingClass != null && (!containingClass.isInterface() || PsiUtil.isLanguageLevel8OrHigher(containingClass));
    InplaceChangeSignature inplaceChangeSignature = editor != null ? InplaceChangeSignature.getCurrentRefactoring(editor) : null;
    ChangeInfo initialChange = inplaceChangeSignature != null ? inplaceChangeSignature.getStableChange() : null;
    boolean isInplace = Registry.is("inplace.change.signature") && editor != null && editor.getSettings().isVariableInplaceRenameEnabled() && (initialChange == null || initialChange.getMethod() != method) && refExpr == null;
    PsiIdentifier nameIdentifier = method.getNameIdentifier();
    LOG.assertTrue(nameIdentifier != null);
    if (isInplace) {
        CommandProcessor.getInstance().executeCommand(project, () -> new InplaceChangeSignature(project, editor, nameIdentifier), REFACTORING_NAME, null);
    } else {
        JavaMethodDescriptor methodDescriptor = new JavaMethodDescriptor(method);
        if (initialChange != null) {
            JavaChangeInfo currentInfo = (JavaChangeInfo) inplaceChangeSignature.getCurrentInfo();
            if (currentInfo != null) {
                methodDescriptor = new JavaMethodDescriptor(method) {

                    @Override
                    public String getName() {
                        return currentInfo.getNewName();
                    }

                    @Override
                    public List<ParameterInfoImpl> getParameters() {
                        return Arrays.asList((ParameterInfoImpl[]) currentInfo.getNewParameters());
                    }

                    @Override
                    public String getVisibility() {
                        return currentInfo.getNewVisibility();
                    }

                    @Override
                    public int getParametersCount() {
                        return currentInfo.getNewParameters().length;
                    }

                    @Nullable
                    @Override
                    public String getReturnTypeText() {
                        return currentInfo.getNewReturnType().getTypeText();
                    }
                };
            }
            inplaceChangeSignature.cancel();
        }
        final DialogWrapper dialog = new JavaChangeSignatureDialog(project, methodDescriptor, allowDelegation, refExpr == null ? method : refExpr);
        dialog.show();
    }
}
Also used : DialogWrapper(com.intellij.openapi.ui.DialogWrapper) List(java.util.List) InplaceChangeSignature(com.intellij.refactoring.changeSignature.inplace.InplaceChangeSignature) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

DialogWrapper (com.intellij.openapi.ui.DialogWrapper)37 Project (com.intellij.openapi.project.Project)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 ActionEvent (java.awt.event.ActionEvent)6 Nullable (org.jetbrains.annotations.Nullable)6 JBScrollPane (com.intellij.ui.components.JBScrollPane)5 ActionListener (java.awt.event.ActionListener)4 AnAction (com.intellij.openapi.actionSystem.AnAction)3 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)3 Document (com.intellij.openapi.editor.Document)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 MockDocument (com.intellij.mock.MockDocument)2 MockPsiFile (com.intellij.mock.MockPsiFile)2 javax.swing (javax.swing)2 HyperlinkEvent (javax.swing.event.HyperlinkEvent)2 NotNull (org.jetbrains.annotations.NotNull)2 AnnotationTargetUtil (com.intellij.codeInsight.AnnotationTargetUtil)1 DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1 HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)1