View | Details | Raw Unified | Return to bug 22712 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java (+4 lines)
Lines 1103-1108 Link Here
1103
		};
1103
		};
1104
		action.setId(ITextEditorActionConstants.CONTEXT_PREFERENCES);
1104
		action.setId(ITextEditorActionConstants.CONTEXT_PREFERENCES);
1105
		setAction(ITextEditorActionConstants.CONTEXT_PREFERENCES, action);
1105
		setAction(ITextEditorActionConstants.CONTEXT_PREFERENCES, action);
1106
1107
		IAction showWhitespaceCharactersAction= getAction(ITextEditorActionConstants.SHOW_WHITESPACE_CHARACTERS);
1108
		if (showWhitespaceCharactersAction instanceof ShowWhitespaceCharactersAction)
1109
			((ShowWhitespaceCharactersAction)showWhitespaceCharactersAction).setPreferenceStore(EditorsUI.getPreferenceStore());
1106
	}
1110
	}
1107
1111
1108
	public Object getAdapter(Class adapter) {
1112
	public Object getAdapter(Class adapter) {
(-)src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditorPreferenceConstants.java (+11 lines)
Lines 358-363 Link Here
358
	public static final String EDITOR_SMART_HOME_END= AbstractTextEditor.PREFERENCE_NAVIGATION_SMART_HOME_END;
358
	public static final String EDITOR_SMART_HOME_END= AbstractTextEditor.PREFERENCE_NAVIGATION_SMART_HOME_END;
359
359
360
	/**
360
	/**
361
	 * A named preference that controls the display of invisible characters.
362
	 * <p>
363
	 * Value is of type <code>Boolean</code>.
364
	 * </p>
365
	 *
366
	 * @since 3.3
367
	 */
368
	public static final String EDITOR_SHOW_INVISIBLE_CHARACTERS= AbstractTextEditor.PREFERENCE_SHOW_WHITESPACE_CHARACTERS;
369
370
	/**
361
	 * A named preference that controls the display of the range indicator.
371
	 * A named preference that controls the display of the range indicator.
362
	 * <p>
372
	 * <p>
363
	 * Value is of type <code>Boolean</code>.
373
	 * Value is of type <code>Boolean</code>.
Lines 487-492 Link Here
487
497
488
		store.setDefault(EDITOR_WARN_IF_INPUT_DERIVED, true);
498
		store.setDefault(EDITOR_WARN_IF_INPUT_DERIVED, true);
489
		store.setDefault(EDITOR_SMART_HOME_END, true);
499
		store.setDefault(EDITOR_SMART_HOME_END, true);
500
		store.setDefault(EDITOR_SHOW_INVISIBLE_CHARACTERS, false);
490
		
501
		
491
		MarkerAnnotationPreferences.initializeDefaultValues(store);
502
		MarkerAnnotationPreferences.initializeDefaultValues(store);
492
	}
503
	}
(-)src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties (+1 lines)
Lines 30-35 Link Here
30
TextEditorDefaultsPreferencePage_range_indicator=Show &range indicator
30
TextEditorDefaultsPreferencePage_range_indicator=Show &range indicator
31
TextEditorDefaultsPreferencePage_warn_if_derived= War&n before editing a derived file
31
TextEditorDefaultsPreferencePage_warn_if_derived= War&n before editing a derived file
32
TextEditorDefaultsPreferencePage_smartHomeEnd= &Smart caret positioning at line start and end
32
TextEditorDefaultsPreferencePage_smartHomeEnd= &Smart caret positioning at line start and end
33
TextEditorDefaultsPreferencePage_showWhitespaceCharacters= Show wh&itespace characters
33
TextEditorPreferencePage_colorsAndFonts_link= More colors can be configured on the <a>Colors and Fonts</a> preference page.
34
TextEditorPreferencePage_colorsAndFonts_link= More colors can be configured on the <a>Colors and Fonts</a> preference page.
34
TextEditorPreferencePage_colorsAndFonts_link_tooltip= Show the Colors and Fonts preferences
35
TextEditorPreferencePage_colorsAndFonts_link_tooltip= Show the Colors and Fonts preferences
35
36
(-)src/org/eclipse/ui/internal/editors/text/TextEditorMessages.java (+1 lines)
Lines 118-123 Link Here
118
	public static String TextEditorDefaultsPreferencePage_range_indicator;
118
	public static String TextEditorDefaultsPreferencePage_range_indicator;
119
	public static String TextEditorDefaultsPreferencePage_smartHomeEnd;
119
	public static String TextEditorDefaultsPreferencePage_smartHomeEnd;
120
	public static String TextEditorDefaultsPreferencePage_warn_if_derived;
120
	public static String TextEditorDefaultsPreferencePage_warn_if_derived;
121
	public static String TextEditorDefaultsPreferencePage_showWhitespaceCharacters;
121
	public static String LinkedModeConfigurationBlock_annotationPresentationOptions;
122
	public static String LinkedModeConfigurationBlock_annotationPresentationOptions;
122
	public static String LinkedModeConfigurationBlock_SQUIGGLES;
123
	public static String LinkedModeConfigurationBlock_SQUIGGLES;
123
	public static String LinkedModeConfigurationBlock_UNDERLINE;
124
	public static String LinkedModeConfigurationBlock_UNDERLINE;
(-)src/org/eclipse/ui/internal/editors/text/TextEditorDefaultsPreferencePage.java (-2 / +6 lines)
Lines 7-17 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Anton Leherbauer (Wind River Systems) - https://bugs.eclipse.org/bugs/show_bug.cgi?id=22712
10
 *******************************************************************************/
11
 *******************************************************************************/
11
12
package org.eclipse.ui.internal.editors.text;
12
package org.eclipse.ui.internal.editors.text;
13
13
14
15
import java.util.ArrayList;
14
import java.util.ArrayList;
16
import java.util.HashSet;
15
import java.util.HashSet;
17
import java.util.Iterator;
16
import java.util.Iterator;
Lines 449-454 Link Here
449
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINK_KEY_MODIFIER));
448
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINK_KEY_MODIFIER));
450
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINK_KEY_MODIFIER_MASK));
449
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINK_KEY_MODIFIER_MASK));
451
450
451
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_INVISIBLE_CHARACTERS));
452
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.SHOW_RANGE_INDICATOR));
452
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.SHOW_RANGE_INDICATOR));
453
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_WARN_IF_INPUT_DERIVED));
453
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_WARN_IF_INPUT_DERIVED));
454
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SMART_HOME_END));
454
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SMART_HOME_END));
Lines 534-539 Link Here
534
		Preference showMagnet= new Preference(AbstractDecoratedTextEditorPreferenceConstants.SHOW_RANGE_INDICATOR, label, null);
534
		Preference showMagnet= new Preference(AbstractDecoratedTextEditorPreferenceConstants.SHOW_RANGE_INDICATOR, label, null);
535
		addCheckBox(appearanceComposite, showMagnet, new BooleanDomain(), 0);
535
		addCheckBox(appearanceComposite, showMagnet, new BooleanDomain(), 0);
536
		
536
		
537
		label= TextEditorMessages.TextEditorDefaultsPreferencePage_showWhitespaceCharacters;
538
		Preference showWhitespaceCharacters= new Preference(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_INVISIBLE_CHARACTERS, label, null);
539
		addCheckBox(appearanceComposite, showWhitespaceCharacters, new BooleanDomain(), 0);
540
		
537
		label= TextEditorMessages.TextEditorDefaultsPreferencePage_warn_if_derived;
541
		label= TextEditorMessages.TextEditorDefaultsPreferencePage_warn_if_derived;
538
		Preference warnIfDerived= new Preference(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_WARN_IF_INPUT_DERIVED, label, null);
542
		Preference warnIfDerived= new Preference(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_WARN_IF_INPUT_DERIVED, label, null);
539
		addCheckBox(appearanceComposite, warnIfDerived, new BooleanDomain(), 0);
543
		addCheckBox(appearanceComposite, warnIfDerived, new BooleanDomain(), 0);
(-)plugin.properties (-1 / +1 lines)
Lines 116-122 Link Here
116
conversionActionSet.label= Convert Line Delimiters
116
conversionActionSet.label= Convert Line Delimiters
117
conversionSubMenu.label= Con&vert Line Delimiters To
117
conversionSubMenu.label= Con&vert Line Delimiters To
118
118
119
preferenceKeywords.general= text editor tab width undo history ruler print margin overview hyperlink overwrite colors line numbers range indicator typing appearance derived navigation smart caret positioning
119
preferenceKeywords.general= text editor tab width undo history ruler print margin overview hyperlink overwrite colors line numbers range indicator typing appearance derived navigation smart caret positioning invisible whitespace characters
120
preferenceKeywords.annotations= annotations vertical ruler overview colors text editor
120
preferenceKeywords.annotations= annotations vertical ruler overview colors text editor
121
preferenceKeywords.quickdiff= quick diff compare reference colors text editor
121
preferenceKeywords.quickdiff= quick diff compare reference colors text editor
122
preferenceKeywords.accessibility= accessibility caret cursor quick diff text editor
122
preferenceKeywords.accessibility= accessibility caret cursor quick diff text editor
(-)src/org/eclipse/ui/texteditor/ConstructedEditorMessages.properties (+5 lines)
Lines 218-220 Link Here
218
Editor.Recenter.tooltip= Recenter
218
Editor.Recenter.tooltip= Recenter
219
Editor.Recenter.image=
219
Editor.Recenter.image=
220
Editor.Recenter.description= Put the line containing the cursor at the middle of the screen 
220
Editor.Recenter.description= Put the line containing the cursor at the middle of the screen 
221
222
Editor.ShowWhitespaceCharacters.label= Show Whitespace Characters
223
Editor.ShowWhitespaceCharacters.description= Shows whitespace characters in current text editor
224
Editor.ShowWhitespaceCharacters.image=
225
Editor.ShowWhitespaceCharacters.tooltip= Show Whitespace Characters
(-)src/org/eclipse/ui/texteditor/ITextEditorActionDefinitionIds.java (+8 lines)
Lines 529-538 Link Here
529
	 * @since 3.3
529
	 * @since 3.3
530
	 */
530
	 */
531
	String REVISION_ID_TOGGLE= "org.eclipse.ui.editors.revisions.id.toggle"; //$NON-NLS-1$
531
	String REVISION_ID_TOGGLE= "org.eclipse.ui.editors.revisions.id.toggle"; //$NON-NLS-1$
532
	
532
	 /**
533
	 /**
533
	 * Command ID of the recenter command.
534
	 * Command ID of the recenter command.
534
	 * Value: <code>"org.eclipse.ui.edit.text.recenter"</code>).
535
	 * Value: <code>"org.eclipse.ui.edit.text.recenter"</code>).
535
	 * @since 3.3
536
	 * @since 3.3
536
	 */
537
	 */
537
	String RECENTER= "org.eclipse.ui.edit.text.recenter"; //$NON-NLS-1$
538
	String RECENTER= "org.eclipse.ui.edit.text.recenter"; //$NON-NLS-1$
539
540
	 /**
541
	 * Command ID of the command to toggle the display of invisible whitespace characters.
542
	 * Value: <code>"org.eclipse.ui.edit.text.toggleShowWhitespaceCharacters"</code>).
543
	 * @since 3.3
544
	 */
545
	String SHOW_WHITESPACE_CHARACTERS = "org.eclipse.ui.edit.text.toggleShowWhitespaceCharacters"; //$NON-NLS-1$
538
}
546
}
(-)src/org/eclipse/ui/texteditor/IAbstractTextEditorHelpContextIds.java (-2 / +9 lines)
Lines 179-192 Link Here
179
	 * Value: <code>"org.eclipse.ui.goto_next_annotation_action_context"</code>
179
	 * Value: <code>"org.eclipse.ui.goto_next_annotation_action_context"</code>
180
	 * @since 3.2
180
	 * @since 3.2
181
	 */
181
	 */
182
	String GOTO_NEXT_ANNOTATION_ACTION= PREFIX + "goto_next_annotation" + ACTION_POSTFIX;; //$NON-NLS-1$
182
	String GOTO_NEXT_ANNOTATION_ACTION= PREFIX + "goto_next_annotation" + ACTION_POSTFIX; //$NON-NLS-1$
183
	
183
	
184
	/**
184
	/**
185
	 * Help context id for the action.
185
	 * Help context id for the action.
186
	 * Value: <code>"org.eclipse.ui.goto_previous_annotation_action_context"</code>
186
	 * Value: <code>"org.eclipse.ui.goto_previous_annotation_action_context"</code>
187
	 * @since 3.2
187
	 * @since 3.2
188
	 */
188
	 */
189
	String GOTO_PREVIOUS_ANNOTATION_ACTION= PREFIX + "goto_previous_annotation" + ACTION_POSTFIX;;	 //$NON-NLS-1$
189
	String GOTO_PREVIOUS_ANNOTATION_ACTION= PREFIX + "goto_previous_annotation" + ACTION_POSTFIX;	 //$NON-NLS-1$
190
	
190
	
191
	/**
191
	/**
192
	 * Help context id for the action.
192
	 * Help context id for the action.
Lines 338-341 Link Here
338
     * @since 3.3
338
     * @since 3.3
339
     */
339
     */
340
    String RECENTER_ACTION=PREFIX + "recenter" + ACTION_POSTFIX; //$NON-NLS-1$
340
    String RECENTER_ACTION=PREFIX + "recenter" + ACTION_POSTFIX; //$NON-NLS-1$
341
342
    /**
343
     * Help context id for the show invisible characters action.
344
     * Value: <code>"show_invisible_characters_action_context"</code>
345
     * @since 3.3
346
     */
347
	String SHOW_INVISIBLE_CHARACTERS_ACTION=PREFIX + "show_invisible_characters" + ACTION_POSTFIX; //$NON-NLS-1$
341
}
348
}
(-)src/org/eclipse/ui/texteditor/BasicTextEditorActionContributor.java (+1 lines)
Lines 211-216 Link Here
211
		IActionBars actionBars= getActionBars();
211
		IActionBars actionBars= getActionBars();
212
		for (int i= 0; i < ACTIONS.length; i++)
212
		for (int i= 0; i < ACTIONS.length; i++)
213
			actionBars.setGlobalActionHandler(ACTIONS[i], getAction(editor, ACTIONS[i]));
213
			actionBars.setGlobalActionHandler(ACTIONS[i], getAction(editor, ACTIONS[i]));
214
		actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.SHOW_WHITESPACE_CHARACTERS, getAction(editor, ITextEditorActionConstants.SHOW_WHITESPACE_CHARACTERS));
214
215
215
		fFindNext.setAction(getAction(editor, ITextEditorActionConstants.FIND_NEXT));
216
		fFindNext.setAction(getAction(editor, ITextEditorActionConstants.FIND_NEXT));
216
		fFindPrevious.setAction(getAction(editor, ITextEditorActionConstants.FIND_PREVIOUS));
217
		fFindPrevious.setAction(getAction(editor, ITextEditorActionConstants.FIND_PREVIOUS));
(-)src/org/eclipse/ui/texteditor/AbstractTextEditor.java (+21 lines)
Lines 1788-1793 Link Here
1788
	 * @since 3.3
1788
	 * @since 3.3
1789
	 */
1789
	 */
1790
	public static final String PREFERENCE_RULER_CONTRIBUTIONS= "rulerContributions"; //$NON-NLS-1$
1790
	public static final String PREFERENCE_RULER_CONTRIBUTIONS= "rulerContributions"; //$NON-NLS-1$
1791
	/**
1792
	 * A named preference that controls the display of invisible characters.
1793
	 * <p>
1794
	 * Value is of type <code>Boolean</code>.
1795
	 * </p>
1796
	 *
1797
	 * @since 3.3
1798
	 */
1799
	public static final String PREFERENCE_SHOW_WHITESPACE_CHARACTERS= "showWhitespaceCharacters"; //$NON-NLS-1$
1791
1800
1792
1801
1793
	/** Menu id for the editor context menu. */
1802
	/** Menu id for the editor context menu. */
Lines 3708-3713 Link Here
3708
			}
3717
			}
3709
		}
3718
		}
3710
		
3719
		
3720
		if (PREFERENCE_SHOW_WHITESPACE_CHARACTERS.equals(property)) {
3721
			IAction action= getAction(ITextEditorActionConstants.SHOW_WHITESPACE_CHARACTERS);
3722
			if (action instanceof IUpdate)
3723
				((IUpdate)action).update();
3724
		}
3725
		
3711
	}
3726
	}
3712
3727
3713
	/**
3728
	/**
Lines 4876-4881 Link Here
4876
		action.setHelpContextId(IAbstractTextEditorHelpContextIds.RECENTER_ACTION);
4891
		action.setHelpContextId(IAbstractTextEditorHelpContextIds.RECENTER_ACTION);
4877
		action.setActionDefinitionId(ITextEditorActionDefinitionIds.RECENTER);
4892
		action.setActionDefinitionId(ITextEditorActionDefinitionIds.RECENTER);
4878
		setAction(ITextEditorActionConstants.RECENTER, action);
4893
		setAction(ITextEditorActionConstants.RECENTER, action);
4894
		
4895
		action= new ShowWhitespaceCharactersAction(EditorMessages.getBundleForConstructedKeys(), "Editor.ShowWhitespaceCharacters.", this, getPreferenceStore()); //$NON-NLS-1$
4896
		action.setHelpContextId(IAbstractTextEditorHelpContextIds.SHOW_INVISIBLE_CHARACTERS_ACTION);
4897
		action.setActionDefinitionId(ITextEditorActionDefinitionIds.SHOW_WHITESPACE_CHARACTERS);
4898
		setAction(ITextEditorActionConstants.SHOW_WHITESPACE_CHARACTERS, action);
4899
		
4879
4900
4880
		PropertyDialogAction openProperties= new PropertyDialogAction(
4901
		PropertyDialogAction openProperties= new PropertyDialogAction(
4881
				new IShellProvider() {
4902
				new IShellProvider() {
(-)src/org/eclipse/ui/texteditor/ITextEditorActionConstants.java (+7 lines)
Lines 610-613 Link Here
610
	 * @since 3.3
610
	 * @since 3.3
611
	 */
611
	 */
612
	String RECENTER= "Recenter"; //$NON-NLS-1$	
612
	String RECENTER= "Recenter"; //$NON-NLS-1$	
613
614
	/**
615
	 * Name of the action for toggling the display of whitespace characters.
616
	 * Value: <code>"ShowWhitespaceCharacters"</code>
617
	 * @since 3.3
618
	 */
619
	String SHOW_WHITESPACE_CHARACTERS = "ShowWhitespaceCharacters"; //$NON-NLS-1$
613
}
620
}
(-)plugin.xml (+20 lines)
Lines 409-414 Link Here
409
            categoryId="org.eclipse.ui.category.textEditor"
409
            categoryId="org.eclipse.ui.category.textEditor"
410
            id="org.eclipse.ui.edit.text.recenter">
410
            id="org.eclipse.ui.edit.text.recenter">
411
	  </command>     
411
	  </command>     
412
	  <command
413
	        name="%showWhitespaceCharacters.label"
414
	        description="%showWhitespaceCharacters.description"
415
	        categoryId="org.eclipse.ui.category.textEditor"
416
	        id="org.eclipse.ui.edit.text.toggleShowWhitespaceCharacters">
417
	  </command>
412
	</extension>
418
	</extension>
413
   
419
   
414
	<extension
420
	<extension
Lines 989-994 Link Here
989
               retarget="true"
995
               retarget="true"
990
               tooltip="%onlyShowSelectedElement.tooltip">
996
               tooltip="%onlyShowSelectedElement.tooltip">
991
         </action>
997
         </action>
998
         <action
999
               allowLabelUpdate="true"
1000
               definitionId="org.eclipse.ui.edit.text.toggleShowWhitespaceCharacters"
1001
               disabledIcon="$nl$/icons/full/dtool16/show_invisible_chars.gif"
1002
               helpContextId="show_invisible_characters_action_context"
1003
               hoverIcon="$nl$/icons/full/ctool16/show_invisible_chars.gif"
1004
               icon="$nl$/icons/full/etool16/show_invisible_chars.gif"
1005
               id="org.eclipse.ui.edit.text.toggleShowWhitespaceCharacters"
1006
               label="%showWhitespaceCharacters.label"
1007
               retarget="true"
1008
               style="toggle"
1009
               toolbarPath="Normal/Presentation"
1010
               tooltip="%showWhitespaceCharacters.tooltip">
1011
        </action>
992
      </actionSet>
1012
      </actionSet>
993
   </extension>
1013
   </extension>
994
</plugin>
1014
</plugin>
(-)plugin.properties (+4 lines)
Lines 23-28 Link Here
23
onlyShowSelectedElement.tooltip= Show Selected Element Only
23
onlyShowSelectedElement.tooltip= Show Selected Element Only
24
onlyShowSelectedElement.description= Show Selected Element Only
24
onlyShowSelectedElement.description= Show Selected Element Only
25
25
26
showWhitespaceCharacters.label= Show Invisible Characters
27
showWhitespaceCharacters.tooltip= Show Invisible Characters
28
showWhitespaceCharacters.description= Shows whitespace characters in current text editor
29
26
smartEnter.label= Insert Line Below Current Line
30
smartEnter.label= Insert Line Below Current Line
27
smartEnter.description= Adds a new line below the current line
31
smartEnter.description= Adds a new line below the current line
28
smartEnterInverse.label= Insert Line Above Current Line
32
smartEnterInverse.label= Insert Line Above Current Line
(-)icons/full/etool16/show_invisible_chars.gif (+1 lines)
Added Link Here
1
GIF89a÷(((888<<<BBBqqqsss‡‡‡¯¯¯´´´ÃÃÃÐÐÐÕÕÕ×××âââøøøÿÿÿ!ù,L)H° Áƒ"Œà ¡ƒ	!Á€	P Á€B?;*lP ¤G…©P –-_žT¨ €„‹-8˜ð°¥ÏŸ@;
(-)icons/full/dtool16/show_invisible_chars.gif (+1 lines)
Added Link Here
1
GIF89a÷(((888<<<BBBqqqsss‡‡‡¯¯¯´´´ÃÃÃÐÐÐÕÕÕ×××âââøøøÿÿÿ!ù,L)H° Áƒ"Œà ¡ƒ	!Á€	P Á€B?;*lP ¤G…©P –-_žT¨ €„‹-8˜ð°¥ÏŸ@;
(-)src/org/eclipse/ui/texteditor/ShowWhitespaceCharactersAction.java (+146 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 Wind River Systems, Inc. and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.texteditor;
12
13
import java.util.ResourceBundle;
14
15
import org.eclipse.jface.action.IAction;
16
import org.eclipse.jface.preference.IPreferenceStore;
17
18
import org.eclipse.jface.text.IPainter;
19
import org.eclipse.jface.text.ITextViewer;
20
import org.eclipse.jface.text.ITextViewerExtension2;
21
import org.eclipse.jface.text.InvisibleCharacterPainter;
22
23
24
/**
25
 * This action toggles the display of whitespace characters by
26
 * attaching/detaching an {@link InvisibleCharacterPainter} to the
27
 * associated text editor.
28
 * 
29
 * @since 3.3
30
 */
31
public class ShowWhitespaceCharactersAction extends TextEditorAction {
32
33
	/** The preference store. */
34
	private IPreferenceStore fStore;
35
	/** The painter. */
36
	private IPainter fInvisibleCharPainter;
37
	
38
	/**
39
	 * Construct the action and initialize its state.
40
	 * 
41
	 * @param resourceBundle  the resource bundle to construct label and tooltip from
42
	 * @param prefix  the prefix to use for constructing resource bundle keys
43
	 * @param editor  the editor this action is associated with
44
	 * @param store  the preference store (may be <code>null</code>)
45
	 */
46
	public ShowWhitespaceCharactersAction(ResourceBundle resourceBundle, String prefix, ITextEditor editor, IPreferenceStore store) {
47
		super(resourceBundle, prefix, editor, IAction.AS_CHECK_BOX);
48
		fStore= store;
49
		synchronizeWithPreference();
50
	}
51
52
	/**
53
	 * Sets the preference store of this action.
54
	 * 
55
	 * @param store the preference store
56
	 */
57
	public void setPreferenceStore(IPreferenceStore store) {
58
		fStore= store;
59
		synchronizeWithPreference();
60
	}
61
62
	/*
63
	 * @see org.eclipse.jface.action.Action#run()
64
	 */
65
	public void run() {
66
		togglePainterState(isChecked());
67
		if (fStore != null)
68
			fStore.setValue(AbstractTextEditor.PREFERENCE_SHOW_WHITESPACE_CHARACTERS, isChecked());
69
	}
70
71
	/*
72
	 * @see org.eclipse.ui.texteditor.TextEditorAction#update()
73
	 */
74
	public void update() {
75
		setEnabled(getTextViewer() instanceof ITextViewerExtension2);
76
		synchronizeWithPreference();
77
	}
78
79
	/**
80
	 * Installs the painter on the editor.
81
	 */
82
	private void installPainter() {
83
		ITextViewer viewer= getTextViewer();
84
		if (viewer instanceof ITextViewerExtension2) {
85
			ITextViewerExtension2 viewerExt2= (ITextViewerExtension2)viewer;
86
			if (fInvisibleCharPainter == null) {
87
				fInvisibleCharPainter= new InvisibleCharacterPainter(viewer);
88
			}
89
			viewerExt2.addPainter(fInvisibleCharPainter);
90
		}
91
	}
92
93
	/**
94
	 * Remove the painter from the current editor.
95
	 */
96
	private void uninstallPainter() {
97
		if (fInvisibleCharPainter == null)
98
			return;
99
		
100
		ITextViewer viewer= getTextViewer();
101
		if (viewer instanceof ITextViewerExtension2) {
102
			ITextViewerExtension2 viewerExt2= (ITextViewerExtension2)viewer;
103
			viewerExt2.removePainter(fInvisibleCharPainter);
104
		}
105
		fInvisibleCharPainter.deactivate(true);
106
	}
107
108
	/**
109
	 * Get the <code>ITextViewer</code> from an <code>ITextEditor</code>.
110
	 * 
111
	 * @return  the text viewer or <code>null</code>
112
	 */
113
	private ITextViewer getTextViewer() {
114
		ITextEditor editor= getTextEditor();
115
		if (editor instanceof AbstractTextEditor)
116
			return ((AbstractTextEditor)editor).getSourceViewer();
117
		
118
		return null;
119
	}
120
121
	/**
122
	 * Synchronize state with the preference.
123
	 */
124
	private void synchronizeWithPreference() {
125
		boolean checked= false;
126
		if (fStore != null)
127
			checked= fStore.getBoolean(AbstractTextEditor.PREFERENCE_SHOW_WHITESPACE_CHARACTERS);
128
		
129
		if (checked != isChecked()) {
130
			setChecked(checked);
131
			togglePainterState(checked);
132
		}
133
	}
134
135
	/**
136
	 * Toggles the painter state.
137
	 * 
138
	 * @param newState <code>true</code> if the painter should be installed 
139
	 */
140
	private void togglePainterState(boolean newState) {
141
		if (newState)
142
			installPainter();
143
		else
144
			uninstallPainter();
145
	}
146
}
(-)icons/full/ctool16/show_invisible_chars.gif (+1 lines)
Added Link Here
1
GIF89a÷(((888<<<BBBqqqsss‡‡‡¯¯¯´´´ÃÃÃÐÐÐÕÕÕ×××âââøøøÿÿÿ!ù,L)H° Áƒ"Œà ¡ƒ	!Á€	P Á€B?;*lP ¤G…©P –-_žT¨ €„‹-8˜ð°¥ÏŸ@;
(-)src/org/eclipse/jface/text/InvisibleCharacterPainter.java (+296 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 Wind River Systems, Inc. and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Anton Leherbauer (Wind River Systems) - initial API and implementation - https://bugs.eclipse.org/bugs/show_bug.cgi?id=22712
10
 *******************************************************************************/
11
package org.eclipse.jface.text;
12
13
import org.eclipse.swt.custom.StyleRange;
14
import org.eclipse.swt.custom.StyledText;
15
import org.eclipse.swt.custom.StyledTextContent;
16
import org.eclipse.swt.events.PaintEvent;
17
import org.eclipse.swt.events.PaintListener;
18
import org.eclipse.swt.graphics.Color;
19
import org.eclipse.swt.graphics.GC;
20
import org.eclipse.swt.graphics.Point;
21
22
23
/**
24
 * A painter for drawing visible characters for (invisible) whitespace 
25
 * characters.
26
 * 
27
 * @since 3.3
28
 */
29
public class InvisibleCharacterPainter implements IPainter, PaintListener {
30
31
	private static final char SPACE_SIGN= '\u00b7';
32
	private static final char TAB_SIGN= '\u00bb';
33
	private static final char CARRIAGE_RETURN_SIGN= '\u00a4';
34
	private static final char LINE_FEED_SIGN= '\u00b6';
35
	
36
	/** Indicates whether this painter is active */
37
	private boolean fIsActive= false;
38
	/** The source viewer this painter is attached to */
39
	private ITextViewer fTextViewer;
40
	/** The viewer's widget */
41
	private StyledText fTextWidget;
42
43
	/**
44
	 * Creates a new painter for the given text viewer.
45
	 * @param textViewer  the text viewer the painter should be attached to
46
	 */
47
	public InvisibleCharacterPainter(ITextViewer textViewer) {
48
		super();
49
		fTextViewer= textViewer;
50
		fTextWidget= textViewer.getTextWidget();
51
	}
52
53
	/*
54
	 * @see org.eclipse.jface.text.IPainter#dispose()
55
	 */
56
	public void dispose() {
57
		fTextViewer= null;
58
		fTextWidget= null;
59
	}
60
61
	/*
62
	 * @see org.eclipse.jface.text.IPainter#paint(int)
63
	 */
64
	public void paint(int reason) {
65
		IDocument document= fTextViewer.getDocument();
66
		if (document == null) {
67
			deactivate(false);
68
			return;
69
		}
70
		if (!fIsActive) {
71
			fIsActive= true;
72
			fTextWidget.addPaintListener(this);
73
			redrawAll(true);
74
		} else if (reason == CONFIGURATION || reason == INTERNAL) {
75
			redrawAll(false);
76
		} else if (reason == TEXT_CHANGE) {
77
			// redraw current line only
78
			try {
79
				IRegion lineRegion =
80
					document.getLineInformationOfOffset(getDocumentOffset(fTextWidget.getCaretOffset()));
81
				int widgetOffset= getWidgetOffset(lineRegion.getOffset());
82
				int charCount= fTextWidget.getCharCount();
83
				int redrawLength= Math.min(lineRegion.getLength(), charCount - widgetOffset);
84
				if (widgetOffset >= 0 && redrawLength > 0) {
85
					fTextWidget.redrawRange(widgetOffset, redrawLength, true);
86
				}
87
			} catch (BadLocationException e) {
88
				// ignore
89
			}
90
		}
91
	}
92
93
	/*
94
	 * @see org.eclipse.jface.text.IPainter#deactivate(boolean)
95
	 */
96
	public void deactivate(boolean redraw) {
97
		if (fIsActive) {
98
			fIsActive= false;
99
			fTextWidget.removePaintListener(this);
100
			if (redraw) {
101
				redrawAll(true);
102
			}
103
		}
104
	}
105
106
	/*
107
	 * @see org.eclipse.jface.text.IPainter#setPositionManager(org.eclipse.jface.text.IPaintPositionManager)
108
	 */
109
	public void setPositionManager(IPaintPositionManager manager) {
110
		// no need for a position manager
111
	}
112
113
	/*
114
	 * @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent)
115
	 */
116
	public void paintControl(PaintEvent event) {
117
		if (fTextWidget != null) {
118
			handleDrawRequest(event.gc, event.x, event.y, event.width, event.height);
119
		}
120
	}
121
122
	/**
123
	 * Draw characters in view range.
124
	 * @param gc
125
	 * @param x
126
	 * @param y
127
	 * @param w
128
	 * @param h
129
	 */
130
	private void handleDrawRequest(GC gc, int x, int y, int w, int h) {
131
		int lineCount= fTextWidget.getLineCount();
132
		int startLine= (y + fTextWidget.getTopPixel()) / fTextWidget.getLineHeight();
133
		int endLine= (y + h - 1 + fTextWidget.getTopPixel()) / fTextWidget.getLineHeight();
134
		if (startLine <= endLine && startLine < lineCount) {
135
			int startOffset= fTextWidget.getOffsetAtLine(startLine);
136
			int endOffset =
137
				endLine < lineCount - 1 ? fTextWidget.getOffsetAtLine(endLine + 1) : fTextWidget.getCharCount();
138
			int alpha= gc.getAlpha();
139
			gc.setAlpha(100);
140
			handleDrawRequest(gc, startOffset, endOffset);
141
			gc.setAlpha(alpha);
142
		}
143
	}
144
145
	/**
146
	 * Draw characters of content range.
147
	 * @param gc
148
	 * @param startOffset inclusive start index
149
	 * @param endOffset exclusive end index
150
	 */
151
	private void handleDrawRequest(GC gc, int startOffset, int endOffset) {
152
		StyledTextContent content= fTextWidget.getContent();
153
		int length= endOffset - startOffset;
154
		String text= content.getTextRange(startOffset, length);
155
		StyleRange styleRange= null;
156
		Color fg= null;
157
		Point selection= fTextWidget.getSelection();
158
		StringBuffer visibleChar= new StringBuffer(10);
159
		for (int textOffset= 0; textOffset <= length; ++textOffset) {
160
			int delta= 0;
161
			boolean eol= false;
162
			if (textOffset < length) {
163
				delta= 1;
164
				char c= text.charAt(textOffset);
165
				switch (c) {
166
				case ' ' :
167
					visibleChar.append(SPACE_SIGN);
168
					// 'continue' would improve performance but may produce drawing errors
169
					// for long runs of space if width of space and dot differ
170
					break;
171
				case '\t' :
172
					visibleChar.append(TAB_SIGN);
173
					break;
174
				case '\r' :
175
					visibleChar.append(CARRIAGE_RETURN_SIGN);
176
					if (textOffset >= length - 1 || text.charAt(textOffset + 1) != '\n') {
177
						eol= true;
178
						break;
179
					}
180
					continue;
181
				case '\n' :
182
					visibleChar.append(LINE_FEED_SIGN);
183
					eol= true;
184
					break;
185
				default :
186
					delta= 0;
187
					break;
188
				}
189
			}
190
			if (visibleChar.length() > 0) {
191
				int widgetOffset= startOffset + textOffset - visibleChar.length() + delta;
192
				if (!eol || !isFoldedLine(content.getLineAtOffset(widgetOffset))) {
193
					if (widgetOffset >= selection.x && widgetOffset < selection.y) {
194
						fg= fTextWidget.getSelectionForeground();
195
					} else if (styleRange == null || styleRange.start + styleRange.length <= widgetOffset) {
196
						styleRange= fTextWidget.getStyleRangeAtOffset(widgetOffset);
197
						if (styleRange == null || styleRange.foreground == null) {
198
							fg= fTextWidget.getForeground();
199
						} else {
200
							fg= styleRange.foreground;
201
						}
202
					}
203
					draw(gc, widgetOffset, visibleChar.toString(), fg);
204
				}
205
				visibleChar.delete(0, visibleChar.length());
206
			}
207
		}
208
	}
209
210
	/**
211
	 * Check if the given widget line is a folded line.
212
	 * @param widgetLine  the widget line number
213
	 * @return <code>true</code> if the line is folded
214
	 */
215
	private boolean isFoldedLine(int widgetLine) {
216
		if (fTextViewer instanceof ITextViewerExtension5) {
217
			ITextViewerExtension5 extension= (ITextViewerExtension5)fTextViewer;
218
			int modelLine= extension.widgetLine2ModelLine(widgetLine);
219
			int widgetLine2= extension.modelLine2WidgetLine(modelLine + 1);
220
			return widgetLine2 == -1;
221
		}
222
		return false;
223
	}
224
225
	/**
226
	 * Redraw all of the text widgets visible content.
227
	 * @param redrawBackground  If true, clean background before painting text.
228
	 */
229
	private void redrawAll(boolean redrawBackground) {
230
		int startLine= fTextWidget.getTopPixel() / fTextWidget.getLineHeight();
231
		int startOffset= fTextWidget.getOffsetAtLine(startLine);
232
		int endLine= 1 + (fTextWidget.getTopPixel() + fTextWidget.getClientArea().height) / fTextWidget.getLineHeight();
233
		int endOffset;
234
		if (endLine >= fTextWidget.getLineCount()) {
235
			endOffset= fTextWidget.getCharCount();
236
		} else {
237
			endOffset= fTextWidget.getOffsetAtLine(endLine);
238
		}
239
		if (startOffset < endOffset) {
240
			// add 2 for line separator characters
241
			endOffset= Math.min(endOffset + 2, fTextWidget.getCharCount());
242
			int redrawOffset= startOffset;
243
			int redrawLength= endOffset - redrawOffset;
244
			fTextWidget.redrawRange(startOffset, redrawLength, redrawBackground);
245
		}
246
	}
247
248
	/**
249
	 * Draw string at widget offset.
250
	 * @param gc
251
	 * @param offset the widget offset
252
	 * @param s the string to be drawn
253
	 * @param fg the foreground color
254
	 */
255
	private void draw(GC gc, int offset, String s, Color fg) {
256
		Point pos= fTextWidget.getLocationAtOffset(offset);
257
		gc.setForeground(fg);
258
		gc.drawString(s, pos.x, pos.y, true);
259
	}
260
261
	/**
262
	 * Convert a document offset to the corresponding widget offset.
263
	 * @param documentOffset
264
	 * @return widget offset
265
	 */
266
	private int getWidgetOffset(int documentOffset) {
267
		if (fTextViewer instanceof ITextViewerExtension5) {
268
			ITextViewerExtension5 extension= (ITextViewerExtension5)fTextViewer;
269
			return extension.modelOffset2WidgetOffset(documentOffset);
270
		}
271
		IRegion visible= fTextViewer.getVisibleRegion();
272
		int widgetOffset= documentOffset - visible.getOffset();
273
		if (widgetOffset > visible.getLength()) {
274
			return -1;
275
		}
276
		return widgetOffset;
277
	}
278
279
	/**
280
	 * Convert a widget offset to the corresponding document offset.
281
	 * @param widgetOffset
282
	 * @return document offset
283
	 */
284
	private int getDocumentOffset(int widgetOffset) {
285
		if (fTextViewer instanceof ITextViewerExtension5) {
286
			ITextViewerExtension5 extension= (ITextViewerExtension5)fTextViewer;
287
			return extension.widgetOffset2ModelOffset(widgetOffset);
288
		}
289
		IRegion visible= fTextViewer.getVisibleRegion();
290
		if (widgetOffset > visible.getLength()) {
291
			return -1;
292
		}
293
		return widgetOffset + visible.getOffset();
294
	}
295
296
}

Return to bug 22712