Search in sources :

Example 31 with EditorWindow

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

the class SplitAction method update.

public void update(final AnActionEvent event) {
    final Project project = event.getData(CommonDataKeys.PROJECT);
    final EditorWindow window = event.getData(EditorWindow.DATA_KEY);
    final int minimum = myCloseSource ? 2 : 1;
    final boolean enabled = project != null && window != null && window.getTabCount() >= minimum && !window.getOwner().isPreview();
    event.getPresentation().setEnabled(enabled);
}
Also used : Project(com.intellij.openapi.project.Project) EditorWindow(com.intellij.openapi.fileEditor.impl.EditorWindow)

Example 32 with EditorWindow

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

the class QuickEditHandler method navigate.

public void navigate(int injectedOffset) {
    if (myAction.isShowInBalloon()) {
        final JComponent component = myAction.createBalloonComponent(myNewFile);
        if (component != null)
            showBalloon(myEditor, myNewFile, component);
    } else {
        final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(myProject);
        final FileEditor[] editors = fileEditorManager.getEditors(myNewVirtualFile);
        if (editors.length == 0) {
            final EditorWindow curWindow = fileEditorManager.getCurrentWindow();
            mySplittedWindow = curWindow.split(SwingConstants.HORIZONTAL, false, myNewVirtualFile, true);
        }
        Editor editor = fileEditorManager.openTextEditor(new OpenFileDescriptor(myProject, myNewVirtualFile, injectedOffset), true);
        // fold missing values
        if (editor != null) {
            editor.putUserData(QuickEditAction.QUICK_EDIT_HANDLER, this);
            final FoldingModel foldingModel = editor.getFoldingModel();
            foldingModel.runBatchFoldingOperation(() -> {
                for (RangeMarker o : ContainerUtil.reverse(((DocumentEx) myNewDocument).getGuardedBlocks())) {
                    String replacement = o.getUserData(REPLACEMENT_KEY);
                    if (StringUtil.isEmpty(replacement))
                        continue;
                    FoldRegion region = foldingModel.addFoldRegion(o.getStartOffset(), o.getEndOffset(), replacement);
                    if (region != null)
                        region.setExpanded(false);
                }
            });
        }
        SwingUtilities.invokeLater(() -> myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE));
    }
}
Also used : FileEditor(com.intellij.openapi.fileEditor.FileEditor) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx) EditorWindow(com.intellij.openapi.fileEditor.impl.EditorWindow)

Example 33 with EditorWindow

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

the class FileDropHandler method findEditorWindow.

@Nullable
private EditorWindow findEditorWindow(Project project) {
    final Document document = myEditor.getDocument();
    final VirtualFile file = FileDocumentManager.getInstance().getFile(document);
    if (file != null) {
        final FileEditorManagerEx fileEditorManager = (FileEditorManagerEx) FileEditorManager.getInstance(project);
        final EditorWindow[] windows = fileEditorManager.getWindows();
        for (EditorWindow window : windows) {
            final EditorWithProviderComposite composite = window.findFileComposite(file);
            if (composite == null) {
                continue;
            }
            for (FileEditor editor : composite.getEditors()) {
                if (editor instanceof TextEditor && ((TextEditor) editor).getEditor() == myEditor) {
                    return window;
                }
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) EditorWithProviderComposite(com.intellij.openapi.fileEditor.impl.EditorWithProviderComposite) Document(com.intellij.openapi.editor.Document) FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx) EditorWindow(com.intellij.openapi.fileEditor.impl.EditorWindow) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

EditorWindow (com.intellij.openapi.fileEditor.impl.EditorWindow)33 FileEditorManagerEx (com.intellij.openapi.fileEditor.ex.FileEditorManagerEx)22 Project (com.intellij.openapi.project.Project)16 VirtualFile (com.intellij.openapi.vfs.VirtualFile)14 EditorWithProviderComposite (com.intellij.openapi.fileEditor.impl.EditorWithProviderComposite)5 FileEditor (com.intellij.openapi.fileEditor.FileEditor)3 EditorComposite (com.intellij.openapi.fileEditor.impl.EditorComposite)3 Pair (com.intellij.openapi.util.Pair)3 CommandProcessor (com.intellij.openapi.command.CommandProcessor)2 Document (com.intellij.openapi.editor.Document)2 FileColorManager (com.intellij.ui.FileColorManager)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 HprofEditor (com.android.tools.idea.editors.hprof.HprofEditor)1 Presentation (com.intellij.openapi.actionSystem.Presentation)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 TextEditor (com.intellij.openapi.fileEditor.TextEditor)1 EditorTabbedContainer (com.intellij.openapi.fileEditor.impl.EditorTabbedContainer)1 EditorsSplitters (com.intellij.openapi.fileEditor.impl.EditorsSplitters)1