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

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

Introduction

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

Prototype

@Nullable
    public FileEditor getNewEditor() 

Source Link

Usage

From source file:com.chrisrm.idea.tabs.MTTabsPainterPatcherComponent.java

License:Open Source License

@Override
public void initComponent() {
    final MessageBus bus = ApplicationManagerEx.getApplicationEx().getMessageBus();

    final MessageBusConnection connect = bus.connect();
    connect.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {
        @Override//from   w  ww  .ja v  a  2 s  .  c  o  m
        public void selectionChanged(@NotNull final FileEditorManagerEvent event) {
            final FileEditor editor = event.getNewEditor();
            if (editor != null) {
                Component component = editor.getComponent();
                while (component != null) {
                    if (component instanceof JBEditorTabs) {
                        patchPainter((JBEditorTabs) component);
                        return;
                    }
                    component = component.getParent();
                }
            }
        }
    });

    // Listen to option save to set tab height
    setTabsHeight();
    connect.subscribe(ConfigNotifier.CONFIG_TOPIC, mtConfig -> setTabsHeight());

    try {
        hackTabsGetHeight();
        hackToolWindowHeader();
    } catch (final Exception e) {
        e.printStackTrace();
    }
}

From source file:com.intellij.ui.AutoScrollFromSourceHandler.java

License:Apache License

public void install() {
    final MessageBusConnection connection = myProject.getMessageBus().connect(myProject);
    connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() {
        @Override/* w w  w .j av  a  2 s  .  com*/
        public void selectionChanged(@NotNull FileEditorManagerEvent event) {
            final FileEditor editor = event.getNewEditor();
            if (editor != null && myComponent.isShowing() && isAutoScrollEnabled()) {
                myAlarm.cancelAllRequests();
                myAlarm.addRequest(new Runnable() {
                    @Override
                    public void run() {
                        selectElementFromEditor(editor);
                    }
                }, getAlarmDelay(), getModalityState());
            }
        }
    });
}

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 ww. ja  va2  s. co 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   w w  w.  j a  v a 2s  . c  om*/
    }

    // 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();
    }
}

From source file:io.flutter.coverage.FlutterLiveCoverageManager.java

License:Open Source License

private FileEditor editorFor(FileEditorManagerEvent event) {
    if (!(event.getNewEditor() instanceof TextEditor)) {
        return null;
    }//from w ww. j  a v  a2 s  .  c o m
    return event.getNewEditor();
}

From source file:io.flutter.preview.PreviewView.java

License:Open Source License

public PreviewView(@NotNull Project project) {
    this.project = project;

    flutterAnalysisServer = FlutterDartAnalysisServer.getInstance(project);

    if (FlutterSettings.getInstance().isShowPreviewArea()) {
        myRenderHelper = new RenderHelper(project, renderListener);
    } else {//from  ww w  .  j a  va  2s.co m
        myRenderHelper = null;
    }

    // Show preview for the file selected when the view is being opened.
    final VirtualFile[] selectedFiles = FileEditorManager.getInstance(project).getSelectedFiles();
    if (selectedFiles.length != 0) {
        setSelectedFile(selectedFiles[0]);
    }

    final FileEditor[] selectedEditors = FileEditorManager.getInstance(project).getSelectedEditors();
    if (selectedEditors.length != 0) {
        setSelectedEditor(selectedEditors[0]);
    }

    // Listen for selecting files.
    final MessageBusConnection bus = project.getMessageBus().connect(project);
    bus.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {
        @Override
        public void selectionChanged(@NotNull FileEditorManagerEvent event) {
            setSelectedFile(event.getNewFile());
            setSelectedEditor(event.getNewEditor());
        }
    });

    actionCenter = new QuickAssistAction("dart.assist.flutter.wrap.center", FlutterIcons.Center,
            "Center widget");
    actionPadding = new QuickAssistAction("dart.assist.flutter.wrap.padding", FlutterIcons.Padding,
            "Add padding");
    actionColumn = new QuickAssistAction("dart.assist.flutter.wrap.column", FlutterIcons.Column,
            "Wrap with Column");
    actionRow = new QuickAssistAction("dart.assist.flutter.wrap.row", FlutterIcons.Row, "Wrap with Row");
    actionMoveUp = new QuickAssistAction("dart.assist.flutter.move.up", FlutterIcons.Up, "Move widget up");
    actionMoveDown = new QuickAssistAction("dart.assist.flutter.move.down", FlutterIcons.Down,
            "Move widget down");
    actionRemove = new QuickAssistAction("dart.assist.flutter.removeWidget", FlutterIcons.RemoveWidget,
            "Remove widget");
    actionExtractMethod = new ExtractMethodAction();
}