Permalink
Browse files

ToolItem/MenuItem fixes

- Properly order toolbar items when inserted.
- Set enabled properly when created
- Set ToolItem.ID from Command.ID
  • Loading branch information...
1 parent 00c0c7c commit 9f86e8cd0cdd8c6dd90e8e173cf4a3204a1828d3 @cwensley cwensley committed Mar 31, 2014
@@ -12,7 +12,7 @@ public class ButtonToolItemHandler : ToolItemHandler<Gtk.ToolButton, ButtonToolI
#endregion
- public override void CreateControl(ToolBarHandler handler)
+ public override void CreateControl(ToolBarHandler handler, int index)
{
Gtk.Toolbar tb = handler.Control;
@@ -21,7 +21,7 @@ public override void CreateControl(ToolBarHandler handler)
Control.Sensitive = Enabled;
//Control.TooltipText = this.ToolTip;
//control.CanFocus = false;
- tb.Insert(Control, -1);
+ tb.Insert(Control, index);
if (tb.Visible) Control.ShowAll();
Control.Clicked += Connector.HandleClicked;
}
@@ -24,7 +24,7 @@ public bool Checked
}
}
- public override void CreateControl(ToolBarHandler handler)
+ public override void CreateControl(ToolBarHandler handler, int index)
{
Gtk.Toolbar tb = handler.Control;
@@ -36,7 +36,7 @@ public override void CreateControl(ToolBarHandler handler)
Control.Sensitive = Enabled;
Control.CanFocus = false;
Control.IsImportant = true;
- tb.Insert(Control, -1);
+ tb.Insert(Control, index);
if (tb.Visible)
Control.ShowAll();
}
@@ -6,27 +6,27 @@ public class SeparatorToolItemHandler : ToolItemHandler<Gtk.SeparatorToolItem, S
{
SeparatorToolItemType type;
bool expand;
-
- public override void CreateControl (ToolBarHandler handler)
+
+ public override void CreateControl(ToolBarHandler handler, int index)
{
Gtk.Toolbar tb = handler.Control;
Control = new Gtk.SeparatorToolItem();
Control.Expand = expand;
- tb.Insert(Control, -1);
- if (tb.Visible) Control.ShowAll();
+ tb.Insert(Control, index);
+ if (tb.Visible)
+ Control.ShowAll();
}
-
-
- public SeparatorToolItemType Type {
- get {
- return type;
- }
- set {
+
+ public SeparatorToolItemType Type
+ {
+ get { return type; }
+ set
+ {
type = value;
expand = type == SeparatorToolItemType.FlexibleSpace;
- if (Control != null) Control.Expand = expand;
+ if (Control != null)
+ Control.Expand = expand;
}
}
-
}
}
@@ -18,9 +18,9 @@ public ToolBarDock Dock
set { dock = value; }
}
- public void AddButton(ToolItem item)
+ public void AddButton(ToolItem item, int index)
{
- ((IToolBarItemHandler)item.Handler).CreateControl(this);
+ ((IToolBarItemHandler)item.Handler).CreateControl(this, index);
}
public void RemoveButton(ToolItem item)
@@ -5,7 +5,7 @@ namespace Eto.Platform.GtkSharp
{
public interface IToolBarItemHandler
{
- void CreateControl(ToolBarHandler handler);
+ void CreateControl(ToolBarHandler handler, int index);
}
@@ -18,7 +18,7 @@ public abstract class ToolItemHandler<TControl, TWidget> : WidgetHandler<TContro
protected Gtk.Image GtkImage { get; set; }
- public abstract void CreateControl(ToolBarHandler handler);
+ public abstract void CreateControl(ToolBarHandler handler, int index);
public string Text { get; set; }
@@ -73,11 +73,11 @@ public ToolBarDock Dock
set { dock = value; }
}
- public void AddButton(ToolItem item)
+ public void AddButton(ToolItem item, int index)
{
var handler = (IToolBarBaseItemHandler)item.Handler;
- items.Add(handler);
- Control.InsertItem(handler.Identifier, Control.Items.Length);
+ items.Insert(index, handler);
+ Control.InsertItem(handler.Identifier, index);
if (handler != null)
handler.ControlAdded(this);
//Control.ValidateVisibleItems();
@@ -28,9 +28,9 @@ public override bool Enabled
set { control.Enabled = value; }
}
- public override void CreateControl(ToolBarHandler handler)
+ public override void CreateControl(ToolBarHandler handler, int index)
{
- handler.Control.Items.Add(control);
+ handler.Control.Items.Insert(index, control);
}
public override void InvokeButton()
@@ -28,9 +28,9 @@ public bool Checked
set { control.Checked = value; }
}
- public override void CreateControl(ToolBarHandler handler)
+ public override void CreateControl(ToolBarHandler handler, int index)
{
- handler.Control.Items.Add(control);
+ handler.Control.Items.Insert(index, control);
}
@@ -32,9 +32,9 @@ public SeparatorToolItemType Type
}
}
- public void CreateControl(ToolBarHandler handler)
+ public void CreateControl(ToolBarHandler handler, int index)
{
- handler.Control.Items.Add(Control);
+ handler.Control.Items.Insert(index, Control);
}
public string Text
@@ -22,9 +22,9 @@ public ToolBarDock Dock
set { dock = value; }
}
- public void AddButton(ToolItem item)
+ public void AddButton(ToolItem item, int index)
{
- ((IToolBarItemHandler)item.Handler).CreateControl(this);
+ ((IToolBarItemHandler)item.Handler).CreateControl(this, index);
}
public void RemoveButton(ToolItem item)
@@ -7,7 +7,7 @@ namespace Eto.Platform.Windows
{
public interface IToolBarItemHandler
{
- void CreateControl(ToolBarHandler handler);
+ void CreateControl(ToolBarHandler handler, int index);
}
public abstract class ToolItemHandler<TControl, TWidget> : WidgetHandler<TControl, TWidget>, IToolItem, IToolBarItemHandler
@@ -17,7 +17,7 @@ public abstract class ToolItemHandler<TControl, TWidget> : WidgetHandler<TContro
Image image;
int imageSize = 16;
- public abstract void CreateControl(ToolBarHandler handler);
+ public abstract void CreateControl(ToolBarHandler handler, int index);
public virtual void InvokeButton()
{
@@ -6,26 +6,26 @@ namespace Eto.Platform.Wpf.Forms
{
public class ToolBarHandler : WidgetHandler<swc.ToolBar, ToolBar>, IToolBar
{
- public override swc.ToolBar CreateControl ()
+ public override swc.ToolBar CreateControl()
{
var control = new swc.ToolBar { IsTabStop = false };
- swi.KeyboardNavigation.SetTabNavigation (control, swi.KeyboardNavigationMode.Continue);
+ swi.KeyboardNavigation.SetTabNavigation(control, swi.KeyboardNavigationMode.Continue);
return control;
}
- public void AddButton (ToolItem button)
+ public void AddButton(ToolItem button, int index)
{
- Control.Items.Add (button.ControlObject);
+ Control.Items.Insert(index, button.ControlObject);
}
- public void RemoveButton (ToolItem button)
+ public void RemoveButton(ToolItem button)
{
- Control.Items.Remove (button.ControlObject);
+ Control.Items.Remove(button.ControlObject);
}
- public void Clear ()
+ public void Clear()
{
- Control.Items.Clear ();
+ Control.Items.Clear();
}
public ToolBarTextAlign TextAlign
@@ -60,6 +60,7 @@ protected MenuItem(Command command, Generator generator, Type type, bool initial
ToolTip = command.ToolTip;
Shortcut = command.Shortcut;
Click += (sender, e) => command.OnExecuted(e);
+ Enabled = command.Enabled;
command.EnabledChanged += (sender, e) => Enabled = command.Enabled;
if (initialize)
Handler.CreateFromCommand(command);
@@ -18,7 +18,7 @@ public enum ToolBarDock
public interface IToolBar : IInstanceWidget
{
- void AddButton(ToolItem button);
+ void AddButton(ToolItem button, int index);
void RemoveButton(ToolItem button);
@@ -24,10 +24,12 @@ public void OnClick(EventArgs e)
protected ToolItem(Command command, Generator generator, Type type, bool initialize = true)
: base(generator, type, initialize)
{
+ ID = command.ID;
Text = command.ToolBarText;
ToolTip = command.ToolTip;
Image = command.Image;
Click += (sender, e) => command.OnExecuted(e);
+ Enabled = command.Enabled;
command.EnabledChanged += (sender, e) => Enabled = command.Enabled;
Order = -1;
}
@@ -15,7 +15,7 @@ protected internal ToolItemCollection(ToolBar parent)
protected override void InsertItem(int index, ToolItem item)
{
base.InsertItem(index, item);
- parent.Handler.AddButton(item);
+ parent.Handler.AddButton(item, index);
}
protected override void RemoveItem(int index)
@@ -51,9 +51,9 @@ public void Add(Command command, int order = -1)
Add(item);
}
- public void AddSeparator(int order = -1)
+ public void AddSeparator(int order = -1, SeparatorToolItemType type = SeparatorToolItemType.Divider)
{
- Add(new SeparatorToolItem(parent.Generator) { Order = order });
+ Add(new SeparatorToolItem(parent.Generator) { Order = order, Type = type });
}
public void AddRange(IEnumerable<ToolItem> items)

0 comments on commit 9f86e8c

Please sign in to comment.