本文整理汇总了Java中com.intellij.openapi.fileEditor.FileDocumentManager.saveDocument方法的典型用法代码示例。如果您正苦于以下问题:Java FileDocumentManager.saveDocument方法的具体用法?Java FileDocumentManager.saveDocument怎么用?Java FileDocumentManager.saveDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.fileEditor.FileDocumentManager
的用法示例。
在下文中一共展示了FileDocumentManager.saveDocument方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveFiles
import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
protected void saveFiles(PhpClass currentTestClass, Project project) {
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
Document documentTestClass = fileDocumentManager.getDocument(currentTestClass.getContainingFile().getVirtualFile());
if (documentTestClass != null) {
fileDocumentManager.saveDocument(documentTestClass);
}
PhpClass currentTestedClass = Utils.locateTestedClass(project, currentTestClass);
if (currentTestedClass != null) {
Document documentTestedClass = fileDocumentManager.getDocument(currentTestedClass.getContainingFile().getVirtualFile());
if (documentTestedClass != null) {
fileDocumentManager.saveDocument(documentTestedClass);
}
}
}
示例2: save
import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
public static void save(VirtualFile file, String content)
{
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
Document document = fileDocumentManager.getDocument(file);
if (document != null)
{
document.setText(content);
fileDocumentManager.saveDocument(document);
}
}
示例3: changeLineSeparators
import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
public static void changeLineSeparators(@NotNull final Project project,
@NotNull final VirtualFile virtualFile,
@NotNull final String newSeparator)
{
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
Document document = fileDocumentManager.getCachedDocument(virtualFile);
if (document != null) {
fileDocumentManager.saveDocument(document);
}
String currentSeparator = LoadTextUtil.detectLineSeparator(virtualFile, false);
final String commandText;
if (StringUtil.isEmpty(currentSeparator)) {
commandText = "Changed line separators to " + LineSeparator.fromString(newSeparator);
}
else {
commandText = String.format("Changed line separators from %s to %s",
LineSeparator.fromString(currentSeparator), LineSeparator.fromString(newSeparator));
}
new WriteCommandAction(project, commandText) {
@Override
protected void run(@NotNull Result result) throws Throwable {
try {
LoadTextUtil.changeLineSeparators(project, virtualFile, newSeparator, this);
}
catch (IOException e) {
LOG.info(e);
}
}
}.execute();
}
示例4: saveFiles
import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
public static void saveFiles(VirtualFile... files) {
// ensure the validation/conversion runs on the current content
final FileDocumentManager mgr = FileDocumentManager.getInstance();
for (VirtualFile f : files) {
final Document document = mgr.getDocument(f);
if (document != null) {
mgr.saveDocument(document);
}
}
}
示例5: saveDocument
import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
private static void saveDocument(VirtualFile f) {
FileDocumentManager dm = FileDocumentManager.getInstance();
Document document = dm.getDocument(f);
assertNotNull(f.getPath(), document);
dm.saveDocument(document);
}
示例6: add
import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
@Override
public PsiElement add(@NotNull PsiElement element) throws IncorrectOperationException {
checkAdd(element);
if (element instanceof PsiDirectory) {
LOG.error("not implemented");
return null;
}
else if (element instanceof PsiFile) {
PsiFile originalFile = (PsiFile)element;
try {
VirtualFile newVFile;
final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(myManager.getProject());
if (originalFile instanceof PsiFileImpl) {
newVFile = myFile.createChildData(myManager, originalFile.getName());
String text = originalFile.getText();
final PsiFile psiFile = getManager().findFile(newVFile);
final Document document = psiFile == null ? null : psiDocumentManager.getDocument(psiFile);
final FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
if (document != null) {
document.setText(text);
fileDocumentManager.saveDocument(document);
}
else {
String lineSeparator = fileDocumentManager.getLineSeparator(newVFile, getProject());
if (!lineSeparator.equals("\n")) {
text = StringUtil.convertLineSeparators(text, lineSeparator);
}
LoadTextUtil.write(getProject(), newVFile, myManager, text, -1);
}
}
else {
byte[] storedContents = ((PsiBinaryFileImpl)originalFile).getStoredContents();
if (storedContents != null) {
newVFile = myFile.createChildData(myManager, originalFile.getName());
newVFile.setBinaryContent(storedContents);
}
else {
newVFile = VfsUtilCore.copyFile(null, originalFile.getVirtualFile(), myFile);
}
}
psiDocumentManager.commitAllDocuments();
PsiFile newFile = myManager.findFile(newVFile);
updateAddedFile(newFile);
return newFile;
}
catch (IOException e) {
throw new IncorrectOperationException(e);
}
}
else {
LOG.assertTrue(false);
return null;
}
}