[ui] creates desktop entry/launcher script in background (IDEA-187443)

This commit is contained in:
Roman Shevchenko
2018-03-07 17:06:18 +01:00
parent 265e8bdd46
commit 2922e896ec
2 changed files with 21 additions and 45 deletions
@@ -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 {
@@ -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);