1 11 package org.eclipse.ui.texteditor; 12 13 import java.util.StringTokenizer ; 14 15 import org.eclipse.jface.action.Action; 16 import org.eclipse.jface.preference.IPreferenceStore; 17 import org.eclipse.jface.preference.PreferenceConverter; 18 import org.eclipse.jface.resource.ColorRegistry; 19 import org.eclipse.jface.text.hyperlink.DefaultHyperlinkPresenter; 20 import org.eclipse.jface.text.revisions.IRevisionRulerColumnExtension; 21 import org.eclipse.swt.SWT; 22 import org.eclipse.swt.graphics.RGB; 23 import org.eclipse.ui.PlatformUI; 24 import org.eclipse.ui.editors.text.EditorsUI; 25 import org.eclipse.ui.internal.editors.text.EditorsPlugin; 26 import org.eclipse.ui.internal.texteditor.ITextEditorThemeConstants; 27 import org.eclipse.ui.texteditor.spelling.SpellingService; 28 29 34 public class AbstractDecoratedTextEditorPreferenceConstants { 35 36 37 40 private AbstractDecoratedTextEditorPreferenceConstants() { 41 } 42 43 50 public final static String EDITOR_CURRENT_LINE= "currentLine"; 52 62 public final static String EDITOR_CURRENT_LINE_COLOR= "currentLineColor"; 64 71 public final static String EDITOR_TAB_WIDTH= "tabWidth"; 73 81 public final static String EDITOR_SPACES_FOR_TABS= "spacesForTabs"; 83 91 public final static String EDITOR_UNDO_HISTORY_SIZE= "undoHistorySize"; 93 100 public final static String EDITOR_PRINT_MARGIN= "printMargin"; 102 112 public final static String EDITOR_PRINT_MARGIN_COLOR= "printMarginColor"; 114 121 public final static String EDITOR_PRINT_MARGIN_COLUMN= "printMarginColumn"; 123 132 public final static String EDITOR_UNKNOWN_INDICATION= "othersIndication"; 134 146 public final static String EDITOR_UNKNOWN_INDICATION_COLOR= "othersIndicationColor"; 148 156 public final static String EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER= "othersIndicationInOverviewRuler"; 158 165 public final static String EDITOR_OVERVIEW_RULER= "overviewRuler"; 167 174 public final static String EDITOR_LINE_NUMBER_RULER= "lineNumberRuler"; 176 187 public final static String EDITOR_LINE_NUMBER_RULER_COLOR= "lineNumberColor"; 189 196 public static final String USE_ANNOTATIONS_PREFERENCE_PAGE= "useAnnotationsPrefPage"; 198 205 public static final String USE_QUICK_DIFF_PREFERENCE_PAGE= "useQuickDiffPrefPage"; 207 213 public static final String QUICK_DIFF_ALWAYS_ON= "quickdiff.quickDiff"; 215 221 public static final String QUICK_DIFF_DEFAULT_PROVIDER= "quickdiff.defaultProvider"; 223 229 public static final String QUICK_DIFF_CHARACTER_MODE= "quickdiff.characterMode"; 231 239 public static final String EDITOR_USE_CUSTOM_CARETS= AbstractTextEditor.PREFERENCE_USE_CUSTOM_CARETS; 240 241 248 public static final String EDITOR_WIDE_CARET= AbstractTextEditor.PREFERENCE_WIDE_CARET; 249 250 261 public final static String EDITOR_SELECTION_FOREGROUND_COLOR= AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND; 262 263 270 public final static String EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR= AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND_SYSTEM_DEFAULT; 271 272 283 public final static String EDITOR_SELECTION_BACKGROUND_COLOR= AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND; 284 285 292 public final static String EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR= AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND_SYSTEM_DEFAULT; 293 294 302 public static final String EDITOR_HYPERLINKS_ENABLED= AbstractTextEditor.PREFERENCE_HYPERLINKS_ENABLED; 303 304 312 public static final String EDITOR_HYPERLINK_KEY_MODIFIER= AbstractTextEditor.PREFERENCE_HYPERLINK_KEY_MODIFIER; 313 314 325 public static final String EDITOR_HYPERLINK_KEY_MODIFIER_MASK= AbstractTextEditor.PREFERENCE_HYPERLINK_KEY_MODIFIER_MASK; 326 327 338 public final static String EDITOR_HYPERLINK_COLOR= DefaultHyperlinkPresenter.HYPERLINK_COLOR; 339 340 348 public static final String EDITOR_DISABLE_OVERWRITE_MODE= "disable_overwrite_mode"; 350 359 public static final String EDITOR_WARN_IF_INPUT_DERIVED= "warn_if_input_derived"; 361 369 public static final String EDITOR_SMART_HOME_END= AbstractTextEditor.PREFERENCE_NAVIGATION_SMART_HOME_END; 370 371 379 public static final String EDITOR_SHOW_WHITESPACE_CHARACTERS= AbstractTextEditor.PREFERENCE_SHOW_WHITESPACE_CHARACTERS; 380 381 389 public static final String SHOW_RANGE_INDICATOR= "show_range_indicator"; 391 400 public static final String REVISION_ASK_BEFORE_QUICKDIFF_SWITCH= "quickdiff.nowarn.before.switch"; 402 411 public static final String REVISION_RULER_RENDERING_MODE= "revisionRulerRenderingMode"; 413 421 public static final String REVISION_RULER_SHOW_AUTHOR= "revisionRulerShowAuthor"; 423 431 public static final String REVISION_RULER_SHOW_REVISION= "revisionRulerShowRevision"; 433 441 public static final String EDITOR_TEXT_DRAG_AND_DROP_ENABLED= AbstractTextEditor.PREFERENCE_TEXT_DRAG_AND_DROP_ENABLED; 442 443 451 public static final String EDITOR_SHOW_TEXT_HOVER_AFFORDANCE= "showTextHoverAffordance"; 453 458 public static void initializeDefaultValues(IPreferenceStore store) { 459 ColorRegistry registry= null; 460 if (PlatformUI.isWorkbenchRunning()) 461 registry= PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry(); 462 463 store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.USE_ANNOTATIONS_PREFERENCE_PAGE, false); 464 store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.USE_QUICK_DIFF_PREFERENCE_PAGE, false); 465 466 store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE, true); 467 setDefaultAndFireEvent(store, 468 AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR, 469 findRGB(registry, ITextEditorThemeConstants.CURRENT_LINE_COLOR, new RGB(232, 242, 254))); 470 471 store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH, 4); 472 store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS, false); 473 474 store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_UNDO_HISTORY_SIZE, 200); 475 476 store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN, false); 477 store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN, 80); 478 479 setDefaultAndFireEvent(store, 480 AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR, 481 findRGB(registry,ITextEditorThemeConstants.PRINT_MARGIN_COLOR, new RGB(176, 180 , 185))); 482 483 store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER, false); 484 setDefaultAndFireEvent(store, 485 AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR, 486 findRGB(registry, ITextEditorThemeConstants.LINE_NUMBER_RULER_COLOR, new RGB(120, 120, 120))); 487 488 if (!store.getBoolean(USE_QUICK_DIFF_PREFERENCE_PAGE)) { 489 store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_ALWAYS_ON, true); 490 store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_CHARACTER_MODE, false); 491 store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_DEFAULT_PROVIDER, "org.eclipse.ui.internal.editors.quickdiff.LastSaveReferenceProvider"); } 493 494 store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_OVERVIEW_RULER, true); 495 496 store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_UNKNOWN_INDICATION, false); 497 store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER, false); 498 PreferenceConverter.setDefault(store, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR, new RGB(0, 0, 0)); 499 500 store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_USE_CUSTOM_CARETS, false); 501 store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_WIDE_CARET, true); 502 503 store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR, true); 504 store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR, true); 505 506 store.setDefault(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, true); 507 setDefaultAndFireEvent(store, 508 AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, 509 findRGB(registry, ITextEditorThemeConstants.PREFERENCE_COLOR_BACKGROUND, new RGB(255, 255, 255))); 510 511 store.setDefault(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT, true); 512 setDefaultAndFireEvent(store, 513 AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, 514 findRGB(registry, ITextEditorThemeConstants.PREFERENCE_COLOR_FOREGROUND, new RGB(0,0,0))); 515 516 String mod1Name= Action.findModifierString(SWT.MOD1); store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED, true); 518 store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINK_KEY_MODIFIER, mod1Name); 519 store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINK_KEY_MODIFIER_MASK, SWT.MOD1); 520 521 setDefaultAndFireEvent(store, 522 AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINK_COLOR, 523 findRGB(registry,ITextEditorThemeConstants.HYPERLINK_COLOR, new RGB(0, 0, 255))); 524 525 HyperlinkDetectorDescriptor[] descriptors= EditorsUI.getHyperlinkDetectorRegistry().getHyperlinkDetectorDescriptors(); 526 for (int i= 0; i < descriptors.length; i++) { 527 int stateMask= computeStateMask(descriptors[i].getModifierKeys()); 528 if (stateMask == SWT.SHIFT) { 529 EditorsPlugin.logErrorMessage("The '" + descriptors[i].getId() + "' hyperlink detector specifies 'Shift' as modifier. This is not allowed and hence replaced with the default modifier."); stateMask= -1; 531 } 532 store.setDefault(descriptors[i].getId() + HyperlinkDetectorDescriptor.STATE_MASK_POSTFIX, stateMask); 533 } 534 535 store.setToDefault(EDITOR_DISABLE_OVERWRITE_MODE); 536 537 542 boolean isInTestMode= System.getProperty("eclipse.perf.dbloc") != null; boolean isInstalled= EditorsUI.getSpellingService().getSpellingEngineDescriptors().length > 0; 544 store.setDefault(SpellingService.PREFERENCE_SPELLING_ENABLED, !isInTestMode && isInstalled); 545 store.setDefault(SpellingService.PREFERENCE_SPELLING_ENGINE, ""); 547 store.setDefault(SHOW_RANGE_INDICATOR, true); 548 store.setDefault(REVISION_ASK_BEFORE_QUICKDIFF_SWITCH, ""); 550 setDefaultAndFireEvent(store, 551 AbstractTextEditor.PREFERENCE_COLOR_FIND_SCOPE, 552 findRGB(registry, ITextEditorThemeConstants.FIND_SCOPE_COLOR, new RGB(185, 176 , 180))); 553 554 store.setDefault(AbstractTextEditor.PREFERENCE_RULER_CONTRIBUTIONS, ""); store.setDefault(REVISION_RULER_RENDERING_MODE, IRevisionRulerColumnExtension.AGE.name()); 556 store.setDefault(REVISION_RULER_SHOW_AUTHOR, false); 557 store.setDefault(REVISION_RULER_SHOW_REVISION, false); 558 559 store.setDefault(EDITOR_WARN_IF_INPUT_DERIVED, true); 560 store.setDefault(EDITOR_SMART_HOME_END, true); 561 store.setDefault(EDITOR_SHOW_WHITESPACE_CHARACTERS, false); 562 store.setDefault(EDITOR_TEXT_DRAG_AND_DROP_ENABLED, true); 563 store.setDefault(EDITOR_SHOW_TEXT_HOVER_AFFORDANCE, true); 564 565 MarkerAnnotationPreferences.initializeDefaultValues(store); 566 } 567 568 577 private static void setDefaultAndFireEvent(IPreferenceStore store, String key, RGB newValue) { 578 RGB oldValue= null; 579 if (store.isDefault(key)) 580 oldValue= PreferenceConverter.getDefaultColor(store, key); 581 582 PreferenceConverter.setDefault(store, key, newValue); 583 584 if (oldValue != null && !oldValue.equals(newValue)) 585 store.firePropertyChangeEvent(key, oldValue, newValue); 586 } 587 588 597 private static RGB findRGB(ColorRegistry registry, String key, RGB defaultRGB) { 598 if (registry == null) 599 return defaultRGB; 600 601 RGB rgb= registry.getRGB(key); 602 if (rgb != null) 603 return rgb; 604 return defaultRGB; 605 } 606 607 614 private static final int computeStateMask(String modifiers) { 615 if (modifiers == null) 616 return -1; 617 618 if (modifiers.length() == 0) 619 return SWT.NONE; 620 621 int stateMask= 0; 622 StringTokenizer modifierTokenizer= new StringTokenizer (modifiers, ",;.:+-* "); while (modifierTokenizer.hasMoreTokens()) { 624 int modifier= findLocalizedModifier(modifierTokenizer.nextToken()); 625 if (modifier == 0 || (stateMask & modifier) == modifier) 626 return -1; 627 stateMask= stateMask | modifier; 628 } 629 return stateMask; 630 } 631 632 640 private static final int findLocalizedModifier(String modifierName) { 641 if (modifierName == null) 642 return SWT.NONE; 643 644 if (modifierName.equalsIgnoreCase("M1")) return SWT.MOD1; 646 if (modifierName.equalsIgnoreCase("M2")) return SWT.MOD2; 648 if (modifierName.equalsIgnoreCase("M3")) return SWT.MOD3; 650 if (modifierName.equalsIgnoreCase("M4")) return SWT.MOD4; 652 if (modifierName.equalsIgnoreCase(Action.findModifierString(SWT.CTRL))) 653 return SWT.CTRL; 654 if (modifierName.equalsIgnoreCase(Action.findModifierString(SWT.SHIFT))) 655 return SWT.SHIFT; 656 if (modifierName.equalsIgnoreCase(Action.findModifierString(SWT.ALT))) 657 return SWT.ALT; 658 if (modifierName.equalsIgnoreCase(Action.findModifierString(SWT.COMMAND))) 659 return SWT.COMMAND; 660 661 return SWT.NONE; 662 } 663 664 } 665 | Popular Tags |