Search in sources :

Example 1 with TextViewerAction

use of org.tigris.subversion.subclipse.ui.console.TextViewerAction in project subclipse by subclipse.

the class SVNHistoryPage method createText.

/**
 * Create the TextViewer for the logEntry comments
 */
protected void createText(Composite parent) {
    // this.textViewer = new TextViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI |
    // SWT.READ_ONLY);
    SourceViewer result = new SourceViewer(parent, null, null, true, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.READ_ONLY);
    result.getTextWidget().setIndent(2);
    result.configure(new TextSourceViewerConfiguration(EditorsUI.getPreferenceStore()) {

        public Map getHyperlinkDetectorTargets(ISourceViewer sourceViewer) {
            return Collections.singletonMap(// $NON-NLS-1$
            "org.eclipse.ui.DefaultTextEditor.Subclipse", new IAdaptable() {

                public Object getAdapter(Class adapter) {
                    if (adapter == IResource.class && getInput() instanceof IResource) {
                        return getInput();
                    } else if (adapter == ISVNRemoteResource.class && getInput() instanceof ISVNRemoteResource) {
                        return getInput();
                    }
                    return Platform.getAdapterManager().getAdapter(SVNHistoryPage.this, adapter);
                }
            });
        }

        public int getHyperlinkStateMask(ISourceViewer sourceViewer) {
            return SWT.NONE;
        }

        public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
            IHyperlinkDetector[] detectors = super.getHyperlinkDetectors(sourceViewer);
            IHyperlinkDetector[] newDetectors;
            if (detectors == null) {
                newDetectors = new IHyperlinkDetector[1];
            } else {
                newDetectors = new IHyperlinkDetector[detectors.length + 1];
                System.arraycopy(detectors, 0, newDetectors, 0, detectors.length);
            }
            newDetectors[newDetectors.length - 1] = new IHyperlinkDetector() {

                public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
                    if (linkList == null || !linkList.isLinkAt(region.getOffset())) {
                        return null;
                    }
                    final String linkUrl = linkList.getLinkAt(region.getOffset());
                    final int[] linkRange = linkList.getLinkRange(region.getOffset());
                    return new IHyperlink[] { new IHyperlink() {

                        public IRegion getHyperlinkRegion() {
                            return new Region(linkRange[0], linkRange[1]);
                        }

                        public void open() {
                            try {
                                URL url = new URL(linkUrl);
                                PlatformUI.getWorkbench().getBrowserSupport().createBrowser("Subclipse").openURL(// $NON-NLS-1$
                                url);
                            } catch (Exception e1) {
                                Program.launch(linkUrl);
                            }
                        }

                        public String getHyperlinkText() {
                            return null;
                        }

                        public String getTypeLabel() {
                            return null;
                        }
                    } };
                }
            };
            return newDetectors;
        }
    });
    this.textViewer = result;
    this.textViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            copyAction.update();
        }
    });
    Font font = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry().get(ISVNUIConstants.SVN_COMMENT_FONT);
    if (font != null) {
        this.textViewer.getTextWidget().setFont(font);
    }
    // Create actions for the text editor (copy and select all)
    copyAction = new TextViewerAction(this.textViewer, ITextOperationTarget.COPY);
    // $NON-NLS-1$
    copyAction.setText(Policy.bind("HistoryView.copy"));
    selectAllAction = new TextViewerAction(this.textViewer, ITextOperationTarget.SELECT_ALL);
    // $NON-NLS-1$
    selectAllAction.setText(Policy.bind("HistoryView.selectAll"));
    IHistoryPageSite parentSite = getHistoryPageSite();
    IPageSite pageSite = parentSite.getWorkbenchPageSite();
    IActionBars actionBars = pageSite.getActionBars();
    actionBars.setGlobalActionHandler(ITextEditorActionConstants.COPY, copyAction);
    actionBars.setGlobalActionHandler(ITextEditorActionConstants.SELECT_ALL, selectAllAction);
    actionBars.updateActionBars();
    // Contribute actions to popup menu for the comments area
    {
        MenuManager menuMgr = new MenuManager();
        menuMgr.setRemoveAllWhenShown(true);
        menuMgr.addMenuListener(new IMenuListener() {

            public void menuAboutToShow(IMenuManager menuMgr) {
                menuMgr.add(copyAction);
                menuMgr.add(selectAllAction);
            }
        });
        StyledText text = this.textViewer.getTextWidget();
        Menu menu = menuMgr.createContextMenu(text);
        text.setMenu(menu);
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) SourceViewer(org.eclipse.jface.text.source.SourceViewer) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IPageSite(org.eclipse.ui.part.IPageSite) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IHistoryPageSite(org.eclipse.team.ui.history.IHistoryPageSite) IRegion(org.eclipse.jface.text.IRegion) URL(java.net.URL) Font(org.eclipse.swt.graphics.Font) Menu(org.eclipse.swt.widgets.Menu) IActionBars(org.eclipse.ui.IActionBars) TextSourceViewerConfiguration(org.eclipse.ui.editors.text.TextSourceViewerConfiguration) StyledText(org.eclipse.swt.custom.StyledText) IHyperlinkDetector(org.eclipse.jface.text.hyperlink.IHyperlinkDetector) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ISVNRemoteResource(org.tigris.subversion.subclipse.core.ISVNRemoteResource) TextViewerAction(org.tigris.subversion.subclipse.ui.console.TextViewerAction) CoreException(org.eclipse.core.runtime.CoreException) SVNException(org.tigris.subversion.subclipse.core.SVNException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TeamException(org.eclipse.team.core.TeamException) ParseException(java.text.ParseException) IMenuListener(org.eclipse.jface.action.IMenuListener) ITextViewer(org.eclipse.jface.text.ITextViewer) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IMenuManager(org.eclipse.jface.action.IMenuManager) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) Map(java.util.Map) IResource(org.eclipse.core.resources.IResource)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URL (java.net.URL)1 ParseException (java.text.ParseException)1 Map (java.util.Map)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 IMenuListener (org.eclipse.jface.action.IMenuListener)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 MenuManager (org.eclipse.jface.action.MenuManager)1 IRegion (org.eclipse.jface.text.IRegion)1 ITextViewer (org.eclipse.jface.text.ITextViewer)1 Region (org.eclipse.jface.text.Region)1 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)1 IHyperlinkDetector (org.eclipse.jface.text.hyperlink.IHyperlinkDetector)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 SourceViewer (org.eclipse.jface.text.source.SourceViewer)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StyledText (org.eclipse.swt.custom.StyledText)1