21
21
import static org .eclipse .ui .texteditor .AbstractDecoratedTextEditorPreferenceConstants .EDITOR_TAB_WIDTH ;
22
22
23
23
import java .time .Duration ;
24
+ import java .util .Collections ;
24
25
import java .util .List ;
25
26
26
27
import org .eclipse .swt .graphics .Color ;
37
38
import org .eclipse .jface .text .source .IVerticalRuler ;
38
39
39
40
import org .eclipse .ui .internal .editors .text .EditorsPlugin ;
41
+ import org .eclipse .ui .internal .texteditor .stickyscroll .IStickyLinesProvider .StickyLinesProperties ;
40
42
41
43
/**
42
- * A sticky scrolling handler that retrieves stick lines from the {@link StickyLinesProvider } and
44
+ * A sticky scrolling handler that retrieves stick lines from a {@link IStickyLinesProvider } and
43
45
* shows them in a {@link StickyScrollingControl} on top of the given source viewer.
44
46
*/
45
47
public class StickyScrollingHandler implements IViewportListener {
@@ -50,94 +52,95 @@ public class StickyScrollingHandler implements IViewportListener {
50
52
51
53
private StickyScrollingControl stickyScrollingControl ;
52
54
53
- private int tabWidth ;
54
-
55
55
private IPropertyChangeListener propertyChangeListener ;
56
56
57
57
private IPreferenceStore preferenceStore ;
58
58
59
- private StickyLinesProvider stickyLinesProvider ;
59
+ private IStickyLinesProvider stickyLinesProvider ;
60
+
61
+ private StickyLinesProperties stickyLinesProperties ;
60
62
61
63
private Throttler throttler ;
62
64
63
65
private int verticalOffset ;
64
66
65
67
/**
66
- * Creates a StickyScrollingHandlerIndentation that will be linked to the given source viewer.
67
- * The sticky scrolling will be computed by the default {@link StickyLinesProvider }.
68
+ * Creates a StickyScrollingHandler that will be linked to the given source viewer. The sticky
69
+ * lines will be provided by the {@link DefaultStickyLinesProvider }.
68
70
*
69
- * @param sourceViewer The source viewer to link the handler
71
+ * @param sourceViewer The source viewer to link the handler with
70
72
* @param verticalRuler The vertical ruler of the source viewer
71
73
* @param preferenceStore The preference store
72
74
*/
73
75
public StickyScrollingHandler (ISourceViewer sourceViewer , IVerticalRuler verticalRuler , IPreferenceStore preferenceStore ) {
74
- this (sourceViewer , verticalRuler , preferenceStore , new StickyLinesProvider ());
76
+ this (sourceViewer , verticalRuler , preferenceStore , new DefaultStickyLinesProvider ());
75
77
}
76
78
77
79
/**
78
- * Creates a StickyScrollingHandlerIndentation that will be linked to the given source viewer.
80
+ * Creates a StickyScrollingHandler that will be linked to the given source viewer. The sticky
81
+ * lines will be provided by the given <code>stickyLinesProvider</code>.
79
82
*
80
- * @param sourceViewer The source viewer to link the handler
83
+ * @param sourceViewer The source viewer to link the handler with
81
84
* @param verticalRuler The vertical ruler of the source viewer
82
85
* @param preferenceStore The preference store
83
- * @param stickyLinesProvider The sticky scrolling computer
86
+ * @param stickyLinesProvider The sticky scrolling provider
84
87
*/
85
88
public StickyScrollingHandler (ISourceViewer sourceViewer , IVerticalRuler verticalRuler , IPreferenceStore preferenceStore ,
86
- StickyLinesProvider stickyLinesProvider ) {
89
+ IStickyLinesProvider stickyLinesProvider ) {
87
90
this .sourceViewer = sourceViewer ;
88
91
89
92
throttler = new Throttler (sourceViewer .getTextWidget ().getDisplay (), Duration .ofMillis (THROTTLER_DELAY ), this ::calculateAndShowStickyLines );
90
93
this .stickyLinesProvider = stickyLinesProvider ;
91
94
92
- StickyScrollingControlSettings settings = loadAndListenForProperties (preferenceStore );
95
+ listenForPropertiesChanges (preferenceStore );
96
+ stickyLinesProperties = loadStickyLinesProperties (preferenceStore );
97
+ StickyScrollingControlSettings settings = loadControlSettings (preferenceStore );
98
+
93
99
stickyScrollingControl = new StickyScrollingControl (sourceViewer , verticalRuler , settings , this );
94
100
95
101
sourceViewer .addViewportListener (this );
96
102
}
97
103
98
- private StickyScrollingControlSettings loadAndListenForProperties (IPreferenceStore store ) {
104
+ private void listenForPropertiesChanges (IPreferenceStore store ) {
99
105
preferenceStore = store ;
100
106
propertyChangeListener = e -> {
101
107
if (e .getProperty ().equals (EDITOR_TAB_WIDTH ) || e .getProperty ().equals (EDITOR_STICKY_SCROLLING_MAXIMUM_COUNT )
102
108
|| e .getProperty ().equals (EDITOR_CURRENT_LINE_COLOR ) || e .getProperty ().equals (EDITOR_LINE_NUMBER_RULER )
103
109
|| e .getProperty ().equals (STICKY_LINES_SEPARATOR_COLOR )) {
104
110
if (stickyScrollingControl != null && !sourceViewer .getTextWidget ().isDisposed ()) {
105
- StickyScrollingControlSettings settings = loadSettings (preferenceStore );
111
+ StickyScrollingControlSettings settings = loadControlSettings (preferenceStore );
106
112
stickyScrollingControl .applySettings (settings );
107
- stickyLinesProvider . setTabWidth ( tabWidth );
113
+ stickyLinesProperties = loadStickyLinesProperties ( preferenceStore );
108
114
}
109
115
}
110
116
};
111
117
store .addPropertyChangeListener (propertyChangeListener );
112
- return loadSettings (store );
113
118
}
114
119
115
- private StickyScrollingControlSettings loadSettings (IPreferenceStore store ) {
116
- tabWidth = store .getInt (EDITOR_TAB_WIDTH );
117
-
120
+ private StickyScrollingControlSettings loadControlSettings (IPreferenceStore store ) {
118
121
int stickyScrollingMaxCount = store .getInt (EDITOR_STICKY_SCROLLING_MAXIMUM_COUNT );
119
122
120
123
Color lineNumberColor = new Color (PreferenceConverter .getColor (store , EDITOR_LINE_NUMBER_RULER_COLOR ));
121
124
sourceViewer .getTextWidget ().addDisposeListener (e -> lineNumberColor .dispose ());
122
-
123
125
Color stickyLineHoverColor = new Color (PreferenceConverter .getColor (store , EDITOR_CURRENT_LINE_COLOR ));
124
126
sourceViewer .getTextWidget ().addDisposeListener (e -> stickyLineHoverColor .dispose ());
125
-
126
127
Color stickyLineBackgroundColor = sourceViewer .getTextWidget ().getBackground ();
127
-
128
128
boolean showLineNumbers = store .getBoolean (EDITOR_LINE_NUMBER_RULER );
129
-
130
129
Color stickyLineSeparatorColor = null ;
131
130
if (EditorsPlugin .getDefault () != null ) {
132
131
RGB rgb = PreferenceConverter .getColor (store , STICKY_LINES_SEPARATOR_COLOR );
133
132
ISharedTextColors sharedTextColors = EditorsPlugin .getDefault ().getSharedTextColors ();
134
133
stickyLineSeparatorColor = sharedTextColors .getColor (rgb );
135
134
}
136
-
137
135
return new StickyScrollingControlSettings (stickyScrollingMaxCount ,
138
136
lineNumberColor , stickyLineHoverColor , stickyLineBackgroundColor , stickyLineSeparatorColor , showLineNumbers );
139
137
}
140
138
139
+ private StickyLinesProperties loadStickyLinesProperties (IPreferenceStore store ) {
140
+ int tabWidth = store .getInt (EDITOR_TAB_WIDTH );
141
+ return new StickyLinesProperties (tabWidth );
142
+ }
143
+
141
144
@ Override
142
145
public void viewportChanged (int newVerticalOffset ) {
143
146
if (this .verticalOffset == newVerticalOffset ) {
@@ -148,7 +151,10 @@ public void viewportChanged(int newVerticalOffset) {
148
151
}
149
152
150
153
private void calculateAndShowStickyLines () {
151
- List <StickyLine > stickyLines = stickyLinesProvider .get (verticalOffset , sourceViewer );
154
+ List <StickyLine > stickyLines = stickyLinesProvider .getStickyLines (sourceViewer , stickyLinesProperties );
155
+ if (stickyLines == null ) {
156
+ stickyLines = Collections .emptyList ();
157
+ }
152
158
stickyScrollingControl .setStickyLines (stickyLines );
153
159
}
154
160
0 commit comments