本文整理汇总了Java中com.intellij.openapi.fileEditor.FileDocumentManager.getCachedDocument方法的典型用法代码示例。如果您正苦于以下问题:Java FileDocumentManager.getCachedDocument方法的具体用法?Java FileDocumentManager.getCachedDocument怎么用?Java FileDocumentManager.getCachedDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.fileEditor.FileDocumentManager
的用法示例。
在下文中一共展示了FileDocumentManager.getCachedDocument方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doCreateEntry
import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
@Nullable
private Entry doCreateEntry(@NotNull VirtualFile file, boolean forDeletion) {
if (!file.isDirectory()) {
if (!isVersioned(file)) return null;
Pair<StoredContent, Long> contentAndStamps;
if (forDeletion) {
FileDocumentManager m = FileDocumentManager.getInstance();
Document d = m.isFileModified(file) ? m.getCachedDocument(file) : null; // should not try to load document
contentAndStamps = acquireAndClearCurrentContent(file, d);
}
else {
contentAndStamps = getActualContentNoAcquire(file);
}
return new FileEntry(file.getName(), contentAndStamps.first, contentAndStamps.second, !file.isWritable());
}
DirectoryEntry newDir = new DirectoryEntry(file.getName());
doCreateChildren(newDir, iterateDBChildren(file), forDeletion);
if (!isVersioned(file) && newDir.getChildren().isEmpty()) return null;
return newDir;
}
示例2: setName
import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
public static PsiFile setName(@NotNull PsiFile file, @NotNull String newName) throws IncorrectOperationException {
VirtualFile vFile = file.getViewProvider().getVirtualFile();
PsiManagerImpl manager = (PsiManagerImpl)file.getManager();
try{
final FileType newFileType = FileTypeRegistry.getInstance().getFileTypeByFileName(newName);
if (UnknownFileType.INSTANCE.equals(newFileType) || newFileType.isBinary()) {
// before the file becomes unknown or a binary (thus, not openable in the editor), save it to prevent data loss
final FileDocumentManager fdm = FileDocumentManager.getInstance();
final Document doc = fdm.getCachedDocument(vFile);
if (doc != null) {
fdm.saveDocumentAsIs(doc);
}
}
vFile.rename(manager, newName);
}
catch(IOException e){
throw new IncorrectOperationException(e);
}
return file.getViewProvider().isPhysical() ? manager.findFile(vFile) : file;
}
示例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: saveFileIfNecessary
import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
public static void saveFileIfNecessary(PsiFile psiFile) {
if (!needSave(ResourceHelper.getFolderType(psiFile.getVirtualFile()))) { // Avoid need for read lock in get parent
return;
}
VirtualFile file = psiFile.getVirtualFile();
if (file == null) {
return;
}
final FileDocumentManager fileManager = FileDocumentManager.getInstance();
if (!fileManager.isFileModified(file)) {
return;
}
final com.intellij.openapi.editor.Document document;
document = fileManager.getCachedDocument(file);
if (document == null || !fileManager.isDocumentUnsaved(document)) {
return;
}
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
fileManager.saveDocument(document);
}
});
}
}, ModalityState.any());
}
示例5: reloadIn
import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
static void reloadIn(@NotNull final VirtualFile virtualFile, @NotNull final Charset charset) {
final FileDocumentManager documentManager = FileDocumentManager.getInstance();
//Project project = ProjectLocator.getInstance().guessProjectForFile(myFile);
//if (documentManager.isFileModified(myFile)) {
// int result = Messages.showDialog(project, "File is modified. Reload file anyway?", "File is Modified", new String[]{"Reload", "Cancel"}, 0, AllIcons.General.WarningDialog);
// if (result != 0) return;
//}
if (documentManager.getCachedDocument(virtualFile) == null) {
// no need to reload document
EncodingManager.getInstance().setEncoding(virtualFile, charset);
return;
}
final Disposable disposable = Disposer.newDisposable();
MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(disposable);
connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() {
@Override
public void beforeFileContentReload(VirtualFile file, @NotNull Document document) {
if (!file.equals(virtualFile)) return;
Disposer.dispose(disposable); // disconnect
EncodingManager.getInstance().setEncoding(file, charset);
LoadTextUtil.setCharsetWasDetectedFromBytes(file, null);
}
});
// if file was modified, the user will be asked here
try {
EncodingProjectManagerImpl.suppressReloadDuring(new Runnable() {
@Override
public void run() {
((VirtualFileListener)documentManager).contentsChanged(
new VirtualFileEvent(null, virtualFile, virtualFile.getName(), virtualFile.getParent()));
}
});
}
finally {
Disposer.dispose(disposable);
}
}