Another fix for JS library scope UI [r=K.Safonov]

This commit is contained in:
Rustam.Vishnyakov
2011-02-04 14:57:22 +03:00
parent 6e630ff2be
commit 765f7ee7ed
2 changed files with 40 additions and 7 deletions
@@ -51,11 +51,15 @@ public class ScriptingLibraryMappings extends LanguagePerFileMappings<ScriptingL
public ScriptingLibraryMappings(final Project project, final LibraryType libraryType) {
super(project);
myLibraryManager = new ScriptingLibraryManager(project, libraryType);
registerLibraryTableListener(this, this);
Disposer.register(project, this);
}
public void registerLibraryTableListener(LibraryTable.Listener listener, Disposable parentDisposable) {
if (myLibraryManager.ensureModel()) {
LibraryTable libTable = myLibraryManager.getLibraryTable();
if (libTable != null) libTable.addListener(this, this);
if (libTable != null) libTable.addListener(listener, parentDisposable);
}
Disposer.register(project, this);
}
protected String serialize(final ScriptingLibraryTable.LibraryModel library) {
@@ -91,7 +95,6 @@ public class ScriptingLibraryMappings extends LanguagePerFileMappings<ScriptingL
newContainer.addLibrary(libraryModel);
}
}
newContainer.applyChanges();
setMapping(file, newContainer.isEmpty() ? null : newContainer);
if (!newContainer.isEmpty()) {
if (file == null) {
@@ -182,7 +185,7 @@ public class ScriptingLibraryMappings extends LanguagePerFileMappings<ScriptingL
container = new CompoundLibrary();
}
if (!((CompoundLibrary)container).containsLibrary(libName)) {
((CompoundLibrary)container).toggleLibrary(libraryModel);
((CompoundLibrary)container).addLibrary(libraryModel);
setMapping(file, container);
}
updateDependencies(getMappings());
@@ -210,10 +213,9 @@ public class ScriptingLibraryMappings extends LanguagePerFileMappings<ScriptingL
for (String libName : libNames) {
ScriptingLibraryTable.LibraryModel libraryModel = myLibraryManager.getLibraryByName(libName.trim());
if (libraryModel != null) {
compoundLib.toggleLibrary(libraryModel);
compoundLib.addLibrary(libraryModel);
}
}
compoundLib.applyChanges();
if (file == null) {
myProjectLibs = compoundLib;
}
@@ -331,6 +333,7 @@ public class ScriptingLibraryMappings extends LanguagePerFileMappings<ScriptingL
private void addLibrary(@NotNull ScriptingLibraryTable.LibraryModel library) {
final String libName = library.getName();
myLibraries.put(libName, library);
applyChanges();
}
public boolean containsLibrary(String libName) {
@@ -18,9 +18,13 @@ package com.intellij.ide.scriptingContext.ui;
import com.intellij.ide.IdeBundle;
import com.intellij.ide.scriptingContext.LangScriptingContextConfigurable;
import com.intellij.ide.scriptingContext.ScriptingLibraryMappings;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.libraries.scripting.ScriptingLibraryTable;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ui.tree.LanguagePerFileConfigurable;
@@ -33,7 +37,9 @@ import java.util.Map;
/**
* @author Rustam Vishnyakov
*/
public class ScriptingContextsConfigurable extends LanguagePerFileConfigurable<ScriptingLibraryTable.LibraryModel> {
public class ScriptingContextsConfigurable extends LanguagePerFileConfigurable<ScriptingLibraryTable.LibraryModel>
implements LibraryTable.Listener,
Disposable {
private final ScriptingLibraryMappings myScriptingLibraryMappings;
private final LangScriptingContextConfigurable myParent;
@@ -46,6 +52,8 @@ public class ScriptingContextsConfigurable extends LanguagePerFileConfigurable<S
IdeBundle.message("scripting.lib.usageScope.override.title"));
myScriptingLibraryMappings = mappings;
myParent = parent;
mappings.registerLibraryTableListener(this, this);
Disposer.register(project, this);
}
public void resetMappings() {
@@ -115,4 +123,26 @@ public class ScriptingContextsConfigurable extends LanguagePerFileConfigurable<S
return false;
}
@Override
public void dispose() {
}
@Override
public void afterLibraryAdded(Library newLibrary) {
reset();
}
@Override
public void afterLibraryRenamed(Library library) {
reset();
}
@Override
public void beforeLibraryRemoved(Library library) {
}
@Override
public void afterLibraryRemoved(Library library) {
reset();
}
}