1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-30 21:55:31 +02:00

Added preference to enable/disable the launch bar.

This commit is contained in:
Doug Schaefer 2014-06-19 13:49:50 -04:00
parent c2da55547c
commit 359c8976c8
5 changed files with 127 additions and 22 deletions

View file

@ -43,5 +43,20 @@
name="Configure Active Launch Configuration">
</command>
</extension>
<extension
point="org.eclipse.core.runtime.preferences">
<initializer
class="org.eclipse.cdt.launchbar.ui.internal.LaunchBarPreferenceInitializer">
</initializer>
</extension>
<extension
point="org.eclipse.ui.preferencePages">
<page
category="org.eclipse.debug.ui.LaunchingPreferencePage"
class="org.eclipse.cdt.launchbar.ui.internal.LaunchBarPreferencePage"
id="org.eclipse.cdt.launchbar.ui.prefPage"
name="Launch Bar">
</page>
</extension>
</plugin>

View file

@ -49,6 +49,9 @@ public class Activator extends AbstractUIPlugin {
public static final String CMD_STOP = "org.eclipse.cdt.launchbar.ui.command.stop";
public static final String CMD_CONFIG = "org.eclipse.cdt.launchbar.ui.command.configureActiveLaunch";
// Preference ids
public static final String PREF_ENABLE_LAUNCHBAR = "enableLaunchBar";
// The shared instance
private static Activator plugin;

View file

@ -24,6 +24,9 @@ import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;
import org.eclipse.e4.ui.model.application.ui.menu.MToolControl;
import org.eclipse.e4.ui.workbench.UIEvents;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
@ -37,16 +40,9 @@ public class LaunchBarInjector {
@Execute
void execute() {
// Inject the toolbar into all top trims
for (MWindow window : application.getChildren()) {
if (window instanceof MTrimmedWindow) {
for (MTrimBar trimBar : ((MTrimmedWindow) window).getTrimBars()) {
if (trimBar.getSide() == SideValue.TOP) {
injectLaunchBar(trimBar);
}
}
}
}
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
boolean enabled = store.getBoolean(Activator.PREF_ENABLE_LAUNCHBAR);
injectIntoAll(enabled);
// Watch for new trimmed windows and inject there too.
eventBroker.subscribe(UIEvents.TrimmedWindow.TOPIC_TRIMBARS, new EventHandler() {
@ -57,23 +53,74 @@ public class LaunchBarInjector {
Object newValue = event.getProperty(UIEvents.EventTags.NEW_VALUE);
if (newValue instanceof MTrimBar) {
MTrimBar trimBar = (MTrimBar) newValue;
if (trimBar.getSide() == SideValue.TOP)
injectLaunchBar(trimBar);
if (trimBar.getSide() == SideValue.TOP) {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
boolean enabled = store.getBoolean(Activator.PREF_ENABLE_LAUNCHBAR);
injectLaunchBar(trimBar, enabled);
}
}
}
});
// Watch for preference changes
Activator.getDefault().getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
if (event.getProperty().equals(Activator.PREF_ENABLE_LAUNCHBAR)) {
boolean enabled = Boolean.parseBoolean(event.getNewValue().toString());
injectIntoAll(enabled);
}
}
});
}
void injectLaunchBar(MTrimBar trimBar) {
// Skip if we're already there
for (MTrimElement trimElement : trimBar.getChildren())
if (LaunchBarControl.ID.equals(trimElement.getElementId()))
return;
MToolControl launchBar = MMenuFactory.INSTANCE.createToolControl();
launchBar.setElementId(LaunchBarControl.ID);
launchBar.setContributionURI(LaunchBarControl.CLASS_URI);
trimBar.getChildren().add(0, launchBar);
private void injectIntoAll(boolean enabled) {
// Inject the toolbar into all top trims
for (MWindow window : application.getChildren()) {
if (window instanceof MTrimmedWindow) {
for (MTrimBar trimBar : ((MTrimmedWindow) window).getTrimBars()) {
if (trimBar.getSide() == SideValue.TOP) {
injectLaunchBar(trimBar, enabled);
}
}
}
}
}
private void injectLaunchBar(MTrimBar trimBar, boolean enabled) {
// are we enabled or not
// Search for control in trimbar
MTrimElement launchBarElement = null;
for (MTrimElement trimElement : trimBar.getChildren()) {
if (LaunchBarControl.ID.equals(trimElement.getElementId())) {
launchBarElement = trimElement;
break;
}
}
if (launchBarElement != null) {
if (!enabled) {
// remove it if we're disabled
trimBar.getChildren().remove(launchBarElement);
for (MTrimElement trimElement : trimBar.getChildren()) {
if (LaunchBarControl.ID.equals(trimElement.getElementId())) {
launchBarElement = trimElement;
break;
}
}
}
// either way, we're done
return;
}
if (enabled) {
// Add it
MToolControl launchBar = MMenuFactory.INSTANCE.createToolControl();
launchBar.setElementId(LaunchBarControl.ID);
launchBar.setContributionURI(LaunchBarControl.CLASS_URI);
trimBar.getChildren().add(0, launchBar);
}
}
}

View file

@ -0,0 +1,14 @@
package org.eclipse.cdt.launchbar.ui.internal;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;
public class LaunchBarPreferenceInitializer extends AbstractPreferenceInitializer {
@Override
public void initializeDefaultPreferences() {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
store.setDefault(Activator.PREF_ENABLE_LAUNCHBAR, true);
}
}

View file

@ -0,0 +1,26 @@
package org.eclipse.cdt.launchbar.ui.internal;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
public class LaunchBarPreferencePage extends FieldEditorPreferencePage implements
IWorkbenchPreferencePage {
public LaunchBarPreferencePage() {
super(GRID);
}
@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setDescription("Preferences for the Launch Bar.");
}
@Override
protected void createFieldEditors() {
addField(new BooleanFieldEditor(Activator.PREF_ENABLE_LAUNCHBAR, "Enable the Launch Bar (may require restart).", getFieldEditorParent()));
}
}