mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IJPL-180572 Refactor: extract method
GitOrigin-RevId: d264474c00d11690fd940b55012accbc6362298e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
70035c9835
commit
7693a01b70
@@ -23,15 +23,17 @@ import javax.swing.*;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
class InstallFromDiskAction extends DumbAwareAction {
|
||||
public class InstallFromDiskAction extends DumbAwareAction {
|
||||
private static final String PLUGINS_PRESELECTION_PATH = "plugins.preselection.path";
|
||||
|
||||
private final @NotNull InstalledPluginsTableModel myTableModel;
|
||||
private final @NotNull PluginEnabler myPluginEnabler;
|
||||
private final @Nullable JComponent myParentComponent;
|
||||
|
||||
@SuppressWarnings({"unused", "ActionPresentationInstantiatedInCtor"}) // called reflectively
|
||||
@SuppressWarnings({"unused", "ActionPresentationInstantiatedInCtor"})
|
||||
// called reflectively
|
||||
InstallFromDiskAction() {
|
||||
this(new InstalledPluginsTableModel(null), PluginEnabler.HEADLESS, null);
|
||||
}
|
||||
@@ -65,15 +67,35 @@ class InstallFromDiskAction extends DumbAwareAction {
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
var project = e.getProject();
|
||||
var file = e.getData(CommonDataKeys.VIRTUAL_FILE);
|
||||
installPluginFromDisk(file, project, myTableModel, myPluginEnabler, myParentComponent, callbackData -> {
|
||||
onPluginInstalledFromDisk(callbackData, project);
|
||||
});
|
||||
}
|
||||
|
||||
public static void installPluginFromDisk(@Nullable VirtualFile fileToSelect,
|
||||
@Nullable Project project,
|
||||
@NotNull InstalledPluginsTableModel tableModel,
|
||||
@NotNull PluginEnabler pluginEnabler,
|
||||
@Nullable JComponent parentComponent,
|
||||
@NotNull Consumer<? super PluginInstallCallbackData> callback) {
|
||||
doInstall(fileToSelect, project, tableModel, pluginEnabler, parentComponent, callback);
|
||||
}
|
||||
|
||||
private static void doInstall(@Nullable VirtualFile fileToSelect,
|
||||
@Nullable Project project,
|
||||
@NotNull InstalledPluginsTableModel tableModel,
|
||||
@NotNull PluginEnabler pluginEnabler,
|
||||
@Nullable JComponent parentComponent,
|
||||
@NotNull Consumer<? super PluginInstallCallbackData> callback) {
|
||||
if (!PluginManagementPolicy.getInstance().isInstallFromDiskAllowed()) {
|
||||
var message = IdeBundle.message("action.InstallFromDiskAction.not.allowed.description");
|
||||
Messages.showErrorDialog(project, message, IdeBundle.message("action.InstallFromDiskAction.text"));
|
||||
return;
|
||||
}
|
||||
|
||||
var toSelect = e.getData(CommonDataKeys.VIRTUAL_FILE);
|
||||
if (toSelect == null || !toSelect.isInLocalFileSystem() || !hasValidExtension(toSelect)) {
|
||||
toSelect = getFileToSelect(PropertiesComponent.getInstance().getValue(PLUGINS_PRESELECTION_PATH));
|
||||
if (fileToSelect == null || !fileToSelect.isInLocalFileSystem() || !hasValidExtension(fileToSelect)) {
|
||||
fileToSelect = getFileToSelect(PropertiesComponent.getInstance().getValue(PLUGINS_PRESELECTION_PATH));
|
||||
}
|
||||
|
||||
var descriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor()
|
||||
@@ -81,10 +103,10 @@ class InstallFromDiskAction extends DumbAwareAction {
|
||||
.withDescription(IdeBundle.message("install.plugin.chooser.description"))
|
||||
.withExtensionFilter(IdeBundle.message("install.plugin.chooser.label"), "zip", "jar");
|
||||
|
||||
var chosenFile = FileChooser.chooseFile(descriptor, myParentComponent, project, toSelect);
|
||||
var chosenFile = FileChooser.chooseFile(descriptor, parentComponent, project, fileToSelect);
|
||||
if (chosenFile != null) {
|
||||
PropertiesComponent.getInstance().setValue(PLUGINS_PRESELECTION_PATH, chosenFile.getParent().getPath());
|
||||
installFromDisk(chosenFile.toNioPath(), project);
|
||||
installPluginFromDisk(chosenFile.toNioPath(), project, tableModel, pluginEnabler, parentComponent, callback);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,10 +116,13 @@ class InstallFromDiskAction extends DumbAwareAction {
|
||||
}
|
||||
|
||||
@RequiresEdt
|
||||
private void installFromDisk(Path file, @Nullable Project project) {
|
||||
PluginInstaller.installFromDisk(myTableModel, myPluginEnabler, file, project, myParentComponent, callbackData -> {
|
||||
onPluginInstalledFromDisk(callbackData, project);
|
||||
});
|
||||
private static void installPluginFromDisk(Path file,
|
||||
@Nullable Project project,
|
||||
@NotNull InstalledPluginsTableModel tableModel,
|
||||
@NotNull PluginEnabler pluginEnabler,
|
||||
@Nullable JComponent parentComponent,
|
||||
@NotNull Consumer<? super PluginInstallCallbackData> callback) {
|
||||
PluginInstaller.installFromDisk(tableModel, pluginEnabler, file, project, parentComponent, callback);
|
||||
}
|
||||
|
||||
@RequiresEdt
|
||||
|
||||
Reference in New Issue
Block a user