本文整理汇总了Java中com.intellij.openapi.fileEditor.FileDocumentManager.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java FileDocumentManager.getInstance方法的具体用法?Java FileDocumentManager.getInstance怎么用?Java FileDocumentManager.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.fileEditor.FileDocumentManager
的用法示例。
在下文中一共展示了FileDocumentManager.getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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 );
}
}
}
}
示例2: 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);
}
}
}
}
示例3: 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;
}
示例4: 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);
}
}
}
示例5: createPopup
import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
@Nullable
public ListPopup createPopup(@NotNull DataContext dataContext) {
final VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
if (virtualFile == null) return null;
boolean enabled = checkEnabled(virtualFile);
if (!enabled) return null;
Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
FileDocumentManager documentManager = FileDocumentManager.getInstance();
final Document document = documentManager.getDocument(virtualFile);
if (!allowDirectories && virtualFile.isDirectory() || document == null && !virtualFile.isDirectory()) return null;
final byte[] bytes;
try {
bytes = virtualFile.isDirectory() ? null : virtualFile.contentsToByteArray();
}
catch (IOException e) {
return null;
}
DefaultActionGroup group = createActionGroup(virtualFile, editor, document, bytes, null);
return JBPopupFactory.getInstance().createActionGroupPopup(getTemplatePresentation().getText(),
group, dataContext, JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false);
}
示例6: processUnsavedChanges
import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
/**
* Finds modified but unsaved files in the given list of dirty files and notifies the builder about MODIFIED changes.
* Changes contained in <code>alreadyProcessed</code> are skipped - they have already been processed as modified, or else.
*/
public void processUnsavedChanges(ChangelistBuilder builder, Set<FilePath> dirtyFiles, Collection<HgChange> alreadyProcessed) {
// exclude already processed
for (HgChange c : alreadyProcessed) {
dirtyFiles.remove(c.beforeFile().toFilePath());
dirtyFiles.remove(c.afterFile().toFilePath());
}
final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
final FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
for (FilePath filePath : dirtyFiles) {
final VirtualFile vf = filePath.getVirtualFile();
if (vf != null && fileDocumentManager.isFileModified(vf)) {
final VirtualFile root = vcsManager.getVcsRootFor(vf);
if (root != null && HgUtil.isHgRoot(root)) {
final HgRevisionNumber beforeRevisionNumber = new HgWorkingCopyRevisionsCommand(myProject).tip(root);
final ContentRevision beforeRevision = (beforeRevisionNumber == null ? null :
HgContentRevision.create(myProject, new HgFile(myProject, vf), beforeRevisionNumber));
builder.processChange(new Change(beforeRevision, CurrentContentRevision.create(filePath), FileStatus.MODIFIED), myVcsKey);
}
}
}
}
示例7: documentChanged
import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
@Override
public void documentChanged(DocumentEvent event) {
Document document = event.getDocument();
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
VirtualFile file = fileDocumentManager.getFile(document);
if (file == null) {
return;
}
String path = ExternalSystemApiUtil.getLocalFileSystemPath(file);
for (MyEntry entry : myAutoImportAware) {
if (entry.aware.getAffectedExternalProjectPath(path, myProject) != null) {
// Document save triggers VFS event but FileDocumentManager might be registered after the current listener, that's why
// call to 'saveDocument()' might not produce the desired effect. That's why we reschedule document save if necessary.
scheduleDocumentSave(document);
return;
}
}
}
示例8: setupFileEditorAndDocument
import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
@NotNull
private static Document setupFileEditorAndDocument(@NotNull String fileName, @NotNull String fileText) throws IOException {
EncodingProjectManager.getInstance(getProject()).setEncoding(null, CharsetToolkit.UTF8_CHARSET);
EncodingProjectManager.getInstance(ProjectManager.getInstance().getDefaultProject()).setEncoding(null, CharsetToolkit.UTF8_CHARSET);
PostprocessReformattingAspect.getInstance(ourProject).doPostponedFormatting();
deleteVFile();
myVFile = getSourceRoot().createChildData(null, fileName);
VfsUtil.saveText(myVFile, fileText);
final FileDocumentManager manager = FileDocumentManager.getInstance();
final Document document = manager.getDocument(myVFile);
assertNotNull("Can't create document for '" + fileName + "'", document);
manager.reloadFromDisk(document);
document.insertString(0, " ");
document.deleteString(0, 1);
myFile = getPsiManager().findFile(myVFile);
assertNotNull("Can't create PsiFile for '" + fileName + "'. Unknown file type most probably.", myFile);
assertTrue(myFile.isPhysical());
myEditor = createEditor(myVFile);
myVFile.setCharset(CharsetToolkit.UTF8_CHARSET);
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
return document;
}
示例9: 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);
}
}
示例10: getCopyWithAnswers
import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
static Pair<VirtualFile, TaskFile> getCopyWithAnswers(@NotNull final VirtualFile taskDir,
@NotNull final VirtualFile file,
@NotNull final TaskFile source) {
try {
VirtualFile answerFile = file.copy(taskDir, taskDir, file.getNameWithoutExtension() + EduNames.ANSWERS_POSTFIX + "." + file.getExtension());
final FileDocumentManager documentManager = FileDocumentManager.getInstance();
final Document document = documentManager.getDocument(answerFile);
if (document != null) {
TaskFile answerTaskFile = source.getTask().copy().getTaskFile(StudyUtils.pathRelativeToTask(file));
if (answerTaskFile == null) {
return null;
}
EduDocumentListener listener = new EduDocumentListener(answerTaskFile);
document.addDocumentListener(listener);
for (AnswerPlaceholder answerPlaceholder : answerTaskFile.getActivePlaceholders()) {
final int start = answerPlaceholder.getOffset();
final int end = start + answerPlaceholder.getRealLength();
final String text = answerPlaceholder.getPossibleAnswer();
document.replaceString(start, end, text);
}
ApplicationManager.getApplication().runWriteAction(() -> documentManager.saveDocument(document));
return Pair.create(answerFile, answerTaskFile);
}
}
catch (IOException e) {
LOG.error(e);
}
return null;
}
示例11: saveDocument
import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
private void saveDocument(VirtualFile file) {
if (file == null) {
return;
}
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
Document documentToSave = ApplicationManager.getApplication().runReadAction(new Computable<Document>() {
@Override
public Document compute() {
return fileDocumentManager.getDocument(file);
}
});
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
if (documentToSave != null && fileDocumentManager.isDocumentUnsaved(documentToSave)) {
fileDocumentManager.saveDocument(documentToSave);
}
}
});
}
}, ModalityState.NON_MODAL);
}
示例12: buildSourceBinding
import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
@Nullable
public static GradleEditorSourceBinding buildSourceBinding(@NotNull Location location, @NotNull Project project) {
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
Document document = fileDocumentManager.getDocument(location.file);
if (document == null) {
LOG.warn(String.format("Can't obtain a document for file %s for processing location '%s'",
location.file, location));
return null;
}
RangeMarker rangeMarker = document.createRangeMarker(location.range);
return new GradleEditorSourceBinding(project, location.file, rangeMarker);
}
示例13: getFile
import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
private static PsiFile getFile(final Editor editor ,
final DataContext context )
{
final Project project = (Project) context.getData(DataConstants.PROJECT);
final Document document = editor.getDocument();
final FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
final VirtualFile virtualFile = fileDocumentManager.getFile(document);
final PsiManager psiManager = PsiManager.getInstance(project);
return psiManager.findFile(virtualFile);
}
示例14: 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());
}
示例15: 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();
}