mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IDEA-15100: Applying a dependency to multiple modules efficiently
This commit is contained in:
+14
-4
@@ -204,19 +204,29 @@ public class LibraryEditingUtil {
|
||||
};
|
||||
}
|
||||
|
||||
public static List<Module> getSuitableModules(@NotNull ModuleStructureConfigurable rootConfigurable, final @Nullable LibraryType type) {
|
||||
public static List<Module> getSuitableModules(@NotNull ModuleStructureConfigurable rootConfigurable,
|
||||
final @Nullable LibraryType type, @Nullable Library library) {
|
||||
final List<Module> modules = new ArrayList<Module>();
|
||||
for (Module module : rootConfigurable.getModules()) {
|
||||
if (type == null || type.isSuitableModule(module, rootConfigurable.getFacetConfigurator())) {
|
||||
modules.add(module);
|
||||
if (type != null && !type.isSuitableModule(module, rootConfigurable.getFacetConfigurator())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (library != null) {
|
||||
final ModuleRootModel rootModel = rootConfigurable.getContext().getModulesConfigurator().getRootModel(module);
|
||||
if (!getNotAddedLibrariesCondition(rootModel).apply(library)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
modules.add(module);
|
||||
}
|
||||
return modules;
|
||||
}
|
||||
|
||||
public static void showDialogAndAddLibraryToDependencies(@NotNull Library library, @NotNull Project project) {
|
||||
final ModuleStructureConfigurable moduleStructureConfigurable = ModuleStructureConfigurable.getInstance(project);
|
||||
final List<Module> modules = getSuitableModules(moduleStructureConfigurable, ((LibraryEx)library).getType());
|
||||
final List<Module> modules = getSuitableModules(moduleStructureConfigurable, ((LibraryEx)library).getType(), library);
|
||||
if (modules.isEmpty()) return;
|
||||
final ChooseModulesDialog
|
||||
dlg = new ChooseModulesDialog(moduleStructureConfigurable.getProject(), modules, ProjectBundle.message("choose.modules.dialog.title"),
|
||||
|
||||
+1
-1
@@ -131,7 +131,7 @@ public class CreateNewLibraryAction extends DumbAwareAction {
|
||||
if (librariesConfigurable instanceof ProjectLibrariesConfigurable) {
|
||||
final ModuleStructureConfigurable configurable = ModuleStructureConfigurable.getInstance(project);
|
||||
for (LibraryType<?> extension : extensions) {
|
||||
if (!LibraryEditingUtil.getSuitableModules(configurable, extension).isEmpty()) {
|
||||
if (!LibraryEditingUtil.getSuitableModules(configurable, extension, null).isEmpty()) {
|
||||
suitableTypes.add(extension);
|
||||
}
|
||||
}
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.
|
||||
*/
|
||||
package com.intellij.openapi.roots.ui.configuration.projectRoot;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryEditingUtil;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.LibraryProjectStructureElement;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class AddLibraryToModuleDependenciesAction extends DumbAwareAction {
|
||||
@NotNull private final Project myProject;
|
||||
@NotNull private final BaseLibrariesConfigurable myConfigurable;
|
||||
|
||||
public AddLibraryToModuleDependenciesAction(@NotNull Project project, @NotNull BaseLibrariesConfigurable configurable) {
|
||||
super("Add to Modules...", "Add the library to the dependencies list of chosen modules", null);
|
||||
myProject = project;
|
||||
myConfigurable = configurable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
final ProjectStructureElement element = myConfigurable.getSelectedElement();
|
||||
boolean visible = false;
|
||||
if (element instanceof LibraryProjectStructureElement) {
|
||||
final LibraryEx library = (LibraryEx)((LibraryProjectStructureElement)element).getLibrary();
|
||||
visible = !LibraryEditingUtil.getSuitableModules(ModuleStructureConfigurable.getInstance(myProject), library.getType(), library).isEmpty();
|
||||
}
|
||||
e.getPresentation().setVisible(visible);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final LibraryProjectStructureElement element = (LibraryProjectStructureElement)myConfigurable.getSelectedElement();
|
||||
if (element == null) return;
|
||||
final Library library = element.getLibrary();
|
||||
LibraryEditingUtil.showDialogAndAddLibraryToDependencies(library, myProject);
|
||||
}
|
||||
}
|
||||
+4
-3
@@ -186,10 +186,11 @@ public abstract class BaseLibrariesConfigurable extends BaseStructureConfigurabl
|
||||
@NotNull
|
||||
protected List<? extends AnAction> createCopyActions(boolean fromPopup) {
|
||||
final ArrayList<AnAction> actions = new ArrayList<AnAction>();
|
||||
actions.add(new MyCopyAction());
|
||||
actions.add(new CopyLibraryAction());
|
||||
if (fromPopup) {
|
||||
final BaseLibrariesConfigurable targetGroup = getOppositeGroup();
|
||||
actions.add(new ChangeLibraryLevelAction(myProject, myTree, this, targetGroup));
|
||||
actions.add(new AddLibraryToModuleDependenciesAction(myProject, this));
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
@@ -314,8 +315,8 @@ public abstract class BaseLibrariesConfigurable extends BaseStructureConfigurabl
|
||||
return "Select a library to view or edit its details here";
|
||||
}
|
||||
|
||||
private class MyCopyAction extends AnAction {
|
||||
private MyCopyAction() {
|
||||
private class CopyLibraryAction extends AnAction {
|
||||
private CopyLibraryAction() {
|
||||
super(CommonBundle.message("button.copy"), CommonBundle.message("button.copy"), COPY_ICON);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user