Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #83 from zaubererty/menuitem

[Mac] Make menuitems working
  • Loading branch information...
commit c6481dd3145bdf307143901d6d368e01d9e7361d 2 parents ca39566 + 5343700
@slluis slluis authored
Showing with 24 additions and 0 deletions.
  1. +24 −0 Xwt.Mac/Xwt.Mac/MenuItemBackend.cs
View
24 Xwt.Mac/Xwt.Mac/MenuItemBackend.cs
@@ -26,13 +26,17 @@
using System;
using Xwt.Backends;
+using Xwt.Engine;
using MonoMac.AppKit;
+using System.Collections.Generic;
namespace Xwt.Mac
{
public class MenuItemBackend: IMenuItemBackend
{
NSMenuItem item;
+ IMenuItemEventSink eventSink;
+ List<MenuItemEvent> enabledEvents;
public MenuItemBackend (): this (new NSMenuItem ())
{
@@ -49,6 +53,7 @@ public MenuItemBackend (NSMenuItem item)
public void Initialize (IMenuItemEventSink eventSink)
{
+ this.eventSink = eventSink;
}
public void SetSubmenu (IMenuBackend menu)
@@ -111,12 +116,31 @@ public void Initialize (object frontend)
public void EnableEvent (object eventId)
{
+ if (eventId is MenuItemEvent) {
+ if (enabledEvents == null)
+ enabledEvents = new List<MenuItemEvent> ();
+ enabledEvents.Add ((MenuItemEvent)eventId);
+ if ((MenuItemEvent)eventId == MenuItemEvent.Clicked)
+ item.Activated += HandleItemActivated;
+ }
}
public void DisableEvent (object eventId)
{
+ if (eventId is MenuItemEvent) {
+ enabledEvents.Remove ((MenuItemEvent)eventId);
+ if ((MenuItemEvent)eventId == MenuItemEvent.Clicked)
+ item.Activated -= HandleItemActivated;
+ }
}
#endregion
+
+ void HandleItemActivated (object sender, EventArgs e)
+ {
+ Toolkit.Invoke (delegate {
+ eventSink.OnClicked ();
+ });
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.