From 2922e896ec2a9449206da739bb734c406acf2320 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 7 Mar 2018 17:05:55 +0100 Subject: [PATCH] [ui] creates desktop entry/launcher script in background (IDEA-187443) --- .../ide/actions/CreateDesktopEntryAction.java | 27 +++---------- .../actions/CreateLauncherScriptAction.java | 39 ++++++++----------- 2 files changed, 21 insertions(+), 45 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/actions/CreateDesktopEntryAction.java b/platform/platform-impl/src/com/intellij/ide/actions/CreateDesktopEntryAction.java index f0c54d93f88c..cd1f87cf1559 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/CreateDesktopEntryAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/CreateDesktopEntryAction.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.actions; import com.intellij.execution.ExecutionException; @@ -28,7 +14,6 @@ import com.intellij.openapi.application.ApplicationNamesInfo; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; @@ -95,16 +80,14 @@ public class CreateDesktopEntryAction extends DumbAwareAction { return; } - final boolean globalEntry = dialog.myGlobalEntryCheckBox.isSelected(); - ProgressManager.getInstance().run(new Task.Backgroundable(project, ApplicationBundle.message("desktop.entry.title")) { + boolean globalEntry = dialog.myGlobalEntryCheckBox.isSelected(); + new Task.Backgroundable(project, ApplicationBundle.message("desktop.entry.title")) { @Override public void run(@NotNull ProgressIndicator indicator) { try { - indicator.setIndeterminate(true); - createDesktopEntry(globalEntry); - final String message = ApplicationBundle.message("desktop.entry.success", ApplicationNamesInfo.getInstance().getProductName()); + String message = ApplicationBundle.message("desktop.entry.success", ApplicationNamesInfo.getInstance().getProductName()); Notifications.Bus.notify( new Notification(Notifications.SYSTEM_MESSAGES_GROUP_ID, "Desktop Entry Created", message, NotificationType.INFORMATION), getProject()); @@ -113,7 +96,7 @@ public class CreateDesktopEntryAction extends DumbAwareAction { reportFailure(e, getProject()); } } - }); + }.queue(); } public static void createDesktopEntry(boolean globalEntry) throws Exception { diff --git a/platform/platform-impl/src/com/intellij/ide/actions/CreateLauncherScriptAction.java b/platform/platform-impl/src/com/intellij/ide/actions/CreateLauncherScriptAction.java index 3a90552a5353..3094e929b87a 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/CreateLauncherScriptAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/CreateLauncherScriptAction.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.actions; import com.intellij.execution.ExecutionException; @@ -25,6 +11,8 @@ import com.intellij.notification.Notifications; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.application.*; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; @@ -96,12 +84,17 @@ public class CreateLauncherScriptAction extends DumbAwareAction { } } - try { - createLauncherScript(target.getAbsolutePath()); - } - catch (Exception e) { - reportFailure(e, project); - } + new Task.Backgroundable(project, ApplicationBundle.message("launcher.script.title")) { + @Override + public void run(@NotNull ProgressIndicator indicator) { + try { + createLauncherScript(target.getAbsolutePath()); + } + catch (Exception e) { + reportFailure(e, project); + } + } + }.queue(); } public static void createLauncherScript(@NotNull String pathName) throws Exception { @@ -140,9 +133,9 @@ public class CreateLauncherScriptAction extends DumbAwareAction { } } - public static void reportFailure(@NotNull Exception e, @Nullable final Project project) { + public static void reportFailure(@NotNull Exception e, @Nullable Project project) { LOG.warn(e); - final String message = ExceptionUtil.getNonEmptyMessage(e, "Internal error"); + String message = ExceptionUtil.getNonEmptyMessage(e, "Internal error"); Notifications.Bus.notify( new Notification(Notifications.SYSTEM_MESSAGES_GROUP_ID, "Launcher Script Creation Failed", message, NotificationType.ERROR), project);