Example usage for com.intellij.openapi.ui Messages showInputDialog

List of usage examples for com.intellij.openapi.ui Messages showInputDialog

Introduction

In this page you can find the example usage for com.intellij.openapi.ui Messages showInputDialog.

Prototype

@Nullable
public static String showInputDialog(@NotNull Component parent, String message,
        @Nls(capitalization = Nls.Capitalization.Title) String title, @Nullable Icon icon) 

Source Link

Usage

From source file:consulo.restclient.actions.SaveAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();/* w  w  w  .  j  a  v  a 2  s.c o  m*/
    RequestBean requestBean = RestClientPanel.getInstance(project).getRequestBean();
    if (requestBean == null) {
        return;
    }
    String name = Messages.showInputDialog(project, "Name", "Enter Name", null);
    if (name == null) {
        return;
    }
    RestClientHistoryManager.getInstance(project).getRequests().put(name, requestBean);
}

From source file:git4idea.actions.GitClone.java

License:Apache License

@Override
public void perform(@NotNull Project project, GitVcs vcs, @NotNull List<VcsException> exceptions,
        @NotNull VirtualFile[] affectedFiles) throws VcsException {
    saveAll();/*from   w w  w  . j a  v  a  2 s  .c om*/

    // TODO: implement remote repository login/password - setup remote repos in Git config,
    // TODO: then just reference repo name here
    final String src_repo = Messages.showInputDialog(project, "Specify source repository URL", "clone",
            Messages.getQuestionIcon());
    if (src_repo == null)
        return;

    FileChooserDescriptor fcd = new FileChooserDescriptor(false, true, false, false, false, false);
    fcd.setShowFileSystemRoots(true);
    fcd.setTitle("Destination Directory");
    fcd.setDescription("Select destination directory for clone.");
    fcd.setHideIgnored(false);
    VirtualFile[] files = FileChooser.chooseFiles(project, fcd, null);
    if (files.length != 1 || files[0] == null) {
        return;
    }

    final Map<VirtualFile, List<VirtualFile>> roots = GitUtil.sortFilesByVcsRoot(project, affectedFiles);
    for (VirtualFile root : roots.keySet()) {
        GitCommandRunnable cmdr = new GitCommandRunnable(project, vcs.getSettings(), root);
        cmdr.setCommand(GitCommand.CLONE_CMD);
        cmdr.setArgs(new String[] { src_repo, files[0].getPath() });

        ProgressManager manager = ProgressManager.getInstance();
        //TODO: make this async so the git command output can be seen in the version control window as it happens...
        manager.runProcessWithProgressSynchronously(cmdr, "Cloning source repo " + src_repo, false, project);

        VcsException ex = cmdr.getException();
        if (ex != null) {
            Messages.showErrorDialog(project, ex.getMessage(), "Error occurred during 'git clone'");
            break;
        }
    }

    VcsDirtyScopeManager mgr = VcsDirtyScopeManager.getInstance(project);
    for (VirtualFile file : affectedFiles) {
        mgr.fileDirty(file);
        file.refresh(true, true);
    }
}

From source file:git4idea.actions.GitTag.java

License:Apache License

@Override
public void perform(@NotNull Project project, GitVcs vcs, @NotNull List<VcsException> exceptions,
        @NotNull VirtualFile[] affectedFiles) throws VcsException {
    saveAll();/* w w w  . ja  v a 2  s  .  c  om*/

    if (!ProjectLevelVcsManager.getInstance(project).checkAllFilesAreUnder(vcs, affectedFiles)) {
        Messages.showErrorDialog(project, "ERROR: Files not tagged, not all are under VCS root!", "Tag Result");
        return;
    }

    final String tagName = Messages.showInputDialog(project, "Specify tag name: ", "Tag",
            Messages.getQuestionIcon());
    if (tagName == null || tagName.length() == 0)
        return;

    final Map<VirtualFile, List<VirtualFile>> roots = GitUtil.sortFilesByVcsRoot(project, affectedFiles);

    for (VirtualFile root : roots.keySet()) {
        GitCommandRunnable cmdr = new GitCommandRunnable(project, vcs.getSettings(), root);
        cmdr.setCommand(GitCommand.TAG_CMD);
        cmdr.setArgs(new String[] { tagName });

        ProgressManager manager = ProgressManager.getInstance();
        //TODO: make this async so the git command output can be seen in the version control window as it happens...
        manager.runProcessWithProgressSynchronously(cmdr, "Tagging files... ", false, project);

        VcsException ex = cmdr.getException();
        if (ex != null) {
            Messages.showErrorDialog(project, ex.getMessage(), "Error occurred during 'git tag'");
            break;
        }
    }
}

From source file:io.ballerina.plugins.idea.completion.inserthandlers.AutoImportInsertHandler.java

License:Open Source License

@Override
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement item) {
    ApplicationManager.getApplication().invokeLater(() -> {
        CommandProcessor.getInstance().runUndoTransparentAction(() -> {
            PsiElement element = item.getPsiElement();
            if (element == null) {
                return;
            }/*from   www  . ja va 2  s.com*/
            String organizationName = element.getUserData(BallerinaCompletionUtils.ORGANIZATION_NAME);
            if (!(element instanceof PsiDirectory)) {
                return;
            }
            String packageName = ((PsiDirectory) element).getName();
            PsiFile file = context.getFile();
            if (!(file instanceof BallerinaFile)) {
                return;
            }
            Editor editor = context.getEditor();
            Project project = editor.getProject();
            if (suggestAlias) {
                alias = Messages.showInputDialog(project,
                        "Package '" + ((PsiDirectory) element).getName()
                                + "' already imported. Please enter an alias:",
                        "Enter Alias", Messages.getInformationIcon());
                if (alias == null || alias.isEmpty()) {
                    Messages.showErrorDialog("Alias cannot be null or empty.", "Error");
                    return;
                }
            }
            // Import the package.
            autoImport(context, organizationName, packageName, alias);
            if (project == null) {
                return;
            }
            if (!isCompletionCharAtSpace(editor)) {
                if (suggestAlias) {
                    // InsertHandler inserts the old package name. So we need to change it to the new alias.
                    PsiElement currentPackageName = file.findElementAt(context.getStartOffset());
                    if (currentPackageName != null) {
                        if (alias == null || alias.isEmpty()) {
                            return;
                        }
                        ApplicationManager.getApplication().runWriteAction(() -> {
                            // Add a new identifier node.
                            PsiElement identifier = BallerinaElementFactory.createIdentifierFromText(project,
                                    alias);
                            currentPackageName.getParent().addBefore(identifier, currentPackageName);
                            // Delete the current identifier node.
                            currentPackageName.delete();
                        });
                    }
                }
                if (myTriggerAutoPopup) {
                    ApplicationManager.getApplication().runWriteAction(() -> {
                        PsiDocumentManager.getInstance(project)
                                .doPostponedOperationsAndUnblockDocument(editor.getDocument());
                        EditorModificationUtil.insertStringAtCaret(editor, ":");
                        PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
                    });
                }
            } else {
                editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() + 1);
            }
            // Invoke the popup.
            if (myTriggerAutoPopup) {
                // We need to invoke the popup with a delay. Otherwise it might not show.
                ApplicationManager.getApplication().invokeLater(
                        () -> AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null));
            }
        });
    });
}

From source file:myPlugin.src.TextBoxes.java

License:Apache License

public void actionPerformed(AnActionEvent event) {
    Project project = event.getData(PlatformDataKeys.PROJECT);
    String txt = Messages.showInputDialog(project, "Android Class Name", "Android Class Name",
            Messages.getQuestionIcon());
    String recommendation = "";
    rulesForClass = parser.getRuleForClass(rules, txt);
    int i = 1;/*from w  w  w  .j a v  a 2s.c o m*/
    for (Rule rule : rulesForClass) {
        recommendation += i + ") " + rule.right_hand_side + "\t Confidece: " + rule.confidence + "\n\n";
        i++;
    }
    Messages.showMessageDialog(project, recommendation, "Recommended Intent Actions",
            Messages.getInformationIcon());
}

From source file:org.ballerinalang.plugins.idea.completion.AutoImportInsertHandler.java

License:Open Source License

@Override
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement item) {
    ApplicationManager.getApplication().invokeLater(() -> {
        CommandProcessor.getInstance().runUndoTransparentAction(() -> {
            PsiElement element = item.getPsiElement();
            if (element == null || !(element instanceof PsiDirectory)) {
                return;
            }/*from   w w  w . j a  v  a 2s .  com*/
            Editor editor = context.getEditor();
            Project project = editor.getProject();

            if (suggestAlias) {
                alias = Messages.showInputDialog(project,
                        "Package '" + ((PsiDirectory) element).getName()
                                + "' already imported. Please enter an alias:",
                        "Enter Alias", Messages.getInformationIcon());
                if (alias == null || alias.isEmpty()) {
                    Messages.showErrorDialog("Alias cannot be null or empty.", "Error");
                    return;
                }
            }
            // Import the package.
            autoImport(context, element, alias);
            if (project == null) {
                return;
            }
            if (!isCompletionCharAtSpace(editor)) {
                if (suggestAlias) {
                    // InsertHandler inserts the old package name. So we need to change it to the new alias.
                    PsiFile file = context.getFile();
                    PsiElement currentPackageName = file.findElementAt(context.getStartOffset());
                    if (currentPackageName != null) {
                        if (alias == null || alias.isEmpty()) {
                            return;
                        }
                        ApplicationManager.getApplication().runWriteAction(() -> {
                            // Add a new identifier node.
                            PsiElement identifier = BallerinaElementFactory.createIdentifier(project, alias);
                            currentPackageName.getParent().addBefore(identifier, currentPackageName);
                            // Delete the current identifier node.
                            currentPackageName.delete();
                        });
                    }
                }
                if (myTriggerAutoPopup) {
                    ApplicationManager.getApplication().runWriteAction(() -> {
                        PsiDocumentManager.getInstance(project)
                                .doPostponedOperationsAndUnblockDocument(editor.getDocument());
                        EditorModificationUtil.insertStringAtCaret(editor, ":");
                        PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
                    });
                }
            } else {
                editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() + 1);
            }
            // Invoke the popup.
            if (myTriggerAutoPopup) {
                // We need to invoke the popup with a delay. Otherwise it might not show.
                ApplicationManager.getApplication().invokeLater(
                        () -> AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null));
            }
        });
    });
}

From source file:org.coding.git.util.CodingNetUtil.java

License:Apache License

private static void getTwoFactorAuthData(@NotNull final Project project,
        @NotNull final CodingNetAuthDataHolder authHolder, @NotNull final ProgressIndicator indicator,
        @NotNull final CodingNetAuthData oldAuth) throws CodingNetOperationCanceledException {
    authHolder.runTransaction(oldAuth, () -> {
        if (authHolder.getAuthData().getAuthType() != CodingNetAuthData.AuthType.BASIC) {
            throw new CodingNetOperationCanceledException(
                    "Two factor authentication can be used only with Login/Password");
        }/*from w  ww.j a v a 2  s . co m*/

        //CodingNetApiUtil.askForTwoFactorCodeSMS(new CodingNetConnection(oldAuth, false));

        final Ref<String> codeRef = new Ref<String>();
        ApplicationManager.getApplication().invokeAndWait(() -> {
            codeRef.set(Messages.showInputDialog(project, "Authentication Code",
                    "Coding Two-Factor Authentication", null));
        }, indicator.getModalityState());
        if (codeRef.isNull()) {
            throw new CodingNetOperationCanceledException("Can't get two factor authentication code");
        }

        CodingNetSettings settings = CodingNetSettings.getInstance();
        if (settings.getAuthType() == CodingNetAuthData.AuthType.BASIC
                && StringUtil.equalsIgnoreCase(settings.getLogin(), oldAuth.getBasicAuth().getLogin())) {
            settings.setValidGitAuth(false);
        }

        return oldAuth.copyWithTwoFactorCode(codeRef.get());
    });
}

From source file:org.intellij.lang.xpath.xslt.refactoring.extractTemplate.XsltExtractTemplateAction.java

License:Apache License

private boolean extractFrom(final @NotNull PsiElement start, final PsiElement end, String newName) {
    final XmlTag outerTemplate = XsltCodeInsightUtil.getTemplateTag(start, false);
    if (outerTemplate == null) {
        return false;
    }//from  ww  w  .j av  a2  s  .  c  o  m
    final XmlTag parentScope = PsiTreeUtil.getParentOfType(start, XmlTag.class, true);
    if (parentScope == null) {
        return false;
    }

    final StringBuilder sb = new StringBuilder("\n");
    final Set<String> vars = new LinkedHashSet<String>();

    final int startOffset = start.getTextRange().getStartOffset();
    final int endOffset = end.getTextRange().getEndOffset();

    PsiElement e = start;
    while (e != null) {
        if (e instanceof XmlTag) {
            final XmlTag tag = (XmlTag) e;
            if (XsltSupport.isVariable(tag)) {
                final XsltVariable variable = XsltElementFactory.getInstance().wrapElement(tag,
                        XsltVariable.class);
                final LocalSearchScope searchScope = new LocalSearchScope(parentScope);
                final Query<PsiReference> query = ReferencesSearch.search(variable, searchScope);
                for (PsiReference reference : query) {
                    final XmlElement context = PsiTreeUtil.getContextOfType(reference.getElement(),
                            XmlElement.class, true);
                    if (context == null || context.getTextRange().getStartOffset() > endOffset) {
                        return false;
                    }
                }
            }
        }
        sb.append(e.getText());

        final List<XPathVariableReference> references = RefactoringUtil.collectVariableReferences(e);
        for (XPathVariableReference reference : references) {
            final XPathVariable variable = reference.resolve();
            if (variable instanceof XsltVariable) {
                final XmlTag var = ((XsltVariable) variable).getTag();
                if (var.getTextRange().getStartOffset() < startOffset) {
                    // don't pass through global parameters and variables
                    if (XsltCodeInsightUtil.getTemplateTag(variable, false) != null) {
                        vars.add(variable.getName());
                    }
                }
            } else if (variable == null) {
                // TODO just copy unresolved refs or fail?
                vars.add(reference.getReferencedName());
            }
        }

        if (e == end) {
            break;
        }
        e = e.getNextSibling();
    }
    sb.append("\n");

    final String s = newName == null ? Messages.showInputDialog(start.getProject(), "Template Name: ",
            getRefactoringName(), Messages.getQuestionIcon()) : newName;

    if (s != null) {
        new WriteCommandAction(start.getProject()) {
            protected void run(Result result) throws Throwable {
                final PsiFile containingFile = start.getContainingFile();

                XmlTag templateTag = parentScope.createChildTag("template", XsltSupport.XSLT_NS, sb.toString(),
                        false);
                templateTag.setAttribute("name", s);

                final PsiElement dummy = XmlElementFactory.getInstance(start.getProject())
                        .createDisplayText(" ");
                final PsiElement outerParent = outerTemplate.getParent();
                final PsiElement element = outerParent.addAfter(dummy, outerTemplate);
                templateTag = (XmlTag) outerParent.addAfter(templateTag, element);

                final TextRange adjust = templateTag.getTextRange();

                final PsiDocumentManager psiDocumentManager = PsiDocumentManager
                        .getInstance(start.getProject());
                final Document doc = psiDocumentManager.getDocument(containingFile);
                assert doc != null;
                psiDocumentManager.doPostponedOperationsAndUnblockDocument(doc);
                CodeStyleManager.getInstance(start.getManager().getProject()).adjustLineIndent(containingFile,
                        adjust);

                final PsiElement parent = start.getParent();
                XmlTag callTag = parentScope.createChildTag("call-template", XsltSupport.XSLT_NS, null, false);
                callTag.setAttribute("name", s);

                if (start instanceof XmlToken
                        && ((XmlToken) start).getTokenType() == XmlTokenType.XML_DATA_CHARACTERS) {
                    assert start == end;
                    callTag = (XmlTag) start.replace(callTag);
                } else {
                    callTag = (XmlTag) parent.addBefore(callTag, start);
                    parent.deleteChildRange(start, end);
                }

                for (String var : vars) {
                    final XmlTag param = templateTag.createChildTag("param", XsltSupport.XSLT_NS, null, false);
                    param.setAttribute("name", var);
                    RefactoringUtil.addParameter(templateTag, param);

                    final XmlTag arg = RefactoringUtil.addWithParam(callTag);
                    arg.setAttribute("name", var);
                    arg.setAttribute("select", "$" + var);
                }
            }
        }.execute().logException(Logger.getInstance(getClass().getName()));
    }
    return true;
}

From source file:org.intellij.lang.xpath.xslt.refactoring.XsltExtractFunctionAction.java

License:Apache License

protected RefactoringOptions getSettings(XPathExpression expression, Set<XPathExpression> matchingExpressions) {
    final String name = Messages.showInputDialog(expression.getProject(), "Function Name: ",
            getRefactoringName(), Messages.getQuestionIcon());
    final boolean[] b = new boolean[] { false };
    if (name != null) {
        final String[] parts = name.split(":", 2);
        if (parts.length < 2) {
            Messages.showMessageDialog(expression.getProject(), "Custom functions require a prefixed name",
                    "Error", Messages.getErrorIcon());
            b[0] = true;//  www .  j a v a  2 s.c o m
        }
        final XmlElement context = PsiTreeUtil.getContextOfType(expression, XmlElement.class);
        final NamespaceContext namespaceContext = expression.getXPathContext().getNamespaceContext();
        if (namespaceContext != null && context != null
                && namespaceContext.resolve(parts[0], context) == null) {
            Messages.showMessageDialog(expression.getProject(), "Prefix '" + parts[0] + "' is not defined",
                    "Error", Messages.getErrorIcon());
            b[0] = true;
        }
    }
    return new RefactoringOptions() {
        @Override
        public boolean isCanceled() {
            return b[0];
        }

        @Override
        public String getName() {
            return name;
        }
    };
}

From source file:org.jetbrains.plugins.ruby.rails.actions.shortcuts.RegisteredActionNamesPanel.java

License:Apache License

private void addNode(final boolean isGroup) {
    final MySortableTreeNode selectedNode = getSelectedNode();
    if (selectedNode == null) {
        return;/*from   w  w w  .j  a v  a 2  s.  c  om*/
    }
    final String msg = RBundle.message("dialog.register.shortcut.input.dialog.label");
    final String title = isGroup ? RBundle.message("dialog.register.shortcut.input.dialog.group.title")
            : RBundle.message("dialog.register.shortcut.input.dialog.title");
    final String cmdName = Messages.showInputDialog(myContentPanel, msg, title, null);
    if (TextUtil.isEmpty(cmdName)) {
        return;
    }
    final MySortableTreeNode childNode = addNode(cmdName, isGroup, selectedNode, getTreeState(), false);
    if (childNode != null) {
        myNamesTree.scrollPathToVisible(new TreePath(childNode.getPath()));
        myNamesTree.updateUI();
    }
}