List of usage examples for com.intellij.openapi.ui Messages showYesNoDialog
@YesNoResult public static int showYesNoDialog(@NotNull Component parent, String message, @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title, @Nullable Icon icon)
From source file:org.jetbrains.idea.svn.SvnAuthenticationNotifier.java
License:Apache License
public static void clearAuthenticationCache(@NotNull final Project project, final Component component, final String configDirPath) { if (configDirPath != null) { int result; if (component == null) { result = Messages.showYesNoDialog(project, SvnBundle.message("confirmation.text.delete.stored.authentication.information"), SvnBundle.message("confirmation.title.clear.authentication.cache"), Messages.getWarningIcon()); } else {// ww w . ja v a2 s. c o m result = Messages.showYesNoDialog(component, SvnBundle.message("confirmation.text.delete.stored.authentication.information"), SvnBundle.message("confirmation.title.clear.authentication.cache"), Messages.getWarningIcon()); } if (result == Messages.YES) { SvnConfiguration.RUNTIME_AUTH_CACHE.clear(); clearAuthenticationDirectory(SvnConfiguration.getInstance(project)); } } }
From source file:org.jetbrains.idea.svn.update.SvnUpdateEnvironment.java
License:Apache License
private boolean checkAncestry(final File sourceFile, final SVNURL targetUrl, final SVNRevision targetRevision) throws SVNException { final SVNInfo sourceSvnInfo = myVcs.getInfo(sourceFile); final SVNInfo targetSvnInfo = myVcs.getInfo(targetUrl, targetRevision); if (sourceSvnInfo == null || targetSvnInfo == null) { // cannot check return true; }/* ww w . j a v a 2s.c om*/ final SVNURL copyFromTarget = targetSvnInfo.getCopyFromURL(); final SVNURL copyFromSource = sourceSvnInfo.getCopyFromURL(); if ((copyFromSource != null) || (copyFromTarget != null)) { if (sourceSvnInfo.getURL().equals(copyFromTarget) || targetUrl.equals(copyFromSource)) { return true; } } final int result = Messages.showYesNoDialog(myVcs.getProject(), SvnBundle.message("switch.target.not.copy.current"), SvnBundle.message("switch.target.problem.title"), Messages.getWarningIcon()); return (Messages.YES == result); }
From source file:org.jetbrains.jet.plugin.refactoring.move.moveTopLevelDeclarations.ui.MoveKotlinTopLevelDeclarationsDialog.java
License:Apache License
@Nullable private KotlinMoveTarget selectMoveTarget() { String message = verifyBeforeRun(); if (message != null) { setErrorText(message);//from w ww . j a v a2 s .c om return null; } setErrorText(null); if (isMoveToPackage()) { String packageName = getTargetPackage().trim(); RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, packageName); PackageWrapper targetPackage = new PackageWrapper(PsiManager.getInstance(myProject), packageName); if (!targetPackage.exists()) { int ret = Messages.showYesNoDialog(myProject, RefactoringBundle.message("package.does.not.exist", packageName), RefactoringBundle.message("move.title"), Messages.getQuestionIcon()); if (ret != Messages.YES) return null; } MoveDestination moveDestination = ((DestinationFolderComboBox) destinationFolderCB) .selectDirectory(targetPackage, false); return moveDestination != null ? new MoveDestinationKotlinMoveTarget(moveDestination) : null; } JetFile jetFile = (JetFile) RefactoringPackage.toPsiFile(new File(getTargetFilePath()), myProject); assert jetFile != null : "Non-Kotlin files must be filtered out before starting the refactoring"; return new JetFileKotlinMoveTarget(jetFile); }
From source file:org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.ui.MoveKotlinTopLevelDeclarationsDialog.java
License:Apache License
@Nullable private MoveDestination selectPackageBasedMoveDestination(boolean askIfDoesNotExist) { String packageName = getTargetPackage(); RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, packageName); PackageWrapper targetPackage = new PackageWrapper(PsiManager.getInstance(myProject), packageName); if (!targetPackage.exists() && askIfDoesNotExist) { int ret = Messages.showYesNoDialog(myProject, RefactoringBundle.message("package.does.not.exist", packageName), RefactoringBundle.message("move.title"), Messages.getQuestionIcon()); if (ret != Messages.YES) return null; }//from ww w. j a va2 s. c om return ((DestinationFolderComboBox) destinationFolderCB).selectDirectory(targetPackage, false); }
From source file:org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.ui.MoveKotlinTopLevelDeclarationsDialog.java
License:Apache License
@Nullable private KotlinMoveTarget selectMoveTarget() { String message = verifyBeforeRun(); if (message != null) { setErrorText(message);// w w w .j a v a 2 s .c o m return null; } setErrorText(null); List<KtFile> sourceFiles = getSourceFiles(getSelectedElementsToMove()); PsiDirectory sourceDirectory = getSourceDirectory(sourceFiles); if (isMoveToPackage()) { final MoveDestination moveDestination = selectPackageBasedMoveDestination(true); if (moveDestination == null) return null; final String targetFileName = sourceFiles.size() > 1 ? null : tfFileNameInPackage.getText(); if (targetFileName != null && !checkTargetFileName(targetFileName)) return null; PsiDirectory targetDirectory = moveDestination.getTargetIfExists(sourceDirectory); List<PsiFile> filesExistingInTargetDir = getFilesExistingInTargetDir(sourceFiles, targetFileName, targetDirectory); if (!filesExistingInTargetDir.isEmpty()) { if (!CollectionsKt.intersect(sourceFiles, filesExistingInTargetDir).isEmpty()) { setErrorText("Can't move to the original file(s)"); return null; } if (filesExistingInTargetDir.size() > 1) { String filePathsToReport = StringUtil.join(filesExistingInTargetDir, new Function<PsiFile, String>() { @Override public String fun(PsiFile file) { return file.getVirtualFile().getPath(); } }, "\n"); Messages.showErrorDialog(myProject, "Cannot perform refactoring since the following files already exist:\n\n" + filePathsToReport, RefactoringBundle.message("move.title")); return null; } String question = String.format( "File '%s' already exists. Do you want to move selected declarations to this file?", filesExistingInTargetDir.get(0).getVirtualFile().getPath()); int ret = Messages.showYesNoDialog(myProject, question, RefactoringBundle.message("move.title"), Messages.getQuestionIcon()); if (ret != Messages.YES) return null; } // All source files must be in the same directory return new KotlinMoveTargetForDeferredFile(new FqName(getTargetPackage()), moveDestination.getTargetIfExists(sourceFiles.get(0)), new Function1<KtFile, KtFile>() { @Override public KtFile invoke(@NotNull KtFile originalFile) { return JetRefactoringUtilKt.getOrCreateKotlinFile( targetFileName != null ? targetFileName : originalFile.getName(), moveDestination.getTargetDirectory(originalFile)); } }); } final File targetFile = new File(getTargetFilePath()); if (!checkTargetFileName(targetFile.getName())) return null; KtFile jetFile = (KtFile) JetRefactoringUtilKt.toPsiFile(targetFile, myProject); if (jetFile != null) { if (sourceFiles.size() == 1 && sourceFiles.contains(jetFile)) { setErrorText("Can't move to the original file"); return null; } return new KotlinMoveTargetForExistingElement(jetFile); } File targetDir = targetFile.getParentFile(); final PsiDirectory psiDirectory = targetDir != null ? JetRefactoringUtilKt.toPsiDirectory(targetDir, myProject) : null; if (psiDirectory == null) { setErrorText("No directory found for file: " + targetFile.getPath()); return null; } Set<FqName> sourcePackageFqNames = CollectionsKt.mapTo(sourceFiles, new LinkedHashSet<FqName>(), new Function1<KtFile, FqName>() { @Override public FqName invoke(KtFile file) { return file.getPackageFqName(); } }); FqName targetPackageFqName = CollectionsKt.singleOrNull(sourcePackageFqNames); if (targetPackageFqName == null) { PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage(psiDirectory); if (psiPackage == null) { setErrorText("Could not find package corresponding to " + targetDir.getPath()); return null; } targetPackageFqName = new FqName(psiPackage.getQualifiedName()); } final String finalTargetPackageFqName = targetPackageFqName.asString(); return new KotlinMoveTargetForDeferredFile(targetPackageFqName, psiDirectory, new Function1<KtFile, KtFile>() { @Override public KtFile invoke(@NotNull KtFile originalFile) { return JetRefactoringUtilKt.getOrCreateKotlinFile(targetFile.getName(), psiDirectory, finalTargetPackageFqName); } }); }
From source file:org.jetbrains.kotlin.idea.refactoring.move.moveTopLevelDeclarations.ui.MoveKotlinTopLevelDeclarationsDialog.java
License:Apache License
@Nullable private KotlinMoveTarget selectMoveTarget() { String message = verifyBeforeRun(); if (message != null) { setErrorText(message);//from w w w.ja va2 s . c om return null; } setErrorText(null); List<KtFile> sourceFiles = getSourceFiles(getSelectedElementsToMove()); PsiDirectory sourceDirectory = getSourceDirectory(sourceFiles); if (isMoveToPackage()) { final MoveDestination moveDestination = selectPackageBasedMoveDestination(true); if (moveDestination == null) return null; final String targetFileName = sourceFiles.size() > 1 ? null : tfFileNameInPackage.getText(); if (targetFileName != null && !checkTargetFileName(targetFileName)) return null; PsiDirectory targetDirectory = moveDestination.getTargetIfExists(sourceDirectory); List<PsiFile> filesExistingInTargetDir = getFilesExistingInTargetDir(sourceFiles, targetFileName, targetDirectory); if (!filesExistingInTargetDir.isEmpty()) { if (!CollectionsKt.intersect(sourceFiles, filesExistingInTargetDir).isEmpty()) { setErrorText("Can't move to the original file(s)"); return null; } if (filesExistingInTargetDir.size() > 1) { String filePathsToReport = StringUtil.join(filesExistingInTargetDir, new Function<PsiFile, String>() { @Override public String fun(PsiFile file) { return file.getVirtualFile().getPath(); } }, "\n"); Messages.showErrorDialog(myProject, "Cannot perform refactoring since the following files already exist:\n\n" + filePathsToReport, RefactoringBundle.message("move.title")); return null; } String question = String.format( "File '%s' already exists. Do you want to move selected declarations to this file?", filesExistingInTargetDir.get(0).getVirtualFile().getPath()); int ret = Messages.showYesNoDialog(myProject, question, RefactoringBundle.message("move.title"), Messages.getQuestionIcon()); if (ret != Messages.YES) return null; } return new DeferredJetFileKotlinMoveTarget(myProject, new FqName(getTargetPackage()), new Function1<KtFile, KtFile>() { @Override public KtFile invoke(@NotNull KtFile originalFile) { return JetRefactoringUtilKt.getOrCreateKotlinFile( targetFileName != null ? targetFileName : originalFile.getName(), moveDestination.getTargetDirectory(originalFile)); } }); } final File targetFile = new File(getTargetFilePath()); if (!checkTargetFileName(targetFile.getName())) return null; KtFile jetFile = (KtFile) JetRefactoringUtilKt.toPsiFile(targetFile, myProject); if (jetFile != null) { if (sourceFiles.size() == 1 && sourceFiles.contains(jetFile)) { setErrorText("Can't move to the original file"); return null; } return new JetFileKotlinMoveTarget(jetFile); } File targetDir = targetFile.getParentFile(); final PsiDirectory psiDirectory = JetRefactoringUtilKt.toPsiDirectory(targetDir, myProject); assert psiDirectory != null : "No directory found: " + targetDir.getPath(); PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage(psiDirectory); if (psiPackage == null) { setErrorText("Could not find package corresponding to " + targetDir.getPath()); return null; } return new DeferredJetFileKotlinMoveTarget(myProject, new FqName(psiPackage.getQualifiedName()), new Function1<KtFile, KtFile>() { @Override public KtFile invoke(@NotNull KtFile originalFile) { return JetRefactoringUtilKt.getOrCreateKotlinFile(targetFile.getName(), psiDirectory); } }); }
From source file:org.jetbrains.plugins.github.util.GithubNotifications.java
License:Apache License
@Messages.YesNoResult public static int showYesNoDialog(final @Nullable Project project, final @NotNull String title, final @NotNull String message) { return Messages.showYesNoDialog(project, message, title, Messages.getQuestionIcon()); }
From source file:org.jetbrains.plugins.groovy.actions.generate.equals.GroovyGenerateEqualsHandler.java
License:Apache License
@Nullable protected ClassMember[] chooseOriginalMembers(PsiClass aClass, Project project) { myEqualsFields = null;/*from w w w. j av a2s . c o m*/ myHashCodeFields = null; myNonNullFields = PsiField.EMPTY_ARRAY; GlobalSearchScope scope = aClass.getResolveScope(); final PsiMethod equalsMethod = GroovyGenerateEqualsHelper.findMethod(aClass, GroovyGenerateEqualsHelper.getEqualsSignature(project, scope)); final PsiMethod hashCodeMethod = GroovyGenerateEqualsHelper.findMethod(aClass, GroovyGenerateEqualsHelper.getHashCodeSignature()); boolean needEquals = equalsMethod == null; boolean needHashCode = hashCodeMethod == null; if (!needEquals && !needHashCode) { String text = aClass instanceof PsiAnonymousClass ? GroovyCodeInsightBundle .message("generate.equals.and.hashcode.already.defined.warning.anonymous") : GroovyCodeInsightBundle.message("generate.equals.and.hashcode.already.defined.warning", aClass.getQualifiedName()); if (Messages.showYesNoDialog(project, text, GroovyCodeInsightBundle.message("generate.equals.and.hashcode.already.defined.title"), Messages.getQuestionIcon()) == DialogWrapper.OK_EXIT_CODE) { if (!ApplicationManager.getApplication().runWriteAction(new Computable<Boolean>() { public Boolean compute() { try { equalsMethod.delete(); hashCodeMethod.delete(); return Boolean.TRUE; } catch (IncorrectOperationException e) { LOG.error(e); return Boolean.FALSE; } } }).booleanValue()) { return null; } else { needEquals = needHashCode = true; } } else { return null; } } GenerateEqualsWizard wizard = new GenerateEqualsWizard(project, aClass, needEquals, needHashCode); wizard.show(); if (!wizard.isOK()) return null; myEqualsFields = wizard.getEqualsFields(); myHashCodeFields = wizard.getHashCodeFields(); myNonNullFields = wizard.getNonNullFields(); return DUMMY_RESULT; }
From source file:org.jetbrains.plugins.groovy.actions.generate.missing.GroovyGenerateMethodMissingHandler.java
License:Apache License
@Nullable @Override/*from w ww . j a va 2 s . co m*/ protected ClassMember[] chooseOriginalMembers(PsiClass aClass, Project project) { final PsiMethod[] missings = aClass.findMethodsByName("methodMissing", true); PsiMethod method = null; for (PsiMethod missing : missings) { final PsiParameter[] parameters = missing.getParameterList().getParameters(); if (parameters.length == 2) { if (isNameParam(parameters[0])) { method = missing; } } } if (method != null) { String text = GroovyCodeInsightBundle.message("generate.method.missing.already.defined.warning"); if (Messages.showYesNoDialog(project, text, GroovyCodeInsightBundle.message("generate.method.missing.already.defined.title"), Messages.getQuestionIcon()) == DialogWrapper.OK_EXIT_CODE) { final PsiMethod finalMethod = method; if (!ApplicationManager.getApplication().runWriteAction(new Computable<Boolean>() { public Boolean compute() { try { finalMethod.delete(); return Boolean.TRUE; } catch (IncorrectOperationException e) { LOG.error(e); return Boolean.FALSE; } } }).booleanValue()) { return null; } } else { return null; } } return new ClassMember[1]; }
From source file:org.jetbrains.plugins.groovy.actions.generate.missing.GroovyGeneratePropertyMissingHandler.java
License:Apache License
@Nullable @Override// www.j a v a 2s.co m protected ClassMember[] chooseOriginalMembers(PsiClass aClass, Project project) { final PsiMethod[] missings = aClass.findMethodsByName("propertyMissing", true); PsiMethod getter = null; PsiMethod setter = null; for (PsiMethod missing : missings) { final PsiParameter[] parameters = missing.getParameterList().getParameters(); if (parameters.length == 1) { if (isNameParam(parameters[0])) { getter = missing; } } else if (parameters.length == 2) { if (isNameParam(parameters[0])) { setter = missing; } } } if (setter != null && getter != null) { String text = GroovyCodeInsightBundle.message("generate.property.missing.already.defined.warning"); if (Messages.showYesNoDialog(project, text, GroovyCodeInsightBundle.message("generate.property.missing.already.defined.title"), Messages.getQuestionIcon()) == DialogWrapper.OK_EXIT_CODE) { final PsiMethod finalGetter = getter; final PsiMethod finalSetter = setter; if (!ApplicationManager.getApplication().runWriteAction(new Computable<Boolean>() { public Boolean compute() { try { finalSetter.delete(); finalGetter.delete(); return Boolean.TRUE; } catch (IncorrectOperationException e) { LOG.error(e); return Boolean.FALSE; } } }).booleanValue()) { return null; } } else { return null; } } return new ClassMember[1]; }