5
// Michael Hutchinson <m.j.hutchinson@gmail.com>
7
// Copyright (c) 2013 Xamarin Inc.
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30
using MonoDevelop.Components.Commands;
31
using MonoMac.Foundation;
32
using System.Diagnostics;
33
using MonoDevelop.Core;
35
namespace MonoDevelop.MacIntegration.MacMenu
39
static readonly string servicesID = (string) CommandManager.ToCommandId (MacIntegrationCommands.Services);
41
public MDMenu (CommandManager manager, CommandEntrySet ces)
43
this.WeakDelegate = this;
45
AutoEnablesItems = false;
47
Title = (ces.Name ?? "").Replace ("_", "");
49
foreach (CommandEntry ce in ces) {
50
if (ce.CommandId == Command.Separator) {
51
AddItem (NSMenuItem.SeparatorItem);
55
if (string.Equals (ce.CommandId as string, servicesID, StringComparison.Ordinal)) {
56
AddItem (new MDServicesMenuItem ());
60
var subset = ce as CommandEntrySet;
62
AddItem (new MDSubMenuItem (manager, subset));
66
var lce = ce as LinkCommandEntry;
68
AddItem (new MDLinkMenuItem (lce));
72
Command cmd = manager.GetCommand (ce.CommandId);
74
LoggingService.LogError ("MacMenu: '{0}' maps to null command", ce.CommandId);
78
if (cmd is CustomCommand) {
79
LoggingService.LogWarning ("MacMenu: '{0}' is unsupported custom-rendered command' '", ce.CommandId);
83
var acmd = cmd as ActionCommand;
85
LoggingService.LogWarning ("MacMenu: '{0}' has unknown command type '{1}'", cmd.GetType (), ce.CommandId);
89
AddItem (new MDMenuItem (manager, ce, acmd));
93
// http://lists.apple.com/archives/cocoa-dev/2008/Apr/msg01696.html
96
var f35 = ((char)0xF726).ToString ();
97
var blink = new NSMenuItem ("* blink *") {
100
var f35Event = NSEvent.KeyEvent (
101
NSEventType.KeyDown, System.Drawing.PointF.Empty, NSEventModifierMask.CommandKeyMask, 0, 0,
102
NSGraphicsContext.CurrentContext, f35, f35, false, 0);
104
PerformKeyEquivalent (f35Event);
108
public bool FlashIfContainsCommand (object command)
110
foreach (var item in ItemArray ().OfType<MDMenuItem> ()) {
111
if (item.CommandEntry.CommandId == command) {
115
var submenu = item.Submenu as MDMenu;
116
if (submenu != null && submenu.FlashIfContainsCommand (command))
122
public void UpdateCommands ()
124
NSMenuItem lastSeparator = NSMenuItem.SeparatorItem;
126
for (int i = 0; i < Count; i++) {
127
var item = this.ItemAt (i);
129
if (item.IsSeparatorItem) {
130
if (lastSeparator == null) {
131
lastSeparator = item;
137
var mdItem = item as IUpdatableMenuItem;
138
if (mdItem != null) {
139
mdItem.Update (this, ref lastSeparator, ref i);
143
//hide unknown builtins
148
[ExportAttribute ("menuNeedsUpdate:")]
149
void MenuNeedsUpdate (NSMenu menu)
151
Debug.Assert (menu == this);
155
public static void ShowLastSeparator (ref NSMenuItem lastSeparator)
157
if (lastSeparator != null) {
158
lastSeparator.Hidden = false;
159
lastSeparator = null;
164
interface IUpdatableMenuItem
166
void Update (MDMenu parent, ref NSMenuItem lastSeparator, ref int index);