14
14
import org .eclipse .core .runtime .preferences .DefaultScope ;
15
15
import org .eclipse .core .runtime .preferences .IEclipsePreferences ;
16
16
import org .eclipse .core .runtime .preferences .InstanceScope ;
17
- import org .eclipse .e4 .core .services .events .IEventBroker ;
18
- import org .eclipse .e4 .ui .css .swt .theme .IThemeEngine ;
19
17
import org .eclipse .jface .preference .PreferenceConverter ;
20
18
import org .eclipse .jface .resource .StringConverter ;
19
+ import org .eclipse .jface .util .IPropertyChangeListener ;
21
20
import org .eclipse .swt .graphics .Color ;
22
21
import org .eclipse .swt .graphics .RGB ;
23
- import org .eclipse .ui .IWorkbench ;
24
22
import org .eclipse .ui .PlatformUI ;
25
23
import org .eclipse .ui .plugin .AbstractUIPlugin ;
26
24
import org .eclipse .ui .texteditor .AbstractTextEditor ;
27
25
import org .eclipse .ui .themes .ColorUtil ;
28
26
import org .osgi .framework .BundleContext ;
29
- import org .osgi .service .event .EventHandler ;
30
27
31
28
import net .certiv .tools .indentguide .preferences .Settings ;
32
29
33
- @ SuppressWarnings ("restriction" )
34
30
public class Activator extends AbstractUIPlugin {
35
31
36
32
public static final String PLUGIN_ID = "net.certiv.tools.indentguide" ; //$NON-NLS-1$
37
33
private static final String EditorsID = "org.eclipse.ui.editors" ; //$NON-NLS-1$
34
+ private static final String PREFIX = "Indent Guide: " ; //$NON-NLS-1$
38
35
39
36
private static Activator plugin ;
40
37
41
- private final IEclipsePreferences [] scopes = new IEclipsePreferences [2 ];
42
- private final EventHandler themeChange = event -> {
38
+ private final IEclipsePreferences [] editorScopes = new IEclipsePreferences [] {
39
+ InstanceScope .INSTANCE .getNode (EditorsID ), DefaultScope .INSTANCE .getNode (EditorsID ) };
40
+
41
+ private final IPropertyChangeListener themeChange = event -> {
43
42
disposeLineColor ();
44
43
log ("Theme change '%s'" , event );
45
44
};
@@ -51,35 +50,24 @@ public Activator() {
51
50
}
52
51
53
52
/** Returns the shared instance */
54
- public static Activator getDefault () { return plugin ; }
53
+ public static Activator getDefault () {
54
+ return plugin ;
55
+ }
55
56
56
57
@ Override
57
58
public void start (BundleContext context ) throws Exception {
58
59
super .start (context );
59
60
plugin = this ;
60
61
61
- log ("Indent guide: startup" );
62
-
63
- scopes [0 ] = InstanceScope .INSTANCE .getNode (EditorsID );
64
- scopes [1 ] = DefaultScope .INSTANCE .getNode (EditorsID );
65
-
66
- IWorkbench wb = PlatformUI .getWorkbench ();
67
- IEventBroker broker = wb .getService (IEventBroker .class );
68
- if (broker != null ) {
69
- broker .subscribe (IThemeEngine .Events .THEME_CHANGED , themeChange );
70
- }
62
+ PlatformUI .getWorkbench ().getThemeManager ().addPropertyChangeListener (themeChange );
63
+ log ("Startup" );
71
64
}
72
65
73
66
@ Override
74
67
public void stop (BundleContext context ) throws Exception {
75
- IWorkbench wb = PlatformUI .getWorkbench ();
76
- IEventBroker broker = wb .getService (IEventBroker .class );
77
- if (broker != null ) {
78
- broker .unsubscribe (themeChange );
79
- }
80
-
68
+ PlatformUI .getWorkbench ().getThemeManager ().removePropertyChangeListener (themeChange );
81
69
disposeLineColor ();
82
- scopes [0 ] = scopes [1 ] = null ;
70
+ editorScopes [0 ] = editorScopes [1 ] = null ;
83
71
plugin = null ;
84
72
super .stop (context );
85
73
}
@@ -92,11 +80,20 @@ public Color getColor() {
92
80
}
93
81
String spec = getPreferenceStore ().getString (key );
94
82
color = new Color (PlatformUI .getWorkbench ().getDisplay (), ColorUtil .getColorValue (spec ));
95
- log (String . format ( "Line color set %s -> %s" , key , spec ) );
83
+ log ("Line color set %s -> %s" , key , spec );
96
84
}
97
85
return color ;
98
86
}
99
87
88
+ public void setColor (Color color ) {
89
+ disposeLineColor ();
90
+ this .color = color ;
91
+ }
92
+
93
+ public void setColor (RGB rgb ) {
94
+ setColor (new Color (PlatformUI .getWorkbench ().getDisplay (), rgb ));
95
+ }
96
+
100
97
/**
101
98
* Returns {@code true} if the current theme is 'dark', defined as where the foreground color is
102
99
* relatively darker than the background color. (black -> '0'; white -> '255*3')
@@ -108,19 +105,14 @@ public boolean isDarkTheme() {
108
105
}
109
106
110
107
private RGB getRawRGB (String key ) {
111
- String value = Platform .getPreferencesService ().get (key , null , scopes );
108
+ String value = Platform .getPreferencesService ().get (key , null , editorScopes );
112
109
if (value == null ) return PreferenceConverter .COLOR_DEFAULT_DEFAULT ;
113
110
114
111
RGB rgb = StringConverter .asRGB (value , null );
115
112
if (rgb == null ) return PreferenceConverter .COLOR_DEFAULT_DEFAULT ;
116
113
return rgb ;
117
114
}
118
115
119
- public void setColor (Color color ) {
120
- disposeLineColor ();
121
- this .color = color ;
122
- }
123
-
124
116
private void disposeLineColor () {
125
117
if (color != null ) {
126
118
color .dispose ();
@@ -129,7 +121,7 @@ private void disposeLineColor() {
129
121
}
130
122
131
123
public static void log (String fmt , Object ... args ) {
132
- plugin .getLog ().log (new Status (IStatus .INFO , PLUGIN_ID , String .format (fmt , args )));
124
+ plugin .getLog ().log (new Status (IStatus .INFO , PLUGIN_ID , PREFIX + String .format (fmt , args )));
133
125
}
134
126
135
127
public static void log (Throwable e ) {
0 commit comments