List of usage examples for com.intellij.openapi.ui Messages showYesNoDialog
@YesNoResult public static int showYesNoDialog(String message, @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title, @NotNull String yesText, @NotNull String noText, @Nullable Icon icon, @Nullable DialogWrapper.DoNotAskOption doNotAskOption)
From source file:com.android.tools.idea.fd.actions.SubmitFeedback.java
License:Apache License
@Override public void actionPerformed(AnActionEvent e) { Project project = e.getProject();/*from w w w . j a v a 2 s . c o m*/ if (project == null) { Logger.getInstance(SubmitFeedback.class).info("Unable to identify current project"); return; } if (!InstantRunSettings.isInstantRunEnabled() || !InstantRunSettings.isRecorderEnabled()) { int result = Messages.showYesNoDialog(project, AndroidBundle.message("instant.run.flr.would.you.like.to.enable"), AndroidBundle.message("instant.run.flr.dialog.title"), "Yes, I'd like to help", "Cancel", Messages.getQuestionIcon()); if (result == Messages.NO) { return; } InstantRunSettings.setInstantRunEnabled(true); InstantRunSettings.setRecorderEnabled(true); Messages.showInfoMessage(project, AndroidBundle.message("instant.run.flr.howto"), AndroidBundle.message("instant.run.flr.dialog.title")); return; } InstantRunFeedbackDialog dialog = new InstantRunFeedbackDialog(project); boolean ok = dialog.showAndGet(); if (ok) { new Task.Backgroundable(project, "Submitting Instant Run Issue") { public CompletableFuture<String> myReport; @Override public void run(@NotNull ProgressIndicator indicator) { myReport = GoogleCrash.getInstance().submit(FlightRecorder.get(project), dialog.getIssueText(), dialog.getLogs()); while (!myReport.isDone()) { try { myReport.get(200, TimeUnit.MILLISECONDS); } catch (Exception ignored) { } if (indicator.isCanceled()) { return; } } } @Override public void onSuccess() { if (myReport.isDone()) { String reportId; try { reportId = myReport.getNow("00"); } catch (CancellationException e) { Logger.getInstance(SubmitFeedback.class) .info("Submission of flight recorder logs cancelled"); return; } catch (CompletionException e) { FLR_NOTIFICATION_GROUP.createNotification( "Unexpected error while submitting instant run logs: " + e.getMessage(), NotificationType.ERROR); Logger.getInstance(SubmitFeedback.class).info(e); return; } String message = String.format("<html>Thank you for submitting the bug report.<br>" + "If you would like to follow up on this report, please file a bug at <a href=\"bug\">b.android.com</a> and specify the report id '%1$s'<html>", reportId); FLR_NOTIFICATION_GROUP.createNotification("", message, NotificationType.INFORMATION, (notification, event) -> { Escaper escaper = UrlEscapers.urlFormParameterEscaper(); String comment = String.format("Build: %1$s\nInstant Run Report: %2$s", ApplicationInfo.getInstance().getFullVersion(), reportId); String url = String.format( "https://code.google.com/p/android/issues/entry?template=%1$s&comment=%2$s&status=New", escaper.escape("Android Studio Instant Run Bug"), escaper.escape(comment)); BrowserUtil.browse(url); }).notify(project); } } }.queue(); } }
From source file:com.android.tools.idea.run.AndroidRunConfigurationBase.java
License:Apache License
@Override public RunProfileState getState(@NotNull final Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException { validateBeforeRun(executor);/*from w ww.j a v a 2 s . c o m*/ final Module module = getConfigurationModule().getModule(); assert module != null : "Enforced by fatal validation check in checkConfiguration."; final AndroidFacet facet = AndroidFacet.getInstance(module); assert facet != null : "Enforced by fatal validation check in checkConfiguration."; Project project = env.getProject(); boolean forceColdswap = !InstantRunUtils.isInvokedViaHotswapAction(env); boolean couldHaveHotswapped = false; boolean debug = false; if (executor instanceof DefaultDebugExecutor) { if (!AndroidSdkUtils.activateDdmsIfNecessary(facet.getModule().getProject())) { throw new ExecutionException( "Unable to obtain debug bridge. Please check if there is a different tool using adb that is active."); } debug = true; } DeviceFutures deviceFutures = null; AndroidSessionInfo info = AndroidSessionInfo.findOldSession(project, null, getUniqueID()); // note: we look for this run config with any executor if (info != null && supportsInstantRun()) { // if there is an existing previous session, then see if we can detect devices to fast deploy to deviceFutures = getFastDeployDevices(executor, facet, info); // HACK: We also need to support re-run // In the case of re-run, we need to pick the devices from the previous run, but then terminate the app. // This call to destroyProcess doesn't really belong here in the overall flow, but everything else in the flow just fits // without any changes if we can recover the device first and then terminate the process. The alternative would be for // the ReRun action itself to pass in the device just like it happens for the restart device, but that has the complication // that the ReRun is now a global action and doesn't really know much details about each run (and doing that seems like a hack too.) if (InstantRunUtils.isReRun(env)) { killSession(info); info = null; } } if (info != null && deviceFutures == null) { // If we should not be fast deploying, but there is an existing session, then terminate those sessions. Otherwise, we might end up // with 2 active sessions of the same launch, especially if we first think we can do a fast deploy, then end up doing a full launch boolean continueLaunch = promptAndKillSession(executor, project, info); if (!continueLaunch) { return null; } } else if (info != null && forceColdswap) { // the user could have invoked the hotswap action in this scenario, but they chose to force a coldswap (by pressing run) couldHaveHotswapped = true; // forcibly kill app in case of run action (which forces a cold swap) // normally, installing the apk will force kill the app, but we need to forcibly kill it in the case that there were no changes killSession(info); } // If we are not fast deploying, then figure out (prompting user if needed) where to deploy if (deviceFutures == null) { DeployTarget deployTarget = getDeployTarget(executor, env, debug, facet); if (deployTarget == null) { return null; } DeployTargetState deployTargetState = getDeployTargetContext().getCurrentDeployTargetState(); if (deployTarget.hasCustomRunProfileState(executor)) { return deployTarget.getRunProfileState(executor, env, deployTargetState); } deviceFutures = deployTarget.getDevices(deployTargetState, facet, getDeviceCount(debug), debug, getUniqueID()); if (deviceFutures == null) { // The user deliberately canceled, or some error was encountered and exposed by the chooser. Quietly exit. return null; } } if (deviceFutures.get().isEmpty()) { throw new ExecutionException(AndroidBundle.message("deployment.target.not.found")); } ApplicationIdProvider applicationIdProvider = getApplicationIdProvider(facet); InstantRunContext instantRunContext = null; if (supportsInstantRun() && InstantRunSettings.isInstantRunEnabled()) { InstantRunGradleSupport gradleSupport = canInstantRun(module, deviceFutures.getDevices()); if (gradleSupport == TARGET_PLATFORM_NOT_INSTALLED) { AndroidVersion version = deviceFutures.getDevices().get(0).getVersion(); String message = AndroidBundle.message("instant.run.quickfix.missing.platform", SdkVersionInfo.getVersionWithCodename(version)); int result = Messages.showYesNoDialog(project, message, "Instant Run", "Install and Continue", // yes button "Proceed without Instant Run", // no button Messages.getQuestionIcon()); if (result == Messages.OK) { // if ok, install platform and continue with instant run ModelWizardDialog dialog = SdkQuickfixUtils.createDialogForPaths(project, ImmutableList.of(DetailsTypes.getPlatformPath(version))); if (dialog == null) { LOG.warn( "Unable to get quick fix wizard to install missing platform required for instant run."); } else if (dialog.showAndGet()) { gradleSupport = SUPPORTED; } } } if (gradleSupport == SUPPORTED) { if (!AndroidEnableAdbServiceAction.isAdbServiceEnabled()) { throw new ExecutionException( "Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled."); } InstantRunUtils.setInstantRunEnabled(env, true); instantRunContext = InstantRunGradleUtils.createGradleProjectContext(facet); } else { InstantRunManager.LOG .warn("Instant Run enabled, but not doing an instant run build since: " + gradleSupport); String notificationText = gradleSupport.getUserNotification(); if (notificationText != null) { InstantRunNotificationTask.showNotification(env.getProject(), null, notificationText); } } } else { String msg = "Not using instant run for this launch: "; if (InstantRunSettings.isInstantRunEnabled()) { msg += getType().getDisplayName() + " does not support instant run"; } else { msg += "instant run is disabled"; } InstantRunManager.LOG.info(msg); } // Store the chosen target on the execution environment so before-run tasks can access it. AndroidRunConfigContext runConfigContext = new AndroidRunConfigContext(); env.putCopyableUserData(AndroidRunConfigContext.KEY, runConfigContext); runConfigContext.setTargetDevices(deviceFutures); runConfigContext .setSameExecutorAsPreviousSession(info != null && executor.getId().equals(info.getExecutorId())); runConfigContext.setCleanRerun(InstantRunUtils.isCleanReRun(env)); runConfigContext.setForceColdSwap(forceColdswap, couldHaveHotswapped); // Save the instant run context so that before-run task can access it env.putCopyableUserData(InstantRunContext.KEY, instantRunContext); if (debug) { String error = canDebug(deviceFutures, facet, module.getName()); if (error != null) { throw new ExecutionException(error); } } LaunchOptions launchOptions = getLaunchOptions().setDebug(debug).build(); ProcessHandler processHandler = null; if (info != null && info.getExecutorId().equals(executor.getId())) { processHandler = info.getProcessHandler(); } ApkProvider apkProvider = getApkProvider(facet, applicationIdProvider); LaunchTasksProviderFactory providerFactory = new AndroidLaunchTasksProviderFactory(this, env, facet, applicationIdProvider, apkProvider, deviceFutures, launchOptions, processHandler, instantRunContext); InstantRunStatsService.get(project).notifyBuildStarted(); return new AndroidRunState(env, getName(), module, applicationIdProvider, getConsoleProvider(), deviceFutures, providerFactory, processHandler); }
From source file:com.android.tools.idea.welcome.install.InstallOperation.java
License:Apache License
/** * Shows a retry prompt. Throws an exception to stop the setup process if the user preses cancel or returns normally otherwise. *///from w ww . j a v a 2 s . c om protected final void promptToRetry(@NotNull final String prompt, @NotNull String failureDescription, @Nullable Exception e) throws WizardException { final AtomicBoolean response = new AtomicBoolean(false); Application application = ApplicationManager.getApplication(); application.invokeAndWait(new Runnable() { @Override public void run() { int i = Messages.showYesNoDialog(null, prompt, "Android Studio Setup", "Retry", "Cancel", Messages.getErrorIcon()); response.set(i == Messages.YES); } }, application.getAnyModalityState()); if (!response.get()) { Throwables.propagateIfInstanceOf(e, WizardException.class); throw new WizardException(failureDescription, e); } else { myContext.print(failureDescription + "\n", ConsoleViewContentType.ERROR_OUTPUT); } }
From source file:com.intellij.execution.ProgramRunnerUtil.java
License:Apache License
public static void executeConfiguration(@NotNull ExecutionEnvironment environment, boolean showSettings, boolean assignNewId) { if (ExecutorRegistry.getInstance().isStarting(environment)) { return;//from w w w . j a v a 2s.c o m } RunnerAndConfigurationSettings runnerAndConfigurationSettings = environment .getRunnerAndConfigurationSettings(); if (runnerAndConfigurationSettings != null) { if (!ExecutionTargetManager.canRun(environment)) { ExecutionUtil.handleExecutionError(environment, new ExecutionException( StringUtil.escapeXml("Cannot run '" + environment.getRunProfile().getName() + "' on '" + environment.getExecutionTarget().getDisplayName() + "'"))); return; } if (!RunManagerImpl.canRunConfiguration(environment) || (showSettings && runnerAndConfigurationSettings.isEditBeforeRun())) { if (!RunDialog.editConfiguration(environment, "Edit configuration")) { return; } while (!RunManagerImpl.canRunConfiguration(environment)) { if (Messages.YES == Messages.showYesNoDialog(environment.getProject(), "Configuration is still incorrect. Do you want to edit it again?", "Change Configuration Settings", "Edit", "Continue Anyway", Messages.getErrorIcon())) { if (!RunDialog.editConfiguration(environment, "Edit configuration")) { return; } } else { break; } } } ConfigurationType configurationType = runnerAndConfigurationSettings.getType(); if (configurationType != null) { UsageTrigger.trigger("execute." + ConvertUsagesUtil.ensureProperKey(configurationType.getId()) + "." + environment.getExecutor().getId()); } } try { if (assignNewId) { environment.assignNewExecutionId(); } environment.getRunner().execute(environment); } catch (ExecutionException e) { String name = runnerAndConfigurationSettings != null ? runnerAndConfigurationSettings.getName() : null; if (name == null) { name = environment.getRunProfile().getName(); } if (name == null && environment.getContentToReuse() != null) { name = environment.getContentToReuse().getDisplayName(); } if (name == null) { name = "<Unknown>"; } ExecutionUtil.handleExecutionError(environment.getProject(), environment.getExecutor().getToolWindowId(), name, e); } }
From source file:com.intellij.ide.impl.ProjectUtil.java
License:Apache License
/** * @return {@link com.intellij.ide.GeneralSettings#OPEN_PROJECT_SAME_WINDOW} * {@link com.intellij.ide.GeneralSettings#OPEN_PROJECT_NEW_WINDOW} * {@link com.intellij.openapi.ui.Messages#CANCEL} - if user canceled the dialog * @param isNewProject/*ww w . ja v a 2 s .co m*/ */ public static int confirmOpenNewProject(boolean isNewProject) { final GeneralSettings settings = GeneralSettings.getInstance(); int confirmOpenNewProject = settings.getConfirmOpenNewProject(); if (confirmOpenNewProject == GeneralSettings.OPEN_PROJECT_ASK) { if (isNewProject) { int exitCode = Messages.showYesNoDialog(IdeBundle.message("prompt.open.project.in.new.frame"), IdeBundle.message("title.new.project"), IdeBundle.message("button.existingframe"), IdeBundle.message("button.newframe"), Messages.getQuestionIcon(), new ProjectNewWindowDoNotAskOption()); return exitCode == 0 ? GeneralSettings.OPEN_PROJECT_SAME_WINDOW : GeneralSettings.OPEN_PROJECT_NEW_WINDOW; } else { int exitCode = Messages.showYesNoCancelDialog(IdeBundle.message("prompt.open.project.in.new.frame"), IdeBundle.message("title.open.project"), IdeBundle.message("button.existingframe"), IdeBundle.message("button.newframe"), CommonBundle.getCancelButtonText(), Messages.getQuestionIcon(), new ProjectNewWindowDoNotAskOption()); return exitCode == 0 ? GeneralSettings.OPEN_PROJECT_SAME_WINDOW : exitCode == 1 ? GeneralSettings.OPEN_PROJECT_NEW_WINDOW : Messages.CANCEL; } } return confirmOpenNewProject; }
From source file:com.intellij.refactoring.rename.inplace.InplaceRefactoring.java
License:Apache License
public static void unableToStartWarning(Project project, Editor editor) { final StartMarkAction startMarkAction = StartMarkAction.canStart(project); final String message = startMarkAction.getCommandName() + " is not finished yet."; final Document oldDocument = startMarkAction.getDocument(); if (editor == null || oldDocument != editor.getDocument()) { final int exitCode = Messages.showYesNoDialog(project, message, RefactoringBundle.getCannotRefactorMessage(null), "Continue Started", "Cancel Started", Messages.getErrorIcon()); navigateToStarted(oldDocument, project, exitCode); } else {// w w w.j av a 2s.c o m CommonRefactoringUtil.showErrorHint(project, editor, message, RefactoringBundle.getCannotRefactorMessage(null), null); } }
From source file:com.microsoft.alm.plugin.idea.common.utils.IdeaHelper.java
License:Open Source License
/** * Shows a dialog with OK and cancel actions to prompt for confirmation from user * * @return true if user clicks on ok action and false if user clicks on cancel action *//* w ww . ja v a 2 s .c o m*/ public static boolean showConfirmationDialog(@NotNull final Project project, final String message, final String title, final Icon logo, final String okActionMessage, final String cancelActionMessage) { final int result = Messages.showYesNoDialog(project, message, title, okActionMessage, cancelActionMessage, logo); return result == 0 ? true : false; }
From source file:com.microsoft.intellij.ui.JdkServerPanel.java
License:Open Source License
private boolean showAcceptDialog(String name, String url) { StringBuilder sb = new StringBuilder("<html>").append(String.format(message("aggMsg"), name)); sb.append(String.format(message("aggLnk"), url, url)).append("</html>"); return Messages.showYesNoDialog(project, sb.toString(), message("aggTtl"), message("acptBtn"), "Cancel", null) == Messages.YES;//from w ww . jav a 2 s . c om }
From source file:com.microsoftopentechnologies.intellij.ui.JdkServerPanel.java
License:Apache License
public boolean createAccLicenseAggDlg() { String jdkName = (String) thirdPartyJdkName.getSelectedItem(); StringBuilder sb = new StringBuilder("<html>").append(String.format(message("aggMsg"), jdkName)); String url = ""; try {/*w w w. jav a 2s. co m*/ url = WindowsAzureProjectManager.getLicenseUrl(jdkName, AzurePlugin.cmpntFile); } catch (WindowsAzureInvalidProjectOperationException e) { log(e.getMessage(), e); } sb.append(String.format(message("aggLnk"), url, url)).append("</html>"); return Messages.showYesNoDialog(project, sb.toString(), message("aggTtl"), message("acptBtn"), "Cancel", null) == Messages.YES; }
From source file:net.andydvorak.intellij.lessc.ui.configurable.VfsLocationChangeDialog.java
License:Apache License
public synchronized boolean shouldMoveCssFile(final VirtualFileEvent virtualFileEvent) { DialogWrapper.DoNotAskOption option = new DialogWrapper.DoNotAskOption() { @Override//from ww w. j av a 2s . c om public boolean isToBeShown() { return myLessProjectState.isPromptOnMove(); } @Override public void setToBeShown(boolean value, int exitCode) { myLessProjectState.setPromptOnMove(value); } @Override public boolean canBeHidden() { return true; } @Override public boolean shouldSaveOptionsOnCancel() { return true; } @Override public String getDoNotShowMessage() { return UIBundle.message("do.not.ask.me.again"); } }; if (option.isToBeShown()) { if (System.currentTimeMillis() - lastPrompt > promptIntervalMillis) { result = Messages.showYesNoDialog( UIBundle.message("vfs.move.message", virtualFileEvent.getFileName()), UIBundle.message("vfs.move.title"), // Title UIBundle.message("vfs.move.yes"), // "Yes" button text UIBundle.message("vfs.move.no"), // "No" button text Messages.getQuestionIcon(), option); } } else { result = myLessProjectState.isMoveCssFiles() ? DialogWrapper.OK_EXIT_CODE : DialogWrapper.CANCEL_EXIT_CODE; } lastPrompt = System.currentTimeMillis(); final boolean shouldMove = result == DialogWrapper.OK_EXIT_CODE; myLessProjectState.setMoveCssFiles(shouldMove); return shouldMove; }