当前位置: 首页>>代码示例>>Java>>正文


Java FileDocumentManager.getCachedDocument方法代码示例

本文整理汇总了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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:IdeaGateway.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:PsiFileImplUtil.java

示例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();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:AbstractConvertLineSeparatorsAction.java

示例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());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:34,代码来源:LayoutPullParserFactory.java

示例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);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:43,代码来源:EncodingUtil.java


注:本文中的com.intellij.openapi.fileEditor.FileDocumentManager.getCachedDocument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。