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.intellij.ide.actions.CreateDirectoryOrPackageAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    IdeView view = e.getData(LangDataKeys.IDE_VIEW);
    Project project = e.getData(CommonDataKeys.PROJECT);

    if (view == null || project == null) {
        return;/*  w  ww  .j a  va 2 s.c o m*/
    }

    val directory = DirectoryChooserUtil.getOrChooseDirectory(view);

    if (directory == null) {
        return;
    }

    val info = getInfo(directory);

    val validator = new CreateDirectoryOrPackageHandler(project, directory,
            info.getThird() == ChildType.Directory, info.getThird().getSeparator());
    Messages.showInputDialog(project, IdeBundle.message("prompt.enter.new.name"), info.getThird().getName(),
            Messages.getQuestionIcon(), "", validator);

    val result = validator.getCreatedElement();
    if (result != null) {
        view.selectElement(result);
    }
}

From source file:com.intellij.ide.actions.CreateFileAction.java

License:Apache License

@Override
@NotNull//from   ww w. ja v a2s.  c o  m
protected PsiElement[] invokeDialog(final Project project, PsiDirectory directory) {
    MyInputValidator validator = new MyValidator(project, directory);
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        try {
            return validator.create("test");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else {
        Messages.showInputDialog(project, IdeBundle.message("prompt.enter.new.file.name"),
                IdeBundle.message("title.new.file"), Messages.getQuestionIcon(), null, validator);
        return validator.getCreatedElements();
    }
}

From source file:com.intellij.ide.bookmarks.BookmarkManager.java

License:Apache License

public void editDescription(@NotNull Bookmark bookmark) {
    String description = Messages.showInputDialog(myProject,
            IdeBundle.message("action.bookmark.edit.description.dialog.message"),
            IdeBundle.message("action.bookmark.edit.description.dialog.title"), Messages.getQuestionIcon(),
            bookmark.getDescription(), new InputValidator() {
                @Override//from w w  w .  jav a 2s. c  o m
                public boolean checkInput(String inputString) {
                    return true;
                }

                @Override
                public boolean canClose(String inputString) {
                    return true;
                }
            });
    if (description != null) {
        setDescription(bookmark, description);
    }
}

From source file:com.intellij.ide.favoritesTreeView.actions.AddNewFavoritesListAction.java

License:Apache License

public static String doAddNewFavoritesList(final Project project) {
    final FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
    final String name = Messages.showInputDialog(project,
            IdeBundle.message("prompt.input.new.favorites.list.name"),
            IdeBundle.message("title.add.new.favorites.list"), Messages.getInformationIcon(),
            getUniqueName(project), new InputValidator() {
                @Override/*from w w w . j  a v  a  2s .c  o m*/
                public boolean checkInput(String inputString) {
                    return inputString != null && inputString.trim().length() > 0;
                }

                @Override
                public boolean canClose(String inputString) {
                    inputString = inputString.trim();
                    if (favoritesManager.getAvailableFavoritesListNames().contains(inputString)) {
                        Messages.showErrorDialog(project,
                                IdeBundle.message("error.favorites.list.already.exists", inputString.trim()),
                                IdeBundle.message("title.unable.to.add.favorites.list"));
                        return false;
                    }
                    return inputString.length() > 0;
                }
            });
    if (name == null || name.length() == 0)
        return null;
    favoritesManager.createNewList(name);
    return name;
}

From source file:com.intellij.ide.favoritesTreeView.FavoritesManager.java

License:Apache License

public void renameList(final Project project, @NotNull String listName) {
    final String newName = Messages.showInputDialog(project,
            IdeBundle.message("prompt.input.favorites.list.new.name", listName),
            IdeBundle.message("title.rename.favorites.list"), Messages.getInformationIcon(), listName,
            new InputValidator() {
                @Override//from  w  w  w  . j  a v  a  2  s  . c om
                public boolean checkInput(String inputString) {
                    return inputString != null && inputString.trim().length() > 0;
                }

                @Override
                public boolean canClose(String inputString) {
                    inputString = inputString.trim();
                    if (myName2FavoritesRoots.keySet().contains(inputString)
                            || myProviders.keySet().contains(inputString)) {
                        Messages.showErrorDialog(project,
                                IdeBundle.message("error.favorites.list.already.exists", inputString.trim()),
                                IdeBundle.message("title.unable.to.add.favorites.list"));
                        return false;
                    }
                    return !inputString.isEmpty();
                }
            });

    if (newName != null && renameFavoritesList(listName, newName)) {
        rootsChanged();
    }
}

From source file:com.intellij.ide.projectView.impl.RenameModuleHandler.java

License:Apache License

@Override
public void invoke(@NotNull final Project project, @NotNull PsiElement[] elements,
        @NotNull DataContext dataContext) {
    final Module module = LangDataKeys.MODULE_CONTEXT.getData(dataContext);
    LOG.assertTrue(module != null);//www. j a va  2  s . co  m
    Messages.showInputDialog(project, IdeBundle.message("prompt.enter.new.module.name"),
            IdeBundle.message("title.rename.module"), Messages.getQuestionIcon(), module.getName(),
            new MyInputValidator(project, module));
}

From source file:com.intellij.ide.util.PackageChooserDialog.java

License:Apache License

private void createNewPackage() {
    final PsiJavaPackage selectedPackage = getTreeSelection();
    if (selectedPackage == null)
        return;/* w  w  w.  ja  v a2 s.c  om*/

    final String newPackageName = Messages.showInputDialog(myProject,
            IdeBundle.message("prompt.enter.a.new.package.name"), IdeBundle.message("title.new.package"),
            Messages.getQuestionIcon(), "", new InputValidator() {
                public boolean checkInput(final String inputString) {
                    return inputString != null && inputString.length() > 0;
                }

                public boolean canClose(final String inputString) {
                    return checkInput(inputString);
                }
            });
    if (newPackageName == null)
        return;

    CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
        public void run() {
            final Runnable action = new Runnable() {
                public void run() {

                    try {
                        String newQualifiedName = selectedPackage.getQualifiedName();
                        if (!Comparing.strEqual(newQualifiedName, ""))
                            newQualifiedName += ".";
                        newQualifiedName += newPackageName;
                        final PsiDirectory dir = PackageUtil.findOrCreateDirectoryForPackage(myProject,
                                newQualifiedName, null, false);
                        if (dir == null)
                            return;
                        final PsiJavaPackage newPackage = JavaDirectoryService.getInstance().getPackage(dir);

                        DefaultMutableTreeNode node = (DefaultMutableTreeNode) myTree.getSelectionPath()
                                .getLastPathComponent();
                        final DefaultMutableTreeNode newChild = new DefaultMutableTreeNode();
                        newChild.setUserObject(newPackage);
                        node.add(newChild);

                        final DefaultTreeModel model = (DefaultTreeModel) myTree.getModel();
                        model.nodeStructureChanged(node);

                        final TreePath selectionPath = myTree.getSelectionPath();
                        TreePath path;
                        if (selectionPath == null) {
                            path = new TreePath(newChild.getPath());
                        } else {
                            path = selectionPath.pathByAddingChild(newChild);
                        }
                        myTree.setSelectionPath(path);
                        myTree.scrollPathToVisible(path);
                        myTree.expandPath(path);

                    } catch (IncorrectOperationException e) {
                        Messages.showMessageDialog(getContentPane(), StringUtil.getMessage(e),
                                CommonBundle.getErrorTitle(), Messages.getErrorIcon());
                        if (LOG.isDebugEnabled()) {
                            LOG.debug(e);
                        }
                    }
                }
            };
            ApplicationManager.getApplication().runReadAction(action);
        }
    }, IdeBundle.message("command.create.new.package"), null);
}

From source file:com.intellij.ide.util.scopeChooser.EditScopesDialog.java

License:Apache License

@Override
protected void doOKAction() {
    final Object selectedObject = ((ScopeChooserConfigurable) getConfigurable()).getSelectedObject();
    if (selectedObject instanceof NamedScope) {
        mySelectedScope = (NamedScope) selectedObject;
    }/*from www. jav  a  2  s .c o m*/
    super.doOKAction();
    if (myCheckShared && mySelectedScope != null) {
        final Project project = getProject();
        final DependencyValidationManager manager = DependencyValidationManager.getInstance(project);
        NamedScope scope = manager.getScope(mySelectedScope.getName());
        if (scope == null) {
            if (Messages.showYesNoDialog(IdeBundle.message("scope.unable.to.save.scope.message"),
                    IdeBundle.message("scope.unable.to.save.scope.title"),
                    Messages.getErrorIcon()) == DialogWrapper.OK_EXIT_CODE) {
                final String newName = Messages.showInputDialog(project,
                        IdeBundle.message("add.scope.name.label"),
                        IdeBundle.message("scopes.save.dialog.title.shared"), Messages.getQuestionIcon(),
                        mySelectedScope.getName(), new InputValidator() {
                            @Override
                            public boolean checkInput(String inputString) {
                                return inputString != null && inputString.length() > 0
                                        && manager.getScope(inputString) == null;
                            }

                            @Override
                            public boolean canClose(String inputString) {
                                return checkInput(inputString);
                            }
                        });
                if (newName != null) {
                    final PackageSet packageSet = mySelectedScope.getValue();
                    scope = new NamedScope(newName, packageSet != null ? packageSet.createCopy() : null);
                    mySelectedScope = scope;
                    manager.addScope(mySelectedScope);
                }
            }
        }
    }
}

From source file:com.intellij.ide.util.scopeChooser.ScopeChooserConfigurable.java

License:Apache License

private void createScope(final boolean isLocal, String title, final PackageSet set) {
    final String newName = Messages.showInputDialog(myTree, IdeBundle.message("add.scope.name.label"), title,
            Messages.getInformationIcon(), createUniqueName(), new InputValidator() {
                @Override//from   w  w w .j a v a 2  s.  co m
                public boolean checkInput(String inputString) {
                    final NamedScopesHolder holder = isLocal ? myLocalScopesManager : mySharedScopesManager;
                    for (NamedScope scope : holder.getPredefinedScopes()) {
                        if (Comparing.strEqual(scope.getName(), inputString.trim())) {
                            return false;
                        }
                    }
                    return inputString.trim().length() > 0;
                }

                @Override
                public boolean canClose(String inputString) {
                    return checkInput(inputString);
                }
            });
    if (newName != null) {
        final NamedScope scope = new NamedScope(newName, set);
        addNewScope(scope, isLocal);
    }
}

From source file:com.intellij.lang.properties.editor.actions.AddPropertyKeyAction.java

License:Apache License

@Override
public void actionPerformed(final AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final List<PropertiesFile> propertiesFiles = myResourceBundle.getPropertiesFiles(project);

    final String message = Messages.showInputDialog(project,
            PropertiesBundle.message("add.dialog.property.name"),
            PropertiesBundle.message("add.dialog.property.title"), AllIcons.General.QuestionDialog, null,
            new InputValidator() {
                @Override//  www  .ja v a 2 s  .  c  om
                public boolean checkInput(String inputString) {
                    if (StringUtil.isEmptyOrSpaces(inputString)) {
                        return false;
                    }

                    boolean hasInAll = true;
                    for (PropertiesFile propertiesFile : propertiesFiles) {
                        if (propertiesFile.findPropertyByKey(inputString) == null) {
                            hasInAll = false;
                        }
                    }
                    return !hasInAll && !inputString.contains(" ");
                }

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

    if (message == null) {
        return;
    }

    new WriteCommandAction(project) {
        @Override
        protected void run(Result result) throws Throwable {
            for (PropertiesFile propertiesFile : propertiesFiles) {
                final String temp = message.trim();
                propertiesFile.addProperty(temp, temp);
            }

            myTreeBuilder.queueUpdate();
        }
    }.execute();
}