|
Lines 23-29
Link Here
|
| 23 |
import org.eclipse.jface.text.ITextViewer; |
23 |
import org.eclipse.jface.text.ITextViewer; |
| 24 |
import org.eclipse.jface.text.Region; |
24 |
import org.eclipse.jface.text.Region; |
| 25 |
import org.eclipse.jface.text.hyperlink.IHyperlink; |
25 |
import org.eclipse.jface.text.hyperlink.IHyperlink; |
|
|
26 |
import org.eclipse.mylyn.internal.tasks.core.AbstractTask; |
| 27 |
import org.eclipse.mylyn.internal.tasks.ui.actions.CopyTaskDetailsAction; |
| 28 |
import org.eclipse.mylyn.internal.tasks.ui.actions.CopyTaskDetailsAction.Mode; |
| 29 |
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal; |
| 30 |
import org.eclipse.mylyn.tasks.core.TaskRepository; |
| 26 |
import org.eclipse.mylyn.tasks.ui.AbstractTaskHyperlinkDetector; |
31 |
import org.eclipse.mylyn.tasks.ui.AbstractTaskHyperlinkDetector; |
|
|
32 |
import org.eclipse.osgi.util.NLS; |
| 27 |
|
33 |
|
| 28 |
/** |
34 |
/** |
| 29 |
* Detects URLs based on a regular expression. |
35 |
* Detects URLs based on a regular expression. |
|
Lines 37-42
Link Here
|
| 37 |
// so we do the same here |
43 |
// so we do the same here |
| 38 |
private static final Pattern URL_PATTERN = Pattern.compile("([a-zA-Z][a-zA-Z+.-]{0,10}://[a-zA-Z0-9%._~!$&?#'()*+,;:@/=-]*[a-zA-Z0-9%_~!$&?#'(*+;:@/=-])"); //$NON-NLS-1$ |
44 |
private static final Pattern URL_PATTERN = Pattern.compile("([a-zA-Z][a-zA-Z+.-]{0,10}://[a-zA-Z0-9%._~!$&?#'()*+,;:@/=-]*[a-zA-Z0-9%_~!$&?#'(*+;:@/=-])"); //$NON-NLS-1$ |
| 39 |
|
45 |
|
|
|
46 |
private final boolean detectAllUrls; |
| 47 |
|
| 48 |
/** |
| 49 |
* @param detectAllUrls |
| 50 |
* if false, only known task URLs are detected |
| 51 |
*/ |
| 52 |
public TaskUrlHyperlinkDetector(boolean detectAllUrls) { |
| 53 |
this.detectAllUrls = detectAllUrls; |
| 54 |
} |
| 55 |
|
| 56 |
public TaskUrlHyperlinkDetector() { |
| 57 |
this(false); |
| 58 |
} |
| 59 |
|
| 40 |
@Override |
60 |
@Override |
| 41 |
protected List<IHyperlink> detectHyperlinks(ITextViewer textViewer, String content, int indexInContent, |
61 |
protected List<IHyperlink> detectHyperlinks(ITextViewer textViewer, String content, int indexInContent, |
| 42 |
int contentOffset) { |
62 |
int contentOffset) { |
|
Lines 44-59
Link Here
|
| 44 |
Matcher m = URL_PATTERN.matcher(content); |
64 |
Matcher m = URL_PATTERN.matcher(content); |
| 45 |
while (m.find()) { |
65 |
while (m.find()) { |
| 46 |
if (isInRegion(indexInContent, m)) { |
66 |
if (isInRegion(indexInContent, m)) { |
| 47 |
try { |
67 |
String urlString = m.group(1); |
| 48 |
String urlString = m.group(1); |
68 |
TaskUrlHyperlink link = null; |
| 49 |
new URL(urlString); |
69 |
if (getAdapter(TaskRepository.class) != null) { |
|
|
70 |
try { |
| 71 |
new URL(urlString); |
| 72 |
link = new TaskUrlHyperlink(determineRegion(contentOffset, m), urlString); |
| 73 |
} catch (MalformedURLException e) { |
| 74 |
// ignore |
| 75 |
} |
| 76 |
|
| 77 |
} else { |
| 78 |
AbstractTask task = TasksUiInternal.getTaskByUrl(urlString); |
| 79 |
if (task != null) { |
| 80 |
String text = NLS.bind(Messages.TaskUrlHyperlink_Open_URL_in_Task_Editor, |
| 81 |
CopyTaskDetailsAction.getTextForTask(task, Mode.SUMMARY)); |
| 82 |
link = new TaskUrlHyperlink(determineRegion(contentOffset, m), urlString, text); |
| 83 |
} |
| 84 |
} |
| 50 |
|
85 |
|
|
|
86 |
if (link != null) { |
| 51 |
if (links == null) { |
87 |
if (links == null) { |
| 52 |
links = new ArrayList<IHyperlink>(); |
88 |
links = new ArrayList<IHyperlink>(); |
| 53 |
} |
89 |
} |
| 54 |
links.add(new TaskUrlHyperlink(determineRegion(contentOffset, m), urlString)); |
90 |
links.add(link); |
| 55 |
} catch (MalformedURLException e) { |
|
|
| 56 |
// ignore |
| 57 |
} |
91 |
} |
| 58 |
} |
92 |
} |
| 59 |
} |
93 |
} |