View | Details | Raw Unified | Return to bug 197745 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 12-18 Link Here
12
 org.eclipse.ecf.presence,
12
 org.eclipse.ecf.presence,
13
 org.eclipse.ecf.presence.ui,
13
 org.eclipse.ecf.presence.ui,
14
 org.eclipse.jface.text,
14
 org.eclipse.jface.text,
15
 org.eclipse.ecf.provider.irc
15
 org.eclipse.ecf.provider.irc,
16
 org.eclipse.ui.workbench.texteditor
16
Eclipse-LazyStart: true
17
Eclipse-LazyStart: true
17
Export-Package: org.eclipse.ecf.internal.irc.ui;x-internal:=true,
18
Export-Package: org.eclipse.ecf.internal.irc.ui;x-internal:=true,
18
 org.eclipse.ecf.internal.irc.ui.wizards;x-internal:=true
19
 org.eclipse.ecf.internal.irc.ui.wizards;x-internal:=true
(-)plugin.properties (+1 lines)
Lines 11-16 Link Here
11
11
12
TextEditorHyperlinkTarget= Textual Editors
12
TextEditorHyperlinkTarget= Textual Editors
13
IRCHyperlinkDetector= IRC
13
IRCHyperlinkDetector= IRC
14
ChannelHyperlinkDetector= Channel 
14
15
15
KickAction_Label=Kick
16
KickAction_Label=Kick
16
BanAction_Label=Ban
17
BanAction_Label=Ban
(-)plugin.xml (+18 lines)
Lines 9-14 Link Here
9
            id="org.eclipse.ecf.provider.ui.irc.connectWizard"
9
            id="org.eclipse.ecf.provider.ui.irc.connectWizard"
10
            name="IRC"/>
10
            name="IRC"/>
11
   </extension>
11
   </extension>
12
   
12
13
13
   <extension
14
   <extension
14
         point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
15
         point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
Lines 19-24 Link Here
19
            name="%IRCHyperlinkDetector"
20
            name="%IRCHyperlinkDetector"
20
            targetId="org.eclipse.ui.DefaultTextEditor">
21
            targetId="org.eclipse.ui.DefaultTextEditor">
21
      </hyperlinkDetector>
22
      </hyperlinkDetector>
23
      <hyperlinkDetector
24
            activate="true"
25
            class="org.eclipse.ecf.internal.irc.ui.hyperlink.ChannelHyperlinkDetector"
26
            id="org.eclipse.ecf.internal.irc.ui.hyperlink.ChannelHyperlinkDetector"
27
            name="%ChannelHyperlinkDetector"
28
            targetId="org.eclipse.ui.DefaultTextEditor">
29
      </hyperlinkDetector>
22
   </extension>
30
   </extension>
23
   <extension
31
   <extension
24
         point="org.eclipse.ui.popupMenus">
32
         point="org.eclipse.ui.popupMenus">
Lines 75-79 Link Here
75
         </visibility>
83
         </visibility>
76
      </viewerContribution>
84
      </viewerContribution>
77
   </extension>
85
   </extension>
86
   <extension
87
         point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectorTargets">
88
      <target
89
            id="org.eclipse.ui.DefaultTextEditor"
90
            name="Charoom View">
91
         <context
92
               type="org.eclipse.ui.IViewPart">
93
         </context>
94
      </target>
95
   </extension>
78
96
79
</plugin>
97
</plugin>
(-)src/org/eclipse/ecf/internal/irc/ui/hyperlink/ChannelHyperlink.java (+45 lines)
Added Link Here
1
package org.eclipse.ecf.internal.irc.ui.hyperlink;
2
3
import org.eclipse.ecf.presence.chatroom.IChatRoomManager;
4
import org.eclipse.ecf.presence.ui.chatroom.ChatRoomManagerView;
5
import org.eclipse.jface.text.IRegion;
6
import org.eclipse.jface.text.Region;
7
import org.eclipse.jface.text.hyperlink.IHyperlink;
8
9
public class ChannelHyperlink implements IHyperlink {
10
	private Region region;
11
12
	private String channel;
13
14
	private String typeLabel;
15
16
	private String hyperlinkText;
17
18
	private ChatRoomManagerView view;
19
20
	public ChannelHyperlink(ChatRoomManagerView view, String channel,
21
			Region region) {
22
		this.channel = channel;
23
		this.region = region;
24
		this.view = view;
25
	}
26
27
	public IRegion getHyperlinkRegion() {
28
		return this.region;
29
	}
30
31
	public String getHyperlinkText() {
32
		return this.hyperlinkText;
33
	}
34
35
	public String getTypeLabel() {
36
		return this.typeLabel;
37
	}
38
39
	public void open() {
40
		IChatRoomManager manager = (IChatRoomManager) view.getRootChatRoomContainer();
41
42
		view.joinRoom(manager.getChatRoomInfo(channel), "");
43
	}
44
45
}
(-)src/org/eclipse/ecf/internal/irc/ui/hyperlink/ChannelHyperlinkDetector.java (+92 lines)
Added Link Here
1
package org.eclipse.ecf.internal.irc.ui.hyperlink;
2
3
import java.util.StringTokenizer;
4
5
import org.eclipse.ecf.presence.ui.chatroom.ChatRoomManagerView;
6
import org.eclipse.jface.text.BadLocationException;
7
import org.eclipse.jface.text.IDocument;
8
import org.eclipse.jface.text.IRegion;
9
import org.eclipse.jface.text.ITextViewer;
10
import org.eclipse.jface.text.Region;
11
import org.eclipse.jface.text.hyperlink.IHyperlink;
12
import org.eclipse.ui.IViewPart;
13
14
public class ChannelHyperlinkDetector extends
15
		org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector {
16
	public static final String DEFAULT_PREFIX = "#"; //$NON-NLS-1$
17
	public static final String DEFAULT_ENDDELIMITERS = " \t\n\r\f<>"; //$NON-NLS-1$
18
19
	/*
20
	 * (non-Javadoc)
21
	 * 
22
	 * @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector#detectHyperlinks(org.eclipse.jface.text.ITextViewer,
23
	 *      org.eclipse.jface.text.IRegion, boolean)
24
	 */
25
	public IHyperlink[] detectHyperlinks(ITextViewer textViewer,
26
			IRegion region, boolean canShowMultipleHyperlinks) {
27
		if (region == null || textViewer == null)
28
			return null;
29
30
		ChatRoomManagerView view = (ChatRoomManagerView) getAdapter(IViewPart.class);
31
32
		IDocument document = textViewer.getDocument();
33
		if (document == null)
34
			return null;
35
36
		int offset = region.getOffset();
37
38
		IRegion lineInfo;
39
		String line;
40
		try {
41
			lineInfo = document.getLineInformationOfOffset(offset);
42
			line = document.get(lineInfo.getOffset(), lineInfo.getLength());
43
		} catch (BadLocationException ex) {
44
			return null;
45
		}
46
47
		Region detectedRegion = detectRegion(lineInfo, line, offset
48
				- lineInfo.getOffset());
49
50
		if (detectedRegion == null)
51
			return null;
52
53
		int detectedOffset = detectedRegion.getOffset() - lineInfo.getOffset();
54
55
		return createHyperLinksForChannel(view, line.substring(detectedOffset,
56
				detectedOffset + detectedRegion.getLength()), detectedRegion);
57
58
	}
59
60
	private Region detectRegion(IRegion lineInfo, String fromLine,
61
			int offsetInLine) {
62
		int resultLength = 0;
63
64
		int separatorOffset = fromLine.indexOf(DEFAULT_PREFIX);
65
		while (separatorOffset >= 0) {
66
			StringTokenizer tokenizer = new StringTokenizer(fromLine
67
					.substring(separatorOffset + DEFAULT_PREFIX.length()),
68
					DEFAULT_ENDDELIMITERS, false);
69
			if (!tokenizer.hasMoreTokens())
70
				return null;
71
72
			resultLength = tokenizer.nextToken().length()
73
					+ DEFAULT_PREFIX.length();
74
			if (offsetInLine >= separatorOffset
75
					&& offsetInLine <= separatorOffset + resultLength)
76
				break;
77
78
			separatorOffset = fromLine.indexOf(DEFAULT_PREFIX,
79
					separatorOffset + 1);
80
		}
81
82
		if (separatorOffset < 0)
83
			return null;
84
85
		return new Region(lineInfo.getOffset() + separatorOffset, resultLength);
86
	}
87
88
	private IHyperlink[] createHyperLinksForChannel(ChatRoomManagerView view,
89
			String channel, Region region) {
90
		return new IHyperlink[] { new ChannelHyperlink(view, channel, region) };
91
	}
92
}
(-)src/org/eclipse/ecf/presence/ui/chatroom/ChatRoomManagerView.java (-1 / +16 lines)
Lines 17-22 Link Here
17
import java.text.SimpleDateFormat;
17
import java.text.SimpleDateFormat;
18
import java.util.ArrayList;
18
import java.util.ArrayList;
19
import java.util.Date;
19
import java.util.Date;
20
import java.util.HashMap;
20
import java.util.Hashtable;
21
import java.util.Hashtable;
21
import java.util.Iterator;
22
import java.util.Iterator;
22
import java.util.Map;
23
import java.util.Map;
Lines 56-61 Link Here
56
import org.eclipse.jface.text.Document;
57
import org.eclipse.jface.text.Document;
57
import org.eclipse.jface.text.ITextSelection;
58
import org.eclipse.jface.text.ITextSelection;
58
import org.eclipse.jface.text.TextSelection;
59
import org.eclipse.jface.text.TextSelection;
60
import org.eclipse.jface.text.source.ISourceViewer;
59
import org.eclipse.jface.text.source.SourceViewer;
61
import org.eclipse.jface.text.source.SourceViewer;
60
import org.eclipse.jface.util.IPropertyChangeListener;
62
import org.eclipse.jface.util.IPropertyChangeListener;
61
import org.eclipse.jface.util.PropertyChangeEvent;
63
import org.eclipse.jface.util.PropertyChangeEvent;
Lines 282-288 Link Here
282
						true, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI
284
						true, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI
283
								| SWT.READ_ONLY);
285
								| SWT.READ_ONLY);
284
				result.configure(new TextSourceViewerConfiguration(EditorsUI
286
				result.configure(new TextSourceViewerConfiguration(EditorsUI
285
						.getPreferenceStore()));
287
						.getPreferenceStore()){
288
					protected Map getHyperlinkDetectorTargets(
289
							ISourceViewer sourceViewer) {
290
						Map targets = new HashMap();
291
						targets
292
								.put(
293
										"org.eclipse.ui.DefaultTextEditor", ChatRoomManagerView.this); //$NON-NLS-1$
294
						return targets;
295
					}
296
				});
286
				result.setDocument(new Document());
297
				result.setDocument(new Document());
287
				return result.getTextWidget();
298
				return result.getTextWidget();
288
			} catch (Exception e) {
299
			} catch (Exception e) {
Lines 509-514 Link Here
509
		}
520
		}
510
	}
521
	}
511
522
523
	public IChatRoomContainer getRootChatRoomContainer() {
524
		return container;
525
	}
526
	
512
	/**
527
	/**
513
	 * @return chat room container of currently selected tab or null if none found.
528
	 * @return chat room container of currently selected tab or null if none found.
514
	 */
529
	 */

Return to bug 197745