Java Code Examples for com.intellij.openapi.fileEditor.TextEditor#getEditor()

The following examples show how to use com.intellij.openapi.fileEditor.TextEditor#getEditor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BreadcrumbsInitializingActivity.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void reinitBreadcrumbsComponent(@Nonnull final FileEditorManager fileEditorManager, @Nonnull VirtualFile file) {
  boolean above = EditorSettingsExternalizable.getInstance().isBreadcrumbsAbove();
  for (FileEditor fileEditor : fileEditorManager.getAllEditors(file)) {
    if (fileEditor instanceof TextEditor) {
      TextEditor textEditor = (TextEditor)fileEditor;
      Editor editor = textEditor.getEditor();
      BreadcrumbsWrapper wrapper = BreadcrumbsWrapper.getBreadcrumbsComponent(editor);
      if (isSuitable(textEditor, file)) {
        if (wrapper != null) {
          if (wrapper.breadcrumbs.above != above) {
            remove(fileEditorManager, fileEditor, wrapper);
            wrapper.breadcrumbs.above = above;
            add(fileEditorManager, fileEditor, wrapper);
          }
          wrapper.queueUpdate();
        }
        else {
          registerWrapper(fileEditorManager, fileEditor, new BreadcrumbsWrapper(editor));
        }
      }
      else if (wrapper != null) {
        disposeWrapper(fileEditorManager, fileEditor, wrapper);
      }
    }
  }
}
 
Example 2
Source File: FindManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean findNextUsageInFile(@Nonnull FileEditor fileEditor, @Nonnull SearchResults.Direction direction) {
  if (fileEditor instanceof TextEditor) {
    TextEditor textEditor = (TextEditor)fileEditor;
    Editor editor = textEditor.getEditor();
    editor.getCaretModel().removeSecondaryCarets();
    if (tryToFindNextUsageViaEditorSearchComponent(editor, direction)) {
      return true;
    }

    RangeHighlighter[] highlighters = ((HighlightManagerImpl)HighlightManager.getInstance(myProject)).getHighlighters(editor);
    if (highlighters.length > 0) {
      return highlightNextHighlighter(highlighters, editor, editor.getCaretModel().getOffset(), direction == SearchResults.Direction.DOWN, false);
    }
  }

  if (direction == SearchResults.Direction.DOWN) {
    return myFindUsagesManager.findNextUsageInFile(fileEditor);
  }
  return myFindUsagesManager.findPreviousUsageInFile(fileEditor);
}
 
Example 3
Source File: EditorUtils.java    From SmartIM4IntelliJ with Apache License 2.0 5 votes vote down vote up
public static Editor openTextEditor(Project project, VirtualFile virtualFile) {
    Editor editor = null;
    FileEditor[] fileEditors = FileEditorManager.getInstance(project).openFile(virtualFile, true);
    for (FileEditor fileEditor : fileEditors) {
        if (fileEditor instanceof TextEditor) {
            TextEditor textEditor = (TextEditor)fileEditor;
            editor = textEditor.getEditor();
        }
    }
    return editor;
}
 
Example 4
Source File: WidgetEditToolbar.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
Editor getCurrentEditor() {
  final VirtualFile file = activeFile.getValue();
  if (file == null) return null;

  final FileEditor fileEditor = FileEditorManager.getInstance(project).getSelectedEditor(file);
  if (fileEditor instanceof TextEditor) {
    final TextEditor textEditor = (TextEditor)fileEditor;
    final Editor editor = textEditor.getEditor();
    if (!editor.isDisposed()) {
      return editor;
    }
  }
  return null;
}
 
Example 5
Source File: FlutterSampleNotificationProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(
  @NotNull VirtualFile file, @NotNull FileEditor fileEditor, @NotNull Project project) {
  if (!(fileEditor instanceof TextEditor)) {
    return null;
  }

  final FlutterSdk sdk = FlutterSdk.getFlutterSdk(project);
  if (sdk == null) {
    return null;
  }

  final String flutterPackagePath = sdk.getHomePath() + "/packages/flutter/lib/src/";
  final String filePath = file.getPath();

  // Only show for files in the flutter sdk.
  if (!filePath.startsWith(flutterPackagePath)) {
    return null;
  }

  final TextEditor textEditor = (TextEditor)fileEditor;
  final Editor editor = textEditor.getEditor();
  final Document document = editor.getDocument();

  final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
  if (psiFile == null || !psiFile.isValid()) {
    return null;
  }

  // Run the code to query the document in a read action.
  final List<FlutterSample> samples = ApplicationManager.getApplication().
    runReadAction((Computable<List<FlutterSample>>)() -> {
      //noinspection CodeBlock2Expr
      return getSamplesFromDoc(flutterPackagePath, document, filePath);
    });

  return samples.isEmpty() ? null : new FlutterSampleActionsPanel(samples);
}
 
Example 6
Source File: WidgetEditToolbar.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
Editor getCurrentEditor() {
  final VirtualFile file = activeFile.getValue();
  if (file == null) return null;

  final FileEditor fileEditor = FileEditorManager.getInstance(project).getSelectedEditor(file);
  if (fileEditor instanceof TextEditor) {
    final TextEditor textEditor = (TextEditor)fileEditor;
    final Editor editor = textEditor.getEditor();
    if (!editor.isDisposed()) {
      return editor;
    }
  }
  return null;
}
 
Example 7
Source File: FlutterSampleNotificationProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(
  @NotNull VirtualFile file, @NotNull FileEditor fileEditor, @NotNull Project project) {
  if (!(fileEditor instanceof TextEditor)) {
    return null;
  }

  final FlutterSdk sdk = FlutterSdk.getFlutterSdk(project);
  if (sdk == null) {
    return null;
  }

  final String flutterPackagePath = sdk.getHomePath() + "/packages/flutter/lib/src/";
  final String filePath = file.getPath();

  // Only show for files in the flutter sdk.
  if (!filePath.startsWith(flutterPackagePath)) {
    return null;
  }

  final TextEditor textEditor = (TextEditor)fileEditor;
  final Editor editor = textEditor.getEditor();
  final Document document = editor.getDocument();

  final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
  if (psiFile == null || !psiFile.isValid()) {
    return null;
  }

  // Run the code to query the document in a read action.
  final List<FlutterSample> samples = ApplicationManager.getApplication().
    runReadAction((Computable<List<FlutterSample>>)() -> {
      //noinspection CodeBlock2Expr
      return getSamplesFromDoc(flutterPackagePath, document, filePath);
    });

  return samples.isEmpty() ? null : new FlutterSampleActionsPanel(samples);
}
 
Example 8
Source File: CodeGeneratorController.java    From android-codegenerator-plugin-intellij with Apache License 2.0 5 votes vote down vote up
private Editor getEditor(Project project, Editor editor, VirtualFile file) {
    if (editor == null) {
        TextEditor textEditor = getTextEditor(project, file);
        if (textEditor != null) {
            return textEditor.getEditor();
        }
    }
    return editor;
}
 
Example 9
Source File: FindUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void searchBack(Project project, FileEditor fileEditor, @Nullable DataContext dataContext) {
  if (!(fileEditor instanceof TextEditor)) return;
  TextEditor textEditor = (TextEditor)fileEditor;
  Editor editor = textEditor.getEditor();

  searchBack(project, editor, dataContext);
}
 
Example 10
Source File: FindUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean searchAgain(Project project, FileEditor fileEditor, @Nullable DataContext context) {
  if (!(fileEditor instanceof TextEditor)) return false;
  TextEditor textEditor = (TextEditor)fileEditor;
  Editor editor = textEditor.getEditor();

  return searchAgain(project, editor, context);
}
 
Example 11
Source File: FindManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void findUsagesInEditor(@Nonnull PsiElement element, @Nonnull FileEditor fileEditor) {
  if (fileEditor instanceof TextEditor) {
    TextEditor textEditor = (TextEditor)fileEditor;
    Editor editor = textEditor.getEditor();
    Document document = editor.getDocument();
    PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(document);

    myFindUsagesManager.findUsages(element, psiFile, fileEditor, false, null);
  }
}