Mercurial > projects > dwt-addons
changeset 33:f25582573129
menus
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 03 Apr 2008 20:41:52 +0200 |
parents | 5802cda3813d |
children | b3c8e32d406f |
files | dwtx/jface/menus/AbstractTrimWidget.d dwtx/jface/menus/IWidget.d dwtx/jface/menus/TextState.d |
diffstat | 3 files changed, 252 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /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 <benoit@tionex.de> + ******************************************************************************/ + +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. + * <p> + * This class is intended to be the base for any trim contributions. + * </p> + * @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. + * <p> + * For example: If the implementation is constructing a {@link ToolBar} and + * the orientation were to change from horizontal to vertical it would have + * to <code>dispose</code> its old ToolBar and create a new one with the + * correct orientation. + * </p> + * <p> + * The sides can be one of: + * <ul> + * <li>{@link DWT#TOP}</li> + * <li>{@link DWT#BOTTOM}</li> + * <li>{@link DWT#LEFT}</li> + * <li>{@link DWT#RIGHT}</li> + * </ul> + * </p> + * <p> + * + * @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) { + } +}
--- /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 <benoit@tionex.de> + *******************************************************************************/ + +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; + +/** + * <p> + * 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. + * </p> + * <p> + * It is possible for fill and dispose to be called multiple times for a single + * instance of <code>IWidget</code>. + * </p> + * <p> + * Clients may implement, but must not extend. + * </p> + * + * @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 <code>-1</code> + * 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 <code>-1</code> + * 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 <code>-1</code> + * to insert at the end + */ + public void fill(CoolBar parent, int index); +}
--- /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 <benoit@tionex.de> + *******************************************************************************/ + +module dwtx.jface.menus.TextState; + +import dwtx.core.commands.INamedHandleStateIds; +import dwtx.jface.commands.PersistentState; +import dwtx.jface.preference.IPreferenceStore; + +import dwt.dwthelper.utils; + +/** + * <p> + * A piece of state carrying a single {@link String}. + * </p> + * <p> + * 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}. + * </p> + * <p> + * Clients may instantiate this class, but must not extend. + * </p> + * + * @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); + } + +}