Esempio n. 1
0
        static void BuildDynamicSubMenu(IntPtr rootMenu, IntPtr parentMenu, ushort index, uint macCmdID, CommandInfoSet cinfoSet)
        {
            IntPtr menuRef = HIToolbox.CreateMenu(idSeq++, GetCleanCommandText(cinfoSet), MenuAttributes.CondenseSeparators);

            objectsToDestroyOnMenuClose.Add(new DestructableMenu(menuRef));
            HIToolbox.CheckResult(HIToolbox.SetMenuItemHierarchicalMenu(parentMenu, index, menuRef));

            ushort count = (ushort)cinfoSet.CommandInfos.Count;

            for (ushort i = 1, j = 0; i <= count; i++)
            {
                CommandInfo ci = cinfoSet.CommandInfos[j++];
                if (ci.IsArraySeparator)
                {
                    HIToolbox.AppendMenuSeparator(menuRef);
                }
                else
                {
                    HIToolbox.AppendMenuItem(menuRef, ci.Text, 0, macCmdID);
                    UpdateMenuItem(rootMenu, menuRef, ref i, ref count, macCmdID, ci);

                    objectsToDestroyOnMenuClose.Add(ci.DataItem);
                    uint refcon = (uint)objectsToDestroyOnMenuClose.Count;
                    HIToolbox.SetMenuItemReferenceConstant(new HIMenuItem(menuRef, i), refcon);
                }
            }
        }
Esempio n. 2
0
        static void CreateChildren(IntPtr parentMenu, CommandEntrySet entrySet, HashSet <object> ignoreCommands)
        {
            var menuId = HIToolbox.GetMenuID(parentMenu);

            foreach (CommandEntry entry in entrySet)
            {
                CommandEntrySet ces = entry as CommandEntrySet;

                if (ces == null)
                {
                    ushort pos;

                    if (ignoreCommands.Contains(entry.CommandId))
                    {
                        continue;
                    }

                    if (entry.CommandId == Command.Separator)
                    {
                        HIToolbox.AppendMenuSeparator(parentMenu);
                        continue;
                    }

                    if (entry is LinkCommandEntry)
                    {
                        LinkCommandEntry lce = (LinkCommandEntry)entry;
                        pos = HIToolbox.AppendMenuItem(parentMenu, (lce.Text ?? "").Replace("_", ""), 0, linkCommandId);
                        HIToolbox.SetMenuItemReferenceConstant(new HIMenuItem(parentMenu, pos), (uint)linkCommands.Count);
                        linkCommands.Add(lce.Url);
                        continue;
                    }

                    Command cmd = manager.GetCommand(entry.CommandId);
                    if (cmd == null)
                    {
                        MonoDevelop.Core.LoggingService.LogError(
                            "Mac main menu '{0}' child '{1}' maps to null command", entrySet.Name, entry.CommandId);
                        continue;
                    }

                    if (cmd is CustomCommand)
                    {
                        MonoDevelop.Core.LoggingService.LogWarning(
                            "Mac main menu does not support custom command widgets for command '{0}'", entry.CommandId);
                        continue;
                    }

                    menuIdMap[entry.CommandId] = menuId;

                    ActionCommand acmd = cmd as ActionCommand;
                    if (acmd == null)
                    {
                        MonoDevelop.Core.LoggingService.LogWarning(
                            "Mac main menu does not support command type '{0}' for command '{1}'", cmd.GetType(), entry.CommandId);
                        continue;
                    }

                    uint macCmdId = GetNewMenuItemId(cmd);

                    pos = HIToolbox.AppendMenuItem(parentMenu, (cmd.Text ?? "").Replace("_", ""), 0, macCmdId);
                }
                else
                {
                    var    macCmdId = (ces.AutoHide) ? autohideSubmenuCommandId : submenuCommandId;
                    IntPtr menuRef  = HIToolbox.CreateMenu(idSeq++, GetName(ces), MenuAttributes.CondenseSeparators);
                    mainMenus.Add(menuRef);
                    CreateChildren(menuRef, ces, ignoreCommands);
                    ushort pos = HIToolbox.AppendMenuItem(parentMenu, GetName(ces), 0, macCmdId);
                    HIToolbox.CheckResult(HIToolbox.SetMenuItemHierarchicalMenu(parentMenu, pos, menuRef));
                }
            }
        }