Search in sources :

Example 6 with FileEditorManagerListener

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

the class EditorWindow method closeFile.

public void closeFile(@NotNull final VirtualFile file, final boolean disposeIfNeeded, final boolean transferFocus) {
    final FileEditorManagerImpl editorManager = getManager();
    editorManager.runChange(splitters -> {
        final List<EditorWithProviderComposite> editors = splitters.findEditorComposites(file);
        if (editors.isEmpty())
            return;
        try {
            final EditorWithProviderComposite editor = findFileComposite(file);
            final FileEditorManagerListener.Before beforePublisher = editorManager.getProject().getMessageBus().syncPublisher(FileEditorManagerListener.Before.FILE_EDITOR_MANAGER);
            beforePublisher.beforeFileClosed(editorManager, file);
            if (myTabbedPane != null && editor != null) {
                final int componentIndex = findComponentIndex(editor.getComponent());
                if (componentIndex >= 0) {
                    final int indexToSelect = calcIndexToSelect(file, componentIndex);
                    Pair<String, Integer> pair = Pair.create(file.getUrl(), componentIndex);
                    myRemovedTabs.push(pair);
                    if (myTabsHidingInProgress.get()) {
                        myHiddenTabs.push(pair);
                    }
                    myTabbedPane.removeTabAt(componentIndex, indexToSelect, transferFocus);
                    editorManager.disposeComposite(editor);
                }
            } else {
                if (inSplitter()) {
                    Splitter splitter = (Splitter) myPanel.getParent();
                    JComponent otherComponent = splitter.getOtherComponent(myPanel);
                    if (otherComponent != null) {
                        IdeFocusManager.findInstance().requestFocus(otherComponent, true);
                    }
                }
                myPanel.removeAll();
                if (editor != null) {
                    editorManager.disposeComposite(editor);
                }
            }
            if (disposeIfNeeded && getTabCount() == 0) {
                removeFromSplitter();
                if (UISettings.getInstance().getEditorTabPlacement() == UISettings.TABS_NONE) {
                    final EditorsSplitters owner = getOwner();
                    if (owner != null) {
                        final ThreeComponentsSplitter splitter = UIUtil.getParentOfType(ThreeComponentsSplitter.class, owner);
                        if (splitter != null) {
                            splitter.revalidate();
                            splitter.repaint();
                        }
                    }
                }
            } else {
                myPanel.revalidate();
                if (myTabbedPane == null) {
                    myPanel.repaint();
                }
            }
        } finally {
            editorManager.removeSelectionRecord(file, this);
            editorManager.notifyPublisher(() -> {
                final Project project = editorManager.getProject();
                if (!project.isDisposed()) {
                    final FileEditorManagerListener afterPublisher = project.getMessageBus().syncPublisher(FileEditorManagerListener.FILE_EDITOR_MANAGER);
                    afterPublisher.fileClosed(editorManager, file);
                }
            });
            splitters.afterFileClosed(file);
        }
    }, myOwner);
}
Also used : ThreeComponentsSplitter(com.intellij.openapi.ui.ThreeComponentsSplitter) Splitter(com.intellij.openapi.ui.Splitter) OnePixelSplitter(com.intellij.ui.OnePixelSplitter) ThreeComponentsSplitter(com.intellij.openapi.ui.ThreeComponentsSplitter) Project(com.intellij.openapi.project.Project) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener)

Example 7 with FileEditorManagerListener

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

the class OutdatedVersionNotifier method projectOpened.

@Override
public void projectOpened() {
    final FileEditorManagerListener myFileEditorManagerListener = new MyFileEditorManagerListener();
    myFileEditorManager.addFileEditorManagerListener(myFileEditorManagerListener, myProject);
}
Also used : FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener)

Example 8 with FileEditorManagerListener

use of com.intellij.openapi.fileEditor.FileEditorManagerListener in project android by JetBrains.

the class FloatingToolWindowManagerTest method before.

@Before
public void before() {
    initMocks(this);
    KeyboardFocusManager.setCurrentKeyboardFocusManager(myKeyboardFocusManager);
    Project project = ProjectManager.getInstance().getDefaultProject();
    myEditorManager = FileEditorManager.getInstance(project);
    when(myWorkBench1.getFloatingToolWindows()).thenReturn(ImmutableList.of(myAttachedToolWindow1));
    when(myWorkBench2.getFloatingToolWindows()).thenReturn(ImmutableList.of(myAttachedToolWindow2));
    when(myAttachedToolWindow1.getDefinition()).thenReturn(PalettePanelToolContent.getDefinition());
    when(myAttachedToolWindow2.getDefinition()).thenReturn(PalettePanelToolContent.getOtherDefinition());
    when(myFloatingToolWindowFactory.create(any(Project.class), any(ToolWindowDefinition.class))).thenReturn(myFloatingToolWindow1, myFloatingToolWindow2, null);
    myManager = new FloatingToolWindowManager(ApplicationManager.getApplication(), project, StartupManager.getInstance(project), FileEditorManager.getInstance(project));
    myManager.initComponent();
    myManager.setFloatingToolWindowFactory(myFloatingToolWindowFactory);
    assert myManager.getComponentName().equals("FloatingToolWindowManager");
    when(myEditorManager.getSelectedEditors()).thenReturn(new FileEditor[0]);
    when(project.getMessageBus()).thenReturn(myMessageBus);
    when(myMessageBus.connect(eq(project))).thenReturn(myConnection).thenReturn(null);
    myManager.projectOpened();
    ArgumentCaptor<FileEditorManagerListener> captor = ArgumentCaptor.forClass(FileEditorManagerListener.class);
    //noinspection unchecked
    verify(myConnection).subscribe(any(Topic.class), captor.capture());
    when(myFileEditor1.getComponent()).thenReturn(new JPanel());
    when(myFileEditor2.getComponent()).thenReturn(new JPanel());
    myListener = captor.getValue();
    myManager.register(myFileEditor1, myWorkBench1);
    myManager.register(myFileEditor2, myWorkBench2);
}
Also used : Project(com.intellij.openapi.project.Project) Topic(com.intellij.util.messages.Topic) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) Before(org.junit.Before)

Example 9 with FileEditorManagerListener

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

the class EditorTracker method projectOpened.

@Override
public void projectOpened() {
    myIdeFrame = ((WindowManagerEx) myWindowManager).getFrame(myProject);
    myProject.getMessageBus().connect(myProject).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {

        @Override
        public void selectionChanged(@NotNull FileEditorManagerEvent event) {
            if (myIdeFrame == null || myIdeFrame.getFocusOwner() == null)
                return;
            setActiveWindow(myIdeFrame);
        }
    });
    final MyEditorFactoryListener myEditorFactoryListener = new MyEditorFactoryListener();
    myEditorFactory.addEditorFactoryListener(myEditorFactoryListener, myProject);
    Disposer.register(myProject, new Disposable() {

        @Override
        public void dispose() {
            myEditorFactoryListener.executeOnRelease(null);
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable) FileEditorManagerEvent(com.intellij.openapi.fileEditor.FileEditorManagerEvent) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener)

Example 10 with FileEditorManagerListener

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

the class BraceHighlighter method runActivity.

@Override
public void runActivity(@NotNull final Project project) {
    // sorry, upsource
    if (ApplicationManager.getApplication().isHeadlessEnvironment())
        return;
    final EditorEventMulticaster eventMulticaster = EditorFactory.getInstance().getEventMulticaster();
    CaretListener myCaretListener = new CaretAdapter() {

        @Override
        public void caretPositionChanged(CaretEvent e) {
            myAlarm.cancelAllRequests();
            Editor editor = e.getEditor();
            final SelectionModel selectionModel = editor.getSelectionModel();
            // Don't update braces in case of the active selection.
            if (editor.getProject() != project || selectionModel.hasSelection()) {
                return;
            }
            final Document document = editor.getDocument();
            int line = e.getNewPosition().line;
            if (line < 0 || line >= document.getLineCount()) {
                return;
            }
            updateBraces(editor, myAlarm);
        }
    };
    eventMulticaster.addCaretListener(myCaretListener, project);
    final SelectionListener mySelectionListener = new SelectionListener() {

        @Override
        public void selectionChanged(SelectionEvent e) {
            myAlarm.cancelAllRequests();
            Editor editor = e.getEditor();
            if (editor.getProject() != project) {
                return;
            }
            final TextRange oldRange = e.getOldRange();
            final TextRange newRange = e.getNewRange();
            if (oldRange != null && newRange != null && !(oldRange.isEmpty() ^ newRange.isEmpty())) {
                // Don't perform braces update in case of active/absent selection.
                return;
            }
            updateBraces(editor, myAlarm);
        }
    };
    eventMulticaster.addSelectionListener(mySelectionListener, project);
    DocumentListener documentListener = new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            myAlarm.cancelAllRequests();
            Editor[] editors = EditorFactory.getInstance().getEditors(e.getDocument(), project);
            for (Editor editor : editors) {
                updateBraces(editor, myAlarm);
            }
        }
    };
    eventMulticaster.addDocumentListener(documentListener, project);
    final FocusChangeListener myFocusChangeListener = new FocusChangeListener() {

        @Override
        public void focusLost(Editor editor) {
            clearBraces(editor);
        }

        @Override
        public void focusGained(Editor editor) {
            updateBraces(editor, myAlarm);
        }
    };
    ((EditorEventMulticasterEx) eventMulticaster).addFocusChangeListner(myFocusChangeListener, project);
    final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
    fileEditorManager.addFileEditorManagerListener(new FileEditorManagerListener() {

        @Override
        public void selectionChanged(@NotNull FileEditorManagerEvent e) {
            myAlarm.cancelAllRequests();
        }
    }, project);
}
Also used : TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) EditorEventMulticasterEx(com.intellij.openapi.editor.ex.EditorEventMulticasterEx) SelectionModel(com.intellij.openapi.editor.SelectionModel) Editor(com.intellij.openapi.editor.Editor) FileEditorManagerEvent(com.intellij.openapi.fileEditor.FileEditorManagerEvent) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) FocusChangeListener(com.intellij.openapi.editor.ex.FocusChangeListener)

Aggregations

FileEditorManagerListener (com.intellij.openapi.fileEditor.FileEditorManagerListener)13 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)5 FileEditorManagerEvent (com.intellij.openapi.fileEditor.FileEditorManagerEvent)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Project (com.intellij.openapi.project.Project)3 NotNull (org.jetbrains.annotations.NotNull)3 Document (com.intellij.openapi.editor.Document)2 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)2 Nullable (org.jetbrains.annotations.Nullable)2 ConsoleViewImpl (com.intellij.execution.impl.ConsoleViewImpl)1 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)1 CloseAction (com.intellij.execution.ui.actions.CloseAction)1 Disposable (com.intellij.openapi.Disposable)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 Editor (com.intellij.openapi.editor.Editor)1 SelectionModel (com.intellij.openapi.editor.SelectionModel)1 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)1 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)1 EditorEventMulticasterEx (com.intellij.openapi.editor.ex.EditorEventMulticasterEx)1 FocusChangeListener (com.intellij.openapi.editor.ex.FocusChangeListener)1