001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.texteditor;
011:
012: import java.util.StringTokenizer;
013:
014: import org.eclipse.jface.action.Action;
015: import org.eclipse.jface.preference.IPreferenceStore;
016: import org.eclipse.jface.preference.PreferenceConverter;
017: import org.eclipse.jface.resource.ColorRegistry;
018: import org.eclipse.jface.text.hyperlink.DefaultHyperlinkPresenter;
019: import org.eclipse.jface.text.revisions.IRevisionRulerColumnExtension;
020: import org.eclipse.swt.SWT;
021: import org.eclipse.swt.graphics.RGB;
022: import org.eclipse.ui.PlatformUI;
023: import org.eclipse.ui.editors.text.EditorsUI;
024: import org.eclipse.ui.internal.editors.text.EditorsPlugin;
025: import org.eclipse.ui.internal.texteditor.ITextEditorThemeConstants;
026: import org.eclipse.ui.texteditor.spelling.SpellingService;
027:
028: /**
029: * Preference constants used in the extended text editor preference store.
030: *
031: * @since 3.0
032: */
033: public class AbstractDecoratedTextEditorPreferenceConstants {
034:
035: /**
036: * Prevent initialization.
037: */
038: private AbstractDecoratedTextEditorPreferenceConstants() {
039: }
040:
041: /**
042: * A named preference that controls whether the current line highlighting is turned on or off
043: * (value <code>"currentLine"</code>).
044: * <p>
045: * The preference value is of type <code>Boolean</code>.
046: * </p>
047: */
048: public final static String EDITOR_CURRENT_LINE = "currentLine"; //$NON-NLS-1$
049:
050: /**
051: * A named preference that holds the color used to highlight the current line
052: * (value <code>"currentLineColor"</code>).
053: * <p>
054: * The preference value is of type <code>String</code>. A RGB color value encoded as a string
055: * using class <code>PreferenceConverter</code>.
056: * </p>
057: * @see org.eclipse.jface.resource.StringConverter
058: * @see PreferenceConverter
059: */
060: public final static String EDITOR_CURRENT_LINE_COLOR = "currentLineColor"; //$NON-NLS-1$
061:
062: /**
063: * A named preference that holds the number of spaces used per tab in the text editor.
064: * <p>
065: * Value is of type <code>int</code>: positive int value specifying the number of
066: * spaces per tab.
067: * </p>
068: */
069: public final static String EDITOR_TAB_WIDTH = "tabWidth"; //$NON-NLS-1$
070:
071: /**
072: * A named preference that specifies if the editor uses spaces for tabs.
073: * <p>
074: * Value is of type <code>Boolean</code>. If <code>true</code>spaces instead of tabs are used
075: * in the editor. If <code>false</code> the editor inserts a tab character when pressing the tab
076: * key.
077: * </p>
078: */
079: public final static String EDITOR_SPACES_FOR_TABS = "spacesForTabs"; //$NON-NLS-1$
080:
081: /**
082: * A named preference that holds the size of the editor's undo history.
083: * <p>
084: * Value is of type <code>int</code>: 0 or positive int value specifying the size of
085: * the editor's undo history.
086: * </p>
087: * @since 3.1
088: */
089: public final static String EDITOR_UNDO_HISTORY_SIZE = "undoHistorySize"; //$NON-NLS-1$
090:
091: /**
092: * A named preference that controls whether the print margin is turned on or off
093: * (value <code>"printMargin"</code>).
094: * <p>
095: * The preference value is of type <code>Boolean</code>.
096: * </p>
097: */
098: public final static String EDITOR_PRINT_MARGIN = "printMargin"; //$NON-NLS-1$
099:
100: /**
101: * A named preference that holds the color used to render the print margin
102: * (value <code>"printMarginColor"</code>).
103: * <p>
104: * The preference value is of type <code>String</code>. A RGB color value encoded as a string
105: * using class <code>PreferenceConverter</code>.
106: * </p>
107: * @see org.eclipse.jface.resource.StringConverter
108: * @see PreferenceConverter
109: */
110: public final static String EDITOR_PRINT_MARGIN_COLOR = "printMarginColor"; //$NON-NLS-1$
111:
112: /**
113: * Print margin column
114: * (value <code>"printMarginColumn"</code>).
115: * <p>
116: * The preference value is of type <code>int</code>.
117: * </p>
118: */
119: public final static String EDITOR_PRINT_MARGIN_COLUMN = "printMarginColumn"; //$NON-NLS-1$
120:
121: /**
122: * A named preference that controls whether the editor shows unknown
123: * indicators in text (squiggly lines).
124: * (value <code>"othersIndication"</code>).
125: * <p>
126: * The preference value is of type <code>Boolean</code>.
127: * </p>
128: * @deprecated as of 3.0 there are no UNKNOWN annotations any more
129: */
130: public final static String EDITOR_UNKNOWN_INDICATION = "othersIndication"; //$NON-NLS-1$
131:
132: /**
133: * A named preference that holds the color used to render unknown indicators
134: * (value <code>"othersIndicationColor"</code>).
135: * <p>
136: * The preference value is of type <code>String</code>. A RGB color value encoded as a string
137: * using class <code>PreferenceConverter</code>.
138: * </p>
139: * @see #EDITOR_UNKNOWN_INDICATION
140: * @see org.eclipse.jface.resource.StringConverter
141: * @see PreferenceConverter
142: * @deprecated As of 3.0, there are no UNKNOWN annotations any more
143: */
144: public final static String EDITOR_UNKNOWN_INDICATION_COLOR = "othersIndicationColor"; //$NON-NLS-1$
145:
146: /**
147: * A named preference that controls whether the overview ruler shows unknown indicators
148: * (value <code>"othersIndicationInOverviewRuler"</code>).
149: * <p>
150: * The preference value is of type <code>Boolean</code>.
151: * </p>
152: * @deprecated As of 3.0, there are no UNKNOWN annotations any more
153: */
154: public final static String EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER = "othersIndicationInOverviewRuler"; //$NON-NLS-1$
155:
156: /**
157: * A named preference that controls if the overview ruler is shown in the UI
158: * (value <code>"overviewRuler"</code>).
159: * <p>
160: * The preference value is of type <code>Boolean</code>.
161: * </p>
162: */
163: public final static String EDITOR_OVERVIEW_RULER = "overviewRuler"; //$NON-NLS-1$
164:
165: /**
166: * A named preference that controls if the line number ruler is shown in the UI
167: * (value <code>"lineNumberRuler"</code>).
168: * <p>
169: * The preference value is of type <code>Boolean</code>.
170: * </p>
171: */
172: public final static String EDITOR_LINE_NUMBER_RULER = "lineNumberRuler"; //$NON-NLS-1$
173:
174: /**
175: * A named preference that holds the color used to render line numbers inside the line number ruler
176: * (value <code>"lineNumberColor"</code>).
177: * <p>
178: * The preference value is of type <code>String</code>. A RGB color value encoded as a string
179: * using class <code>PreferenceConverter</code>.
180: * </p>
181: * @see org.eclipse.jface.resource.StringConverter
182: * @see PreferenceConverter
183: * @see #EDITOR_LINE_NUMBER_RULER
184: */
185: public final static String EDITOR_LINE_NUMBER_RULER_COLOR = "lineNumberColor"; //$NON-NLS-1$
186:
187: /**
188: * A named preference that controls whether this plug-in's
189: * Annotations preference page is used to configure annotations.
190: * <p>
191: * Value is of type <code>boolean</code>.
192: * </p>
193: */
194: public static final String USE_ANNOTATIONS_PREFERENCE_PAGE = "useAnnotationsPrefPage"; //$NON-NLS-1$
195:
196: /**
197: * A named preference that controls whether this plug-in's
198: * Quick Diff preference page is used to configure Quick Diff.
199: * <p>
200: * Value is of type <code>boolean</code>.
201: * </p>
202: */
203: public static final String USE_QUICK_DIFF_PREFERENCE_PAGE = "useQuickDiffPrefPage"; //$NON-NLS-1$
204:
205: /**
206: * A named preference that controls whether quick diff colors are shown on the line number bar.
207: * <p>
208: * Value is of type <code>boolean</code>.
209: * </p>
210: */
211: public static final String QUICK_DIFF_ALWAYS_ON = "quickdiff.quickDiff"; //$NON-NLS-1$
212:
213: /**
214: * A named preference that controls the default quick diff reference provider.
215: * <p>
216: * Value is of type <code>String</code>.
217: * </p>
218: */
219: public static final String QUICK_DIFF_DEFAULT_PROVIDER = "quickdiff.defaultProvider"; //$NON-NLS-1$
220:
221: /**
222: * A named preference that controls the default quick diff reference provider.
223: * <p>
224: * Value is of type <code>String</code>.
225: * </p>
226: */
227: public static final String QUICK_DIFF_CHARACTER_MODE = "quickdiff.characterMode"; //$NON-NLS-1$
228:
229: /**
230: * A named preference that controls whether custom carets are used in the
231: * editor or not.
232: * <p>
233: * Value is of type <code>Boolean</code>. If <code>false</code>, only
234: * the default caret is used in the editor.
235: * </p>
236: */
237: public static final String EDITOR_USE_CUSTOM_CARETS = AbstractTextEditor.PREFERENCE_USE_CUSTOM_CARETS;
238:
239: /**
240: * A named preference that controls whether carets are drawn wide or not.
241: * <p>
242: * Value is of type <code>Boolean</code>. If <code>true</code>, the caret is
243: * twice as wide as the default caret.
244: * </p>
245: */
246: public static final String EDITOR_WIDE_CARET = AbstractTextEditor.PREFERENCE_WIDE_CARET;
247:
248: /**
249: * A named preference that holds the color used as the text selection foreground.
250: * This value has no effect if the system default color is used.
251: * <p>
252: * Value is of type <code>String</code>. A RGB color value encoded as a string
253: * using class <code>PreferenceConverter</code>
254: * </p>
255: *
256: * @see org.eclipse.jface.resource.StringConverter
257: * @see PreferenceConverter
258: */
259: public final static String EDITOR_SELECTION_FOREGROUND_COLOR = AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND;
260:
261: /**
262: * A named preference that describes if the system default selection foreground color
263: * is used as the text selection foreground.
264: * <p>
265: * Value is of type <code>Boolean</code>.
266: * </p>
267: */
268: public final static String EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR = AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND_SYSTEM_DEFAULT;
269:
270: /**
271: * A named preference that holds the color used as the text selection background.
272: * This value has no effect if the system default color is used.
273: * <p>
274: * Value is of type <code>String</code>. A RGB color value encoded as a string
275: * using class <code>PreferenceConverter</code>
276: * </p>
277: *
278: * @see org.eclipse.jface.resource.StringConverter
279: * @see PreferenceConverter
280: */
281: public final static String EDITOR_SELECTION_BACKGROUND_COLOR = AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND;
282:
283: /**
284: * A named preference that describes if the system default selection background color
285: * is used as the text selection background.
286: * <p>
287: * Value is of type <code>Boolean</code>.
288: * </p>
289: */
290: public final static String EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR = AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND_SYSTEM_DEFAULT;
291:
292: /**
293: * A named preference that controls if hyperlinks are turned on or off.
294: * <p>
295: * Value is of type <code>Boolean</code>.
296: * </p>
297: *
298: * @since 3.1
299: */
300: public static final String EDITOR_HYPERLINKS_ENABLED = AbstractTextEditor.PREFERENCE_HYPERLINKS_ENABLED;
301:
302: /**
303: * A named preference that controls the key modifier for hyperlinks.
304: * <p>
305: * Value is of type <code>String</code>.
306: * </p>
307: *
308: * @since 3.1
309: */
310: public static final String EDITOR_HYPERLINK_KEY_MODIFIER = AbstractTextEditor.PREFERENCE_HYPERLINK_KEY_MODIFIER;
311:
312: /**
313: * A named preference that controls the key modifier mask for hyperlinks.
314: * The value is only used if the value of <code>EDITOR_HYPERLINK_KEY_MODIFIER</code>
315: * cannot be resolved to valid SWT modifier bits.
316: * <p>
317: * Value is of type <code>String</code>.
318: * </p>
319: *
320: * @see #EDITOR_HYPERLINK_KEY_MODIFIER
321: * @since 3.1
322: */
323: public static final String EDITOR_HYPERLINK_KEY_MODIFIER_MASK = AbstractTextEditor.PREFERENCE_HYPERLINK_KEY_MODIFIER_MASK;
324:
325: /**
326: * A named preference that holds the color used for hyperlinks.
327: * <p>
328: * Value is of type <code>String</code>. A RGB color value encoded as a string
329: * using class <code>PreferenceConverter</code>
330: * </p>
331: *
332: * @see org.eclipse.jface.resource.StringConverter
333: * @see org.eclipse.jface.preference.PreferenceConverter
334: * @since 3.1
335: */
336: public final static String EDITOR_HYPERLINK_COLOR = DefaultHyperlinkPresenter.HYPERLINK_COLOR;
337:
338: /**
339: * A named preference that controls disabling of the overwrite mode.
340: * <p>
341: * Value is of type <code>Boolean</code>.
342: * </p>
343: *
344: * @since 3.1
345: */
346: public static final String EDITOR_DISABLE_OVERWRITE_MODE = "disable_overwrite_mode"; //$NON-NLS-1$
347:
348: /**
349: * A named preference that controls whether a confirmation
350: * dialog is shown before editing derived input.
351: * <p>
352: * Value is of type <code>Boolean</code>.
353: * </p>
354: *
355: * @since 3.3
356: */
357: public static final String EDITOR_WARN_IF_INPUT_DERIVED = "warn_if_input_derived"; //$NON-NLS-1$
358:
359: /**
360: * A named preference that controls if smart home/end navigation is on or off
361: * <p>
362: * Value is of type <code>Boolean</code>.
363: * </p>
364: *
365: * @since 3.3
366: */
367: public static final String EDITOR_SMART_HOME_END = AbstractTextEditor.PREFERENCE_NAVIGATION_SMART_HOME_END;
368:
369: /**
370: * A named preference that controls the display of whitespace characters.
371: * <p>
372: * Value is of type <code>Boolean</code>.
373: * </p>
374: *
375: * @since 3.3
376: */
377: public static final String EDITOR_SHOW_WHITESPACE_CHARACTERS = AbstractTextEditor.PREFERENCE_SHOW_WHITESPACE_CHARACTERS;
378:
379: /**
380: * A named preference that controls the display of the range indicator.
381: * <p>
382: * Value is of type <code>Boolean</code>.
383: * </p>
384: *
385: * @since 3.1
386: */
387: public static final String SHOW_RANGE_INDICATOR = "show_range_indicator"; //$NON-NLS-1$
388:
389: /**
390: * A named preference that controls whether the user is asked before switching the quick diff
391: * reference when showing revision information..
392: * <p>
393: * Value is of type <code>String</code>.
394: * </p>
395: *
396: * @since 3.2
397: */
398: public static final String REVISION_ASK_BEFORE_QUICKDIFF_SWITCH = "quickdiff.nowarn.before.switch"; //$NON-NLS-1$
399:
400: /**
401: * A named preference that controls the rendering mode of the revision ruler.
402: * <p>
403: * Value is of type <code>String</code> and should contain the name of a
404: * {@link org.eclipse.jface.text.revisions.IRevisionRulerColumnExtension.RenderingMode}.
405: * </p>
406: *
407: * @since 3.3
408: */
409: public static final String REVISION_RULER_RENDERING_MODE = "revisionRulerRenderingMode"; //$NON-NLS-1$
410:
411: /**
412: * A named preference that controls the rendering of the author on the revision ruler.
413: * <p>
414: * Value is of type <code>Boolean</code>.
415: * </p>
416: *
417: * @since 3.3
418: */
419: public static final String REVISION_RULER_SHOW_AUTHOR = "revisionRulerShowAuthor"; //$NON-NLS-1$
420:
421: /**
422: * A named preference that controls rendering of the revision on the revision ruler.
423: * <p>
424: * Value is of type <code>Boolean</code>.
425: * </p>
426: *
427: * @since 3.3
428: */
429: public static final String REVISION_RULER_SHOW_REVISION = "revisionRulerShowRevision"; //$NON-NLS-1$
430:
431: /**
432: * A named preference that controls whether text drag and drop is enabled.
433: * <p>
434: * Value is of type <code>Boolean</code>.
435: * </p>
436: *
437: * @since 3.3
438: */
439: public static final String EDITOR_TEXT_DRAG_AND_DROP_ENABLED = AbstractTextEditor.PREFERENCE_TEXT_DRAG_AND_DROP_ENABLED;
440:
441: /**
442: * A named preference that defines whether the hint to make hover sticky should be shown.
443: * <p>
444: * Value is of type <code>Boolean</code>.
445: * </p>
446: *
447: * @since 3.3
448: */
449: public static final String EDITOR_SHOW_TEXT_HOVER_AFFORDANCE = "showTextHoverAffordance"; //$NON-NLS-1$
450:
451: /**
452: * Initializes the given preference store with the default values.
453: *
454: * @param store the preference store to be initialized
455: */
456: public static void initializeDefaultValues(IPreferenceStore store) {
457: ColorRegistry registry = null;
458: if (PlatformUI.isWorkbenchRunning())
459: registry = PlatformUI.getWorkbench().getThemeManager()
460: .getCurrentTheme().getColorRegistry();
461:
462: store
463: .setDefault(
464: AbstractDecoratedTextEditorPreferenceConstants.USE_ANNOTATIONS_PREFERENCE_PAGE,
465: false);
466: store
467: .setDefault(
468: AbstractDecoratedTextEditorPreferenceConstants.USE_QUICK_DIFF_PREFERENCE_PAGE,
469: false);
470:
471: store
472: .setDefault(
473: AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE,
474: true);
475: setDefaultAndFireEvent(
476: store,
477: AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR,
478: findRGB(registry,
479: ITextEditorThemeConstants.CURRENT_LINE_COLOR,
480: new RGB(232, 242, 254)));
481:
482: store
483: .setDefault(
484: AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH,
485: 4);
486: store
487: .setDefault(
488: AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS,
489: false);
490:
491: store
492: .setDefault(
493: AbstractDecoratedTextEditorPreferenceConstants.EDITOR_UNDO_HISTORY_SIZE,
494: 200);
495:
496: store
497: .setDefault(
498: AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN,
499: false);
500: store
501: .setDefault(
502: AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN,
503: 80);
504:
505: setDefaultAndFireEvent(
506: store,
507: AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR,
508: findRGB(registry,
509: ITextEditorThemeConstants.PRINT_MARGIN_COLOR,
510: new RGB(176, 180, 185)));
511:
512: store
513: .setDefault(
514: AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER,
515: false);
516: setDefaultAndFireEvent(
517: store,
518: AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR,
519: findRGB(
520: registry,
521: ITextEditorThemeConstants.LINE_NUMBER_RULER_COLOR,
522: new RGB(120, 120, 120)));
523:
524: if (!store.getBoolean(USE_QUICK_DIFF_PREFERENCE_PAGE)) {
525: store
526: .setDefault(
527: AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_ALWAYS_ON,
528: true);
529: store
530: .setDefault(
531: AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_CHARACTER_MODE,
532: false);
533: store
534: .setDefault(
535: AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_DEFAULT_PROVIDER,
536: "org.eclipse.ui.internal.editors.quickdiff.LastSaveReferenceProvider"); //$NON-NLS-1$
537: }
538:
539: store
540: .setDefault(
541: AbstractDecoratedTextEditorPreferenceConstants.EDITOR_OVERVIEW_RULER,
542: true);
543:
544: store
545: .setDefault(
546: AbstractDecoratedTextEditorPreferenceConstants.EDITOR_UNKNOWN_INDICATION,
547: false);
548: store
549: .setDefault(
550: AbstractDecoratedTextEditorPreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER,
551: false);
552: PreferenceConverter
553: .setDefault(
554: store,
555: AbstractDecoratedTextEditorPreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR,
556: new RGB(0, 0, 0));
557:
558: store
559: .setDefault(
560: AbstractDecoratedTextEditorPreferenceConstants.EDITOR_USE_CUSTOM_CARETS,
561: false);
562: store
563: .setDefault(
564: AbstractDecoratedTextEditorPreferenceConstants.EDITOR_WIDE_CARET,
565: true);
566:
567: store
568: .setDefault(
569: AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR,
570: true);
571: store
572: .setDefault(
573: AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR,
574: true);
575:
576: store
577: .setDefault(
578: AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT,
579: true);
580: setDefaultAndFireEvent(
581: store,
582: AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND,
583: findRGB(
584: registry,
585: ITextEditorThemeConstants.PREFERENCE_COLOR_BACKGROUND,
586: new RGB(255, 255, 255)));
587:
588: store
589: .setDefault(
590: AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT,
591: true);
592: setDefaultAndFireEvent(
593: store,
594: AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND,
595: findRGB(
596: registry,
597: ITextEditorThemeConstants.PREFERENCE_COLOR_FOREGROUND,
598: new RGB(0, 0, 0)));
599:
600: String mod1Name = Action.findModifierString(SWT.MOD1); // SWT.COMMAND on MAC; SWT.CONTROL elsewhere
601: store
602: .setDefault(
603: AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED,
604: true);
605: store
606: .setDefault(
607: AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINK_KEY_MODIFIER,
608: mod1Name);
609: store
610: .setDefault(
611: AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINK_KEY_MODIFIER_MASK,
612: SWT.MOD1);
613:
614: setDefaultAndFireEvent(
615: store,
616: AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINK_COLOR,
617: findRGB(registry,
618: ITextEditorThemeConstants.HYPERLINK_COLOR,
619: new RGB(0, 0, 255)));
620:
621: HyperlinkDetectorDescriptor[] descriptors = EditorsUI
622: .getHyperlinkDetectorRegistry()
623: .getHyperlinkDetectorDescriptors();
624: for (int i = 0; i < descriptors.length; i++) {
625: int stateMask = computeStateMask(descriptors[i]
626: .getModifierKeys());
627: if (stateMask == SWT.SHIFT) {
628: EditorsPlugin
629: .logErrorMessage("The '" + descriptors[i].getId() + "' hyperlink detector specifies 'Shift' as modifier. This is not allowed and hence replaced with the default modifier."); //$NON-NLS-1$ //$NON-NLS-2$
630: stateMask = -1;
631: }
632: store.setDefault(descriptors[i].getId()
633: + HyperlinkDetectorDescriptor.STATE_MASK_POSTFIX,
634: stateMask);
635: }
636:
637: store.setToDefault(EDITOR_DISABLE_OVERWRITE_MODE);
638:
639: /*
640: * As of 3.3 we enabled spell checking per default
641: * but do not want this to impact our performance tests. For this
642: * reason we disable it when running the UI test application.
643: */
644: boolean isInTestMode = System.getProperty("eclipse.perf.dbloc") != null; //$NON-NLS-1$
645: boolean isInstalled = EditorsUI.getSpellingService()
646: .getSpellingEngineDescriptors().length > 0;
647: store.setDefault(SpellingService.PREFERENCE_SPELLING_ENABLED,
648: !isInTestMode && isInstalled);
649: store
650: .setDefault(SpellingService.PREFERENCE_SPELLING_ENGINE,
651: ""); //$NON-NLS-1$
652:
653: store.setDefault(SHOW_RANGE_INDICATOR, true);
654: store.setDefault(REVISION_ASK_BEFORE_QUICKDIFF_SWITCH, ""); //$NON-NLS-1$
655:
656: setDefaultAndFireEvent(store,
657: AbstractTextEditor.PREFERENCE_COLOR_FIND_SCOPE,
658: findRGB(registry,
659: ITextEditorThemeConstants.FIND_SCOPE_COLOR,
660: new RGB(185, 176, 180)));
661:
662: store.setDefault(
663: AbstractTextEditor.PREFERENCE_RULER_CONTRIBUTIONS, ""); //$NON-NLS-1$
664: store.setDefault(REVISION_RULER_RENDERING_MODE,
665: IRevisionRulerColumnExtension.AGE.name());
666: store.setDefault(REVISION_RULER_SHOW_AUTHOR, false);
667: store.setDefault(REVISION_RULER_SHOW_REVISION, false);
668:
669: store.setDefault(EDITOR_WARN_IF_INPUT_DERIVED, true);
670: store.setDefault(EDITOR_SMART_HOME_END, true);
671: store.setDefault(EDITOR_SHOW_WHITESPACE_CHARACTERS, false);
672: store.setDefault(EDITOR_TEXT_DRAG_AND_DROP_ENABLED, true);
673: store.setDefault(EDITOR_SHOW_TEXT_HOVER_AFFORDANCE, true);
674:
675: MarkerAnnotationPreferences.initializeDefaultValues(store);
676: }
677:
678: /**
679: * Sets the default value and fires a property
680: * change event if necessary.
681: *
682: * @param store the preference store
683: * @param key the preference key
684: * @param newValue the new value
685: * @since 3.3
686: */
687: private static void setDefaultAndFireEvent(IPreferenceStore store,
688: String key, RGB newValue) {
689: RGB oldValue = null;
690: if (store.isDefault(key))
691: oldValue = PreferenceConverter.getDefaultColor(store, key);
692:
693: PreferenceConverter.setDefault(store, key, newValue);
694:
695: if (oldValue != null && !oldValue.equals(newValue))
696: store.firePropertyChangeEvent(key, oldValue, newValue);
697: }
698:
699: /**
700: * Returns the RGB for the given key in the given color registry.
701: *
702: * @param registry the color registry
703: * @param key the key for the constant in the registry
704: * @param defaultRGB the default RGB if no entry is found
705: * @return RGB the RGB
706: * @since 3.3
707: */
708: private static RGB findRGB(ColorRegistry registry, String key,
709: RGB defaultRGB) {
710: if (registry == null)
711: return defaultRGB;
712:
713: RGB rgb = registry.getRGB(key);
714: if (rgb != null)
715: return rgb;
716: return defaultRGB;
717: }
718:
719: /**
720: * Computes the state mask out of the given modifiers string.
721: *
722: * @param modifiers a string containing modifiers
723: * @return the state mask
724: * @since 3.3
725: */
726: private static final int computeStateMask(String modifiers) {
727: if (modifiers == null)
728: return -1;
729:
730: if (modifiers.length() == 0)
731: return SWT.NONE;
732:
733: int stateMask = 0;
734: StringTokenizer modifierTokenizer = new StringTokenizer(
735: modifiers, ",;.:+-* "); //$NON-NLS-1$
736: while (modifierTokenizer.hasMoreTokens()) {
737: int modifier = findLocalizedModifier(modifierTokenizer
738: .nextToken());
739: if (modifier == 0 || (stateMask & modifier) == modifier)
740: return -1;
741: stateMask = stateMask | modifier;
742: }
743: return stateMask;
744: }
745:
746: /**
747: * Maps the localized modifier name to a code in the same
748: * manner as #findModifier.
749: *
750: * @param modifierName the modifier name
751: * @return the SWT modifier bit, or <code>0</code> if no match was found
752: * @since 3.3
753: */
754: private static final int findLocalizedModifier(String modifierName) {
755: if (modifierName == null)
756: return SWT.NONE;
757:
758: if (modifierName.equalsIgnoreCase("M1")) //$NON-NLS-1$
759: return SWT.MOD1;
760: if (modifierName.equalsIgnoreCase("M2")) //$NON-NLS-1$
761: return SWT.MOD2;
762: if (modifierName.equalsIgnoreCase("M3")) //$NON-NLS-1$
763: return SWT.MOD3;
764: if (modifierName.equalsIgnoreCase("M4")) //$NON-NLS-1$
765: return SWT.MOD4;
766: if (modifierName.equalsIgnoreCase(Action
767: .findModifierString(SWT.CTRL)))
768: return SWT.CTRL;
769: if (modifierName.equalsIgnoreCase(Action
770: .findModifierString(SWT.SHIFT)))
771: return SWT.SHIFT;
772: if (modifierName.equalsIgnoreCase(Action
773: .findModifierString(SWT.ALT)))
774: return SWT.ALT;
775: if (modifierName.equalsIgnoreCase(Action
776: .findModifierString(SWT.COMMAND)))
777: return SWT.COMMAND;
778:
779: return SWT.NONE;
780: }
781:
782: }
|