# HG changeset patch # User Frank Benoit # Date 1207248112 -7200 # Node ID f255825731295d7c463c129dc9a118a3b394a3b5 # Parent 5802cda3813d3b0185746ac7545d6c972a9ceea1 menus diff -r 5802cda3813d -r f25582573129 dwtx/jface/menus/AbstractTrimWidget.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtx/jface/menus/AbstractTrimWidget.d Thu Apr 03 20:41:52 2008 +0200 @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit + ******************************************************************************/ + +module dwtx.jface.menus.AbstractTrimWidget; + +import dwtx.jface.menus.IWidget; + +import dwt.DWT; +import dwt.widgets.Composite; +import dwt.widgets.CoolBar; +import dwt.widgets.Menu; +import dwt.widgets.ToolBar; + +import dwt.dwthelper.utils; + +/** + * This extension to the {@link IWidget} interface allows clients adding + * elements to the trim to receive notifications if the User moves the widget to + * another trim area. + *

+ * This class is intended to be the base for any trim contributions. + *

+ * @since 3.2 + * + */ +public abstract class AbstractTrimWidget : IWidget { + /** + * This method is called to initially construct the widget and is also + * called whenever the widget's composite has been moved to a trim area on a + * different side of the workbench. It is the client's responsibility to + * control the life-cycle of the Control it manages. + *

+ * For example: If the implementation is constructing a {@link ToolBar} and + * the orientation were to change from horizontal to vertical it would have + * to dispose its old ToolBar and create a new one with the + * correct orientation. + *

+ *

+ * The sides can be one of: + *

+ *

+ *

+ * + * @param parent + * The parent to (re)create the widget under + * + * @param oldSide + * The previous side ({@link DWT#DEFAULT} on the initial fill) + * @param newSide + * The current side + */ + public abstract void fill(Composite parent, int oldSide, int newSide); + + /* (non-Javadoc) + * @see dwtx.jface.menus.IWidget#dispose() + */ + public abstract void dispose(); + + /* (non-Javadoc) + * @see dwtx.jface.menus.IWidget#fill(dwt.widgets.Composite) + */ + public void fill(Composite parent) { + } + + /* (non-Javadoc) + * @see dwtx.jface.menus.IWidget#fill(dwt.widgets.Menu, int) + */ + public void fill(Menu parent, int index) { + } + + /* (non-Javadoc) + * @see dwtx.jface.menus.IWidget#fill(dwt.widgets.ToolBar, int) + */ + public void fill(ToolBar parent, int index) { + } + + /* (non-Javadoc) + * @see dwtx.jface.menus.IWidget#fill(dwt.widgets.CoolBar, int) + */ + public void fill(CoolBar parent, int index) { + } +} diff -r 5802cda3813d -r f25582573129 dwtx/jface/menus/IWidget.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtx/jface/menus/IWidget.d Thu Apr 03 20:41:52 2008 +0200 @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2005, 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit + *******************************************************************************/ + +module dwtx.jface.menus.IWidget; + +import dwt.widgets.Composite; +import dwt.widgets.CoolBar; +import dwt.widgets.Menu; +import dwt.widgets.ToolBar; + +import dwt.dwthelper.utils; + +/** + *

+ * Provides a hook by which third-party code can contribute DWT widgets to a + * menu, tool bar or status line. This can be used, for example, to add a combo + * box to the status line, or a "Location" bar to the tool bar. + *

+ *

+ * It is possible for fill and dispose to be called multiple times for a single + * instance of IWidget. + *

+ *

+ * Clients may implement, but must not extend. + *

+ * + * @since 3.2 + */ +public interface IWidget { + + /** + * Disposes of the underlying widgets. This can be called when the widget is + * becoming hidden. + */ + public void dispose(); + + /** + * Fills the given composite control with controls representing this widget. + * + * @param parent + * the parent control + */ + public void fill(Composite parent); + + /** + * Fills the given menu with controls representing this widget. + * + * @param parent + * the parent menu + * @param index + * the index where the controls are inserted, or -1 + * to insert at the end + */ + public void fill(Menu parent, int index); + + /** + * Fills the given tool bar with controls representing this contribution + * item. + * + * @param parent + * the parent tool bar + * @param index + * the index where the controls are inserted, or -1 + * to insert at the end + */ + public void fill(ToolBar parent, int index); + + /** + * Fills the given cool bar with controls representing this contribution + * item. + * + * @param parent + * the parent cool bar + * @param index + * the index where the controls are inserted, or -1 + * to insert at the end + */ + public void fill(CoolBar parent, int index); +} diff -r 5802cda3813d -r f25582573129 dwtx/jface/menus/TextState.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtx/jface/menus/TextState.d Thu Apr 03 20:41:52 2008 +0200 @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2005, 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit + *******************************************************************************/ + +module dwtx.jface.menus.TextState; + +import dwtx.core.commands.INamedHandleStateIds; +import dwtx.jface.commands.PersistentState; +import dwtx.jface.preference.IPreferenceStore; + +import dwt.dwthelper.utils; + +/** + *

+ * A piece of state carrying a single {@link String}. + *

+ *

+ * If this state is registered using {@link INamedHandleStateIds#NAME} or + * {@link INamedHandleStateIds#DESCRIPTION}, then this allows the handler to + * communicate a textual change for a given command. This is typically used by + * graphical applications to allow more specific text to be displayed in the + * menus. For example, "Undo" might become "Undo Typing" through the use of a + * {@link TextState}. + *

+ *

+ * Clients may instantiate this class, but must not extend. + *

+ * + * @since 3.2 + * @see INamedHandleStateIds + */ +public class TextState : PersistentState { + + public final void load(IPreferenceStore store, + String preferenceKey) { + String value = store.getString(preferenceKey); + setValue(stringcast(value)); + } + + public final void save(IPreferenceStore store, + String preferenceKey) { + Object value = getValue(); + if ( cast(ArrayWrapperString)value ) { + store.setValue(preferenceKey, stringcast(value)); + } + } + + public void setValue(Object value) { + if (!( cast(ArrayWrapperString)value )) { + throw new IllegalArgumentException( + "TextState takes a String as a value"); //$NON-NLS-1$ + } + + super.setValue(value); + } + +}