Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 74848 Details for
Bug 197991
[IRC] Add hyperlink support for the word 'bug <#>'
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Patch to add new hyperlink support for bugs (II)
197991_2_patch.diff (text/plain), 6.63 KB, created by
Abner Ballardo
on 2007-07-27 23:25:47 EDT
(
hide
)
Description:
Patch to add new hyperlink support for bugs (II)
Filename:
MIME Type:
Creator:
Abner Ballardo
Created:
2007-07-27 23:25:47 EDT
Size:
6.63 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ecf.provider.irc.ui >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.ecf/plugins/org.eclipse.ecf.provider.irc.ui/plugin.xml,v >retrieving revision 1.6 >diff -u -r1.6 plugin.xml >--- plugin.xml 24 Jul 2007 15:25:19 -0000 1.6 >+++ plugin.xml 28 Jul 2007 03:10:20 -0000 >@@ -19,6 +19,13 @@ > name="%IRCHyperlinkDetector" > targetId="org.eclipse.ui.DefaultTextEditor"> > </hyperlinkDetector> >+ <hyperlinkDetector >+ activate="true" >+ class="org.eclipse.ecf.internal.irc.ui.hyperlink.BugHyperlinkDetector" >+ id="org.eclipse.ecf.internal.irc.ui.hyperlink.BugHyperlinkDetector" >+ name="Bug" >+ targetId="org.eclipse.ui.DefaultTextEditor"> >+ </hyperlinkDetector> > </extension> > <extension > point="org.eclipse.ui.popupMenus"> >Index: src/org/eclipse/ecf/internal/irc/ui/hyperlink/BugHyperlinkDetector.java >=================================================================== >RCS file: src/org/eclipse/ecf/internal/irc/ui/hyperlink/BugHyperlinkDetector.java >diff -N src/org/eclipse/ecf/internal/irc/ui/hyperlink/BugHyperlinkDetector.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/ecf/internal/irc/ui/hyperlink/BugHyperlinkDetector.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,98 @@ >+package org.eclipse.ecf.internal.irc.ui.hyperlink; >+ >+import java.util.StringTokenizer; >+ >+import org.eclipse.jface.text.BadLocationException; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.IRegion; >+import org.eclipse.jface.text.ITextViewer; >+import org.eclipse.jface.text.Region; >+import org.eclipse.jface.text.hyperlink.IHyperlink; >+ >+public class BugHyperlinkDetector extends >+ org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector { >+ >+ public static final String DEFAULT_PREFIX = "bug "; //$NON-NLS-1$ >+ public static final String DEFAULT_ENDDELIMITERS = " \t\n\r\f<>"; //$NON-NLS-1$ >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector#detectHyperlinks(org.eclipse.jface.text.ITextViewer, >+ * org.eclipse.jface.text.IRegion, boolean) >+ */ >+ public IHyperlink[] detectHyperlinks(ITextViewer textViewer, >+ IRegion region, boolean canShowMultipleHyperlinks) { >+ if (region == null || textViewer == null) >+ return null; >+ >+ IDocument document = textViewer.getDocument(); >+ if (document == null) >+ return null; >+ >+ int offset = region.getOffset(); >+ >+ IRegion lineInfo; >+ String line; >+ try { >+ lineInfo = document.getLineInformationOfOffset(offset); >+ line = document.get(lineInfo.getOffset(), lineInfo.getLength()); >+ } catch (BadLocationException ex) { >+ return null; >+ } >+ >+ String detectedSubstring = detectSubstring(line, offset >+ - lineInfo.getOffset()); >+ String bugNumber = detectedSubstring.substring(DEFAULT_PREFIX.length()); >+ >+ if (detectedSubstring != null && isBugNumber(bugNumber)) >+ return createHyperLinksForBug(bugNumber, new Region( >+ lineInfo.getOffset() + line.indexOf(detectedSubstring), >+ detectedSubstring.length())); >+ >+ return null; >+ } >+ >+ private boolean isBugNumber(String bug) { >+ try { >+ Integer.parseInt(bug); >+ return true; >+ } catch (NumberFormatException e) { >+ } >+ >+ return false; >+ } >+ >+ private IHyperlink[] createHyperLinksForBug(String bugNumber, Region region) { >+ return new IHyperlink[] { new BugHyperlink(bugNumber, region) }; >+ } >+ >+ private String detectSubstring(String fromLine, int offsetInLine) { >+ int resultLength = 0; >+ >+ int separatorOffset = fromLine.indexOf(DEFAULT_PREFIX); >+ while (separatorOffset >= 0) { >+ StringTokenizer tokenizer = new StringTokenizer(fromLine >+ .substring(separatorOffset + DEFAULT_PREFIX.length()), >+ DEFAULT_ENDDELIMITERS, false); >+ if (!tokenizer.hasMoreTokens()) >+ return null; >+ >+ resultLength = tokenizer.nextToken().length() >+ + DEFAULT_PREFIX.length(); >+ if (offsetInLine >= separatorOffset >+ && offsetInLine <= separatorOffset + resultLength) >+ break; >+ >+ separatorOffset = fromLine.indexOf(DEFAULT_PREFIX, >+ separatorOffset + 1); >+ } >+ >+ if (separatorOffset < 0) >+ return null; >+ >+ return fromLine.substring(separatorOffset, separatorOffset >+ + resultLength); >+ } >+ >+} >Index: src/org/eclipse/ecf/internal/irc/ui/hyperlink/BugHyperlink.java >=================================================================== >RCS file: src/org/eclipse/ecf/internal/irc/ui/hyperlink/BugHyperlink.java >diff -N src/org/eclipse/ecf/internal/irc/ui/hyperlink/BugHyperlink.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/ecf/internal/irc/ui/hyperlink/BugHyperlink.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,79 @@ >+package org.eclipse.ecf.internal.irc.ui.hyperlink; >+ >+import java.net.MalformedURLException; >+import java.net.URL; >+ >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.jface.text.IRegion; >+import org.eclipse.jface.text.Region; >+import org.eclipse.jface.text.hyperlink.IHyperlink; >+import org.eclipse.ui.PartInitException; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.browser.IWebBrowser; >+import org.eclipse.ui.browser.IWorkbenchBrowserSupport; >+ >+public class BugHyperlink implements IHyperlink { >+ public static final String HYPERLINK_BUG_DEFAULT_URL = "https://bugs.eclipse.org/bugs/show_bug.cgi?id=<bug#>"; >+ >+ public static final String BROWSER_BUG_TITLE = "Bug #"; >+ >+ public static final String BUG_NUMBER = "<bug#>"; >+ >+ private Region region; >+ >+ private String bugNumber; >+ >+ private String typeLabel; >+ >+ private String hyperlinkText; >+ >+ public BugHyperlink(Region region) { >+ } >+ >+ public BugHyperlink(String bugNumber, Region region) { >+ this.region = region; >+ this.bugNumber = bugNumber; >+ } >+ >+ public IRegion getHyperlinkRegion() { >+ return this.region; >+ } >+ >+ public String getHyperlinkText() { >+ return this.hyperlinkText; >+ } >+ >+ public String getTypeLabel() { >+ return this.typeLabel; >+ } >+ >+ public void open() { >+ IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench() >+ .getBrowserSupport(); >+ >+ URL webUrl; >+ >+ try { >+ String url = Platform.getPreferencesService().getString( >+ "org.eclipse.ecf.presence.ui", >+ "chatroom.hyperlink.bug.url", HYPERLINK_BUG_DEFAULT_URL, >+ null).replaceAll(BUG_NUMBER, bugNumber); >+ webUrl = new URL(url); >+ } catch (MalformedURLException e) { >+ return; >+ } >+ >+ IWebBrowser browser; >+ try { >+ browser = browserSupport.createBrowser( >+ IWorkbenchBrowserSupport.AS_EDITOR, BROWSER_BUG_TITLE >+ + bugNumber, BROWSER_BUG_TITLE + bugNumber, >+ BROWSER_BUG_TITLE + bugNumber); >+ browser.openURL(webUrl); >+ } catch (PartInitException e) { >+ return; >+ } >+ >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 197991
:
74836
|
74848
|
74849
|
94483
|
95000
|
95001
|
95471