From 7693a01b70bc00871e6ca7cd4e5cfab260ab91cd Mon Sep 17 00:00:00 2001 From: Denis Zaichenko Date: Wed, 25 Jun 2025 16:05:26 +0200 Subject: [PATCH] IJPL-180572 Refactor: extract method GitOrigin-RevId: d264474c00d11690fd940b55012accbc6362298e --- .../ide/plugins/InstallFromDiskAction.java | 47 ++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/InstallFromDiskAction.java b/platform/platform-impl/src/com/intellij/ide/plugins/InstallFromDiskAction.java index 741b9b309c4e..405dc235c3f1 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/InstallFromDiskAction.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/InstallFromDiskAction.java @@ -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 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 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 callback) { + PluginInstaller.installFromDisk(tableModel, pluginEnabler, file, project, parentComponent, callback); } @RequiresEdt