Search in sources :

Example 11 with InputValidator

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

the class EditScopesDialog method doOKAction.

@Override
public void doOKAction() {
    Object selectedObject = myConfigurable.getSelectedObject();
    mySelectedScope = selectedObject instanceof NamedScope ? (NamedScope) selectedObject : null;
    super.doOKAction();
    if (myCheckShared && mySelectedScope != null) {
        final Project project = myProject;
        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()) == Messages.YES) {
                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);
                }
            }
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) DependencyValidationManager(com.intellij.packageDependencies.DependencyValidationManager) NamedScope(com.intellij.psi.search.scope.packageSet.NamedScope) InputValidator(com.intellij.openapi.ui.InputValidator) PackageSet(com.intellij.psi.search.scope.packageSet.PackageSet)

Example 12 with InputValidator

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

the class RenameModuleTest method testRename.

public void testRename() throws Exception {
    String moduleName = "module";
    String newModuleName = "moduleA";
    Module module = createModule(moduleName);
    assertEquals(moduleName, module.getName());
    MapDataContext context = new MapDataContext();
    context.put(LangDataKeys.MODULE_CONTEXT, module);
    final RenameHandler renameHandler = RenameHandlerRegistry.getInstance().getRenameHandler(context);
    assertNotNull(renameHandler);
    Messages.setTestInputDialog(new TestInputDialog() {

        @Override
        public String show(String message) {
            return null;
        }

        @Override
        public String show(String message, @Nullable InputValidator validator) {
            assertNotNull(validator);
            boolean canClose = validator.canClose(newModuleName);
            assertTrue(canClose);
            return newModuleName;
        }
    });
    renameHandler.invoke(myProject, PsiElement.EMPTY_ARRAY, context);
    assertEquals(newModuleName, module.getName());
}
Also used : MapDataContext(com.intellij.testFramework.MapDataContext) InputValidator(com.intellij.openapi.ui.InputValidator) RenameHandler(com.intellij.refactoring.rename.RenameHandler) TestInputDialog(com.intellij.openapi.ui.TestInputDialog) Module(com.intellij.openapi.module.Module)

Example 13 with InputValidator

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

the class RenameShelvedChangeListAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    final List<ShelvedChangeList> changelists = ShelvedChangesViewManager.getShelvedLists(e.getDataContext());
    final ShelvedChangeList changeList = ObjectUtils.assertNotNull(ContainerUtil.getFirstItem(changelists));
    String newName = Messages.showInputDialog(project, VcsBundle.message("shelve.changes.rename.prompt"), VcsBundle.message("shelve.changes.rename.title"), Messages.getQuestionIcon(), changeList.DESCRIPTION, new InputValidator() {

        public boolean checkInput(final String inputString) {
            if (inputString.length() == 0) {
                return false;
            }
            final List<ShelvedChangeList> list = ShelveChangesManager.getInstance(project).getShelvedChangeLists();
            for (ShelvedChangeList oldList : list) {
                if (oldList != changeList && oldList.DESCRIPTION.equals(inputString)) {
                    return false;
                }
            }
            return true;
        }

        public boolean canClose(final String inputString) {
            return checkInput(inputString);
        }
    });
    if (newName != null && !newName.equals(changeList.DESCRIPTION)) {
        ShelveChangesManager.getInstance(project).renameChangeList(changeList, newName);
    }
}
Also used : Project(com.intellij.openapi.project.Project) InputValidator(com.intellij.openapi.ui.InputValidator) List(java.util.List)

Example 14 with InputValidator

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

the class GitCreateNewTag method execute.

public void execute() {
    final String name = Messages.showInputDialog(myProject, "Enter the name of new tag", "Create New Tag On " + myReference, Messages.getQuestionIcon(), "", new InputValidator() {

        @Override
        public boolean checkInput(String inputString) {
            return !StringUtil.isEmpty(inputString) && !StringUtil.containsWhitespaces(inputString);
        }

        @Override
        public boolean canClose(String inputString) {
            return !StringUtil.isEmpty(inputString) && !StringUtil.containsWhitespaces(inputString);
        }
    });
    if (name != null) {
        GitBrancher brancher = GitBrancher.getInstance(myProject);
        brancher.createNewTag(name, myReference, Collections.singletonList(myRepository), myCallInAwtAfterExecution);
    }
}
Also used : InputValidator(com.intellij.openapi.ui.InputValidator) GitBrancher(git4idea.branch.GitBrancher)

Example 15 with InputValidator

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

the class AddSchemaPrefixIntention method invoke.

@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
    final XmlAttribute xmlns = getXmlnsDeclaration(element);
    if (xmlns == null)
        return;
    final String namespace = xmlns.getValue();
    final XmlTag tag = xmlns.getParent();
    if (tag != null) {
        final Set<String> ns = tag.getLocalNamespaceDeclarations().keySet();
        final String nsPrefix = Messages.showInputDialog(project, "Namespace Prefix:", StringUtil.capitalize(NAME), Messages.getInformationIcon(), "", new InputValidator() {

            @Override
            public boolean checkInput(String inputString) {
                return !ns.contains(inputString);
            }

            @Override
            public boolean canClose(String inputString) {
                return checkInput(inputString);
            }
        });
        if (nsPrefix == null)
            return;
        final List<XmlTag> tags = new ArrayList<>();
        final List<XmlAttributeValue> values = new ArrayList<>();
        new WriteCommandAction(project, NAME, tag.getContainingFile()) {

            @Override
            protected void run(@NotNull Result result) throws Throwable {
                tag.accept(new XmlRecursiveElementVisitor() {

                    @Override
                    public void visitXmlTag(XmlTag tag) {
                        if (tag.getNamespace().equals(namespace) && tag.getNamespacePrefix().isEmpty()) {
                            tags.add(tag);
                        }
                        super.visitXmlTag(tag);
                    }

                    @Override
                    public void visitXmlAttributeValue(XmlAttributeValue value) {
                        PsiReference ref = null;
                        boolean skip = false;
                        for (PsiReference reference : value.getReferences()) {
                            if (reference instanceof TypeOrElementOrAttributeReference) {
                                ref = reference;
                            } else if (reference instanceof SchemaPrefixReference) {
                                skip = true;
                                break;
                            }
                        }
                        if (!skip && ref != null) {
                            final PsiElement xmlElement = ref.resolve();
                            if (xmlElement instanceof XmlElement) {
                                final XmlTag tag = PsiTreeUtil.getParentOfType(xmlElement, XmlTag.class, false);
                                if (tag != null) {
                                    if (tag.getNamespace().equals(namespace)) {
                                        if (ref.getRangeInElement().getLength() == value.getValue().length()) {
                                            //no ns prefix
                                            values.add(value);
                                        }
                                    }
                                }
                            }
                        }
                    }
                });
                for (XmlAttributeValue value : values) {
                    ((XmlAttribute) value.getParent()).setValue(nsPrefix + ":" + value.getValue());
                }
                for (XmlTag xmlTag : tags) {
                    xmlTag.setName(nsPrefix + ":" + xmlTag.getLocalName());
                }
                xmlns.setName("xmlns:" + nsPrefix);
            }
        }.execute();
    }
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlRecursiveElementVisitor(com.intellij.psi.XmlRecursiveElementVisitor) ArrayList(java.util.ArrayList) PsiReference(com.intellij.psi.PsiReference) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) TypeOrElementOrAttributeReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.TypeOrElementOrAttributeReference) Result(com.intellij.openapi.application.Result) InputValidator(com.intellij.openapi.ui.InputValidator) XmlElement(com.intellij.psi.xml.XmlElement) SchemaPrefixReference(com.intellij.psi.impl.source.xml.SchemaPrefixReference) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

InputValidator (com.intellij.openapi.ui.InputValidator)15 PsiDirectory (com.intellij.psi.PsiDirectory)4 NotNull (org.jetbrains.annotations.NotNull)4 Project (com.intellij.openapi.project.Project)3 AndroidProjectViewPane (com.android.tools.idea.navigator.AndroidProjectViewPane)2 IdeView (com.intellij.ide.IdeView)2 AbstractProjectViewPane (com.intellij.ide.projectView.impl.AbstractProjectViewPane)2 PsiElement (com.intellij.psi.PsiElement)2 PsiReference (com.intellij.psi.PsiReference)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ProjectGroup (com.intellij.ide.ProjectGroup)1 FavoritesManager (com.intellij.ide.favoritesTreeView.FavoritesManager)1 ASTNode (com.intellij.lang.ASTNode)1 Application (com.intellij.openapi.application.Application)1 Result (com.intellij.openapi.application.Result)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 Module (com.intellij.openapi.module.Module)1 TestInputDialog (com.intellij.openapi.ui.TestInputDialog)1