Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 61ce6cccb01d4b476f8e2e0aa5f600e335056a81 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*******************************************************************************
 * Copyright (c) 2006, 2007, 2011 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:
 *    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.action.IMenuManager;
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.linuxtools.internal.changelog.core.actions.FormatChangeLogAction;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;


/**
 * ChangeLog editor that supports GNU format.
 * 
 * @author klee (Kyu Lee)
 */
public class ChangeLogEditor extends TextEditor {

	FormatChangeLogAction fcla;

	protected boolean forceNewLogEntry;
	
	public ChangeLogEditor() {
		super();

		fcla = new FormatChangeLogAction(this);

		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 ChangeLogDocumentProvider());

	}

	/**
	 * Gets appropriate style editor from user pref.
	 * 
	 * @return configuration for the Changelog editor
	 */
	
	public 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();
	}
	
	/**
	 * Specifies context menu.
	 */
	@Override
	protected void editorContextMenuAboutToShow(IMenuManager menu) {
		super.editorContextMenuAboutToShow(menu);
		menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, fcla);

	}

	public boolean isForceNewLogEntry() {
		return forceNewLogEntry;
	}

	public void setForceNewLogEntry(boolean forceNewLogEntry) {
		this.forceNewLogEntry = forceNewLogEntry;
	}

}

Back to the top