mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
project structure dialog: hide irrelevant to current module libraries (e.g. JavaScript libraries in Java module) in 'Add Library to dependencies' chooser
This commit is contained in:
+8
-3
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.openapi.roots.ui.configuration.classpath;
|
||||
|
||||
import com.intellij.facet.impl.ProjectFacetsConfigurator;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
@@ -72,7 +73,7 @@ class AddLibraryDependencyAction extends AddItemPopupAction<Library> {
|
||||
}
|
||||
|
||||
private boolean hasLibraries() {
|
||||
final Predicate<Library> condition = LibraryEditingUtil.getNotAddedLibrariesCondition(myClasspathPanel.getRootModel());
|
||||
final Predicate<Library> condition = getNotAddedSuitableLibrariesCondition();
|
||||
for (LibraryTable table : ChooseLibrariesFromTablesDialog.getLibraryTables(myClasspathPanel.getProject(), true)) {
|
||||
final LibrariesModifiableModel model = myContext.myLevel2Providers.get(table.getTableLevel());
|
||||
if (model != null) {
|
||||
@@ -86,6 +87,11 @@ class AddLibraryDependencyAction extends AddItemPopupAction<Library> {
|
||||
return false;
|
||||
}
|
||||
|
||||
private Predicate<Library> getNotAddedSuitableLibrariesCondition() {
|
||||
ProjectFacetsConfigurator facetsConfigurator = myContext.getModulesConfigurator().getFacetsConfigurator();
|
||||
return LibraryEditingUtil.getNotAddedSuitableLibrariesCondition(myClasspathPanel.getRootModel(), facetsConfigurator);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected ClasspathTableItem<?> createTableItem(final Library item) {
|
||||
@@ -125,9 +131,8 @@ class AddLibraryDependencyAction extends AddItemPopupAction<Library> {
|
||||
@Override
|
||||
@NotNull
|
||||
public List<Library> chooseElements() {
|
||||
final Predicate<Library> condition = LibraryEditingUtil.getNotAddedLibrariesCondition(myClasspathPanel.getRootModel());
|
||||
ProjectStructureChooseLibrariesDialog dialog = new ProjectStructureChooseLibrariesDialog(myClasspathPanel, myContext,
|
||||
condition);
|
||||
getNotAddedSuitableLibrariesCondition());
|
||||
dialog.show();
|
||||
return dialog.getSelectedLibraries();
|
||||
}
|
||||
|
||||
+10
-2
@@ -28,6 +28,7 @@ import com.intellij.openapi.roots.impl.libraries.LibraryEx;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryImpl;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryTableImplUtil;
|
||||
import com.intellij.openapi.roots.libraries.*;
|
||||
import com.intellij.openapi.roots.ui.configuration.FacetsProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.classpath.ClasspathPanel;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesModifiableModel;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
|
||||
@@ -81,7 +82,7 @@ public class LibraryEditingUtil {
|
||||
return candidateName;
|
||||
}
|
||||
|
||||
public static Predicate<Library> getNotAddedLibrariesCondition(final ModuleRootModel rootModel) {
|
||||
public static Predicate<Library> getNotAddedSuitableLibrariesCondition(final ModuleRootModel rootModel, final FacetsProvider facetsProvider) {
|
||||
final OrderEntry[] orderEntries = rootModel.getOrderEntries();
|
||||
final Set<Library> result = new HashSet<Library>(orderEntries.length);
|
||||
for (OrderEntry orderEntry : orderEntries) {
|
||||
@@ -101,6 +102,13 @@ public class LibraryEditingUtil {
|
||||
final Library source = ((LibraryImpl)library).getSource();
|
||||
if (source != null && result.contains(source)) return false;
|
||||
}
|
||||
PersistentLibraryKind<?> kind = ((LibraryEx)library).getKind();
|
||||
if (kind != null) {
|
||||
LibraryType type = LibraryType.findByKind(kind);
|
||||
if (type != null && !type.isSuitableModule(rootModel.getModule(), facetsProvider)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -200,7 +208,7 @@ public class LibraryEditingUtil {
|
||||
|
||||
if (library != null) {
|
||||
final ModuleRootModel rootModel = rootConfigurable.getContext().getModulesConfigurator().getRootModel(module);
|
||||
if (!getNotAddedLibrariesCondition(rootModel).apply(library)) {
|
||||
if (!getNotAddedSuitableLibrariesCondition(rootModel, rootConfigurable.getFacetConfigurator()).apply(library)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user