List of usage examples for com.intellij.openapi.ui Messages showYesNoCancelDialog
@YesNoCancelResult public static int showYesNoCancelDialog(@NotNull Component parent, String message, @Nls(capitalization = Nls.Capitalization.Title) String title, Icon icon)
From source file:com.intellij.uiDesigner.designSurface.InsertComponentProcessor.java
License:Apache License
private boolean checkAddModuleDependency(final ComponentItem item, final ModuleSourceOrderEntry moduleSourceOrderEntry) { final Module ownerModule = moduleSourceOrderEntry.getOwnerModule(); int rc = Messages.showYesNoCancelDialog(myEditor, UIDesignerBundle.message("add.module.dependency.prompt", item.getClassName(), ownerModule.getName(), myEditor.getModule().getName()), UIDesignerBundle.message("add.module.dependency.title"), Messages.getQuestionIcon()); if (rc == Messages.CANCEL) { return false; }/*from w w w. j a v a 2 s . c om*/ if (rc == Messages.YES) { ModuleRootModificationUtil.addDependency(myEditor.getModule(), ownerModule); } return true; }
From source file:com.intellij.uiDesigner.designSurface.InsertComponentProcessor.java
License:Apache License
private boolean checkAddLibraryDependency(final ComponentItem item, final LibraryOrderEntry libraryOrderEntry) { int rc = Messages.showYesNoCancelDialog(myEditor, UIDesignerBundle.message("add.library.dependency.prompt", item.getClassName(), libraryOrderEntry.getPresentableName(), myEditor.getModule().getName()), UIDesignerBundle.message("add.library.dependency.title"), Messages.getQuestionIcon()); if (rc == Messages.CANCEL) { return false; }//from w ww.ja v a 2 s . c o m if (rc == Messages.YES) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { final ModifiableRootModel model = ModuleRootManager.getInstance(myEditor.getModule()) .getModifiableModel(); if (libraryOrderEntry.isModuleLevel()) { copyModuleLevelLibrary(libraryOrderEntry.getLibrary(), model); } else { model.addLibraryEntry(libraryOrderEntry.getLibrary()); } model.commit(); } }); } return true; }
From source file:manuylov.maxim.ocaml.actions.SwitchModuleFileAction.java
License:Open Source License
public void actionPerformed(final AnActionEvent e) { final Project project = e.getProject(); if (project == null) { return;/*w w w .ja v a 2 s. c o m*/ } final IdeView view = e.getData(LangDataKeys.IDE_VIEW); if (view == null) { return; } final VirtualFile file = e.getData(PlatformDataKeys.VIRTUAL_FILE); if (file == null) { return; } final VirtualFile parent = file.getParent(); if (parent == null) { return; } final File anotherFile = new File(parent.getPath(), OCamlFileUtil.getAnotherFileName(file)); VirtualFile anotherVirtualFile = LocalFileSystem.getInstance().findFileByIoFile(anotherFile); if (anotherVirtualFile == null) { final String anotherFilePath = FileUtil.toSystemDependentName(anotherFile.getAbsolutePath()); final Module module = ModuleUtil.findModuleForFile(file, project); if (OCamlModuleUtil.hasOCamlExtension(module) && ModuleRootManager.getInstance(module).getFileIndex().isInSourceContent(file)) { if (Messages.showYesNoCancelDialog(project, "File \"" + anotherFilePath + "\" does not exist. Do you want to create it?", "Open file \"" + anotherFilePath + "\"", Messages.getQuestionIcon()) != 0) { return; } ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { try { parent.createChildData(SwitchModuleFileAction.this, anotherFile.getName()); } catch (final IOException e) { Messages.showErrorDialog(project, e.getMessage(), "Error"); } } }); anotherVirtualFile = LocalFileSystem.getInstance().findFileByIoFile(anotherFile); if (anotherVirtualFile == null) { return; } } else { Messages.showErrorDialog(project, "File \"" + anotherFilePath + "\" does not exist.", "Open file \"" + anotherFilePath + "\""); return; } } final PsiFile anotherPsiFile = PsiManager.getInstance(project).findFile(anotherVirtualFile); if (anotherPsiFile == null) { return; } view.selectElement(anotherPsiFile); }
From source file:org.jetbrains.android.run.testing.AndroidTestRunConfiguration.java
License:Apache License
@Override public AndroidRunningState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException { final AndroidRunningState state = super.getState(executor, env); if (state == null) { return null; }/* w w w . j ava2s . c o m*/ final AndroidFacet facet = state.getFacet(); final AndroidFacetConfiguration configuration = facet.getConfiguration(); if (!facet.isGradleProject() && !configuration.getState().PACK_TEST_CODE) { final Module module = facet.getModule(); final int count = getTestSourceRootCount(module); if (count > 0) { final String message = "Code and resources under test source " + (count > 1 ? "roots" : "root") + " aren't included into debug APK.\nWould you like to include them and recompile " + module.getName() + " module?" + "\n(You may change this option in Android facet settings later)"; final int result = Messages.showYesNoCancelDialog(getProject(), message, "Test code not included into APK", Messages.getQuestionIcon()); if (result == Messages.YES) { configuration.getState().PACK_TEST_CODE = true; } else if (result == Messages.CANCEL) { return null; } } } return state; }
From source file:org.jetbrains.jet.plugin.actions.JavaToKotlinAction.java
License:Apache License
@Override public void actionPerformed(final AnActionEvent e) { VirtualFile[] virtualFiles = e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY); assert virtualFiles != null; final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext()); assert project != null; final Converter converter = new Converter(project); int result = Messages.showYesNoCancelDialog(project, "Would you like to backup Java files?", "Backup", Messages.getQuestionIcon()); final boolean finalRemoveIt = needToRemoveFiles(result); final List<PsiFile> allJavaFiles = getAllJavaFiles(virtualFiles, project); converter.clearClassIdentifiers();/*www .j a va 2 s .c om*/ for (PsiFile f : allJavaFiles) { if (f.getFileType() instanceof JavaFileType) { setClassIdentifiers(converter, f); } } final List<PsiFile> allJavaFilesNear = getAllJavaFiles(virtualFiles, project); CommandProcessor.getInstance().executeCommand(project, new Runnable() { @Override public void run() { final List<VirtualFile> newFiles = convertFiles(converter, allJavaFilesNear); if (finalRemoveIt) { deleteFiles(allJavaFilesNear); } else { renameFiles(allJavaFiles); } reformatFiles(newFiles, project); for (VirtualFile vf : newFiles) { FileEditorManager.getInstance(project).openFile(vf, true); } } }, "Convert files from Java to Kotlin", "group_id"); }
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()); }//w ww.j a v a2 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
@Override protected void doAction() { KotlinMoveTarget target = selectMoveTarget(); if (target == null) return;//w ww.j av a 2s . c o 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; } 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
@Override protected void doAction() { KotlinMoveTarget target = selectMoveTarget(); if (target == null) return;//from w w w. j av a2 s .c o 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); } }