List of usage examples for com.intellij.openapi.ui Messages YES
int YES
To view the source code for com.intellij.openapi.ui Messages YES.
Click Source Link
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 {//from w w w . jav a2 s.co 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.treeConflict.MergeFromTheirsResolver.java
License:Apache License
private boolean getAddedFilesPlaceOption() { final SvnConfiguration configuration = SvnConfiguration.getInstance(myVcs.getProject()); boolean add = Boolean.TRUE.equals(configuration.isKeepNewFilesAsIsForTreeConflictMerge()); if (configuration.isKeepNewFilesAsIsForTreeConflictMerge() != null) { return add; }//from ww w . ja va2s.c o m if (!containAdditions(myTheirsChanges) && !containAdditions(myTheirsBinaryChanges)) { return false; } return Messages.YES == MessageDialogBuilder .yesNo(TreeConflictRefreshablePanel.TITLE, "Keep newly created file(s) in their original place?") .yesText("Keep").noText("Move").doNotAsk(new DialogWrapper.DoNotAskOption() { @Override public boolean isToBeShown() { return true; } @Override public void setToBeShown(boolean value, int exitCode) { if (!value) { if (exitCode == 0) { // yes configuration.setKeepNewFilesAsIsForTreeConflictMerge(true); } else { configuration.setKeepNewFilesAsIsForTreeConflictMerge(false); } } } @Override public boolean canBeHidden() { return true; } @Override public boolean shouldSaveOptionsOnCancel() { return true; } @Override public String getDoNotShowMessage() { return CommonBundle.message("dialog.options.do.not.ask"); } }).show(); }
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; }/*from ww w. j a va 2 s . com*/ 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 w w. j a v a2 s . com*/ 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.JetRefactoringUtil.java
License:Apache License
@NotNull private static List<? extends PsiElement> askUserForMethodsToSearch(@NotNull KtDeclaration declaration, @NotNull CallableDescriptor declarationDescriptor, @NotNull Map<PsiElement, CallableDescriptor> overriddenElementsToDescriptor, @NotNull List<String> superClasses, @NotNull String actionStringKey) { if (ApplicationManager.getApplication().isUnitTestMode()) { return ContainerUtil.newArrayList(overriddenElementsToDescriptor.keySet()); }//from w w w . j av a 2 s.c o m String superClassesStr = "\n" + StringUtil.join(superClasses, ""); String message = KotlinBundle.message("x.overrides.y.in.class.list", DescriptorRenderer.COMPACT_WITH_SHORT_TYPES.render(declarationDescriptor), IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES .render(declarationDescriptor.getContainingDeclaration()), superClassesStr, KotlinBundle.message(actionStringKey)); int exitCode = Messages.showYesNoCancelDialog(declaration.getProject(), message, IdeBundle.message("title.warning"), Messages.getQuestionIcon()); switch (exitCode) { case Messages.YES: return ContainerUtil.newArrayList(overriddenElementsToDescriptor.keySet()); case Messages.NO: return Collections.singletonList(declaration); default: return Collections.emptyList(); } }
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 w ww .ja va 2 s. c o m*/ 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);/*from w w w . ja v a 2s . 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.moveDeclarations.ui.MoveKotlinTopLevelDeclarationsDialog.java
License:Apache License
@Override protected void doAction() { KotlinMoveTarget target = selectMoveTarget(); if (target == null) return;// w w w.j a v a 2s .c om saveRefactoringSettings(); List<KtNamedDeclaration> elementsToMove = getSelectedElementsToMove(); final List<KtFile> sourceFiles = getSourceFiles(elementsToMove); final PsiDirectory sourceDirectory = getSourceDirectory(sourceFiles); for (PsiElement element : elementsToMove) { String message = target.verify(element.getContainingFile()); if (message != null) { CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("error.title"), message, null, myProject); return; } } try { boolean deleteSourceFile = false; if (isFullFileMove()) { if (isMoveToPackage()) { final MoveDestination moveDestination = selectPackageBasedMoveDestination(false); //noinspection ConstantConditions PsiDirectory targetDir = moveDestination.getTargetIfExists(sourceDirectory); final String targetFileName = sourceFiles.size() > 1 ? null : tfFileNameInPackage.getText(); List<PsiFile> filesExistingInTargetDir = getFilesExistingInTargetDir(sourceFiles, targetFileName, targetDir); if (filesExistingInTargetDir.isEmpty()) { PsiDirectory targetDirectory = ApplicationUtilsKt .runWriteAction(new Function0<PsiDirectory>() { @Override public PsiDirectory invoke() { return moveDestination.getTargetDirectory(sourceDirectory); } }); for (KtFile sourceFile : sourceFiles) { MoveUtilsKt.setUpdatePackageDirective(sourceFile, cbUpdatePackageDirective.isSelected()); } invokeRefactoring(new MoveFilesOrDirectoriesProcessor(myProject, sourceFiles.toArray(new PsiElement[sourceFiles.size()]), targetDirectory, true, isSearchInComments(), isSearchInNonJavaFiles(), new MoveCallback() { @Override public void refactoringCompleted() { try { if (targetFileName != null) { CollectionsKt.single(sourceFiles).setName(targetFileName); } } finally { if (moveCallback != null) { moveCallback.refactoringCompleted(); } } } }, EmptyRunnable.INSTANCE) { @Override protected String getCommandName() { return targetFileName != null ? "Move " + CollectionsKt.single(sourceFiles).getName() : "Move"; } @Override protected void performRefactoring(@NotNull UsageInfo[] usages) { if (targetFileName != null) { KtFile sourceFile = CollectionsKt.single(sourceFiles); //noinspection ConstantConditions String temporaryName = UniqueNameGenerator.generateUniqueName("temp", "", ".kt", ArraysKt.map(sourceFile.getContainingDirectory().getFiles(), new Function1<PsiFile, String>() { @Override public String invoke(PsiFile file) { return file.getName(); } })); sourceFile.setName(temporaryName); } super.performRefactoring(usages); } }); return; } } int ret = Messages.showYesNoCancelDialog(myProject, "You are about to move all declarations out of the source file(s). Do you want to delete empty files?", RefactoringBundle.message("move.title"), Messages.getQuestionIcon()); if (ret == Messages.CANCEL) return; deleteSourceFile = ret == Messages.YES; } MoveDeclarationsDescriptor options = new MoveDeclarationsDescriptor(elementsToMove, target, MoveDeclarationsDelegate.TopLevel.INSTANCE, isSearchInComments(), isSearchInNonJavaFiles(), true, deleteSourceFile, moveCallback, false); invokeRefactoring(new MoveKotlinDeclarationsProcessor(myProject, options, Mover.Default.INSTANCE)); } catch (IncorrectOperationException e) { CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("error.title"), e.getMessage(), null, myProject); } }
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 ww w.ja va 2s . 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; } 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.kotlin.idea.refactoring.move.moveTopLevelDeclarations.ui.MoveKotlinTopLevelDeclarationsDialog.java
License:Apache License
@Override protected void doAction() { KotlinMoveTarget target = selectMoveTarget(); if (target == null) return;/*from w ww . ja v a 2 s .co m*/ saveRefactoringSettings(); List<KtNamedDeclaration> elementsToMove = getSelectedElementsToMove(); final List<KtFile> sourceFiles = getSourceFiles(elementsToMove); final PsiDirectory sourceDirectory = getSourceDirectory(sourceFiles); for (PsiElement element : elementsToMove) { String message = target.verify(element.getContainingFile()); if (message != null) { CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("error.title"), message, null, myProject); return; } } try { boolean deleteSourceFile = false; if (isFullFileMove()) { if (isMoveToPackage()) { final MoveDestination moveDestination = selectPackageBasedMoveDestination(false); //noinspection ConstantConditions PsiDirectory targetDir = moveDestination.getTargetIfExists(sourceDirectory); final String targetFileName = sourceFiles.size() > 1 ? null : tfFileNameInPackage.getText(); List<PsiFile> filesExistingInTargetDir = getFilesExistingInTargetDir(sourceFiles, targetFileName, targetDir); if (filesExistingInTargetDir.isEmpty()) { PsiDirectory targetDirectory = ApplicationUtilsKt .runWriteAction(new Function0<PsiDirectory>() { @Override public PsiDirectory invoke() { return moveDestination.getTargetDirectory(sourceDirectory); } }); for (KtFile sourceFile : sourceFiles) { MoveUtilsKt.setUpdatePackageDirective(sourceFile, cbUpdatePackageDirective.isSelected()); } invokeRefactoring(new MoveFilesOrDirectoriesProcessor(myProject, sourceFiles.toArray(new PsiElement[sourceFiles.size()]), targetDirectory, true, isSearchInComments(), isSearchInNonJavaFiles(), new MoveCallback() { @Override public void refactoringCompleted() { try { if (targetFileName != null) { CollectionsKt.single(sourceFiles).setName(targetFileName); } } finally { if (moveCallback != null) { moveCallback.refactoringCompleted(); } } } }, EmptyRunnable.INSTANCE) { @Override protected String getCommandName() { return targetFileName != null ? "Move " + CollectionsKt.single(sourceFiles).getName() : "Move"; } @Override protected void performRefactoring(@NotNull UsageInfo[] usages) { if (targetFileName != null) { KtFile sourceFile = CollectionsKt.single(sourceFiles); //noinspection ConstantConditions String temporaryName = UniqueNameGenerator.generateUniqueName("temp", "", ".kt", ArraysKt.map(sourceFile.getContainingDirectory().getFiles(), new Function1<PsiFile, String>() { @Override public String invoke(PsiFile file) { return file.getName(); } })); sourceFile.setName(temporaryName); } super.performRefactoring(usages); } }); return; } } int ret = Messages.showYesNoCancelDialog(myProject, "You are about to move all declarations out of the source file(s). Do you want to delete empty files?", RefactoringBundle.message("move.title"), Messages.getQuestionIcon()); if (ret == Messages.CANCEL) return; deleteSourceFile = ret == Messages.YES; } MoveKotlinTopLevelDeclarationsOptions options = new MoveKotlinTopLevelDeclarationsOptions( elementsToMove, target, isSearchInComments(), isSearchInNonJavaFiles(), true, deleteSourceFile, moveCallback); invokeRefactoring( new MoveKotlinTopLevelDeclarationsProcessor(myProject, options, Mover.Default.INSTANCE$)); } catch (IncorrectOperationException e) { CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("error.title"), e.getMessage(), null, myProject); } }