use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class CompilerTester method setFileText.
public void setFileText(final PsiFile file, final String text) throws IOException {
new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
final VirtualFile virtualFile = file.getVirtualFile();
VfsUtil.saveText(ObjectUtils.assertNotNull(virtualFile), text);
}
}.execute().throwException();
touch(file.getVirtualFile());
}
use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class CompilerTester method touch.
public void touch(final VirtualFile file) throws IOException {
new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
file.setBinaryContent(file.contentsToByteArray(), -1, file.getTimeStamp() + 1);
File ioFile = VfsUtilCore.virtualToIoFile(file);
assert ioFile.setLastModified(ioFile.lastModified() - 100000);
file.refresh(false, false);
}
}.execute().throwException();
}
use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class ChangeLibraryLevelActionBase method copyOrMoveFiles.
private boolean copyOrMoveFiles(final Set<File> filesToProcess, @NotNull final String targetDirPath, final Map<String, String> copiedFiles) {
final Ref<Boolean> finished = Ref.create(false);
new Task.Modal(myProject, (myCopy ? "Copying" : "Moving") + " Library Files", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
final File targetDir = new File(FileUtil.toSystemDependentName(targetDirPath));
for (final File from : filesToProcess) {
indicator.checkCanceled();
final File to = FileUtil.findSequentNonexistentFile(targetDir, FileUtil.getNameWithoutExtension(from), FileUtilRt.getExtension(from.getName()));
try {
if (from.isDirectory()) {
if (myCopy) {
FileUtil.copyDir(from, to);
} else {
FileUtil.moveDirWithContent(from, to);
}
} else {
if (myCopy) {
FileUtil.copy(from, to);
} else {
FileUtil.rename(from, to);
}
}
} catch (IOException e) {
final String actionName = getActionName();
final String message = "Cannot " + actionName.toLowerCase() + " file " + from.getAbsolutePath() + ": " + e.getMessage();
Messages.showErrorDialog(ChangeLibraryLevelActionBase.this.myProject, message, "Cannot " + actionName);
LOG.info(e);
return;
}
copiedFiles.put(FileUtil.toSystemIndependentName(from.getAbsolutePath()), FileUtil.toSystemIndependentName(to.getAbsolutePath()));
}
finished.set(true);
}
}.queue();
if (!finished.get()) {
return false;
}
new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
for (Map.Entry<String, String> entry : copiedFiles.entrySet()) {
String fromPath = entry.getKey();
String toPath = entry.getValue();
LocalFileSystem.getInstance().refreshAndFindFileByPath(toPath);
if (!myCopy) {
final VirtualFile parent = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(fromPath).getParentFile());
if (parent != null) {
parent.refresh(false, false);
}
}
}
}
}.execute();
return true;
}
use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class AddSupportForSingleFrameworkDialog method addSupport.
private boolean addSupport() {
final LibraryCompositionSettings librarySettings = myComponent.getLibraryCompositionSettings();
if (librarySettings != null) {
final ModifiableRootModel modifiableModel = myModifiableModelsProvider.getModuleModifiableModel(myModule);
if (!askAndRemoveDuplicatedLibraryEntry(modifiableModel, librarySettings.getLibraryDescription())) {
if (myConfigurable.isOnlyLibraryAdded()) {
myModifiableModelsProvider.disposeModuleModifiableModel(modifiableModel);
return false;
}
return false;
}
new WriteAction() {
protected void run(@NotNull final Result result) {
myModifiableModelsProvider.commitModuleModifiableModel(modifiableModel);
}
}.execute();
final boolean downloaded = librarySettings.downloadFiles(getRootPane());
if (!downloaded) {
int answer = Messages.showYesNoDialog(getRootPane(), ProjectBundle.message("warning.message.some.required.libraries.wasn.t.downloaded"), CommonBundle.getWarningTitle(), Messages.getWarningIcon());
if (answer != Messages.YES) {
return false;
}
}
}
new WriteAction() {
protected void run(@NotNull final Result result) {
final ModifiableRootModel rootModel = myModifiableModelsProvider.getModuleModifiableModel(myModule);
if (librarySettings != null) {
librarySettings.addLibraries(rootModel, new ArrayList<>(), myModel.getLibrariesContainer());
}
myConfigurable.addSupport(myModule, rootModel, myModifiableModelsProvider);
myModifiableModelsProvider.commitModuleModifiableModel(rootModel);
}
}.execute();
return true;
}
use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class ActionRunner method runInsideWriteAction.
public static void runInsideWriteAction(@NotNull final InterruptibleRunnable runnable) throws Exception {
RunResult result = new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
runnable.run();
}
}.execute();
if (result.getThrowable() instanceof Exception)
throw (Exception) result.getThrowable();
result.throwException();
}
Aggregations