Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2008-03-31 17:25:11 +0000
committerslewis2008-03-31 17:25:11 +0000
commitf4eeb46bfd63dae6a34047ccf2b7344b99f0bf34 (patch)
treeb24b6a875ac27e753f575ac79c7b006b9d74794d /providers/bundles/org.eclipse.ecf.provider.irc.ui
parent721db0ac2ecd777ffa66461d67470a941b96462a (diff)
downloadorg.eclipse.ecf-f4eeb46bfd63dae6a34047ccf2b7344b99f0bf34.tar.gz
org.eclipse.ecf-f4eeb46bfd63dae6a34047ccf2b7344b99f0bf34.tar.xz
org.eclipse.ecf-f4eeb46bfd63dae6a34047ccf2b7344b99f0bf34.zip
Apply patch from 197745.
Diffstat (limited to 'providers/bundles/org.eclipse.ecf.provider.irc.ui')
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.irc.ui/META-INF/MANIFEST.MF3
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.irc.ui/plugin.xml14
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/ui/hyperlink/IRCChannelHyperlink.java45
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/ui/hyperlink/IRCChannelHyperlinkDetector.java91
4 files changed, 152 insertions, 1 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.irc.ui/META-INF/MANIFEST.MF b/providers/bundles/org.eclipse.ecf.provider.irc.ui/META-INF/MANIFEST.MF
index 43d3ff7bb..b30643eeb 100644
--- a/providers/bundles/org.eclipse.ecf.provider.irc.ui/META-INF/MANIFEST.MF
+++ b/providers/bundles/org.eclipse.ecf.provider.irc.ui/META-INF/MANIFEST.MF
@@ -12,7 +12,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ecf.presence,
org.eclipse.ecf.presence.ui,
org.eclipse.jface.text,
- org.eclipse.ecf.provider.irc
+ org.eclipse.ecf.provider.irc,
+ org.eclipse.ui.workbench.texteditor;bundle-version="3.4.0"
Eclipse-LazyStart: true
Export-Package: org.eclipse.ecf.internal.irc.ui;x-internal:=true,
org.eclipse.ecf.internal.irc.ui.wizards;x-internal:=true
diff --git a/providers/bundles/org.eclipse.ecf.provider.irc.ui/plugin.xml b/providers/bundles/org.eclipse.ecf.provider.irc.ui/plugin.xml
index 5decad62f..c89bc7301 100644
--- a/providers/bundles/org.eclipse.ecf.provider.irc.ui/plugin.xml
+++ b/providers/bundles/org.eclipse.ecf.provider.irc.ui/plugin.xml
@@ -38,6 +38,13 @@
name="%IRCHyperlinkDetector"
targetId="org.eclipse.ui.DefaultTextEditor">
</hyperlinkDetector>
+ <hyperlinkDetector
+ activate="true"
+ class="org.eclipse.ecf.internal.irc.ui.hyperlink.IRCChannelHyperlinkDetector"
+ id="org.eclipse.ecf.internal.irc.hyperlink.IRCChannelHyperlinkDetector"
+ name="IRC Channel"
+ targetId="org.eclipse.ecf.internal.provider.irc.container">
+ </hyperlinkDetector>
</extension>
<extension
point="org.eclipse.ui.popupMenus">
@@ -117,5 +124,12 @@
</description>
</fontDefinition>
</extension>
+ <extension
+ point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectorTargets">
+ <target
+ id="org.eclipse.ecf.internal.provider.irc.container"
+ name="IRC Chatroom container">
+ </target>
+ </extension>
</plugin>
diff --git a/providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/ui/hyperlink/IRCChannelHyperlink.java b/providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/ui/hyperlink/IRCChannelHyperlink.java
new file mode 100644
index 000000000..b9a325121
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/ui/hyperlink/IRCChannelHyperlink.java
@@ -0,0 +1,45 @@
+package org.eclipse.ecf.internal.irc.ui.hyperlink;
+
+import org.eclipse.ecf.presence.chatroom.IChatRoomManager;
+import org.eclipse.ecf.presence.ui.chatroom.ChatRoomManagerView;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+
+public class IRCChannelHyperlink implements IHyperlink {
+ private Region region;
+
+ private String channel;
+
+ private String typeLabel;
+
+ private String hyperlinkText;
+
+ private ChatRoomManagerView view;
+
+ public IRCChannelHyperlink(ChatRoomManagerView view, String channel,
+ Region region) {
+ this.channel = channel;
+ this.region = region;
+ this.view = view;
+ }
+
+ public IRegion getHyperlinkRegion() {
+ return this.region;
+ }
+
+ public String getHyperlinkText() {
+ return this.hyperlinkText;
+ }
+
+ public String getTypeLabel() {
+ return this.typeLabel;
+ }
+
+ public void open() {
+ IChatRoomManager manager = (IChatRoomManager) view.getRootChatRoomContainer();
+
+ view.joinRoom(manager.getChatRoomInfo(channel), "");
+ }
+
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/ui/hyperlink/IRCChannelHyperlinkDetector.java b/providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/ui/hyperlink/IRCChannelHyperlinkDetector.java
new file mode 100644
index 000000000..f86f479ea
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/ui/hyperlink/IRCChannelHyperlinkDetector.java
@@ -0,0 +1,91 @@
+package org.eclipse.ecf.internal.irc.ui.hyperlink;
+
+import java.util.StringTokenizer;
+
+import org.eclipse.ecf.presence.ui.chatroom.ChatRoomManagerView;
+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 IRCChannelHyperlinkDetector extends
+ org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector {
+ public static final String DEFAULT_PREFIX = "#"; //$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;
+
+ ChatRoomManagerView view = (ChatRoomManagerView) getAdapter(ChatRoomManagerView.class);
+
+ 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;
+ }
+
+ Region detectedRegion = detectRegion(lineInfo, line, offset
+ - lineInfo.getOffset());
+
+ if (detectedRegion == null)
+ return null;
+
+ int detectedOffset = detectedRegion.getOffset() - lineInfo.getOffset();
+
+ return createHyperLinksForChannel(view, line.substring(detectedOffset,
+ detectedOffset + detectedRegion.getLength()), detectedRegion);
+
+ }
+
+ private Region detectRegion(IRegion lineInfo, 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 new Region(lineInfo.getOffset() + separatorOffset, resultLength);
+ }
+
+ private IHyperlink[] createHyperLinksForChannel(ChatRoomManagerView view,
+ String channel, Region region) {
+ return new IHyperlink[] { new IRCChannelHyperlink(view, channel, region) };
+ }
+}

Back to the top