suggest to add a library only to allowed modules

This commit is contained in:
nik
2010-11-16 14:15:00 +03:00
parent e21a30ced4
commit 502b439724
3 changed files with 10 additions and 4 deletions
@@ -116,7 +116,7 @@ class AddNewLibraryItemAction extends ChooseAndAddAction<Library> {
suitableTypes.add(null);
final ModuleType moduleType = classpathPanel.getRootModel().getModule().getModuleType();
for (LibraryType libraryType : LibraryType.EP_NAME.getExtensions()) {
if (libraryType.isSuitableForModuleType(moduleType)) {
if (libraryType.isSuitableModuleType(moduleType)) {
suitableTypes.add(libraryType);
}
}
@@ -31,7 +31,6 @@ import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesModifiab
import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
import com.intellij.openapi.ui.MasterDetailsComponent;
import com.intellij.util.Icons;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -79,7 +78,11 @@ public class CreateNewLibraryAction extends AnAction {
private void appendLibraryToModules(final ModuleStructureConfigurable rootConfigurable, final Library libraryToSelect) {
final List<Module> modules = new ArrayList<Module>();
ContainerUtil.addAll(modules, rootConfigurable.getModules());
for (Module module : rootConfigurable.getModules()) {
if (myType == null || myType.isSuitableModuleType(module.getModuleType())) {
modules.add(module);
}
}
if (modules.isEmpty()) return;
final ChooseModulesDialog dlg = new ChooseModulesDialog(myProject,
modules, ProjectBundle.message("choose.modules.dialog.title"),
@@ -51,7 +51,10 @@ public abstract class LibraryType<P extends LibraryProperties> extends LibraryPr
@NotNull
public abstract P createDefaultProperties();
public boolean isSuitableForModuleType(@NotNull ModuleType moduleType) {
/**
* @return {@code true} if library of this type can be added as a dependency to a module of type {@code moduleType}
*/
public boolean isSuitableModuleType(@NotNull ModuleType moduleType) {
return true;
}