Search in sources :

Example 46 with WriteAction

use of com.intellij.openapi.application.WriteAction in project android by JetBrains.

the class XmlWrongFileTypeInspectionTest method testInvokeInspection.

public void testInvokeInspection() throws Exception {
    final VirtualFile virtualFile = copyFileToProject("animatedVector.xml", "res/anim/animatedVector.xml");
    myFixture.configureFromExistingVirtualFile(virtualFile);
    myFixture.enableInspections(XmlWrongFileTypeInspection.class);
    final IntentionAction action = AndroidTestUtils.getIntentionAction(myFixture, "Move file to \"drawable\"");
    assertNotNull(action);
    new WriteAction() {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            action.invoke(getProject(), myFixture.getEditor(), myFixture.getFile());
        }
    }.execute();
    assertNull(LocalFileSystem.getInstance().refreshAndFindFileByPath("res/anim/animatedVector.xml"));
    assertTrue(virtualFile.getPath().endsWith("res/drawable/animatedVector.xml"));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteAction(com.intellij.openapi.application.WriteAction) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) Result(com.intellij.openapi.application.Result)

Example 47 with WriteAction

use of com.intellij.openapi.application.WriteAction in project intellij-plugins by JetBrains.

the class RubyMotionFacetConfigurator method configure.

public static void configure(VirtualFile baseDir, Module module) {
    final RubyMotionFacet existingFacet = RubyMotionFacet.getInstance(module);
    if (existingFacet != null) {
        return;
    }
    FacetManager facetManager = FacetManager.getInstance(module);
    final ModifiableFacetModel model = facetManager.createModifiableModel();
    RubyMotionFacetType facetType = RubyMotionFacetType.getInstance();
    RubyMotionFacetConfiguration configuration = ProjectFacetManager.getInstance(module.getProject()).createDefaultConfiguration(facetType);
    //configuration.setProjectRootPath(baseDir.getPath());
    VirtualFile testFolder = baseDir.findChild("spec");
    final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
    if (testFolder != null) {
        //configuration.setTestPath(testFolder.getPath());
        addTestSources(testFolder, rootModel);
    }
    VirtualFile libFolder = baseDir.findChild("app");
    if (libFolder != null) {
    //configuration.setLibPath(libFolder.getPath());
    }
    RubyMotionFacet.updateMotionLibrary(rootModel);
    IdeaInternalUtil.runInsideWriteAction(new ActionRunner.InterruptibleRunnable() {

        public void run() throws Exception {
            rootModel.commit();
        }
    });
    RubyMotionFacet facet = facetManager.createFacet(facetType, facetType.getDefaultFacetName(), configuration, null);
    model.addFacet(facet);
    new WriteAction() {

        protected void run(@NotNull final Result result) throws Throwable {
            model.commit();
        }
    }.execute();
    RubyMotionUtilExt.createMotionRunConfiguration(module);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ActionRunner(com.intellij.util.ActionRunner) WriteAction(com.intellij.openapi.application.WriteAction) RubyMotionFacetType(org.jetbrains.plugins.ruby.motion.facet.RubyMotionFacetType) RubyMotionFacetConfiguration(org.jetbrains.plugins.ruby.motion.facet.RubyMotionFacetConfiguration) Result(com.intellij.openapi.application.Result) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) RubyMotionFacet(org.jetbrains.plugins.ruby.motion.facet.RubyMotionFacet) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) ProjectFacetManager(com.intellij.facet.ProjectFacetManager) FacetManager(com.intellij.facet.FacetManager)

Example 48 with WriteAction

use of com.intellij.openapi.application.WriteAction in project intellij-plugins by JetBrains.

the class RubyMotionFacetConfigurator method configureSdk.

private static void configureSdk(final Project project) {
    final ProjectRootManager manager = ProjectRootManager.getInstance(project);
    final Sdk sdk = manager.getProjectSdk();
    if (!RubySdkUtil.isNativeRuby19(sdk)) {
        for (final Sdk newSdk : ProjectJdkTable.getInstance().getSdksOfType(RubySdkType.getInstance())) {
            if (RubySdkUtil.isNativeRuby19(newSdk) && !RubySdkUtil.isNativeRuby20(newSdk) && !RubyRemoteInterpreterManager.getInstance().isRemoteSdk(newSdk)) {
                new WriteAction() {

                    @Override
                    protected void run(@NotNull Result result) throws Throwable {
                        ProjectRootManager.getInstance(project).setProjectSdk(newSdk);
                    }
                }.execute();
            }
        }
    }
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) Sdk(com.intellij.openapi.projectRoots.Sdk) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) Result(com.intellij.openapi.application.Result)

Example 49 with WriteAction

use of com.intellij.openapi.application.WriteAction in project intellij-leiningen-plugin by derkork.

the class ModuleCreationUtils method updateCompilePath.

/**
     * Update the compiler extension to have the appropriate paths as configured in the project map.
     * <p/>
     * SIDE-EFFECT: Changes state of extension
     *
     * @param extension      The compiler extension.
     * @param leinProjectMap The map to extract values from.
     * @return The compiler extension updated with the given settings.
     */
public CompilerModuleExtension updateCompilePath(final CompilerModuleExtension extension, Map leinProjectMap) {
    final String outputPathString = (String) leinProjectMap.get(LEIN_COMPILE_PATH);
    new WriteAction() {

        @Override
        protected void run(Result result) throws Throwable {
            try {
                VirtualFile outputPath = VfsUtil.createDirectoryIfMissing(outputPathString);
                extension.inheritCompilerOutputPath(false);
                extension.setCompilerOutputPath(outputPath);
                extension.setCompilerOutputPathForTests(outputPath);
            } catch (IOException e) {
                throw new RuntimeException("Could not create output directory" + outputPathString);
            }
        }
    }.execute();
    return extension;
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) IOException(java.io.IOException) Result(com.intellij.openapi.application.Result)

Example 50 with WriteAction

use of com.intellij.openapi.application.WriteAction in project intellij-leiningen-plugin by derkork.

the class ModuleCreationUtils method importModule.

/**
     * This method imports a leiningen module from a leiningen project file and imports it into the idea project.
     * <p/>
     * Notes:
     * <p/>
     * Each of the IDEA components has a getModifiableModel on it.  This method returns a new instance each time you
     * invoke it.  Once you have a modifiable model of the component you wish to update, you mutate it to the state
     * you wish.  Once you're done, you call commit() on the modifiable model and it updates the component it came from.
     * <p/>
     * Since a lot of the components are persisted in files, commit() updates these files as well.  Therefore you need
     * to make any calls to commit() from within a WriteAction.
     *
     * @param ideaProject The IDEA project to add the leiningen module to.
     * @param leinProjectFile  The leiningen project file
     * @return The leiningen project map.
     */
public Map importModule(Project ideaProject, VirtualFile leinProjectFile) {
    ClassPathUtils.getInstance().switchToPluginClassLoader();
    Map projectMap = LeiningenAPI.loadProject(leinProjectFile.getPath());
    String name = (String) projectMap.get(LEIN_PROJECT_NAME);
    final ModifiableModuleModel moduleManager = createModuleManager(ideaProject);
    final ModifiableRootModel module = createModule(moduleManager, leinProjectFile.getParent().getPath(), name);
    initializeModulePaths(projectMap, module, leinProjectFile.getParent());
    ProjectRootManagerEx rootManager = ProjectRootManagerEx.getInstanceEx(ideaProject);
    module.setSdk(rootManager.getProjectSdk());
    //Setup the dependencies
    // Based loosely on org.jetbrains.idea.maven.importing.MavenRootModelAdapter#addLibraryDependency
    //We could use the module table here, but then the libraries wouldn't be shared across modules.
    final LibraryTable.ModifiableModel projectLibraries = ProjectLibraryTable.getInstance(ideaProject).getModifiableModel();
    //Load all the dependencies from the project file
    List dependencyMaps = LeiningenAPI.loadDependencies(leinProjectFile.getCanonicalPath());
    final List<LibraryInfo> dependencies = initializeDependencies(module, projectLibraries, dependencyMaps);
    new WriteAction() {

        @Override
        protected void run(Result result) throws Throwable {
            for (LibraryInfo library : dependencies) {
                library.modifiableModel.commit();
            }
            //Save the project libraries
            projectLibraries.commit();
            //Save the module itself to the module file.
            module.commit();
            //Save the list of modules that are in this project to the IDEA project file
            moduleManager.commit();
        }
    }.execute();
    return projectMap;
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) Result(com.intellij.openapi.application.Result) ProjectRootManagerEx(com.intellij.openapi.roots.ex.ProjectRootManagerEx) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Aggregations

Result (com.intellij.openapi.application.Result)85 WriteAction (com.intellij.openapi.application.WriteAction)85 NotNull (org.jetbrains.annotations.NotNull)38 VirtualFile (com.intellij.openapi.vfs.VirtualFile)37 File (java.io.File)20 IOException (java.io.IOException)16 Module (com.intellij.openapi.module.Module)10 PsiFile (com.intellij.psi.PsiFile)7 Sdk (com.intellij.openapi.projectRoots.Sdk)5 RunResult (com.intellij.openapi.application.RunResult)4 Document (com.intellij.openapi.editor.Document)4 Project (com.intellij.openapi.project.Project)4 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)4 Library (com.intellij.openapi.roots.libraries.Library)4 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)4 ModifiableFacetModel (com.intellij.facet.ModifiableFacetModel)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 FacetManager (com.intellij.facet.FacetManager)2 ProjectFacetManager (com.intellij.facet.ProjectFacetManager)2