mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +02:00
Added preference to enable/disable the launch bar.
This commit is contained in:
parent
c2da55547c
commit
359c8976c8
5 changed files with 127 additions and 22 deletions
|
@ -43,5 +43,20 @@
|
||||||
name="Configure Active Launch Configuration">
|
name="Configure Active Launch Configuration">
|
||||||
</command>
|
</command>
|
||||||
</extension>
|
</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>
|
</plugin>
|
||||||
|
|
|
@ -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_STOP = "org.eclipse.cdt.launchbar.ui.command.stop";
|
||||||
public static final String CMD_CONFIG = "org.eclipse.cdt.launchbar.ui.command.configureActiveLaunch";
|
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
|
// The shared instance
|
||||||
private static Activator plugin;
|
private static Activator plugin;
|
||||||
|
|
||||||
|
|
|
@ -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.MMenuFactory;
|
||||||
import org.eclipse.e4.ui.model.application.ui.menu.MToolControl;
|
import org.eclipse.e4.ui.model.application.ui.menu.MToolControl;
|
||||||
import org.eclipse.e4.ui.workbench.UIEvents;
|
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.Event;
|
||||||
import org.osgi.service.event.EventHandler;
|
import org.osgi.service.event.EventHandler;
|
||||||
|
|
||||||
|
@ -37,16 +40,9 @@ public class LaunchBarInjector {
|
||||||
|
|
||||||
@Execute
|
@Execute
|
||||||
void execute() {
|
void execute() {
|
||||||
// Inject the toolbar into all top trims
|
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
|
||||||
for (MWindow window : application.getChildren()) {
|
boolean enabled = store.getBoolean(Activator.PREF_ENABLE_LAUNCHBAR);
|
||||||
if (window instanceof MTrimmedWindow) {
|
injectIntoAll(enabled);
|
||||||
for (MTrimBar trimBar : ((MTrimmedWindow) window).getTrimBars()) {
|
|
||||||
if (trimBar.getSide() == SideValue.TOP) {
|
|
||||||
injectLaunchBar(trimBar);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Watch for new trimmed windows and inject there too.
|
// Watch for new trimmed windows and inject there too.
|
||||||
eventBroker.subscribe(UIEvents.TrimmedWindow.TOPIC_TRIMBARS, new EventHandler() {
|
eventBroker.subscribe(UIEvents.TrimmedWindow.TOPIC_TRIMBARS, new EventHandler() {
|
||||||
|
@ -57,23 +53,74 @@ public class LaunchBarInjector {
|
||||||
Object newValue = event.getProperty(UIEvents.EventTags.NEW_VALUE);
|
Object newValue = event.getProperty(UIEvents.EventTags.NEW_VALUE);
|
||||||
if (newValue instanceof MTrimBar) {
|
if (newValue instanceof MTrimBar) {
|
||||||
MTrimBar trimBar = (MTrimBar) newValue;
|
MTrimBar trimBar = (MTrimBar) newValue;
|
||||||
if (trimBar.getSide() == SideValue.TOP)
|
if (trimBar.getSide() == SideValue.TOP) {
|
||||||
injectLaunchBar(trimBar);
|
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();
|
private void injectIntoAll(boolean enabled) {
|
||||||
launchBar.setElementId(LaunchBarControl.ID);
|
// Inject the toolbar into all top trims
|
||||||
launchBar.setContributionURI(LaunchBarControl.CLASS_URI);
|
for (MWindow window : application.getChildren()) {
|
||||||
trimBar.getChildren().add(0, launchBar);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue