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);
}
}
}
}
}
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());
}
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);
}
}
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);
}
}
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();
}
}
Aggregations