Search in sources :

Example 16 with EditorFactory

use of com.intellij.openapi.editor.EditorFactory in project intellij-community by JetBrains.

the class SearchDialog method createEditor.

protected Editor createEditor(final SearchContext searchContext, String text) {
    Editor editor = null;
    if (fileTypes != null) {
        final FileType fileType = (FileType) fileTypes.getSelectedItem();
        final Language dialect = (Language) dialects.getSelectedItem();
        final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByFileType(fileType);
        if (profile != null) {
            editor = profile.createEditor(searchContext, fileType, dialect, text, useLastConfiguration);
        }
    }
    if (editor == null) {
        final EditorFactory factory = EditorFactory.getInstance();
        final Document document = factory.createDocument("");
        editor = factory.createEditor(document, searchContext.getProject());
        editor.getSettings().setFoldingOutlineShown(false);
    }
    editor.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void beforeDocumentChange(final DocumentEvent event) {
        }

        @Override
        public void documentChanged(final DocumentEvent event) {
            initiateValidation();
        }
    });
    return editor;
}
Also used : DocumentListener(com.intellij.openapi.editor.event.DocumentListener) EditorFactory(com.intellij.openapi.editor.EditorFactory) Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Editor(com.intellij.openapi.editor.Editor) Document(com.intellij.openapi.editor.Document) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Example 17 with EditorFactory

use of com.intellij.openapi.editor.EditorFactory in project intellij-community by JetBrains.

the class GuiEditor method showFormSource.

public void showFormSource() {
    EditorFactory editorFactory = EditorFactory.getInstance();
    Editor editor = editorFactory.createViewer(myDocument, myProject);
    try {
        ((EditorEx) editor).setHighlighter(new LexerEditorHighlighter(new XmlFileHighlighter(), EditorColorsManager.getInstance().getGlobalScheme()));
        JComponent component = editor.getComponent();
        component.setPreferredSize(new Dimension(640, 480));
        DialogBuilder dialog = new DialogBuilder(myProject);
        dialog.title("Form - " + myFile.getPresentableName()).dimensionKey("GuiDesigner.FormSource.Dialog");
        dialog.centerPanel(component).setPreferredFocusComponent(editor.getContentComponent());
        dialog.addOkAction();
        dialog.show();
    } finally {
        editorFactory.releaseEditor(editor);
    }
}
Also used : EditorFactory(com.intellij.openapi.editor.EditorFactory) EditorEx(com.intellij.openapi.editor.ex.EditorEx) LexerEditorHighlighter(com.intellij.openapi.editor.ex.util.LexerEditorHighlighter) XmlFileHighlighter(com.intellij.ide.highlighter.XmlFileHighlighter) UIFormEditor(com.intellij.uiDesigner.editor.UIFormEditor) Editor(com.intellij.openapi.editor.Editor) DialogBuilder(com.intellij.openapi.ui.DialogBuilder)

Example 18 with EditorFactory

use of com.intellij.openapi.editor.EditorFactory in project intellij-community by JetBrains.

the class ConfigProjectComponent method runActivity.

@Override
public void runActivity(@NotNull Project project) {
    // Register project-level config managers
    final EditorFactory editorFactory = EditorFactory.getInstance();
    MessageBus bus = project.getMessageBus();
    EditorSettingsManager editorSettingsManager = new EditorSettingsManager(project);
    EncodingManager encodingManager = new EncodingManager(project);
    LineEndingsManager lineEndingsManager = new LineEndingsManager(project);
    bus.connect().subscribe(AppTopics.FILE_DOCUMENT_SYNC, encodingManager);
    bus.connect().subscribe(AppTopics.FILE_DOCUMENT_SYNC, editorSettingsManager);
    bus.connect().subscribe(AppTopics.FILE_DOCUMENT_SYNC, lineEndingsManager);
    VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileAdapter() {

        @Override
        public void fileCreated(@NotNull VirtualFileEvent event) {
            updateOpenEditors(event);
        }

        @Override
        public void fileDeleted(@NotNull VirtualFileEvent event) {
            updateOpenEditors(event);
        }

        @Override
        public void contentsChanged(@NotNull VirtualFileEvent event) {
            updateOpenEditors(event);
        }

        private void updateOpenEditors(VirtualFileEvent event) {
            final VirtualFile file = event.getFile();
            if (".editorconfig".equals(file.getName())) {
                if (ProjectRootManager.getInstance(project).getFileIndex().isInContent(file) || !Registry.is("editor.config.stop.at.project.root")) {
                    for (Editor editor : editorFactory.getAllEditors()) {
                        if (editor.isDisposed())
                            continue;
                        ;
                        ((EditorEx) editor).reinitSettings();
                    }
                }
            }
        }
    }, project);
}
Also used : EncodingManager(org.editorconfig.configmanagement.EncodingManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) EditorFactory(com.intellij.openapi.editor.EditorFactory) MessageBus(com.intellij.util.messages.MessageBus) EditorSettingsManager(org.editorconfig.configmanagement.EditorSettingsManager) VirtualFileEvent(com.intellij.openapi.vfs.VirtualFileEvent) LineEndingsManager(org.editorconfig.configmanagement.LineEndingsManager) Editor(com.intellij.openapi.editor.Editor) VirtualFileAdapter(com.intellij.openapi.vfs.VirtualFileAdapter)

Example 19 with EditorFactory

use of com.intellij.openapi.editor.EditorFactory in project intellij-community by JetBrains.

the class StructuralSearchProfile method createEditor.

@NotNull
public Editor createEditor(@NotNull SearchContext searchContext, @NotNull FileType fileType, Language dialect, String text, boolean useLastConfiguration) {
    PsiFile codeFragment = createCodeFragment(searchContext.getProject(), text, null);
    if (codeFragment == null) {
        codeFragment = createFileFragment(searchContext, fileType, dialect, text);
    }
    if (codeFragment != null) {
        final Document doc = PsiDocumentManager.getInstance(searchContext.getProject()).getDocument(codeFragment);
        assert doc != null : "code fragment element should be physical";
        DaemonCodeAnalyzer.getInstance(searchContext.getProject()).setHighlightingEnabled(codeFragment, false);
        return UIUtil.createEditor(doc, searchContext.getProject(), true, true, getTemplateContextType());
    }
    final EditorFactory factory = EditorFactory.getInstance();
    final Document document = factory.createDocument(text);
    final EditorEx editor = (EditorEx) factory.createEditor(document, searchContext.getProject());
    editor.getSettings().setFoldingOutlineShown(false);
    return editor;
}
Also used : EditorFactory(com.intellij.openapi.editor.EditorFactory) EditorEx(com.intellij.openapi.editor.ex.EditorEx) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with EditorFactory

use of com.intellij.openapi.editor.EditorFactory in project intellij-community by JetBrains.

the class PyQuickFixUtil method getEditor.

@Nullable
public static Editor getEditor(@NotNull PsiElement element) {
    Document document = PsiDocumentManager.getInstance(element.getProject()).getDocument(element.getContainingFile());
    if (document != null) {
        final EditorFactory instance = EditorFactory.getInstance();
        if (instance == null)
            return null;
        Editor[] editors = instance.getEditors(document);
        if (editors.length > 0) {
            return editors[0];
        }
    }
    return null;
}
Also used : EditorFactory(com.intellij.openapi.editor.EditorFactory) Document(com.intellij.openapi.editor.Document) Editor(com.intellij.openapi.editor.Editor) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

EditorFactory (com.intellij.openapi.editor.EditorFactory)21 Document (com.intellij.openapi.editor.Document)15 EditorEx (com.intellij.openapi.editor.ex.EditorEx)11 Editor (com.intellij.openapi.editor.Editor)10 Disposable (com.intellij.openapi.Disposable)5 EditorSettings (com.intellij.openapi.editor.EditorSettings)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 NotNull (org.jetbrains.annotations.NotNull)3 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)2 EmptyBorder (javax.swing.border.EmptyBorder)2 CodeStyleFacade (com.intellij.codeStyle.CodeStyleFacade)1 CommanderPanel (com.intellij.ide.commander.CommanderPanel)1 XmlFileHighlighter (com.intellij.ide.highlighter.XmlFileHighlighter)1 StartupManagerImpl (com.intellij.ide.startup.impl.StartupManagerImpl)1 StructureViewBuilder (com.intellij.ide.structureView.StructureViewBuilder)1 StructureViewModel (com.intellij.ide.structureView.StructureViewModel)1 TreeBasedStructureViewBuilder (com.intellij.ide.structureView.TreeBasedStructureViewBuilder)1 FileStructureDialog (com.intellij.ide.util.FileStructureDialog)1 com.intellij.lang (com.intellij.lang)1 Language (com.intellij.lang.Language)1