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:com.igormaznitsa.ideamindmap.editor.MindMapDialogProvider.java
License:Apache License
@Override public boolean msgConfirmYesNo(final String title, final String text) { return Messages.showYesNoDialog(this.project, text, title, Messages.getQuestionIcon()) == Messages.YES; }
From source file:com.intellij.application.options.codeStyle.ManageCodeStyleSchemesDialog.java
License:Apache License
@Nullable private String importExternalCodeStyle(String importerName) throws SchemeImportException { final SchemeImporter<CodeStyleScheme> importer = SchemeImporterEP.getImporter(importerName, CodeStyleScheme.class); if (importer != null) { FileChooserDialog fileChooser = FileChooserFactory.getInstance() .createFileChooser(new FileChooserDescriptor(true, false, false, false, false, false) { @Override/*from w w w . j a v a2 s .c o m*/ public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) { return file.isDirectory() || importer.getSourceExtension().equals(file.getExtension()); } @Override public boolean isFileSelectable(VirtualFile file) { return !file.isDirectory() && importer.getSourceExtension().equals(file.getExtension()); } }, null, myContentPane); VirtualFile[] selection = fileChooser.choose(null, CodeStyleSchemesUIConfiguration.Util.getRecentImportFile()); if (selection.length == 1) { VirtualFile selectedFile = selection[0]; selectedFile.refresh(false, false); CodeStyleSchemesUIConfiguration.Util.setRecentImportFile(selectedFile); try { InputStream nameInputStream = selectedFile.getInputStream(); String[] schemeNames; try { schemeNames = importer.readSchemeNames(nameInputStream); } finally { nameInputStream.close(); } CodeStyleScheme currScheme = myModel.getSelectedScheme(); ImportSchemeChooserDialog schemeChooserDialog = new ImportSchemeChooserDialog(myContentPane, schemeNames, !currScheme.isDefault() ? currScheme.getName() : null); if (schemeChooserDialog.showAndGet()) { String schemeName = schemeChooserDialog.getSelectedName(); String targetName = schemeChooserDialog.getTargetName(); CodeStyleScheme targetScheme = null; if (schemeChooserDialog.isUseCurrentScheme()) { targetScheme = myModel.getSelectedScheme(); } else { if (targetName == null) targetName = ApplicationBundle.message("code.style.scheme.import.unnamed"); for (CodeStyleScheme scheme : myModel.getSchemes()) { if (targetName.equals(scheme.getName())) { targetScheme = scheme; break; } } if (targetScheme == null) { int row = mySchemesTableModel.createNewScheme(getSelectedScheme(), targetName); mySchemesTable.getSelectionModel().setSelectionInterval(row, row); targetScheme = mySchemesTableModel.getSchemeAt(row); } else { int result = Messages.showYesNoDialog(myContentPane, ApplicationBundle.message("message.code.style.scheme.already.exists", targetName), ApplicationBundle.message("title.code.style.settings.import"), Messages.getQuestionIcon()); if (result != Messages.YES) { return null; } } } InputStream dataInputStream = selectedFile.getInputStream(); try { importer.importScheme(dataInputStream, schemeName, targetScheme); myModel.fireSchemeChanged(targetScheme); } finally { dataInputStream.close(); } return targetScheme.getName(); } } catch (IOException e) { throw new SchemeImportException(e); } } } return null; }
From source file:com.intellij.application.options.InitialConfigurationDialog.java
License:Apache License
@Override protected void doOKAction() { final Project project = CommonDataKeys.PROJECT .getData(DataManager.getInstance().getDataContext(myMainPanel)); super.doOKAction(); // set keymap ((KeymapManagerImpl) KeymapManager.getInstance()) .setActiveKeymap((Keymap) myKeymapComboBox.getSelectedItem()); // set color scheme EditorColorsManager.getInstance()/* ww w. j a v a 2s.c o m*/ .setGlobalScheme((EditorColorsScheme) myColorSchemeComboBox.getSelectedItem()); // create default todo_pattern for color scheme TodoConfiguration.getInstance().resetToDefaultTodoPatterns(); final boolean createScript = myCreateScriptCheckbox.isSelected(); final boolean createEntry = myCreateEntryCheckBox.isSelected(); if (createScript || createEntry) { final String pathName = myScriptPathTextField.getText(); final boolean globalEntry = myGlobalEntryCheckBox.isSelected(); ProgressManager.getInstance().run(new Task.Backgroundable(project, getTitle()) { @Override public void run(@NotNull final ProgressIndicator indicator) { indicator.setFraction(0.0); if (createScript) { indicator.setText("Creating launcher script..."); CreateLauncherScriptAction.createLauncherScript(project, pathName); indicator.setFraction(0.5); } if (createEntry) { CreateDesktopEntryAction.createDesktopEntry(project, indicator, globalEntry); } indicator.setFraction(1.0); } }); } UIManager.LookAndFeelInfo info = (UIManager.LookAndFeelInfo) myAppearanceComboBox.getSelectedItem(); LafManagerImpl lafManager = (LafManagerImpl) LafManager.getInstance(); if (info.getName().contains("Darcula") != (LafManager.getInstance() .getCurrentLookAndFeel() instanceof DarculaLookAndFeelInfo)) { lafManager.setLookAndFeelAfterRestart(info); int rc = Messages.showYesNoDialog(project, "IDE appearance settings will be applied after restart. Would you like to restart now?", "IDE Appearance", Messages.getQuestionIcon()); if (rc == Messages.YES) { ((ApplicationImpl) ApplicationManager.getApplication()).restart(true); } } else if (!info.equals(lafManager.getCurrentLookAndFeel())) { lafManager.setCurrentLookAndFeel(info); lafManager.updateUI(); } }
From source file:com.intellij.codeInsight.daemon.impl.quickfix.ModifierFix.java
License:Apache License
@Override public void invoke(@NotNull Project project, @NotNull PsiFile file, @Nullable("is null when called from inspection") Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { final PsiModifierList myModifierList = (PsiModifierList) startElement; final PsiVariable variable = myVariable == null ? null : myVariable.getElement(); if (!FileModificationService.getInstance().preparePsiElementForWrite(myModifierList)) return;// w ww .j av a 2 s .c om final List<PsiModifierList> modifierLists = new ArrayList<PsiModifierList>(); final PsiFile containingFile = myModifierList.getContainingFile(); final PsiModifierList modifierList; if (variable != null && variable.isValid()) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { try { variable.normalizeDeclaration(); } catch (IncorrectOperationException e) { LOG.error(e); } } }); modifierList = variable.getModifierList(); assert modifierList != null; } else { modifierList = myModifierList; } PsiElement owner = modifierList.getParent(); if (owner instanceof PsiMethod) { PsiModifierList copy = (PsiModifierList) myModifierList.copy(); changeModifierList(copy); final int accessLevel = PsiUtil.getAccessLevel(copy); OverridingMethodsSearch.search((PsiMethod) owner, owner.getResolveScope(), true) .forEach(new PsiElementProcessorAdapter<PsiMethod>(new PsiElementProcessor<PsiMethod>() { @Override public boolean execute(@NotNull PsiMethod inheritor) { PsiModifierList list = inheritor.getModifierList(); if (inheritor.getManager().isInProject(inheritor) && PsiUtil.getAccessLevel(list) < accessLevel) { modifierLists.add(list); } return true; } })); } if (!FileModificationService.getInstance().prepareFileForWrite(containingFile)) return; if (!modifierLists.isEmpty()) { if (Messages.showYesNoDialog(project, QuickFixBundle.message("change.inheritors.visibility.warning.text"), QuickFixBundle.message("change.inheritors.visibility.warning.title"), Messages.getQuestionIcon()) == DialogWrapper.OK_EXIT_CODE) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { if (!FileModificationService.getInstance().preparePsiElementsForWrite(modifierLists)) { return; } for (final PsiModifierList modifierList : modifierLists) { changeModifierList(modifierList); } } }); } } ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { changeModifierList(modifierList); UndoUtil.markPsiFileForUndo(containingFile); } }); }
From source file:com.intellij.codeInsight.generation.GenerateEqualsHandler.java
License:Apache License
@Override protected ClassMember[] chooseOriginalMembers(PsiClass aClass, Project project, Editor editor) { myEqualsFields = null;/*from w w w .java 2 s. c o m*/ myHashCodeFields = null; myNonNullFields = PsiField.EMPTY_ARRAY; GlobalSearchScope scope = aClass.getResolveScope(); final PsiMethod equalsMethod = GenerateEqualsHelper.findMethod(aClass, GenerateEqualsHelper.getEqualsSignature(project, scope)); final PsiMethod hashCodeMethod = GenerateEqualsHelper.findMethod(aClass, GenerateEqualsHelper.getHashCodeSignature()); boolean needEquals = equalsMethod == null; boolean needHashCode = hashCodeMethod == null; if (!needEquals && !needHashCode) { String text = aClass instanceof PsiAnonymousClass ? CodeInsightBundle.message("generate.equals.and.hashcode.already.defined.warning.anonymous") : CodeInsightBundle.message("generate.equals.and.hashcode.already.defined.warning", aClass.getQualifiedName()); if (Messages.showYesNoDialog(project, text, CodeInsightBundle.message("generate.equals.and.hashcode.already.defined.title"), Messages.getQuestionIcon()) == DialogWrapper.OK_EXIT_CODE) { if (!ApplicationManager.getApplication().runWriteAction(new Computable<Boolean>() { @Override 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; } } boolean hasNonStaticFields = false; for (PsiField field : aClass.getFields()) { if (!field.hasModifierProperty(PsiModifier.STATIC)) { hasNonStaticFields = true; break; } } if (!hasNonStaticFields) { HintManager.getInstance().showErrorHint(editor, "No fields to include in equals/hashCode have been found"); 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:com.intellij.conversion.impl.ConversionServiceImpl.java
License:Apache License
@Override @NotNull// ww w.j av a 2 s .c o m public ConversionResult convertModule(@NotNull final Project project, @NotNull final File moduleFile) { final IProjectStore stateStore = ((ProjectImpl) project).getStateStore(); final String url = stateStore.getPresentableUrl(); assert url != null : project; final String projectPath = FileUtil.toSystemDependentName(url); if (!isConversionNeeded(projectPath, moduleFile)) { return ConversionResultImpl.CONVERSION_NOT_NEEDED; } final int res = Messages.showYesNoDialog(project, IdeBundle.message("message.module.file.has.an.older.format.do.you.want.to.convert.it"), IdeBundle.message("dialog.title.convert.module"), Messages.getQuestionIcon()); if (res != Messages.YES) { return ConversionResultImpl.CONVERSION_CANCELED; } if (!moduleFile.canWrite()) { Messages.showErrorDialog(project, IdeBundle.message("error.message.cannot.modify.file.0", moduleFile.getAbsolutePath()), IdeBundle.message("dialog.title.convert.module")); return ConversionResultImpl.ERROR_OCCURRED; } try { ConversionContextImpl context = new ConversionContextImpl(projectPath); final List<ConversionRunner> runners = createConversionRunners(context, Collections.<String>emptySet()); final File backupFile = ProjectConversionUtil.backupFile(moduleFile); List<ConversionRunner> usedRunners = new ArrayList<ConversionRunner>(); for (ConversionRunner runner : runners) { if (runner.isModuleConversionNeeded(moduleFile)) { runner.convertModule(moduleFile); usedRunners.add(runner); } } context.saveFiles(Collections.singletonList(moduleFile), usedRunners); Messages.showInfoMessage(project, IdeBundle.message( "message.your.module.was.successfully.converted.br.old.version.was.saved.to.0", backupFile.getAbsolutePath()), IdeBundle.message("dialog.title.convert.module")); return new ConversionResultImpl(runners); } catch (CannotConvertException e) { LOG.info(e); Messages.showErrorDialog(IdeBundle.message("error.cannot.load.project", e.getMessage()), "Cannot Convert Module"); return ConversionResultImpl.ERROR_OCCURRED; } catch (IOException e) { LOG.info(e); return ConversionResultImpl.ERROR_OCCURRED; } }
From source file:com.intellij.conversion.impl.ui.ConvertProjectDialog.java
License:Apache License
@Override protected void doOKAction() { final List<File> nonexistentFiles = myContext.getNonExistingModuleFiles(); if (!nonexistentFiles.isEmpty() && !myNonExistingFilesMessageShown) { final String filesString = getFilesString(nonexistentFiles); final int res = Messages.showYesNoDialog(getContentPane(), IdeBundle.message( "message.files.doesn.t.exists.0.so.the.corresponding.modules.won.t.be.converted.do.you.want.to.continue", filesString), IdeBundle.message("dialog.title.convert.project"), Messages.getQuestionIcon()); if (res != 0) { super.doOKAction(); return; }//from ww w. j a v a 2 s . c om myNonExistingFilesMessageShown = false; } try { if (!checkReadOnlyFiles()) { return; } ProjectConversionUtil.backupFiles(myAffectedFiles, myContext.getProjectBaseDir(), myBackupDir); List<ConversionRunner> usedRunners = new ArrayList<ConversionRunner>(); for (ConversionRunner runner : myConversionRunners) { if (runner.isConversionNeeded()) { runner.preProcess(); runner.process(); runner.postProcess(); usedRunners.add(runner); } } myContext.saveFiles(myAffectedFiles, usedRunners); myConverted = true; super.doOKAction(); } catch (CannotConvertException e) { LOG.info(e); showErrorMessage(IdeBundle.message("error.cannot.convert.project", e.getMessage())); } catch (IOException e) { LOG.info(e); showErrorMessage(IdeBundle.message("error.cannot.convert.project", e.getMessage())); } }
From source file:com.intellij.debugger.engine.DebugProcessEvents.java
License:Apache License
private void processLocatableEvent(final SuspendContextImpl suspendContext, final LocatableEvent event) { if (myReturnValueWatcher != null && event instanceof MethodExitEvent) { if (myReturnValueWatcher.processMethodExitEvent(((MethodExitEvent) event))) { return; }/* w ww . jav a2 s . c om*/ } ThreadReference thread = event.thread(); //LOG.assertTrue(thread.isSuspended()); preprocessEvent(suspendContext, thread); //we use schedule to allow processing other events during processing this one //this is especially necessary if a method is breakpoint condition getManagerThread().schedule(new SuspendContextCommandImpl(suspendContext) { @Override public void contextAction() throws Exception { final SuspendManager suspendManager = getSuspendManager(); SuspendContextImpl evaluatingContext = SuspendManagerUtil.getEvaluatingContext(suspendManager, getSuspendContext().getThread()); if (evaluatingContext != null && !DebuggerSession.enableBreakpointsDuringEvaluation()) { // is inside evaluation, so ignore any breakpoints suspendManager.voteResume(suspendContext); return; } final LocatableEventRequestor requestor = (LocatableEventRequestor) getRequestsManager() .findRequestor(event.request()); boolean resumePreferred = requestor != null && DebuggerSettings.SUSPEND_NONE.equals(requestor.getSuspendPolicy()); boolean requestHit; try { requestHit = (requestor != null) && requestor.processLocatableEvent(this, event); } catch (final LocatableEventRequestor.EventProcessingException ex) { if (LOG.isDebugEnabled()) { LOG.debug(ex.getMessage()); } final boolean[] considerRequestHit = new boolean[] { true }; DebuggerInvocationUtil.invokeAndWait(getProject(), new Runnable() { @Override public void run() { DebuggerPanelsManager.getInstance(getProject()).toFront(mySession); final String displayName = requestor instanceof Breakpoint ? ((Breakpoint) requestor).getDisplayName() : requestor.getClass().getSimpleName(); final String message = DebuggerBundle.message( "error.evaluating.breakpoint.condition.or.action", displayName, ex.getMessage()); considerRequestHit[0] = Messages.showYesNoDialog(getProject(), message, ex.getTitle(), Messages.getQuestionIcon()) == Messages.YES; } }, ModalityState.NON_MODAL); requestHit = considerRequestHit[0]; resumePreferred = !requestHit; } if (requestHit && requestor instanceof Breakpoint) { // if requestor is a breakpoint and this breakpoint was hit, no matter its suspend policy ApplicationManager.getApplication().runReadAction(new Runnable() { @Override public void run() { XDebugSession session = getSession().getXDebugSession(); if (session != null) { XBreakpoint breakpoint = ((Breakpoint) requestor).getXBreakpoint(); if (breakpoint != null) { ((XDebugSessionImpl) session).processDependencies(breakpoint); } } } }); } if (!requestHit || resumePreferred) { suspendManager.voteResume(suspendContext); } else { if (myReturnValueWatcher != null) { myReturnValueWatcher.disable(); } //if (suspendContext.getSuspendPolicy() == EventRequest.SUSPEND_ALL) { // // there could be explicit resume as a result of call to voteSuspend() // // e.g. when breakpoint was considered invalid, in that case the filter will be applied _after_ // // resuming and all breakpoints in other threads will be ignored. // // As resume() implicitly cleares the filter, the filter must be always applied _before_ any resume() action happens // myBreakpointManager.applyThreadFilter(DebugProcessEvents.this, event.thread()); //} suspendManager.voteSuspend(suspendContext); showStatusText(DebugProcessEvents.this, event); } } }); }
From source file:com.intellij.debugger.ui.ExportDialog.java
License:Apache License
protected void doOKAction() { String path = myTfFilePath.getText(); File file = new File(path); if (file.isDirectory()) { Messages.showMessageDialog(myProject, DebuggerBundle.message("error.threads.export.dialog.file.is.directory"), DebuggerBundle.message("threads.export.dialog.title"), Messages.getErrorIcon()); } else if (file.exists()) { int answer = Messages.showYesNoDialog(myProject, DebuggerBundle.message("error.threads.export.dialog.file.already.exists", path), DebuggerBundle.message("threads.export.dialog.title"), Messages.getQuestionIcon()); if (answer == 0) { super.doOKAction(); }//from www .j av a 2 s . c o m } else { super.doOKAction(); } }
From source file:com.intellij.diagnostic.ITNReporter2.java
License:Apache License
private static int showYesNoDialog(Component parentComponent, Project project, String message, String title, Icon icon) {//from w w w . j ava 2s . co m if (parentComponent.isShowing()) { return Messages.showYesNoDialog(parentComponent, message, title, icon); } else { return Messages.showYesNoDialog(project, message, title, icon); } }