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"));
}
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);
}
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();
}
}
}
}
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;
}
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;
}
Aggregations