Example usage for com.intellij.openapi.fileEditor FileEditorManagerEvent getOldEditor

List of usage examples for com.intellij.openapi.fileEditor FileEditorManagerEvent getOldEditor

Introduction

In this page you can find the example usage for com.intellij.openapi.fileEditor FileEditorManagerEvent getOldEditor.

Prototype

@Nullable
    public FileEditor getOldEditor() 

Source Link

Usage

From source file:com.intellij.util.xml.ui.PerspectiveFileEditor.java

License:Apache License

protected PerspectiveFileEditor(final Project project, final VirtualFile file) {
    myProject = project;//from  w  w w  .ja  va  2  s .  c o m
    myUndoHelper = new UndoHelper(project, this);
    myFile = file;

    FileEditorManager.getInstance(myProject).addFileEditorManagerListener(new FileEditorManagerAdapter() {
        public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
            if (!isValid())
                return;

            ApplicationManager.getApplication().invokeLater(new Runnable() {
                public void run() {
                    if (myUndoHelper.isShowing() && !getComponent().isShowing()) {
                        deselectNotify();
                    } else if (!myUndoHelper.isShowing() && getComponent().isShowing()) {
                        selectNotify();
                    }
                }
            });

            final FileEditor oldEditor = event.getOldEditor();
            final FileEditor newEditor = event.getNewEditor();
            if (oldEditor == null || newEditor == null)
                return;
            if (oldEditor.getComponent().isShowing() && newEditor.getComponent().isShowing())
                return;

            if (PerspectiveFileEditor.this.equals(oldEditor)) {
                if (newEditor instanceof TextEditor) {
                    ensureInitialized();
                    setSelectionInTextEditor((TextEditor) newEditor, getSelectedDomElement());
                }
            } else if (PerspectiveFileEditor.this.equals(newEditor)) {
                if (oldEditor instanceof TextEditor) {
                    final DomElement element = getSelectedDomElementFromTextEditor((TextEditor) oldEditor);
                    if (element != null) {
                        ensureInitialized();
                        setSelectedDomElement(element);
                    }
                } else if (oldEditor instanceof PerspectiveFileEditor) {
                    ensureInitialized();
                    setSelectedDomElement(((PerspectiveFileEditor) oldEditor).getSelectedDomElement());
                }
            }
        }
    }, this);

    myUndoHelper.startListeningDocuments();

    final PsiFile psiFile = getPsiFile();
    if (psiFile != null) {
        final Document document = PsiDocumentManager.getInstance(getProject()).getDocument(psiFile);
        if (document != null) {
            addWatchedDocument(document);
        }
    }
}

From source file:com.weebly.opus1269.smoothscroller.FileEditorListener.java

License:Open Source License

@Override
public void selectionChanged(@NotNull FileEditorManagerEvent fileEditorManagerEvent) {
    FileEditor oldEditor = fileEditorManagerEvent.getOldEditor();
    FileEditor newEditor = fileEditorManagerEvent.getNewEditor();

    // stop animating old editor
    SmoothScrollerMouseWheelListener listener = mListeners.get(oldEditor);
    if (listener != null) {
        listener.stopAnimating();/*from  ww w.  j av  a 2  s.  co m*/
    }

    // start animating new editor, creating listener if needed
    if (newEditor instanceof TextEditor) {
        listener = mListeners.get(newEditor);
        if (listener == null) {
            listener = new SmoothScrollerMouseWheelListener(newEditor);
            mListeners.put(newEditor, listener);

            Editor editor = ((TextEditor) newEditor).getEditor();
            editor.getContentComponent().addMouseWheelListener(listener);
        }

        listener.startAnimating();
    }
}