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


Java FileDocumentManager类代码示例

本文整理汇总了Java中com.intellij.openapi.fileEditor.FileDocumentManager的典型用法代码示例。如果您正苦于以下问题:Java FileDocumentManager类的具体用法?Java FileDocumentManager怎么用?Java FileDocumentManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FileDocumentManager类属于com.intellij.openapi.fileEditor包,在下文中一共展示了FileDocumentManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getQuickNavigateInfo

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入依赖的package包/类
@Nullable
@Override
public String getQuickNavigateInfo(PsiElement element, PsiElement originalElement) {
  Document document =
      FileDocumentManager.getInstance().getDocument(element.getContainingFile().getVirtualFile());
  if (document == null) return "";

  int lineNum = document.getLineNumber(element.getTextOffset()) + 1 /* count starts at zero */;
  String path = element.getContainingFile().getVirtualFile().getName();
  StringBuilder navigateInfo = new StringBuilder("Defined at ");
  navigateInfo.append(path);
  navigateInfo.append(":");
  navigateInfo.append(lineNum);
  String optDoc = getDocCommentForEnclosingTag(element);
  if (optDoc != null) {
    navigateInfo.append("\n");
    navigateInfo.append(produceCommentPreview(optDoc));
  }
  return navigateInfo.toString();
}
 
开发者ID:google,项目名称:bamboo-soy,代码行数:21,代码来源:SoyDocumentationProvider.java

示例2: diff

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入依赖的package包/类
/**
 * 调用 Android 文件对比
 * @param project
 * @param f1
 * @param f2
 */
public static void diff(final Project project, final File f1, final File f2) {
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
            try {
                VirtualFile v1 = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(f1);
                Document document1 = FileDocumentManager.getInstance().getDocument(v1);
                FileDocumentContentImpl fileDocumentContent1 = new FileDocumentContentImpl(project, document1, v1);
                VirtualFile v2 = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(f2);
                Document document2 = FileDocumentManager.getInstance().getDocument(v2);
                FileDocumentContentImpl fileDocumentContent2 = new FileDocumentContentImpl(project, document2, v2);
                SimpleDiffRequest simpleDiffRequest = new SimpleDiffRequest(Constant.TITLE, fileDocumentContent1, fileDocumentContent2,
                        f1.getName(), f2.getName());
                DiffManager.getInstance().showDiff(project, simpleDiffRequest);
            } catch (Exception e) {
                NotificationUtils.errorNotification("Diff Source Error:" + e.getMessage());
            }
        }
    });
}
 
开发者ID:pengwei1024,项目名称:AndroidSourceViewer,代码行数:27,代码来源:DiffSourceAction.java

示例3: actionPerformed

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入依赖的package包/类
public void actionPerformed( AnActionEvent e ) {
    Editor editor = ( Editor ) e.getDataContext().getData( "editor" );
    SelectionModel selectionModel = editor.getSelectionModel();
    if ( selectionModel != null ) {
        String selectedText = selectionModel.getSelectedText();
        if ( selectedText != null && selectedText.trim().length() > 0 ) {
            Project project = ( Project ) e.getDataContext().getData( DataConstants.PROJECT );
            String panelid = ( String ) project.getUserData( QuickNotes.KEY_PANELID );
            QuickNotesPanel quickNotesPanel = QuickNotesManager.getInstance().getQuickNotesPanel( panelid );
            if ( quickNotesPanel != null ) {
                FileDocumentManager manager = FileDocumentManager.getInstance();
                VirtualFile virtualFile = manager.getFile( editor.getDocument() );
                quickNotesPanel.addNewNote( "[File: " + virtualFile.getPath() + "]\n" + selectedText );
            }
        }
    }
}
 
开发者ID:jrana,项目名称:quicknotes,代码行数:18,代码来源:AddToQuickNotes.java

示例4: getTestsText

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入依赖的package包/类
@NotNull
public String getTestsText(@NotNull final Project project) {
  final Course course = getLesson().getCourse();
  final Language language = course.getLanguageById();
  final EduPluginConfigurator configurator = EduPluginConfigurator.INSTANCE.forLanguage(language);
  final VirtualFile taskDir = getTaskDir(project);
  if (taskDir != null) {
    final VirtualFile file = taskDir.findChild(configurator.getTestFileName());
    if (file == null) return "";
    final Document document = FileDocumentManager.getInstance().getDocument(file);
    if (document != null) {
      return document.getImmutableCharSequence().toString();
    }
  }

  return "";
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:18,代码来源:Task.java

示例5: navigateToPlaceholder

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入依赖的package包/类
private void navigateToPlaceholder(@NotNull final Project project) {
  final Editor selectedEditor = StudyUtils.getSelectedEditor(project);
  if (selectedEditor != null) {
    final FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
    final VirtualFile openedFile = fileDocumentManager.getFile(selectedEditor.getDocument());
    if (openedFile != null) {
      final TaskFile selectedTaskFile = StudyUtils.getTaskFile(project, openedFile);
      if (selectedTaskFile != null) {
        final int offset = selectedEditor.getCaretModel().getOffset();
        final AnswerPlaceholder targetPlaceholder = getTargetPlaceholder(selectedTaskFile, offset);
        if (targetPlaceholder == null) {
          return;
        }
        StudyNavigator.navigateToAnswerPlaceholder(selectedEditor, targetPlaceholder);
      }
    }
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:19,代码来源:StudyWindowNavigationAction.java

示例6: getAnswerPlaceholder

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入依赖的package包/类
@Nullable
private static AnswerPlaceholder getAnswerPlaceholder(PsiElement e, int offset) {
  PsiFile file = e.getContainingFile();
  if (file == null) {
    return null;
  }
  VirtualFile virtualFile = file.getVirtualFile();
  if (virtualFile == null) {
    return null;
  }
  TaskFile taskFile = StudyUtils.getTaskFile(e.getProject(), virtualFile);
  if (taskFile == null) {
    return null;
  }
  Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
  if (document == null) {
    return null;
  }
  Editor editor = FileEditorManager.getInstance(e.getProject()).getSelectedTextEditor();
  return editor == null ? null : taskFile.getAnswerPlaceholder(offset);
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:22,代码来源:StudyAnswerPlaceholderExtendWordHandler.java

示例7: configureByTaskFile

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入依赖的package包/类
protected VirtualFile configureByTaskFile(String name) {
  Task task = StudyTaskManager.getInstance(getProject()).getCourse().getLessons().get(0).getTaskList().get(0);
  TaskFile taskFile = new TaskFile();
  taskFile.setTask(task);
  task.getTaskFiles().put(name, taskFile);
  VirtualFile file = copyFileToTask(name);

  taskFile.name = name;
  myFixture.configureFromExistingVirtualFile(file);
  Document document = FileDocumentManager.getInstance().getDocument(file);
  for (AnswerPlaceholder placeholder : getPlaceholders(document, false)) {
    taskFile.addAnswerPlaceholder(placeholder);
  }
  taskFile.sortAnswerPlaceholders();
  StudyUtils.drawAllAnswerPlaceholders(myFixture.getEditor(), taskFile);
  return file;
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:18,代码来源:CCTestCase.java

示例8: initBuildGradle

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入依赖的package包/类
private void initBuildGradle() {
    SelectFromListDialog.ToStringAspect toStringAspect = String::valueOf;
    VirtualFile gradleVirtualFile = null;
    if (modules.length > 1) {
        SelectFromListDialog dialog = new SelectFromListDialog(project, modules, toStringAspect, "Select Gradle Module", ListSelectionModel.SINGLE_SELECTION);
        boolean isOk = dialog.showAndGet();
        if (isOk) {
            gradleVirtualFile = project.getBaseDir()
                    .findChild(String.valueOf(dialog.getSelection()[0]))
                    .findChild("build.gradle");
        }
    } else {
        gradleVirtualFile = project.getBaseDir()
                .findChild(modules[0])
                .findChild("build.gradle");
    }

    if (gradleVirtualFile != null) {
        buildGradle = FileDocumentManager.getInstance().getDocument(gradleVirtualFile);
    }
}
 
开发者ID:kaygisiz,项目名称:Gradle-External-Library-Helper,代码行数:22,代码来源:GradleManager.java

示例9: getTemporaryBuffer

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入依赖的package包/类
private String getTemporaryBuffer( IjFile file )
{
  final VirtualFile virtualFile = file.getVirtualFile();

  // we're getting the cached documents since getDocument() forces PSI creating which will cause deadlock !!!
  if( virtualFile != null && !virtualFile.getFileType().isBinary() )
  {
    final Document document = FileDocumentManager.getInstance().getCachedDocument( virtualFile );
    final String[] result = new String[1];
    if( document != null )
    {
      if( ApplicationManagerEx.getApplicationEx().tryRunReadAction( () -> result[0] = document.getText() ) )
      {
        return result[0];
      }
      else
      {
        return document.getCharsSequence().toString();
      }
    }
  }

  return null;
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:25,代码来源:IjFile.java

示例10: changeLanguageLevel

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入依赖的package包/类
@Override
public Promise<Void> changeLanguageLevel(@NotNull Module module, @NotNull final LanguageLevel level) {
  if (!myProjectsManager.isMavenizedModule(module)) return null;

  MavenProject mavenProject = myProjectsManager.findProject(module);
  if (mavenProject == null) return null;

  final MavenDomProjectModel model = MavenDomUtil.getMavenDomProjectModel(myProject, mavenProject.getFile());
  if (model == null) return null;

  new WriteCommandAction(myProject, "Add Maven Dependency", DomUtil.getFile(model)) {
    @Override
    protected void run(@NotNull Result result) throws Throwable {
      MavenDomConfiguration configuration = getCompilerPlugin(model).getConfiguration();
      XmlTag tag = configuration.ensureTagExists();
      setChildTagValue(tag, "source", level.getCompilerComplianceDefaultOption());
      setChildTagValue(tag, "target", level.getCompilerComplianceDefaultOption());
      Document document = PsiDocumentManager.getInstance(myProject).getDocument(DomUtil.getFile(model));
      if (document != null) {
        FileDocumentManager.getInstance().saveDocument(document);
      }
    }
  }.execute();
  return myProjectsManager.forceUpdateProjects(Collections.singleton(mavenProject));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:MavenProjectModelModifier.java

示例11: processError

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入依赖的package包/类
private static ObjectStubTree processError(final VirtualFile vFile, String message, @Nullable Exception e) {
  LOG.error(message, e);

  ApplicationManager.getApplication().invokeLater(new Runnable() {
    @Override
    public void run() {
      final Document doc = FileDocumentManager.getInstance().getCachedDocument(vFile);
      if (doc != null) {
        FileDocumentManager.getInstance().saveDocument(doc);
      }
    }
  }, ModalityState.NON_MODAL);

  FileBasedIndex.getInstance().requestReindex(vFile);
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:StubTreeLoaderImpl.java

示例12: testCreateFromEditor

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入依赖的package包/类
public void testCreateFromEditor() throws Throwable {
  VirtualFile file = myProjectRoot.findFileByRelativePath("file.txt");
  assertNotNull(file);

  Document document = FileDocumentManager.getInstance().getDocument(file);
  assertNotNull(document);

  myEditor = EditorFactory.getInstance().createEditor(document, myProject);
  assertNotNull(myEditor);

  List<FileContent> expected = new ArrayList<FileContent>();
  expected.add(new FileContent("file.txt", "file.txt content"));

  List<FileContent> actual = GithubCreateGistAction.collectContents(myProject, myEditor, file, null);

  checkEquals(expected, actual);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:GithubCreateGistContentTest.java

示例13: 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

示例14: toString

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入依赖的package包/类
@Override
public String toString() {
  final String value;
  List<GradleEditorSourceBinding> bindings = getDefinitionValueSourceBindings();
  if (bindings.isEmpty()) {
    value = "<undefined>";
  }
  else if (bindings.size() > 1) {
    value = "<ref>";
  }
  else {
    Document document = FileDocumentManager.getInstance().getDocument(bindings.get(0).getFile());
    RangeMarker rangeMarker = bindings.get(0).getRangeMarker();
    if (document == null) {
      value = "<unexpected!>";
    }
    else {
      value = '[' + document.getCharsSequence().subSequence(rangeMarker.getStartOffset(), rangeMarker.getEndOffset()).toString() + ']';
    }
  }
  return getName() + " " + value;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:AbstractSimpleGradleEditorEntity.java

示例15: replace

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入依赖的package包/类
public static boolean replace(Project project, Editor editor, int offset, FindModel model, ReplaceDelegate delegate) {
  Document document = editor.getDocument();

  if (!FileDocumentManager.getInstance().requestWriting(document, project)) {
    return false;
  }

  document.startGuardedBlockChecking();
  boolean toPrompt = model.isPromptOnReplace();

  try {
    doReplace(project, editor, model, document, offset, toPrompt, delegate);
  }
  catch (ReadOnlyFragmentModificationException e) {
    EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(document).handle(e);
  }
  finally {
    document.stopGuardedBlockChecking();
  }

  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:FindUtil.java


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