Search in sources :

Example 26 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.

the class EditorFixture method moveToLine.

/**
   * Moves the caret to the start of the given line number (0-based).
   *
   * @param lineNumber the line number.
   */
@NotNull
public EditorFixture moveToLine(final int lineNumber) {
    assertThat(lineNumber).isGreaterThanOrEqualTo(0);
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            // TODO: Do this via mouse clicks!
            FileEditorManager manager = FileEditorManager.getInstance(myFrame.getProject());
            Editor editor = manager.getSelectedTextEditor();
            if (editor != null) {
                Document document = editor.getDocument();
                int offset = document.getLineStartOffset(lineNumber);
                editor.getCaretModel().moveToOffset(offset);
                editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
            }
        }
    });
    return this;
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.

the class LightPlatformCodeInsightTestCase method tearDown.

@Override
protected void tearDown() throws Exception {
    try {
        FileEditorManager editorManager = FileEditorManager.getInstance(getProject());
        for (VirtualFile openFile : editorManager.getOpenFiles()) {
            editorManager.closeFile(openFile);
        }
        deleteVFile();
        myEditor = null;
        myFile = null;
        myVFile = null;
    } finally {
        super.tearDown();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager)

Example 28 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.

the class SrcFileAnnotator method showEditorWarningMessage.

private void showEditorWarningMessage(final String message) {
    Editor textEditor = myEditor;
    PsiFile file = myFile;
    ApplicationManager.getApplication().invokeLater(() -> {
        if (textEditor == null || textEditor.isDisposed() || file == null)
            return;
        final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
        final VirtualFile vFile = file.getVirtualFile();
        assert vFile != null;
        Map<FileEditor, EditorNotificationPanel> map = file.getCopyableUserData(NOTIFICATION_PANELS);
        if (map == null) {
            map = new HashMap<>();
            file.putCopyableUserData(NOTIFICATION_PANELS, map);
        }
        final FileEditor[] editors = fileEditorManager.getAllEditors(vFile);
        for (final FileEditor editor : editors) {
            if (isCurrentEditor(editor)) {
                final EditorNotificationPanel panel = new EditorNotificationPanel() {

                    {
                        myLabel.setIcon(AllIcons.General.ExclMark);
                        myLabel.setText(message);
                    }
                };
                panel.createActionLabel("Close", () -> fileEditorManager.removeTopComponent(editor, panel));
                map.put(editor, panel);
                fileEditorManager.addTopComponent(editor, panel);
                break;
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) EditorNotificationPanel(com.intellij.ui.EditorNotificationPanel) PsiFile(com.intellij.psi.PsiFile) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Editor(com.intellij.openapi.editor.Editor)

Example 29 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.

the class HighlightUtils method showRenameTemplate.

public static void showRenameTemplate(PsiElement context, PsiNameIdentifierOwner element, PsiReference... references) {
    context = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(context);
    final Project project = context.getProject();
    final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
    final Editor editor = fileEditorManager.getSelectedTextEditor();
    if (editor == null) {
        return;
    }
    final TemplateBuilderImpl builder = new TemplateBuilderImpl(context);
    final Expression macroCallNode = new MacroCallNode(new SuggestVariableNameMacro());
    final PsiElement identifier = element.getNameIdentifier();
    builder.replaceElement(identifier, "PATTERN", macroCallNode, true);
    for (PsiReference reference : references) {
        builder.replaceElement(reference, "PATTERN", "PATTERN", false);
    }
    final Template template = builder.buildInlineTemplate();
    final TextRange textRange = context.getTextRange();
    final int startOffset = textRange.getStartOffset();
    editor.getCaretModel().moveToOffset(startOffset);
    final TemplateManager templateManager = TemplateManager.getInstance(project);
    templateManager.startTemplate(editor, template);
}
Also used : PsiReference(com.intellij.psi.PsiReference) TextRange(com.intellij.openapi.util.TextRange) Template(com.intellij.codeInsight.template.Template) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) TemplateBuilderImpl(com.intellij.codeInsight.template.TemplateBuilderImpl) Expression(com.intellij.codeInsight.template.Expression) TemplateManager(com.intellij.codeInsight.template.TemplateManager) SuggestVariableNameMacro(com.intellij.codeInsight.template.macro.SuggestVariableNameMacro) MacroCallNode(com.intellij.codeInsight.template.impl.MacroCallNode) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement)

Example 30 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-community by JetBrains.

the class MoveDeclarationIntention method highlightElement.

private static void highlightElement(@NotNull PsiElement element) {
    final Project project = element.getProject();
    final FileEditorManager editorManager = FileEditorManager.getInstance(project);
    final HighlightManager highlightManager = HighlightManager.getInstance(project);
    final EditorColorsManager editorColorsManager = EditorColorsManager.getInstance();
    final Editor editor = editorManager.getSelectedTextEditor();
    final EditorColorsScheme globalScheme = editorColorsManager.getGlobalScheme();
    final TextAttributes textattributes = globalScheme.getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
    final PsiElement[] elements = new PsiElement[] { element };
    highlightManager.addOccurrenceHighlights(editor, elements, textattributes, true, null);
    StatusBar.Info.set(IntentionPowerPackBundle.message("status.bar.escape.highlighting.message"), project);
}
Also used : Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) Editor(com.intellij.openapi.editor.Editor)

Aggregations

FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)66 VirtualFile (com.intellij.openapi.vfs.VirtualFile)35 FileEditor (com.intellij.openapi.fileEditor.FileEditor)29 Editor (com.intellij.openapi.editor.Editor)22 Project (com.intellij.openapi.project.Project)21 TextEditor (com.intellij.openapi.fileEditor.TextEditor)12 PsiFile (com.intellij.psi.PsiFile)10 Document (com.intellij.openapi.editor.Document)9 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)9 Nullable (org.jetbrains.annotations.Nullable)8 TextRange (com.intellij.openapi.util.TextRange)6 NotNull (org.jetbrains.annotations.NotNull)6 FileEditorManagerListener (com.intellij.openapi.fileEditor.FileEditorManagerListener)5 PsiElement (com.intellij.psi.PsiElement)5 StructureViewComponent (com.intellij.ide.structureView.newStructureView.StructureViewComponent)4 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)4 GuiTask (org.fest.swing.edt.GuiTask)4 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)3 ResourceBundleAsVirtualFile (com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile)3 PsiClass (com.intellij.psi.PsiClass)3