Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7a9721024700bd5f3d99b9efe3fe83e7182e48da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*******************************************************************************
 * Copyright (c) 2006, 2018 Red Hat Inc. and others.
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *    Kyu Lee <klee@redhat.com> - initial API and implementation
 *    Kiu Kwan Leung <kleung@redhat.com> - added a boolean field and its getter
 *                                         and setter to help formater properly
 *                                         decide when to add/delete a new line
 *******************************************************************************/
package org.eclipse.linuxtools.internal.changelog.core.editors;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.linuxtools.changelog.core.IEditorChangeLogContrib;
import org.eclipse.linuxtools.internal.changelog.core.ChangelogPlugin;
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.
 */
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", //$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;
	}

}

Back to the top