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);
}
}
Aggregations