Skip to content

Commit 948901d

Browse files
committed
Checkbox "Plugin enabled"; Combo with global theme is restoring value
1 parent 702f004 commit 948901d

File tree

8 files changed

+169
-63
lines changed

8 files changed

+169
-63
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ If there are updates here, they will be released together with [Nodeclipse train
3737
0.50
3838
0.55
3939
0.60
40-
0.65 (2014-08) change icon; combo to apply one of bundled themes to all categories
40+
0.65 (2014-08) change icon;
41+
Checkbox "Plugin enabled";
42+
combo to apply one of bundled themes to all categories
4143
(this is done for case when switching to black themes and back)
4244

4345
## Themes
@@ -109,9 +111,12 @@ pm.eclipse.editbox.provider.java_enabled=true
109111
pm.eclipse.editbox.provider.java_fileNames=*.java,*.class,*.gradle,*.groovy,*.scala
110112
```
111113

112-
Catalog is list of Themes.
113-
Provider `BoxProviderImpl` is Category . Provider is holding theme (Settings object).
114-
Theme `BoxSettingsImpl` is set of colors .
114+
115+
Theme `BoxSettingsImpl` is set of colors .
116+
Provider is theme applied to some category. Provider is holding current theme (Settings object).
117+
Provider `BoxProviderImpl` is associated with category String (aka Provider name).
118+
Catalog is list of Themes, that provider has.
119+
115120

116121
### Build
117122

pm.eclipse.editbox/src/pm/eclipse/editbox/EditBox.java

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,25 @@
22

33
import org.eclipse.core.runtime.IStatus;
44
import org.eclipse.core.runtime.Status;
5+
import org.eclipse.jface.action.ActionContributionItem;
6+
import org.eclipse.jface.action.CoolBarManager;
7+
import org.eclipse.jface.action.IContributionItem;
8+
import org.eclipse.jface.action.IToolBarManager;
9+
import org.eclipse.jface.action.ToolBarContributionItem;
510
import org.eclipse.jface.resource.ImageDescriptor;
11+
import org.eclipse.jface.window.ApplicationWindow;
12+
import org.eclipse.ui.IWorkbenchWindow;
13+
import org.eclipse.ui.PlatformUI;
614
import org.eclipse.ui.plugin.AbstractUIPlugin;
715
import org.osgi.framework.BundleContext;
816

917
import pm.eclipse.editbox.impl.BoxProviderRegistry;
1018

1119
public class EditBox extends AbstractUIPlugin {
1220

13-
private static final String ENABLED = "ENABLED";
14-
1521
public static final String PLUGIN_ID = "pm.eclipse.editbox";
22+
public static final String PREF_ENABLED = "enabled";
23+
public static final String PREF_DEFAULT_THEME = "default_theme";
1624

1725
private static EditBox plugin;
1826

@@ -43,15 +51,49 @@ public BoxProviderRegistry getProviderRegistry(){
4351
return registry == null ? (registry = new BoxProviderRegistry()) : registry;
4452
}
4553

54+
/** check if enabled from PreferenceStore */
4655
public boolean isEnabled() {
4756
//if (getPreferenceStore().contains(ENABLED))
48-
return getPreferenceStore().getBoolean(ENABLED);
57+
return getPreferenceStore().getBoolean(PREF_ENABLED);
4958
//return false;
5059
}
5160

5261
public void setEnabled(boolean flag){
53-
getPreferenceStore().setValue(ENABLED, flag);
62+
getPreferenceStore().setValue(PREF_ENABLED, flag);
63+
}
64+
65+
//+ {
66+
//TODO move to utils class?
67+
/** called from EditboxPreferencePage
68+
* TODO still can't toggle on main window from Preferences
69+
* */
70+
public static void toggleToolBarItemInAllWindows(boolean enabled) {
71+
IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
72+
for (IWorkbenchWindow window: windows){
73+
toggleToolBarItem(window, enabled);
74+
}
5475
}
76+
/** called from EditBoxStartup */
77+
public static void toggleToolBarItem(IWorkbenchWindow window, boolean enabled) {
78+
// any better way to toggle toolbar button in 3.2?
79+
if (window instanceof ApplicationWindow) {
80+
CoolBarManager coolBarManager = ((ApplicationWindow) window).getCoolBarManager();
81+
if (coolBarManager != null) {
82+
IContributionItem item = coolBarManager.find("pm.eclipse.editbox.ActionSetId");
83+
if (item instanceof ToolBarContributionItem) {
84+
IToolBarManager tbMgr2 = ((ToolBarContributionItem) item).getToolBarManager();
85+
if (tbMgr2 != null) {
86+
IContributionItem item2 = tbMgr2.find("pm.eclipse.editbox.EnableEditboxActionId");
87+
if (item2 instanceof ActionContributionItem) {
88+
((ActionContributionItem) item2).getAction().setChecked(enabled);
89+
}
90+
}
91+
}
92+
}
93+
}
94+
}
95+
//}
96+
5597

5698
public static void logError(Object source, String msg, Throwable error) {
5799
String src = "";

pm.eclipse.editbox/src/pm/eclipse/editbox/actions/EditBoxStartup.java

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
public class EditBoxStartup implements IStartup {
2121

22+
@Override
2223
public void earlyStartup() {
2324
if (!EditBox.getDefault().isEnabled())
2425
return;
@@ -37,7 +38,8 @@ public void run() {
3738
if (handlerService != null)
3839
try {
3940
handlerService.executeCommand(new ParameterizedCommand(command, null), null);
40-
toggle(window);
41+
EditBox.toggleToolBarItem(window, true);
42+
//EditBox.toggleToolBarItemInAllWindows(enabled); //no need as there is to be only one window
4143
} catch (Exception e) {
4244
EditBox.logError(this, "Failed to enable EditBox at startup", e);
4345
}
@@ -47,23 +49,4 @@ public void run() {
4749
});
4850
}
4951

50-
protected void toggle(IWorkbenchWindow window) {
51-
// any better way to toggle toolbar button in 3.2?
52-
if (window instanceof ApplicationWindow) {
53-
CoolBarManager coolBarManager = ((ApplicationWindow) window).getCoolBarManager();
54-
if (coolBarManager != null) {
55-
IContributionItem item = coolBarManager.find("pm.eclipse.editbox.ActionSetId");
56-
if (item instanceof ToolBarContributionItem) {
57-
IToolBarManager tbMgr2 = ((ToolBarContributionItem) item).getToolBarManager();
58-
if (tbMgr2 != null) {
59-
IContributionItem item2 = tbMgr2.find("pm.eclipse.editbox.EnableEditboxActionId");
60-
if (item2 instanceof ActionContributionItem) {
61-
((ActionContributionItem) item2).getAction().setChecked(true);
62-
}
63-
}
64-
}
65-
}
66-
}
67-
}
68-
6952
}

pm.eclipse.editbox/src/pm/eclipse/editbox/actions/EnableEditBox.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import pm.eclipse.editbox.impl.BoxProviderRegistry;
1919

2020
//keep it stateless since called from commands
21+
/** this is actually state toggler as both execute() and run() apply opposite state */
2122
public class EnableEditBox extends AbstractHandler implements IWorkbenchWindowActionDelegate {
2223

2324
public static final String COMMAND_ID = "pm.eclipse.editbox.actions.EnableEditBoxCmd";

pm.eclipse.editbox/src/pm/eclipse/editbox/impl/BoxProviderRegistry.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,24 @@ public class BoxProviderRegistry {
2828
private static final String PROVIDERS = "proivders";
2929
// always added. Is it useless?
3030
private static final String PROVIDER_ID_ = "pm.eclipse.editbox.provider.";
31-
//+
31+
//+ {
3232
public static final String[] ALL_THEMES_ARRAY = {"Default", "Whitebox", "OnClick", "GreyGradient", "Java_v_20",
3333
"RainbowDrops", "RainbowDropsLine", "RainbowDropsLineFill",
3434
"BlueToDeepBlue", "OrangeToRed", "BlueGradient22WithDarkBoldLeftBorder", "BlueLight", "PaleBlue"};
3535
private static final List<String> ALL_THEMES_LIST = Arrays.asList(ALL_THEMES_ARRAY);
36+
public static final String DEFAULT_THEME = "PaleBlue";
37+
38+
/** return index within ALL_THEMES_ARRAY or -1 if not found */
39+
public static int getThemeIndex(String preferedThemeName) {
40+
for (int i = 0; i<ALL_THEMES_ARRAY.length; i++){
41+
if (ALL_THEMES_ARRAY[i].equalsIgnoreCase(preferedThemeName)){
42+
return i;
43+
}
44+
}
45+
return -1;
46+
}
47+
//}
48+
3649

3750
protected Collection<IBoxProvider> providers;
3851
protected Map<IWorkbenchPart, IBoxDecorator> decorators;
@@ -99,7 +112,7 @@ protected Collection<IBoxProvider> defaultProviders() {
99112
List<IBoxProvider> result = new ArrayList<IBoxProvider>();
100113
// order important (see BoxProviderImpl.supports())
101114
// refactored to use this more generic method
102-
result.add(createProviderForNameAndExtentions("c++", Arrays.asList("*.c", "*.cpp", "*.h", "*.hpp") ) );
115+
result.add(createProviderForNameAndExtentions("c++", Arrays.asList("*.c", "*.cpp", "*.h", "*.hpp", "*.go") ) );
103116
result.add(createProviderForNameAndExtentions("java", Arrays.asList("*.java", "*.class", "*.gradle", "*.groovy", "*.scala") ) );
104117
result.add(createProviderForNameAndExtentions("js", Arrays.asList("*.js", "*.jjs", "*.jshintrc", "*.mjs", "*.njs", "*.pjs", "*.vjs", "*.ts", "*.coffee", "*.dart") ) );
105118
result.add(createProviderForNameAndExtentions("lua", Arrays.asList("*.lua") ) );
@@ -215,4 +228,5 @@ public void removePartListener(IPartService partService) {
215228
if (oldListener != null)
216229
partService.removePartListener(oldListener);
217230
}
231+
218232
}

pm.eclipse.editbox/src/pm/eclipse/editbox/pref/BoxSettingsTab.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,9 @@ protected Control createControls(Composite parent) {
150150
enabled = new Button(c, SWT.CHECK);
151151
GridData gd = new GridData();
152152
enabled.setLayoutData(gd);
153-
enabled.setText("Enabled");
153+
enabled.setText("Provider enabled");
154154
enabled.setAlignment(SWT.RIGHT);
155155
enabled.addSelectionListener(new SelectionAdapter() {
156-
157156
public void widgetSelected(SelectionEvent e) {
158157
settings.setEnabled(enabled.getSelection());
159158
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package pm.eclipse.editbox.pref;
2+
3+
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
4+
import org.eclipse.jface.preference.IPreferenceStore;
5+
6+
import pm.eclipse.editbox.EditBox;
7+
import pm.eclipse.editbox.impl.BoxProviderRegistry;
8+
9+
public class EditboxPreferenceInitializer extends AbstractPreferenceInitializer {
10+
11+
@Override
12+
public void initializeDefaultPreferences() {
13+
IPreferenceStore store = EditBox.getDefault().getPreferenceStore();
14+
store.setDefault(EditBox.PREF_ENABLED, true);
15+
store.setDefault(EditBox.PREF_DEFAULT_THEME, BoxProviderRegistry.DEFAULT_THEME);
16+
//TODO move defaults from BoxProviderRegistry into this EditboxPreferenceInitializer
17+
}
18+
}

0 commit comments

Comments
 (0)