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,
            @Nullable String initialValue, @Nullable InputValidator validator) 

Source Link

Usage

From source file:com.perl5.lang.perl.idea.generation.handlers.GeneratePerlGetterSetterActionHandlerBase.java

License:Apache License

@Override
protected void generateAtOffset(int targetOffset, Project project, Editor editor, PsiFile file) {
    String name = Messages.showInputDialog(project, getPromtText(), getPromtTitle(), Messages.getQuestionIcon(),
            "", null);

    if (!StringUtil.isEmpty(name)) {
        Document document = editor.getDocument();

        for (String nameChunk : name.split("[ ,]+")) {
            if (!nameChunk.isEmpty() && PerlLexer.IDENTIFIER_PATTERN.matcher(nameChunk).matches()) {
                doGenerate(document, nameChunk, targetOffset);
            }/*from  w w  w . j  ava  2 s  . co  m*/
        }

        PsiDocumentManager.getInstance(project).commitDocument(document);
    }

}

From source file:com.perl5.lang.perl.idea.intentions.StringToHeredocConverter.java

License:Apache License

@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element)
        throws IncorrectOperationException {
    String markerText = Messages.showInputDialog(project, "What here-doc marker should we use?",
            "Input a Heredoc Marker", Messages.getQuestionIcon(), HEREDOC_MARKER, null);
    if (markerText != null)
        if (markerText.isEmpty())
            Messages.showErrorDialog(project, "Empty heredoc markers are not supported", "Marker Error");
        else // converting
        {/*w  w w  . ja  v  a  2s  .  c om*/
            HEREDOC_MARKER = markerText;
            PsiElement parentElement = element.getParent();
            char quoteSymbol = '"';
            if (parentElement instanceof PsiPerlStringSq)
                quoteSymbol = '\'';
            else if (parentElement instanceof PsiPerlStringXq)
                quoteSymbol = '`';

            List<PsiElement> heredocElements = PerlElementFactory.createHereDocElements(project, quoteSymbol,
                    markerText, element.getText());

            PsiFile currentFile = element.getContainingFile();

            PsiElement newLineItem = null;
            int newLineIndex = currentFile.getText().indexOf("\n", element.getTextOffset());
            if (newLineIndex > 1)
                newLineItem = currentFile.findElementAt(newLineIndex);

            if (newLineItem == null) // last statement without newline
            {
                currentFile.addAfter(heredocElements.get(3), currentFile.getLastChild());
                currentFile.addAfter(heredocElements.get(1), currentFile.getLastChild());
                currentFile.addAfter(heredocElements.get(2), currentFile.getLastChild());
                currentFile.addAfter(heredocElements.get(3), currentFile.getLastChild());
            } else {
                PsiElement container = newLineItem.getParent();
                container.addAfter(heredocElements.get(3), container.addAfter(heredocElements.get(2),
                        container.addAfter(heredocElements.get(1), newLineItem)));
            }
            parentElement.replace(heredocElements.get(0));
        }
}

From source file:com.perl5.lang.perl.idea.intentions.StringToHeredocConverterIntention.java

License:Apache License

@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element)
        throws IncorrectOperationException {
    String markerText = Messages.showInputDialog(project, "What here-doc marker should we use?",
            "Input a Heredoc Marker", Messages.getQuestionIcon(), HEREDOC_MARKER, null);
    if (markerText != null) {
        if (markerText.isEmpty()) {
            Messages.showErrorDialog(project, "Empty heredoc markers are not supported", "Marker Error");
        } else // converting
        {/*from   w ww  . ja va  2s . c  o m*/
            HEREDOC_MARKER = markerText;
            super.invoke(project, editor, element);
        }
    }
}

From source file:com.perl5.lang.perl.idea.intentions.StringToHeredocIntention.java

License:Apache License

@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element)
        throws IncorrectOperationException {
    ApplicationManager.getApplication().invokeLater(() -> {
        String markerText = Messages.showInputDialog(project,
                PerlBundle.message("perl.intention.heredoc.dialog.prompt"),
                PerlBundle.message("perl.intention.heredoc.dialog.title"), Messages.getQuestionIcon(),
                HEREDOC_MARKER, null);/*from ww w  .j av  a2s  . c  om*/
        if (markerText != null) {
            if (markerText.isEmpty()) {
                Messages.showErrorDialog(project, PerlBundle.message("perl.intention.heredoc.error.message"),
                        PerlBundle.message("perl.intention.heredoc.error.title"));
            } else // converting
            {
                HEREDOC_MARKER = markerText;
                WriteCommandAction.runWriteCommandAction(project, () -> super.invoke(project, editor, element));
            }
        }
    });
}

From source file:com.suleyman.lua.editor.actions.NewLuaActionBase.java

License:Apache License

@NotNull
protected final PsiElement[] invokeDialog(final Project project, final PsiDirectory directory) {
    log.debug("invokeDialog");
    final MyInputValidator validator = new MyInputValidator(project, directory);
    Messages.showInputDialog(project, getDialogPrompt(), getDialogTitle(), Messages.getQuestionIcon(), "",
            validator);/*from   www. ja  va2  s.com*/

    final PsiElement[] elements = validator.getCreatedElements();
    log.debug("Result: " + Arrays.toString(elements));
    return elements;
}

From source file:consulo.apache.ant.config.actions.CreateNewGroupAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    final AntBuildFileGroupManager groupManager = AntBuildFileGroupManager.getInstance(e.getProject());

    String text = Messages.showInputDialog(e.getProject(), "Name: ", "Enter Group Name", null, null,
            new InputValidator() {
                @Override/*w  ww. j ava 2s .co  m*/
                public boolean checkInput(String inputString) {
                    if (inputString.isEmpty()) {
                        return false;
                    }
                    AntBuildFileGroup[] groups;
                    if (myGroup == null) {
                        groups = groupManager.getFirstLevelGroups();
                    } else {
                        groups = myGroup.getChildren();
                    }

                    for (AntBuildFileGroup group : groups) {
                        if (group.getName().equalsIgnoreCase(inputString)) {
                            return false;
                        }
                    }
                    return true;
                }

                @Override
                public boolean canClose(String inputString) {
                    return checkInput(inputString);
                }
            });

    if (StringUtil.notNullize(text).isEmpty()) {
        return;
    }

    final AntBuildFileGroup group = groupManager.createGroup(myGroup, text);

    final AntBuildFile buildFile = MoveToThisGroupAction.findBuildFile(myTree);
    if (buildFile != null) {
        groupManager.moveToGroup(buildFile, group);
    }

    final AbstractTreeBuilder builder = AbstractTreeBuilder.getBuilderFor(myTree);
    if (builder != null) {
        builder.queueUpdate();
    }
}

From source file:de.fu_berlin.inf.dpp.intellij.ui.util.SafeDialogUtils.java

License:Open Source License

/**
 * Shows an input dialog in the UI thread.
 *///  w w  w  . j  a va  2s.  c  o m
public static String showInputDialog(final String message, final String initialValue, final String title) {
    final StringBuilder response = new StringBuilder();

    UIUtil.invokeAndWaitIfNeeded(new Runnable() {
        @Override
        public void run() {
            String option = Messages.showInputDialog(saros.getProject(), message, title,
                    Messages.getQuestionIcon(), initialValue, null);
            if (option != null) {
                response.append(option);
            }
        }
    });
    return response.toString();
}

From source file:git4idea.actions.GitFetch.java

License:Apache License

@Override
protected 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.  co m*/

    final VirtualFile[] roots = ProjectLevelVcsManager.getInstance(project).getRootsUnderVcs(vcs);
    for (VirtualFile root : roots) {
        GitCommand command = new GitCommand(project, vcs.getSettings(), root);

        String initialValue = null;
        List<GitBranch> rbranches = command.branchList(true);
        if (rbranches != null && rbranches.size() > 0) {
            initialValue = command.remoteRepoURL(rbranches.get(0));
        }
        String repoURL = Messages.showInputDialog(project,
                "Enter remote repository URL to fetch (empty for default):", "Fetch URL",
                Messages.getQuestionIcon(), initialValue, null);

        GitCommandRunnable cmdr = new GitCommandRunnable(project, vcs.getSettings(), root);
        cmdr.setCommand(GitCommand.FETCH_CMD);
        cmdr.setArgs(new String[] { repoURL });

        ProgressManager manager = ProgressManager.getInstance();
        manager.runProcessWithProgressSynchronously(cmdr, "Fetching from " + repoURL, false, project);

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

        cmdr.setArgs(new String[] { "--tags", repoURL });
        manager.runProcessWithProgressSynchronously(cmdr, "Updating tags from " + repoURL, false, project);
        ex = cmdr.getException();
        if (ex != null) {
            Messages.showErrorDialog(project, ex.getMessage(), "Error occurred during 'git fetch --tags'");
            return;
        }
    }
}

From source file:git4idea.actions.GitPull.java

License:Apache License

@Override
protected void perform(@NotNull Project project, GitVcs vcs, @NotNull List<VcsException> exceptions,
        @NotNull VirtualFile[] affectedFiles) throws VcsException {
    saveAll();//from www.j  av  a2  s .  co  m

    final VirtualFile[] roots = ProjectLevelVcsManager.getInstance(project).getRootsUnderVcs(vcs);
    for (VirtualFile root : roots) {
        GitCommand command = new GitCommand(project, vcs.getSettings(), root);

        String initialValue = null;
        List<GitBranch> rbranches = command.branchList(true);
        if (rbranches != null && rbranches.size() > 0) {
            initialValue = command.remoteRepoURL(rbranches.get(0));
        }
        String repoURL = Messages.showInputDialog(project,
                "Enter remote repository URL to pull/merge (empty for default):", "Pull URL",
                Messages.getQuestionIcon(), initialValue, null);

        GitCommandRunnable cmdr = new GitCommandRunnable(project, vcs.getSettings(), root);
        cmdr.setCommand(GitCommand.FETCH_CMD);
        cmdr.setArgs(new String[] { repoURL });

        ProgressManager manager = ProgressManager.getInstance();
        manager.runProcessWithProgressSynchronously(cmdr, "Fetching from " + repoURL, false, project);

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

        cmdr.setArgs(new String[] { "--tags", repoURL });
        manager.runProcessWithProgressSynchronously(cmdr, "Updating tags from " + repoURL, false, project);
        ex = cmdr.getException();
        if (ex != null) {
            Messages.showErrorDialog(project, ex.getMessage(), "Error occurred during 'git fetch --tags'");
            return;
        }

        List<GitBranch> branches = command.branchList();
        String[] branchesList = new String[branches.size()];
        GitBranch selectedBranch = null;
        int i = 0;
        for (GitBranch b : branches) {
            if (!b.isActive() && selectedBranch == null)
                selectedBranch = b;
            branchesList[i++] = b.getName();
        }

        if (selectedBranch == null)
            selectedBranch = branches.get(0);

        int branchNum = Messages.showChooseDialog(
                "Select branch to merge into this one(" + command.currentBranch() + ")", "Merge Branch",
                branchesList, selectedBranch.getName(), Messages.getQuestionIcon());
        if (branchNum < 0) {
            return;
        }

        selectedBranch = branches.get(branchNum);
        cmdr.setCommand(GitCommand.MERGE_CMD);
        cmdr.setArgs(new String[] { selectedBranch.getName() });
        //TODO: make this async so the git command output can be seen in the version control window as it happens...
        manager.runProcessWithProgressSynchronously(cmdr, "Merging branch " + selectedBranch.getName(), false,
                project);
        ex = cmdr.getException();
        if (ex != null) {
            Messages.showErrorDialog(project, ex.getMessage(), "Error occurred during 'git merge'");
        }
    }
}

From source file:git4idea.actions.GitStash.java

License:Apache License

protected void perform(@NotNull Project project, GitVcs vcs, @NotNull List<VcsException> exceptions,
        @NotNull VirtualFile[] affectedFiles) throws VcsException {
    saveAll();//  w  ww  .  j  ava  2s. co  m

    if (!ProjectLevelVcsManager.getInstance(project).checkAllFilesAreUnder(GitVcs.getInstance(project),
            affectedFiles))
        return;

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

    String stashName = Messages.showInputDialog(project, "Enter new stash name/description: ", "Stash",
            Messages.getQuestionIcon(), "", null);

    if (stashName == null || stashName.length() == 0)
        return;

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

        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, "Stashing changes... ", false, project);

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