Skip to main content
summaryrefslogtreecommitdiffstats
blob: d5f3e7b5302855e5c9d88ea8005ea0431721da93 (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*******************************************************************************
 * Copyright (c) 2000, 2008 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.ui.editors.text;

import java.nio.charset.UnmappableCharacterException;

import org.eclipse.core.resources.IResource;

import org.eclipse.core.filebuffers.IFileBuffer;
import org.eclipse.core.filebuffers.IFileBufferStatusCodes;

import org.eclipse.jface.preference.IPreferenceStore;

import org.eclipse.jface.text.source.ISharedTextColors;

import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.editors.text.EditorsPlugin;
import org.eclipse.ui.internal.editors.text.NLSUtility;
import org.eclipse.ui.keys.IBindingService;

import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
import org.eclipse.ui.texteditor.AnnotationPreferenceLookup;
import org.eclipse.ui.texteditor.AnnotationTypeLookup;
import org.eclipse.ui.texteditor.HyperlinkDetectorRegistry;
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
import org.eclipse.ui.texteditor.spelling.SpellingService;


/**
 * The central class for access to this plug-in.
 * This class cannot be instantiated; all functionality is provided by
 * static methods.
 *
 * @since 3.0
 * @noinstantiate This class is not intended to be instantiated by clients.
 */
public final class EditorsUI {

	/**
	 * TextEditor Plug-in ID (value <code>"org.eclipse.ui.editors"</code>).
	 */
	public static final String PLUGIN_ID= "org.eclipse.ui.editors"; //$NON-NLS-1$

	/**
	 * The ID of the default text editor.
	 */
	public static final String DEFAULT_TEXT_EDITOR_ID = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$


	/**
	 * Returns the annotation type lookup of this plug-in.
	 *
	 * @return the annotation type lookup
	 */
	public static AnnotationTypeLookup getAnnotationTypeLookup() {
		return EditorsPlugin.getDefault().getAnnotationTypeLookup();
	}

	/**
	 * Returns the annotation preference lookup of this plug-in.
	 *
	 * @return the annotation preference lookup
	 */
	public static AnnotationPreferenceLookup getAnnotationPreferenceLookup() {
		return EditorsPlugin.getDefault().getAnnotationPreferenceLookup();
	}

	/**
	 * Returns the preference store of this plug-in.
	 *
	 * @return this plug-in's preference store
	 */
	public static IPreferenceStore getPreferenceStore() {
		return EditorsPlugin.getDefault().getPreferenceStore();
	}

	/**
	 * Removes all preference which are handled by this plug-in's
	 * general preference pages from the given store and prevents
	 * setting the default values in the future.
	 * <p>
	 * To access the
	 * general preference from another plug-in use a
	 * {@link org.eclipse.ui.texteditor.ChainedPreferenceStore}:
	 * <pre>
	 *		List stores= new ArrayList(3);
	 *		stores.add(YourPlugin.getDefault().getPreferenceStore());
	 *		stores.add(EditorsUI.getPreferenceStore());
	 *		combinedStore= new ChainedPreferenceStore((IPreferenceStore[]) stores.toArray(new IPreferenceStore[stores.size()]));
	 *
	 * </pre>
	 * </p>
	 * <p>
	 * Note: In order to work this method must be called before
	 * the store's default values are set.
	 * </p>
	 *
	 * @param store the preference store to mark
	 */
	public static void useAnnotationsPreferencePage(IPreferenceStore store) {
		MarkerAnnotationPreferences.useAnnotationsPreferencePage(store);
	}

	/**
	 * Removes all preference which are handled by this plug-in's
	 * Quick Diff preference page from the given store and prevents
	 * setting the default values in the future.
	 * <p>
	 * To access the
	 * general preference from another plug-in use a
	 * {@link org.eclipse.ui.texteditor.ChainedPreferenceStore}:
	 * <pre>
	 *		List stores= new ArrayList(3);
	 *		stores.add(YourPlugin.getDefault().getPreferenceStore());
	 *		stores.add(EditorsUI.getPreferenceStore());
	 *		combinedStore= new ChainedPreferenceStore((IPreferenceStore[]) stores.toArray(new IPreferenceStore[stores.size()]));
	 *
	 * </pre>
	 * </p>
	 * <p>
	 * Note: In order to work this method must be called before
	 * the store's default values are set.
	 * </p>
	 *
	 * @param store the preference store to mark
	 */
	public static void useQuickDiffPreferencePage(IPreferenceStore store) {
		MarkerAnnotationPreferences.useQuickDiffPreferencePage(store);

		store.setToDefault(AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_ALWAYS_ON);
		store.setToDefault(AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_CHARACTER_MODE);
		store.setToDefault(AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_DEFAULT_PROVIDER);
	}

	private EditorsUI() {
		// block instantiation
	}

	/**
	 * Returns the preferences of this plug-in.
	 * 
	 * @return the plug-in preferences
	 * @see org.eclipse.core.runtime.Plugin#getPluginPreferences()
	 * @deprecated As of 3.5, replaced by {@link #getPreferenceStore()}
	 */
	@Deprecated
	public static org.eclipse.core.runtime.Preferences getPluginPreferences() {
		return EditorsPlugin.getDefault().getPluginPreferences();
	}

	/**
	 * Returns the spelling service.
	 *
	 * @return the spelling service
	 * @since 3.1
	 */
	public static SpellingService getSpellingService() {
		return EditorsPlugin.getDefault().getSpellingService();
	}

	/**
	 * Returns the shared text colors of this plug-in.
	 *
	 * @return the shared text colors
	 * @since 3.3
	 */
	public static ISharedTextColors getSharedTextColors() {
		return EditorsPlugin.getDefault().getSharedTextColors();
	}

	/**
	 * Returns the registry that contains the hyperlink detectors contributed
	 * by  the <code>org.eclipse.ui.workbench.texteditor.hyperlinkDetectors</code>
	 * extension point.
	 *
	 * @return the hyperlink detector registry
	 * @since 3.3
	 */
	public static HyperlinkDetectorRegistry getHyperlinkDetectorRegistry() {
		return EditorsPlugin.getDefault().getHyperlinkDetectorRegistry();
	}

	// --------------- Status codes for this plug-in ---------------

	// NOTE: See also IEditorsStatusConstants

	/**
	 * Editor UI plug-in status code indicating that an operation failed
	 * because a character could not be mapped using the given
	 * charset.
	 * <p>
	 * Value: {@value}</p>
	 *
	 * @see UnmappableCharacterException
	 * @since 3.2
	 */
	public static final int CHARSET_MAPPING_FAILED= 1;

	/**
	 * Editor UI plug-in status code indicating that state
	 * validation failed.
	 * <p>
	 * Value: {@value}</p>
	 *
	 * @see IFileBuffer#validateState(org.eclipse.core.runtime.IProgressMonitor, Object)
	 * @since 3.3
	 */
	public static final int STATE_VALIDATION_FAILED= IFileBufferStatusCodes.STATE_VALIDATION_FAILED;

	/**
	 * Editor UI plug-in status code indicating that
	 * a resource is marked derived.
	 * <p>
	 * Value: {@value}</p>
	 *
	 * @see IResource#isDerived()
	 * @since 3.3
	 */
	public static final int DERIVED_FILE= IFileBufferStatusCodes.DERIVED_FILE;

	/**
	 * Returns the tool tip affordance string.
	 *
	 * @return the affordance string which is empty if the preference is enabled
	 *			but the key binding not active or <code>null</code> if the
	 *			preference is disabled or the binding service is unavailable
	 * @since 3.3
	 */
	public static final String getTooltipAffordanceString() {
		if (!getPreferenceStore().getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_TEXT_HOVER_AFFORDANCE))
			return null;

		IBindingService bindingService= PlatformUI.getWorkbench().getAdapter(IBindingService.class);
		if (bindingService == null)
			return null;

		String keySequence= bindingService.getBestActiveBindingFormattedFor(ITextEditorActionDefinitionIds.SHOW_INFORMATION);
		if (keySequence == null)
			return ""; //$NON-NLS-1$

		return NLSUtility.format(TextEditorMessages.Editor_toolTip_affordance, keySequence);
	}

}

Back to the top