Search in sources :

Example 1 with ImageFileEditor

use of org.intellij.images.editor.ImageFileEditor in project intellij-community by JetBrains.

the class DvcsUtil method getSelectedFile.

/**
   * Returns the currently selected file, based on which VcsBranch or StatusBar components will identify the current repository root.
   */
@Nullable
@CalledInAwt
public static VirtualFile getSelectedFile(@NotNull Project project) {
    StatusBar statusBar = WindowManager.getInstance().getStatusBar(project);
    final FileEditor fileEditor = StatusBarUtil.getCurrentFileEditor(project, statusBar);
    VirtualFile result = null;
    if (fileEditor != null) {
        if (fileEditor instanceof TextEditor) {
            Document document = ((TextEditor) fileEditor).getEditor().getDocument();
            result = FileDocumentManager.getInstance().getFile(document);
        } else if (fileEditor instanceof ImageFileEditor) {
            result = ((ImageFileEditor) fileEditor).getImageEditor().getFile();
        }
    }
    if (result == null) {
        final FileEditorManager manager = FileEditorManager.getInstance(project);
        if (manager != null) {
            Editor editor = manager.getSelectedTextEditor();
            if (editor != null) {
                result = FileDocumentManager.getInstance().getFile(editor.getDocument());
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ImageFileEditor(org.intellij.images.editor.ImageFileEditor) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) ImageFileEditor(org.intellij.images.editor.ImageFileEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Document(com.intellij.openapi.editor.Document) TextEditor(com.intellij.openapi.fileEditor.TextEditor) ImageFileEditor(org.intellij.images.editor.ImageFileEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Editor(com.intellij.openapi.editor.Editor) StatusBar(com.intellij.openapi.wm.StatusBar) CalledInAwt(org.jetbrains.annotations.CalledInAwt) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)1 TextEditor (com.intellij.openapi.fileEditor.TextEditor)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 StatusBar (com.intellij.openapi.wm.StatusBar)1 ImageFileEditor (org.intellij.images.editor.ImageFileEditor)1 CalledInAwt (org.jetbrains.annotations.CalledInAwt)1 Nullable (org.jetbrains.annotations.Nullable)1