Search in sources :

Example 1 with ScriptingLibraryMappings

use of com.intellij.webcore.libraries.ScriptingLibraryMappings in project intellij-plugins by JetBrains.

the class ChooseScopeAndCreateLibraryDialog method createLibraryAndAssociate.

@Nullable
private ErrorMessage createLibraryAndAssociate() {
    String libraryName = myLibraryNameTextField.getText();
    ScriptingLibraryModel libraryModel = myLibraryHelper.getOrCreateJsLibraryModel(libraryName);
    try {
        ScriptingLibraryMappings libraryMappings = ServiceManager.getService(myProject, JSLibraryMappings.class);
        if (myModuleSelector.isAssociateWithProjectView()) {
            if (myModuleSelector.isAssociateWithProjectRequested()) {
                libraryMappings.associateWithProject(libraryModel.getName());
                LOG.info("Library '" + libraryModel.getName() + "' has been successfully associated with the project");
            } else {
                libraryMappings.disassociateWithProject(libraryModel.getName());
            }
        } else {
            for (Module module : myModuleSelector.getSelectedModules()) {
                ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
                VirtualFile[] roots = moduleRootManager.getContentRoots();
                for (VirtualFile root : roots) {
                    libraryMappings.associate(root, libraryModel.getName(), false);
                    LOG.info("Library '" + libraryModel.getName() + "' has been associated with " + root);
                }
            }
        }
        myLibraryHelper.commit();
        return null;
    } catch (Exception ex) {
        return new ErrorMessage("Unable to associate '" + libraryName + "' JavaScript library", ex);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ScriptingLibraryModel(com.intellij.webcore.libraries.ScriptingLibraryModel) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Module(com.intellij.openapi.module.Module) ScriptingLibraryMappings(com.intellij.webcore.libraries.ScriptingLibraryMappings) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Module (com.intellij.openapi.module.Module)1 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ScriptingLibraryMappings (com.intellij.webcore.libraries.ScriptingLibraryMappings)1 ScriptingLibraryModel (com.intellij.webcore.libraries.ScriptingLibraryModel)1 Nullable (org.jetbrains.annotations.Nullable)1