Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2017-03-09 14:20:51 +0000
committerAlexander Kurtakov2017-03-10 13:04:33 +0000
commita29efeaac034cba9fe7939613232db0de386c1e4 (patch)
tree43a82711f5af9dd7981b8adf367e74082b61a4b7
parentbf4d309cd282cc0dc05d4ee8f23f823e29e3e403 (diff)
downloadorg.eclipse.linuxtools-a29efeaac034cba9fe7939613232db0de386c1e4.tar.gz
org.eclipse.linuxtools-a29efeaac034cba9fe7939613232db0de386c1e4.tar.xz
org.eclipse.linuxtools-a29efeaac034cba9fe7939613232db0de386c1e4.zip
changelog: Generic editor.
Significantly simplified the hyperlink detector. Change-Id: Ib637f59080da07f57b57e66f2eb2b8c51252af73 Signed-off-by: Alexander Kurtakov <akurtako@redhat.com> Reviewed-on: https://git.eclipse.org/r/92700 Tested-by: Hudson CI
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/META-INF/MANIFEST.MF3
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/plugin.properties4
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/plugin.xml56
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/IEditorChangeLogContrib.java90
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/ChangeLogEditor.java163
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUEditorConfiguration.java216
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUHyperlinkDetector.java266
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUPresentationReconciler.java34
8 files changed, 363 insertions, 469 deletions
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/META-INF/MANIFEST.MF b/changelog/org.eclipse.linuxtools.changelog.core/META-INF/MANIFEST.MF
index 6f6b180a41..a4426d8b53 100644
--- a/changelog/org.eclipse.linuxtools.changelog.core/META-INF/MANIFEST.MF
+++ b/changelog/org.eclipse.linuxtools.changelog.core/META-INF/MANIFEST.MF
@@ -16,7 +16,8 @@ Require-Bundle: org.eclipse.team.ui,
org.eclipse.team.core,
org.eclipse.ui.navigator,
org.eclipse.compare,
- org.eclipse.core.resources
+ org.eclipse.core.resources,
+ org.eclipse.ui.genericeditor;bundle-version="1.0.0"
Export-Package: org.eclipse.linuxtools.changelog.core
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/plugin.properties b/changelog/org.eclipse.linuxtools.changelog.core/plugin.properties
index 9e15727032..f13fb94dcd 100644
--- a/changelog/org.eclipse.linuxtools.changelog.core/plugin.properties
+++ b/changelog/org.eclipse.linuxtools.changelog.core/plugin.properties
@@ -1,4 +1,3 @@
-
pluginName=ChangeLog Plugin
providerName=Eclipse Linux Tools
compareParser=Compare Editor Parser
@@ -35,4 +34,5 @@ target.name = Changelog Editor
hyperlinkDetector.name = Changelog Detector
extension-point.name = Changelog Language Parser Contribution
extension-point.name.0 = Changelog Format Contribution
-extension-point.name.1 = ChangeLog Editor Contribution \ No newline at end of file
+extension-point.name.1 = ChangeLog Editor Contribution
+content-type.name = ChangeLog Content Type \ No newline at end of file
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/plugin.xml b/changelog/org.eclipse.linuxtools.changelog.core/plugin.xml
index f7fe6abb00..c474b6c364 100644
--- a/changelog/org.eclipse.linuxtools.changelog.core/plugin.xml
+++ b/changelog/org.eclipse.linuxtools.changelog.core/plugin.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?><!--
- Copyright (c) 2010 Red Hat, Inc.
+ Copyright (c) 2010, 2017 Red Hat, Inc.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
@@ -9,7 +9,6 @@
Contributors:
Alexander Kurtakov (Red Hat) - initial API and implementation
-->
-
<plugin>
<extension-point id="parserContribution"
@@ -83,7 +82,17 @@
name="%gnuFormatter">
<fileName name="ChangeLog" />
</formatter>
- </extension>
+ </extension>
+ <extension
+ point="org.eclipse.core.contenttype.contentTypes">
+ <content-type
+ base-type="org.eclipse.core.runtime.text"
+ file-names="ChangeLog"
+ id="org.eclipse.linuxtools.changelog.editor.content-type"
+ name="%content-type.name"
+ priority="high">
+ </content-type>
+ </extension>
<extension
id="org.eclipse.linuxtools.changelog.core.editor"
point="org.eclipse.ui.editors">
@@ -93,8 +102,19 @@
default="true"
filenames="ChangeLog"
icon="icons/file_obj.gif"
- id="org.eclipse.linuxtools.changelog.core.editor6"
- name="%editor.name"/>
+ id="org.eclipse.linuxtools.changelog.editor"
+ name="%editor.name">
+ <contentTypeBinding
+ contentTypeId="org.eclipse.linuxtools.changelog.editor.content-type">
+ </contentTypeBinding>
+ </editor>
+ </extension>
+ <extension
+ point="org.eclipse.ui.genericeditor.presentationReconcilers">
+ <presentationReconciler
+ class="org.eclipse.linuxtools.internal.changelog.core.editors.GNUPresentationReconciler"
+ contentType="org.eclipse.linuxtools.changelog.editor.content-type">
+ </presentationReconciler>
</extension>
<extension
point="org.eclipse.linuxtools.changelog.core.editorContribution">
@@ -203,25 +223,15 @@
<initializer
class="org.eclipse.linuxtools.internal.changelog.core.ChangelogPreferenceInitializer" />
</extension>
-
- <extension
- point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectorTargets">
-<target id="org.eclipse.changelog.editor.target"
- name="%target.name">
-<context type="org.eclipse.ui.texteditor.ITextEditor"/>
-</target>
-</extension>
-
-
<extension
- point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
- <hyperlinkDetector
- id="org.eclipse.linuxtools.changelog.GNUHyperlinkDetector"
- targetId="org.eclipse.changelog.editor.target"
- class="org.eclipse.linuxtools.internal.changelog.core.editors.GNUHyperlinkDetector"
- name="%hyperlinkDetector.name">
- </hyperlinkDetector>
-</extension>
+ point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
+ <hyperlinkDetector
+ id="org.eclipse.linuxtools.changelog.GNUHyperlinkDetector"
+ targetId="org.eclipse.ui.DefaultTextEditor"
+ class="org.eclipse.linuxtools.internal.changelog.core.editors.GNUHyperlinkDetector"
+ name="%hyperlinkDetector.name">
+ </hyperlinkDetector>
+ </extension>
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:#TextEditorContext?endof=group.edit">
<command commandId="org.eclipse.linuxtools.changelog.core.formatChangeLog">
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/IEditorChangeLogContrib.java b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/IEditorChangeLogContrib.java
index 679a1f23ea..48a311a5f5 100644
--- a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/IEditorChangeLogContrib.java
+++ b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/IEditorChangeLogContrib.java
@@ -15,59 +15,59 @@ import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
import org.eclipse.jface.text.hyperlink.IHyperlinkPresenter;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.ui.editors.text.TextEditor;
/**
* @author klee (Kyu Lee)
*/
public interface IEditorChangeLogContrib {
- /**
- * Set TextEditor that this configuration is going to be used.
- *
- * @param editor The text editor for this configuration.
- */
- void setTextEditor(TextEditor editor);
+ /**
+ * Set default content type. GNU Changelog only has one type.
+ *
+ * @param sourceViewer
+ * The source viewer to retrieve configured content type for.
+ *
+ * @return default content type.
+ */
+ String[] getConfiguredContentTypes(ISourceViewer sourceViewer);
- /**
- * Set default content type. GNU Changelog only has one type.
- * @param sourceViewer The source viewer to retrieve configured content type for.
- *
- * @return default content type.
- */
- String[] getConfiguredContentTypes(ISourceViewer sourceViewer);
+ /**
+ * Detects hyperlinks in GNU formatted changelogs.
+ *
+ * @param sourceViewer
+ * The source viewer to retrieve hyperlinks for.
+ *
+ * @return link detector for GNU format.
+ */
+ IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer);
- /**
- * Detects hyperlinks in GNU formatted changelogs.
- * @param sourceViewer The source viewer to retrieve hyperlinks for.
- *
- * @return link detector for GNU format.
- */
- IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer);
+ /**
+ * Hyperlink presenter (decorator).
+ *
+ * @param sourceViewer
+ * The source viewer to operate on.
+ *
+ * @return default presenter.
+ */
+ IHyperlinkPresenter getHyperlinkPresenter(ISourceViewer sourceViewer);
- /**
- * Hyperlink presenter (decorator).
- * @param sourceViewer The source viewer to operate on.
- *
- * @return default presenter.
- */
- IHyperlinkPresenter getHyperlinkPresenter(ISourceViewer sourceViewer);
+ /**
+ * Highlights GNU format changelog syntaxes.
+ *
+ * @param sourceViewer
+ * The source viewer to get presentation reconciler for.
+ *
+ * @return reconciler for GNU format changelog.
+ */
+ IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer);
- /**
- * Highlights GNU format changelog syntaxes.
- * @param sourceViewer The source viewer to get presentation reconciler for.
- *
- * @return reconciler for GNU format changelog.
- */
- IPresentationReconciler getPresentationReconciler(
- ISourceViewer sourceViewer);
-
- /**
- * Perform documentation setup. Use this to specify partitioning.
- *
- * @param document to set up.
- *
- * @since 3.0.0
- */
- void setup(IDocument document);
+ /**
+ * Perform documentation setup. Use this to specify partitioning.
+ *
+ * @param document
+ * to set up.
+ *
+ * @since 3.0.0
+ */
+ void setup(IDocument document);
}
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/ChangeLogEditor.java b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/ChangeLogEditor.java
index 68279a4010..cf503cc711 100644
--- a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/ChangeLogEditor.java
+++ b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/ChangeLogEditor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007, 2011 Red Hat Inc. and others.
+ * Copyright (c) 2006, 2017 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -28,7 +28,6 @@ import org.eclipse.linuxtools.internal.changelog.core.Messages;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.editors.text.TextFileDocumentProvider;
-
/**
* ChangeLog editor that supports GNU format.
*
@@ -36,88 +35,82 @@ import org.eclipse.ui.editors.text.TextFileDocumentProvider;
*/
public class ChangeLogEditor extends TextEditor {
- private boolean forceNewLogEntry;
-
- public ChangeLogEditor() {
- super();
-
- SourceViewerConfiguration config = getConfig();
-
- if (config != null) {
- setSourceViewerConfiguration(config);
- } else {
- ChangelogPlugin.getDefault().getLog().log(
- new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR,
- Messages.getString("ChangeLogEditor.ErrConfiguration"), // $NON-NLS-1$
- new Exception(Messages.getString("ChangeLogEditor.ErrConfiguration")))); // $NON-NLS-1$
- }
-
- setDocumentProvider(new TextFileDocumentProvider());
-
- }
-
- @Override
- protected void initializeKeyBindingScopes() {
- setKeyBindingScopes(new String[] { "org.eclipse.linuxtools.changelog.core.changelogEditorScope" }); //$NON-NLS-1$
- }
-
- /**
- * Gets appropriate style editor from user pref.
- *
- * @return configuration for the Changelog editor
- */
-
- private SourceViewerConfiguration getConfig() {
-
- IExtensionPoint editorExtensions = null;
- IEditorChangeLogContrib editorContrib = null;
-
- // get editor which is stored in preference.
- IPreferenceStore store = ChangelogPlugin.getDefault()
- .getPreferenceStore();
- String pref_Editor = store
- .getString("IChangeLogConstants.DEFAULT_EDITOR"); // $NON-NLS-1$
-
- editorExtensions = Platform.getExtensionRegistry().getExtensionPoint(
- "org.eclipse.linuxtools.changelog.core", "editorContribution"); //$NON-NLS-1$ //$NON-NLS-2$
-
- if (editorExtensions != null) {
- IConfigurationElement[] elements = editorExtensions
- .getConfigurationElements();
- for (int i = 0; i < elements.length; i++) {
- if (elements[i].getName().equals("editor") // $NON-NLS-1$
- && (elements[i].getAttribute("name").equals(pref_Editor))) { //$NON-NLS-1$
-
- try {
- IConfigurationElement bob = elements[i];
- editorContrib = (IEditorChangeLogContrib) bob
- .createExecutableExtension("class"); // $NON-NLS-1$
-
- editorContrib.setTextEditor(this);
- return (SourceViewerConfiguration) editorContrib;
- } catch (CoreException e) {
- ChangelogPlugin.getDefault().getLog().log(
- new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID,
- IStatus.ERROR, e.getMessage(), e));
- }
-
- }
- }
- }
-
- return null;
- }
-
- public ISourceViewer getMySourceViewer() {
- return this.getSourceViewer();
- }
-
- public boolean isForceNewLogEntry() {
- return forceNewLogEntry;
- }
-
- public void setForceNewLogEntry(boolean forceNewLogEntry) {
- this.forceNewLogEntry = forceNewLogEntry;
- }
+ private boolean forceNewLogEntry;
+
+ public ChangeLogEditor() {
+ super();
+
+ SourceViewerConfiguration config = getConfig();
+
+ if (config != null) {
+ setSourceViewerConfiguration(config);
+ } else {
+ ChangelogPlugin.getDefault().getLog()
+ .log(new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR,
+ Messages.getString("ChangeLogEditor.ErrConfiguration"), // $NON-NLS-1$
+ new Exception(Messages.getString("ChangeLogEditor.ErrConfiguration")))); // $NON-NLS-1$
+ }
+
+ setDocumentProvider(new TextFileDocumentProvider());
+
+ }
+
+ @Override
+ protected void initializeKeyBindingScopes() {
+ setKeyBindingScopes(new String[] { "org.eclipse.linuxtools.changelog.core.changelogEditorScope" }); //$NON-NLS-1$
+ }
+
+ /**
+ * Gets appropriate style editor from user pref.
+ *
+ * @return configuration for the Changelog editor
+ */
+
+ private SourceViewerConfiguration getConfig() {
+
+ IExtensionPoint editorExtensions = null;
+ IEditorChangeLogContrib editorContrib = null;
+
+ // get editor which is stored in preference.
+ IPreferenceStore store = ChangelogPlugin.getDefault().getPreferenceStore();
+ String pref_Editor = store.getString("IChangeLogConstants.DEFAULT_EDITOR"); // $NON-NLS-1$
+
+ editorExtensions = Platform.getExtensionRegistry().getExtensionPoint("org.eclipse.linuxtools.changelog.core", //$NON-NLS-1$
+ "editorContribution"); //$NON-NLS-1$
+
+ if (editorExtensions != null) {
+ IConfigurationElement[] elements = editorExtensions.getConfigurationElements();
+ for (int i = 0; i < elements.length; i++) {
+ if (elements[i].getName().equals("editor") // $NON-NLS-1$
+ && (elements[i].getAttribute("name").equals(pref_Editor))) { //$NON-NLS-1$
+
+ try {
+ IConfigurationElement bob = elements[i];
+ editorContrib = (IEditorChangeLogContrib) bob.createExecutableExtension("class"); // $NON-NLS-1$
+
+ return (SourceViewerConfiguration) editorContrib;
+ } catch (CoreException e) {
+ ChangelogPlugin.getDefault().getLog().log(
+ new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
+ }
+
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public ISourceViewer getMySourceViewer() {
+ return this.getSourceViewer();
+ }
+
+ public boolean isForceNewLogEntry() {
+ return forceNewLogEntry;
+ }
+
+ public void setForceNewLogEntry(boolean forceNewLogEntry) {
+ this.forceNewLogEntry = forceNewLogEntry;
+ }
}
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUEditorConfiguration.java b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUEditorConfiguration.java
index 42510e9a23..cd6209fc6f 100644
--- a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUEditorConfiguration.java
+++ b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUEditorConfiguration.java
@@ -10,156 +10,104 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.changelog.core.editors;
-import java.util.Map;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentExtension3;
-import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.formatter.ContentFormatter;
import org.eclipse.jface.text.formatter.IContentFormatter;
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
-import org.eclipse.jface.text.presentation.PresentationReconciler;
-import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
import org.eclipse.jface.text.rules.FastPartitioner;
-import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.linuxtools.changelog.core.IEditorChangeLogContrib;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
-
/**
* GNU format ChangeLog editor configuration.
- *
- * @author klee (Kyu Lee)
*/
-public class GNUEditorConfiguration extends TextSourceViewerConfiguration implements
- IEditorChangeLogContrib {
+public class GNUEditorConfiguration extends TextSourceViewerConfiguration implements IEditorChangeLogContrib {
+
+ public static final String CHANGELOG_PARTITIONING = "gnu_changelog_partitioning"; //$NON-NLS-1$
+
+ /**
+ * Prepares configuration.
+ */
+ public GNUEditorConfiguration() {
+ }
- public static final String CHANGELOG_PARTITIONING= "gnu_changelog_partitioning"; //$NON-NLS-1$
+ /**
+ * Get configured content types.
+ *
+ * @return array of configured content types.
+ */
+ @Override
+ public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
+ return new String[] { IDocument.DEFAULT_CONTENT_TYPE, GNUPartitionScanner.CHANGELOG_EMAIL,
+ GNUPartitionScanner.CHANGELOG_SRC_ENTRY };
+ }
- private TextEditor parentEditor;
+ /**
+ * Detects hyperlinks in GNU formatted changelogs.
+ *
+ * @return link detector for GNU format.
+ */
+ @Override
+ public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
+ if (sourceViewer == null)
+ return null;
+
+ return getRegisteredHyperlinkDetectors(sourceViewer);
+ }
+
+ @Override
+ public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
+ return CHANGELOG_PARTITIONING;
+ }
+
+ /**
+ * Set content formatter. For ChangeLog, it just wraps lines.
+ */
+ @Override
+ public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
+
+ ContentFormatter cf = new ContentFormatter();
+
+ // no partitions
+ cf.enablePartitionAwareFormatting(false);
+
+ ChangeLogFormattingStrategy cfs = new ChangeLogFormattingStrategy();
+
+ cf.setFormattingStrategy(cfs, IDocument.DEFAULT_CONTENT_TYPE);
+
+ return cf;
+ }
+
+ /**
+ * Highlights GNU format changelog syntaxes.
+ *
+ * @return reconciler for GNU format changelog.
+ */
+ @Override
+ public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
+ return new GNUPresentationReconciler();
+ }
- /**
- * Prepares configuration.
- */
- public GNUEditorConfiguration() {
+ /**
+ * Perform documentation setup to set up partitioning.
+ *
+ * @param document
+ * to set up partitioning on.
+ */
+ @Override
+ public void setup(IDocument document) {
+ FastPartitioner partitioner = new FastPartitioner(new GNUPartitionScanner(),
+ GNUPartitionScanner.CHANGELOG_PARTITION_TYPES);
+ partitioner.connect(document);
+ if (document instanceof IDocumentExtension3) {
+ IDocumentExtension3 extension3 = (IDocumentExtension3) document;
+ extension3.setDocumentPartitioner(CHANGELOG_PARTITIONING, partitioner);
+ } else {
+ document.setDocumentPartitioner(partitioner);
+ }
}
- /**
- * Sets TextEditor that this configuration is going to be applied.
- */
- @Override
- public void setTextEditor(TextEditor editor) {
- parentEditor = editor;
- }
-
- /**
- * Get configured content types.
- *
- * @return array of configured content types.
- */
- @Override
- public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
- return new String[] { IDocument.DEFAULT_CONTENT_TYPE,
- GNUPartitionScanner.CHANGELOG_EMAIL,
- GNUPartitionScanner.CHANGELOG_SRC_ENTRY};
- }
-
- /**
- * Detects hyperlinks in GNU formatted changelogs.
- *
- * @return link detector for GNU format.
- */
- @Override
- public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
- if (sourceViewer == null)
- return null;
-
- return getRegisteredHyperlinkDetectors(sourceViewer);
- }
-
- @Override
- public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
- return CHANGELOG_PARTITIONING;
- }
-
- /**
- * Set content formatter. For ChangeLog, it just wraps lines.
- */
- @Override
- public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
-
- ContentFormatter cf = new ContentFormatter();
-
- // no partitions
- cf.enablePartitionAwareFormatting(false);
-
- ChangeLogFormattingStrategy cfs = new ChangeLogFormattingStrategy();
-
- cf.setFormattingStrategy(cfs, IDocument.DEFAULT_CONTENT_TYPE);
-
-
- return cf;
- }
-
-
- /**
- * Highlights GNU format changelog syntaxes.
- *
- * @return reconciler for GNU format changelog.
- */
- @Override
- public IPresentationReconciler getPresentationReconciler(
- ISourceViewer sourceViewer) {
- PresentationReconciler reconciler = new PresentationReconciler();
- ColorRegistry colorRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
- GNUElementScanner scanner = new GNUElementScanner();
- scanner.setDefaultReturnToken(new Token(new TextAttribute(
- colorRegistry.get(IChangeLogColorConstants.TEXT))));
- DefaultDamagerRepairer dr = new DefaultDamagerRepairer(scanner);
- reconciler.setDamager(dr, GNUPartitionScanner.CHANGELOG_EMAIL);
- reconciler.setRepairer(dr, GNUPartitionScanner.CHANGELOG_EMAIL);
-
- dr= new GNUFileEntryDamagerRepairer(scanner);
- reconciler.setDamager(dr, GNUPartitionScanner.CHANGELOG_SRC_ENTRY);
- reconciler.setRepairer(dr, GNUPartitionScanner.CHANGELOG_SRC_ENTRY);
-
- dr= new MultilineRuleDamagerRepairer(scanner);
- reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
- reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
-
- return reconciler;
- }
-
- /**
- * Perform documentation setup to set up partitioning.
- *
- * @param document to set up partitioning on.
- */
- @Override
- public void setup(IDocument document) {
- FastPartitioner partitioner =
- new FastPartitioner(
- new GNUPartitionScanner(),
- GNUPartitionScanner.CHANGELOG_PARTITION_TYPES);
- partitioner.connect(document);
- if (document instanceof IDocumentExtension3) {
- IDocumentExtension3 extension3= (IDocumentExtension3) document;
- extension3.setDocumentPartitioner(CHANGELOG_PARTITIONING, partitioner);
- } else {
- document.setDocumentPartitioner(partitioner);
- }
- }
-
- @Override
- protected Map<String, IAdaptable> getHyperlinkDetectorTargets(ISourceViewer sourceViewer) {
- Map<String, IAdaptable> targets = super.getHyperlinkDetectorTargets(sourceViewer);
- targets.put("org.eclipse.changelog.editor.target", parentEditor); //$NON-NLS-1$
- targets.put("org.eclipse.ui.DefaultTextEditor", parentEditor); //$NON-NLS-1$
- return targets;
- }}
+}
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUHyperlinkDetector.java b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUHyperlinkDetector.java
index a1d8d26f0b..2a0c936551 100644
--- a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUHyperlinkDetector.java
+++ b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUHyperlinkDetector.java
@@ -11,13 +11,13 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.changelog.core.editors;
-import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.filebuffers.ITextFileBufferManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
@@ -26,185 +26,93 @@ import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.jface.text.rules.Token;
-import org.eclipse.team.ui.synchronize.SyncInfoCompareInput;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.editors.text.TextEditor;
-import org.eclipse.ui.texteditor.ITextEditor;
-
-/**
- *
- * @author klee (Kyu Lee)
- */
+
public class GNUHyperlinkDetector extends AbstractHyperlinkDetector {
- private IPath documentLocation;
-
- public GNUHyperlinkDetector() {
- }
-
- /**
- * Creates a new URL hyperlink detector for GNU Format changelogs.
- *
- * NOTE: It assumes that the path this ChangeLog is in, is root
- * directory of path names in this ChangeLog.
- *
- * ex) ChangeLog is in /some/project and in ChangeLog, path names are like
- * abc/file.java ghi/file2.java
- *
- * then absolute path of file.java and file2.java are
- * /some/project/abc/file.java and /some/project/ghi/file2.java
- *
- * @param textViewer The text viewer in which to detect the hyperlink.
- * @param editor The editor to fetch document location from.
- */
- public GNUHyperlinkDetector(ITextViewer textViewer, TextEditor editor) {
- Assert.isNotNull(textViewer);
-
- documentLocation = getDocumentLocation(editor);
-
- }
-
- /**
- * Detector using RuleBasedScanner.
- */
- @Override
- public IHyperlink[] detectHyperlinks(ITextViewer textViewer,
- IRegion region, boolean canShowMultipleHyperlinks) {
- if (documentLocation == null) {
- ITextEditor ed = this.getAdapter(ITextEditor.class);
- documentLocation = getDocumentLocation(ed);
- }
-
- IDocument thisDoc = textViewer.getDocument();
-
- GNUHyperlinkScanner scanner = new GNUHyperlinkScanner();
-
- ITypedRegion partitionInfo = null;
-
- try {
- partitionInfo = thisDoc.getPartition(region.getOffset());
- } catch (org.eclipse.jface.text.BadLocationException e1) {
- e1.printStackTrace();
- return null;
- }
-
- scanner.setRange(thisDoc, partitionInfo.getOffset(), partitionInfo.getLength());
-
- Token tmpToken = (Token) scanner.nextToken();
-
- String tokenStr = (String) tmpToken.getData();
-
- if (tokenStr == null) {
- return null;
- }
-
- // try to find non-default token containing region..if none, return null.
- while (region.getOffset() < scanner.getTokenOffset() ||
- region.getOffset() > scanner.getOffset() ||
- tokenStr.equals("_other")) {
- tmpToken = (Token) scanner.nextToken();
- tokenStr = (String) tmpToken.getData();
- if (tokenStr == null)
- return null;
- }
-
- Region tokenRegion = new Region(scanner.getTokenOffset(), scanner
- .getTokenLength());
-
- String line = "";
- try {
- line = thisDoc
- .get(tokenRegion.getOffset(), tokenRegion.getLength());
- } catch (org.eclipse.jface.text.BadLocationException e1) {
- e1.printStackTrace();
- return null;
- }
-
- // process file link
- if (tokenStr.equals(GNUHyperlinkScanner.FILE_NAME)) {
-
- Region pathRegion = null;
-
- int lineOffset = 0;
-
- // cut "* " if necessary
- if (line.startsWith("* ")) {
- lineOffset = 2;
- line = line.substring(2);
- }
-// int trailingWhiteSpace;
-// if (((trailingWhiteSpace = line.indexOf(":")) > 0)
-// || ((trailingWhiteSpace = line.indexOf(" ")) > 0)) {
-//
-// line = line.substring(0, trailingWhiteSpace);
-// pathRegion = new Region(tokenRegion.getOffset() + lineOffset,
-// trailingWhiteSpace);
-// } else {
- pathRegion = new Region(tokenRegion.getOffset() + lineOffset, line
- .length());
-// }
-
-
- if (documentLocation == null)
- return null;
-
- // Replace any escape characters added to name
- line = line.replaceAll("\\\\(.)", "$1");
-
- IFile fileLoc = ResourcesPlugin.getWorkspace().getRoot()
- .getFileForLocation(documentLocation.append(line));
- if (fileLoc.exists()) {
- return new IHyperlink[] { new FileHyperlink(pathRegion, fileLoc) };
- }
-
-
- }
+ private IPath documentLocation;
+
+ /**
+ * Detector using RuleBasedScanner.
+ */
+ @Override
+ public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
+ if (documentLocation == null) {
+ ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
+ ITextFileBuffer buffer = bufferManager.getTextFileBuffer(textViewer.getDocument());
+ documentLocation = buffer.getLocation().removeLastSegments(1);
+ }
+
+ IDocument thisDoc = textViewer.getDocument();
+
+ GNUHyperlinkScanner scanner = new GNUHyperlinkScanner();
+
+ ITypedRegion partitionInfo = null;
+
+ try {
+ partitionInfo = thisDoc.getPartition(region.getOffset());
+ } catch (org.eclipse.jface.text.BadLocationException e1) {
+ e1.printStackTrace();
+ return null;
+ }
+
+ scanner.setRange(thisDoc, partitionInfo.getOffset(), partitionInfo.getLength());
+
+ Token tmpToken = (Token) scanner.nextToken();
+
+ String tokenStr = (String) tmpToken.getData();
+
+ if (tokenStr == null) {
+ return null;
+ }
+
+ // try to find non-default token containing region..if none, return
+ // null.
+ while (region.getOffset() < scanner.getTokenOffset() || region.getOffset() > scanner.getOffset()
+ || tokenStr.equals("_other")) {
+ tmpToken = (Token) scanner.nextToken();
+ tokenStr = (String) tmpToken.getData();
+ if (tokenStr == null)
+ return null;
+ }
+
+ Region tokenRegion = new Region(scanner.getTokenOffset(), scanner.getTokenLength());
+
+ String line = "";
+ try {
+ line = thisDoc.get(tokenRegion.getOffset(), tokenRegion.getLength());
+ } catch (org.eclipse.jface.text.BadLocationException e1) {
+ e1.printStackTrace();
+ return null;
+ }
+
+ // process file link
+ if (tokenStr.equals(GNUHyperlinkScanner.FILE_NAME)) {
+
+ Region pathRegion = null;
+
+ int lineOffset = 0;
+
+ // cut "* " if necessary
+ if (line.startsWith("* ")) {
+ lineOffset = 2;
+ line = line.substring(2);
+ }
+ pathRegion = new Region(tokenRegion.getOffset() + lineOffset, line.length());
+
+ if (documentLocation == null)
+ return null;
+
+ // Replace any escape characters added to name
+ line = line.replaceAll("\\\\(.)", "$1");
- return null;
- }
-
- private IWorkspaceRoot getWorkspaceRoot() {
- return ResourcesPlugin.getWorkspace().getRoot();
- }
-
- /**
- * Get current directory that ChangeLog is in.
- *
- * @param currentEditor
- * @return path that this ChangeLog is in
- */
- private IPath getDocumentLocation(IEditorPart currentEditor) {
- IWorkspaceRoot myWorkspaceRoot = getWorkspaceRoot();
- String WorkspaceRoot = myWorkspaceRoot.getLocation().toOSString();
- IEditorInput cc = currentEditor.getEditorInput();
-
- if (cc instanceof IFileEditorInput) {
- IFileEditorInput test = (IFileEditorInput) cc;
- IFile loc = test.getFile();
-
- IPath docLoc = loc.getLocation();
- docLoc = docLoc.removeLastSegments(1);
- return docLoc;
-
- }
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IFile fileLoc = (IFile) root.findMember(documentLocation.append(line));
+ if (fileLoc.exists()) {
+ return new IHyperlink[] { new FileHyperlink(pathRegion, fileLoc) };
+ }
- if ((cc instanceof SyncInfoCompareInput)
- || (cc instanceof CompareEditorInput)) {
-
- CompareEditorInput test = (CompareEditorInput) cc;
- if (test.getCompareResult() == null)
- return null;
-
- IPath docLoc = new Path(WorkspaceRoot
- + test.getCompareResult().toString());
- docLoc = docLoc.removeLastSegments(1);
- return docLoc;
-
- }
-
- return null;
- }
+ }
+ return null;
+ }
}
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUPresentationReconciler.java b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUPresentationReconciler.java
new file mode 100644
index 0000000000..dfe9b9daef
--- /dev/null
+++ b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/editors/GNUPresentationReconciler.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Red Hat Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.changelog.core.editors;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.presentation.PresentationReconciler;
+import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
+
+public class GNUPresentationReconciler extends PresentationReconciler {
+
+ public GNUPresentationReconciler() {
+ GNUElementScanner scanner = new GNUElementScanner();
+ DefaultDamagerRepairer dr = new DefaultDamagerRepairer(scanner);
+ setDamager(dr, GNUPartitionScanner.CHANGELOG_EMAIL);
+ setRepairer(dr, GNUPartitionScanner.CHANGELOG_EMAIL);
+
+ dr = new GNUFileEntryDamagerRepairer(scanner);
+ setDamager(dr, GNUPartitionScanner.CHANGELOG_SRC_ENTRY);
+ setRepairer(dr, GNUPartitionScanner.CHANGELOG_SRC_ENTRY);
+
+ dr = new MultilineRuleDamagerRepairer(scanner);
+ setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
+ setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
+ }
+
+}

Back to the top