Skip to content

Commit

Permalink
Simplify menu/tool hierarchy even more by eliminating ToolBarItem and…
Browse files Browse the repository at this point in the history
… ActionMenuItem and making the naming more consistent

Added OnLoad/OnUnload to menu/toolbar when set onto a window (+1 squashed commit)
Squashed commits:
[373c5d9] Refactor menu/toolbar to eliminate BaseAction (CommandBase) from the hierarchy so things like MenuText/ToolBarText don’t muddy the api.
BaseAction now becomes Command, which can be used to create a menu or tool item but is a separate, plain class.
  • Loading branch information
cwensley committed Dec 16, 2013
1 parent b5f2ba2 commit 175159d
Show file tree
Hide file tree
Showing 121 changed files with 1,470 additions and 1,499 deletions.
12 changes: 6 additions & 6 deletions Source/Eto.Platform.Gtk/Eto.Platform.Gtk.csproj
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
Expand Down Expand Up @@ -165,7 +165,7 @@
<Compile Include="Forms\Menu\CheckMenuItemHandler.cs"> <Compile Include="Forms\Menu\CheckMenuItemHandler.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Forms\Menu\ImageMenuItemHandler.cs"> <Compile Include="Forms\Menu\ButtonMenuItemHandler.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Forms\Menu\SeparatorMenuItemHandler.cs"> <Compile Include="Forms\Menu\SeparatorMenuItemHandler.cs">
Expand All @@ -180,17 +180,17 @@
<Compile Include="Forms\Menu\MenuBarHandler.cs"> <Compile Include="Forms\Menu\MenuBarHandler.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Forms\ToolBar\CheckToolBarButtonHandler.cs"> <Compile Include="Forms\ToolBar\CheckToolItemHandler.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Forms\ToolBar\SeparatorToolBarItemHandler.cs" /> <Compile Include="Forms\ToolBar\SeparatorToolItemHandler.cs" />
<Compile Include="Forms\ToolBar\ToolBarButtonHandler.cs"> <Compile Include="Forms\ToolBar\ButtonToolItemHandler.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Forms\ToolBar\ToolBarHandler.cs"> <Compile Include="Forms\ToolBar\ToolBarHandler.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Forms\ToolBar\ToolBarItemHandler.cs"> <Compile Include="Forms\ToolBar\ToolItemHandler.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Forms\SelectFolderDialogHandler.cs" /> <Compile Include="Forms\SelectFolderDialogHandler.cs" />
Expand Down
22 changes: 7 additions & 15 deletions Source/Eto.Platform.Gtk/Eto.Platform.Gtk3.csproj
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup> <PropertyGroup>
<ProjectType>Local</ProjectType> <ProjectType>Local</ProjectType>
Expand Down Expand Up @@ -107,6 +107,11 @@
<Compile Include="Forms\Controls\ProgressBarHandler.cs" /> <Compile Include="Forms\Controls\ProgressBarHandler.cs" />
<Compile Include="Forms\Controls\TreeViewHandler.cs" /> <Compile Include="Forms\Controls\TreeViewHandler.cs" />
<Compile Include="Forms\FontDialogHandler.cs" /> <Compile Include="Forms\FontDialogHandler.cs" />
<Compile Include="Forms\Menu\ButtonMenuItemHandler.cs" />
<Compile Include="Forms\ToolBar\ButtonToolItemHandler.cs" />
<Compile Include="Forms\ToolBar\CheckToolItemHandler.cs" />
<Compile Include="Forms\ToolBar\SeparatorToolItemHandler.cs" />
<Compile Include="Forms\ToolBar\ToolItemHandler.cs" />
<Compile Include="Generator.cs"> <Compile Include="Generator.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
Expand Down Expand Up @@ -188,9 +193,6 @@
<Compile Include="Forms\Menu\CheckMenuItemHandler.cs"> <Compile Include="Forms\Menu\CheckMenuItemHandler.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Forms\Menu\ImageMenuItemHandler.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Forms\Menu\SeparatorMenuItemHandler.cs"> <Compile Include="Forms\Menu\SeparatorMenuItemHandler.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
Expand All @@ -203,19 +205,9 @@
<Compile Include="Forms\Menu\MenuBarHandler.cs"> <Compile Include="Forms\Menu\MenuBarHandler.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Forms\ToolBar\CheckToolBarButtonHandler.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Forms\ToolBar\SeparatorToolBarItemHandler.cs" />
<Compile Include="Forms\ToolBar\ToolBarButtonHandler.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Forms\ToolBar\ToolBarHandler.cs"> <Compile Include="Forms\ToolBar\ToolBarHandler.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Forms\ToolBar\ToolBarItemHandler.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Forms\SelectFolderDialogHandler.cs" /> <Compile Include="Forms\SelectFolderDialogHandler.cs" />
<Compile Include="Forms\Controls\ComboBoxHandler.cs" /> <Compile Include="Forms\Controls\ComboBoxHandler.cs" />
<Compile Include="Forms\UITimerHandler.cs" /> <Compile Include="Forms\UITimerHandler.cs" />
Expand Down Expand Up @@ -293,4 +285,4 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
</ItemGroup> </ItemGroup>
</Project> </Project>
9 changes: 7 additions & 2 deletions Source/Eto.Platform.Gtk/Forms/ApplicationHandler.cs
Expand Up @@ -158,10 +158,15 @@ public void Open (string url)
Process.Start (info); Process.Start (info);
} }


public void GetSystemActions(List<CommandBase> actions, ISubMenuWidget menu, ToolBar toolBar, bool addStandardItems) public IEnumerable<Command> GetSystemCommands()
{ {
yield break;
} }


public void CreateStandardMenu(MenuItemCollection menu, IEnumerable<Command> commands)
{
}

public Keys CommonModifier { public Keys CommonModifier {
get { get {
return Keys.Control; return Keys.Control;
Expand Down
2 changes: 1 addition & 1 deletion Source/Eto.Platform.Gtk/Forms/Controls/GtkControl.cs
Expand Up @@ -538,7 +538,7 @@ public string ToolTip
set { Control.TooltipText = value; } set { Control.TooltipText = value; }
} }


public virtual void MapPlatformAction(string systemAction, CommandBase action) public virtual void MapPlatformAction(string systemAction, Command action)
{ {
} }


Expand Down
10 changes: 5 additions & 5 deletions Source/Eto.Platform.Gtk/Forms/GtkWindow.cs
Expand Up @@ -304,19 +304,19 @@ public MenuBar Menu
} }
} }


void SetAccelerators(ISubMenuWidget item) void SetAccelerators(IMenuItemsSource item)
{ {
if (item != null && item.MenuItems != null) if (item != null && item.Items != null)
foreach (var child in item.MenuItems) foreach (var child in item.Items)
{ {
var actionItem = child as MenuActionItem; var actionItem = child;
if (actionItem != null && actionItem.Shortcut != Key.None) if (actionItem != null && actionItem.Shortcut != Key.None)
{ {
var widget = (Gtk.Widget)actionItem.ControlObject; var widget = (Gtk.Widget)actionItem.ControlObject;
var key = new Gtk.AccelKey(actionItem.Shortcut.ToGdkKey(), actionItem.Shortcut.ToGdkModifier(), Gtk.AccelFlags.Visible | Gtk.AccelFlags.Locked); var key = new Gtk.AccelKey(actionItem.Shortcut.ToGdkKey(), actionItem.Shortcut.ToGdkModifier(), Gtk.AccelFlags.Visible | Gtk.AccelFlags.Locked);
widget.AddAccelerator("activate", accelGroup, key); widget.AddAccelerator("activate", accelGroup, key);
} }
SetAccelerators(child as ISubMenuWidget); SetAccelerators(child as IMenuItemsSource);
} }


} }
Expand Down
Expand Up @@ -4,15 +4,15 @@


namespace Eto.Platform.GtkSharp namespace Eto.Platform.GtkSharp
{ {
public class ImageMenuItemHandler : MenuActionItemHandler<Gtk.ImageMenuItem, ImageMenuItem>, IImageMenuItem public class ButtonMenuItemHandler : MenuActionItemHandler<Gtk.ImageMenuItem, ButtonMenuItem>, IButtonMenuItem
{ {
string tooltip; string tooltip;
string text; string text;
Keys shortcut; Keys shortcut;
Image image; Image image;
readonly Gtk.AccelLabel label; readonly Gtk.AccelLabel label;


public ImageMenuItemHandler() public ButtonMenuItemHandler()
{ {
Control = new Gtk.ImageMenuItem(); Control = new Gtk.ImageMenuItem();
Control.Activated += control_Activated; Control.Activated += control_Activated;
Expand Down Expand Up @@ -72,13 +72,13 @@ public Image Image
} }
} }


public override void AddMenu(int index, MenuItem item) public void AddMenu(int index, MenuItem item)
{ {
if (Control.Submenu == null) Control.Submenu = new Gtk.Menu(); if (Control.Submenu == null) Control.Submenu = new Gtk.Menu();
((Gtk.Menu)Control.Submenu).Insert((Gtk.Widget)item.ControlObject, index); ((Gtk.Menu)Control.Submenu).Insert((Gtk.Widget)item.ControlObject, index);
} }


public override void RemoveMenu(MenuItem item) public void RemoveMenu(MenuItem item)
{ {
if (Control.Submenu == null) return; if (Control.Submenu == null) return;
var menu = (Gtk.Menu)Control.Submenu; var menu = (Gtk.Menu)Control.Submenu;
Expand All @@ -89,7 +89,7 @@ public override void RemoveMenu(MenuItem item)
} }
} }


public override void Clear() public void Clear()
{ {
foreach (Gtk.Widget w in Control.Children) foreach (Gtk.Widget w in Control.Children)
{ {
Expand Down
11 changes: 0 additions & 11 deletions Source/Eto.Platform.Gtk/Forms/Menu/CheckMenuItemHandler.cs
Expand Up @@ -68,17 +68,6 @@ public bool Enabled
set { Control.Sensitive = value; } set { Control.Sensitive = value; }
} }


public override void AddMenu(int index, MenuItem item)
{
}

public override void RemoveMenu(MenuItem item)
{
}

public override void Clear()
{
}
void control_Activated(object sender, EventArgs e) void control_Activated(object sender, EventArgs e)
{ {
if (!isBeingChecked) if (!isBeingChecked)
Expand Down
6 changes: 3 additions & 3 deletions Source/Eto.Platform.Gtk/Forms/Menu/ContextMenuHandler.cs
Expand Up @@ -10,18 +10,18 @@ public ContextMenuHandler()
Control = new Gtk.Menu(); Control = new Gtk.Menu();
} }


public override void AddMenu(int index, MenuItem item) public void AddMenu(int index, MenuItem item)
{ {
Control.Insert((Gtk.Widget)item.ControlObject, index); Control.Insert((Gtk.Widget)item.ControlObject, index);


} }


public override void RemoveMenu(MenuItem item) public void RemoveMenu(MenuItem item)
{ {
Control.Remove((Gtk.Widget)item.ControlObject); Control.Remove((Gtk.Widget)item.ControlObject);
} }


public override void Clear() public void Clear()
{ {
foreach (Gtk.Widget w in Control.Children) foreach (Gtk.Widget w in Control.Children)
{ {
Expand Down
6 changes: 3 additions & 3 deletions Source/Eto.Platform.Gtk/Forms/Menu/MenuBarHandler.cs
Expand Up @@ -13,18 +13,18 @@ public MenuBarHandler()
Control = new Gtk.MenuBar(); Control = new Gtk.MenuBar();
} }


public override void AddMenu(int index, MenuItem item) public void AddMenu(int index, MenuItem item)
{ {
Control.Insert((Gtk.Widget)item.ControlObject, index); Control.Insert((Gtk.Widget)item.ControlObject, index);


} }


public override void RemoveMenu(MenuItem item) public void RemoveMenu(MenuItem item)
{ {
Control.Remove((Gtk.Widget)item.ControlObject); Control.Remove((Gtk.Widget)item.ControlObject);
} }


public override void Clear() public void Clear()
{ {
foreach (Gtk.Widget w in Control.Children) foreach (Gtk.Widget w in Control.Children)
{ {
Expand Down
15 changes: 2 additions & 13 deletions Source/Eto.Platform.Gtk/Forms/Menu/MenuHandler.cs
Expand Up @@ -9,23 +9,12 @@ public abstract class MenuHandler<TControl, TWidget> : WidgetHandler<TControl, T
{ {
protected void ValidateItems() protected void ValidateItems()
{ {
var subMenu = Widget as ISubMenuWidget; var subMenu = Widget as IMenuItemsSource;
if (subMenu != null) { if (subMenu != null) {
foreach (var item in subMenu.MenuItems.OfType<MenuActionItem>()) { foreach (var item in subMenu.Items) {
item.OnValidate(EventArgs.Empty); item.OnValidate(EventArgs.Empty);
} }
} }
} }


#region IMenu Members

public abstract void AddMenu(int index, MenuItem item);

public abstract void RemoveMenu(MenuItem item);

public abstract void Clear();

#endregion
} }
} }
6 changes: 3 additions & 3 deletions Source/Eto.Platform.Gtk/Forms/Menu/RadioMenuItemHandler.cs
Expand Up @@ -83,14 +83,14 @@ public void Create (RadioMenuItem controller)
set { Control.Sensitive = value; } set { Control.Sensitive = value; }
} }


public override void AddMenu (int index, MenuItem item) public void AddMenu (int index, MenuItem item)
{ {
if (Control.Submenu == null) if (Control.Submenu == null)
Control.Submenu = new Gtk.Menu (); Control.Submenu = new Gtk.Menu ();
((Gtk.Menu)Control.Submenu).Insert ((Gtk.Widget)item.ControlObject, index); ((Gtk.Menu)Control.Submenu).Insert ((Gtk.Widget)item.ControlObject, index);
} }


public override void RemoveMenu (MenuItem item) public void RemoveMenu (MenuItem item)
{ {
if (Control.Submenu == null) if (Control.Submenu == null)
return; return;
Expand All @@ -101,7 +101,7 @@ public override void RemoveMenu (MenuItem item)
} }
} }


public override void Clear () public void Clear ()
{ {
foreach (Gtk.Widget w in Control.Children) { foreach (Gtk.Widget w in Control.Children) {
Control.Remove (w); Control.Remove (w);
Expand Down
26 changes: 19 additions & 7 deletions Source/Eto.Platform.Gtk/Forms/Menu/SeparatorMenuItemHandler.cs
Expand Up @@ -5,25 +5,37 @@ namespace Eto.Platform.GtkSharp
{ {
public class SeparatorMenuItemHandler : MenuHandler<Gtk.SeparatorMenuItem, SeparatorMenuItem>, ISeparatorMenuItem public class SeparatorMenuItemHandler : MenuHandler<Gtk.SeparatorMenuItem, SeparatorMenuItem>, ISeparatorMenuItem
{ {

public SeparatorMenuItemHandler() public SeparatorMenuItemHandler()
{ {
Control = new Gtk.SeparatorMenuItem(); Control = new Gtk.SeparatorMenuItem();
} }


public override void AddMenu(int index, MenuItem item) public void CreateFromCommand(Command command)
{
}

public string Text
{
get { return null; }
set { throw new NotSupportedException(); }
}

public string ToolTip
{ {
throw new NotSupportedException("Cannot add items to a separator"); get { return null; }
set { throw new NotSupportedException(); }
} }


public override void RemoveMenu(MenuItem item) public Keys Shortcut
{ {
throw new NotSupportedException("Separators do not contain any items to remove"); get { return Keys.None; }
set { throw new NotSupportedException(); }
} }


public override void Clear() public bool Enabled
{ {
throw new NotSupportedException("Separators do not contain any items to remove"); get { return false; }
set { }
} }
} }
} }
Expand Up @@ -4,7 +4,7 @@
namespace Eto.Platform.GtkSharp namespace Eto.Platform.GtkSharp
{ {


public class ToolBarButtonHandler : ToolBarItemHandler<Gtk.ToolButton, ToolBarButton>, IToolBarButton public class ButtonToolItemHandler : ToolItemHandler<Gtk.ToolButton, ButtonToolItem>, IButtonToolItem
{ {


#region IToolBarButton Members #region IToolBarButton Members
Expand Down
Expand Up @@ -4,7 +4,7 @@
namespace Eto.Platform.GtkSharp namespace Eto.Platform.GtkSharp
{ {


public class CheckToolBarButtonHandler : ToolBarItemHandler<Gtk.ToggleToolButton, CheckToolBarButton>, ICheckToolBarButton public class CheckToolItemHandler : ToolItemHandler<Gtk.ToggleToolButton, CheckToolItem>, ICheckToolItem
{ {
bool ischecked; bool ischecked;
bool isBeingChecked; bool isBeingChecked;
Expand Down
Expand Up @@ -2,9 +2,9 @@


namespace Eto.Platform.GtkSharp namespace Eto.Platform.GtkSharp
{ {
public class SeparatorToolBarItemHandler : ToolBarItemHandler<Gtk.SeparatorToolItem, SeparatorToolBarItem>, ISeparatorToolBarItem public class SeparatorToolItemHandler : ToolItemHandler<Gtk.SeparatorToolItem, SeparatorToolItem>, ISeparatorToolItem
{ {
SeparatorToolBarItemType type; SeparatorToolItemType type;
bool expand; bool expand;


public override void CreateControl (ToolBarHandler handler) public override void CreateControl (ToolBarHandler handler)
Expand All @@ -17,13 +17,13 @@ public override void CreateControl (ToolBarHandler handler)
} }




public SeparatorToolBarItemType Type { public SeparatorToolItemType Type {
get { get {
return type; return type;
} }
set { set {
type = value; type = value;
expand = type == SeparatorToolBarItemType.FlexibleSpace; expand = type == SeparatorToolItemType.FlexibleSpace;
if (Control != null) Control.Expand = expand; if (Control != null) Control.Expand = expand;
} }
} }
Expand Down

0 comments on commit 175159d

Please sign in to comment.