private AbstractTextEditor getActiveTextEditor(ExecutionEvent event) { IWorkbenchPart part= HandlerUtil.getActiveEditor(event); if (part instanceof AbstractTextEditor) { return (AbstractTextEditor)part; } else if ((part instanceof AbstractMultiEditor) && ((AbstractMultiEditor)part).getActiveEditor() instanceof AbstractTextEditor) { return (AbstractTextEditor)((AbstractMultiEditor)part).getActiveEditor(); } else if ((part instanceof MultiPageEditorPart) && ((MultiPageEditorPart)part).getSelectedPage() instanceof AbstractTextEditor) { return (AbstractTextEditor)((MultiPageEditorPart)part).getSelectedPage(); } return null; }
private AbstractTextEditor getActiveTextEditor(IEditorPart part) { if (part instanceof AbstractTextEditor) { return (AbstractTextEditor)part; } else if ((part instanceof AbstractMultiEditor) && ((AbstractMultiEditor)part).getActiveEditor() instanceof AbstractTextEditor) { return (AbstractTextEditor)((AbstractMultiEditor)part).getActiveEditor(); } else if ((part instanceof MultiPageEditorPart) && ((MultiPageEditorPart)part).getSelectedPage() instanceof AbstractTextEditor) { return (AbstractTextEditor)((MultiPageEditorPart)part).getSelectedPage(); } return part != null ? part.getAdapter(AbstractTextEditor.class) : null; }
public static ISourceViewer fromEditorPart(IEditorPart editorPart) { Object activeEditor = editorPart; if (editorPart instanceof MultiPageEditorPart) { MultiPageEditorPart multiPageEditorPart = (MultiPageEditorPart) editorPart; activeEditor = multiPageEditorPart.getSelectedPage(); } if (activeEditor instanceof AbstractTextEditor) { return fromAbstractTextEditor((AbstractTextEditor) activeEditor); } else { logger.info("Unable to get ISourceViewer from " + editorPart + " of type " + editorPart.getClass().getCanonicalName()); return null; } }
@Override public IEditorInput getActiveEditorInput() { IEditorPart editor= getActiveEditor(); if (editor == null) return null; // Handle multi-page editors if (editor instanceof MultiPageEditorPart) { Object page= ((MultiPageEditorPart)editor).getSelectedPage(); if (page instanceof IEditorPart) editor= (IEditorPart)page; else return null; } return editor.getEditorInput(); }
public MultiPageMinimapPage(MultiPageEditorPart multiPageEditor) { this.fMultiPageEditor = multiPageEditor; this.fTextWidgetMap = new HashMap<>(); this.fPageChangedListener = e -> { Object selectedPage = multiPageEditor.getSelectedPage(); // Find from cache the minimap for the selected page Control textWidget = fTextWidgetMap.get(selectedPage); if (textWidget != null) { fPageBook.showPage(textWidget); return; } MinimapPage minimapPage = null; if (selectedPage instanceof ITextEditor) { // Create and show a minimap page for the given text editor page ITextEditor textEditor = (ITextEditor) selectedPage; minimapPage = MinimapPage.createMinimapPage(textEditor); } if (minimapPage != null) { minimapPage.createControl(fPageBook); textWidget = minimapPage.getControl(); fTextWidgetMap.put(selectedPage, textWidget); fPageBook.showPage(textWidget); } else { fTextWidgetMap.put(selectedPage, fErrorLabel); fPageBook.showPage(fErrorLabel); } }; multiPageEditor.addPageChangedListener(fPageChangedListener); }
Object selectedPage = getSelectedPage(); if (selectedPage != null) { firePageChanged(new PageChangedEvent(this, selectedPage));