示例#1
0
        public void Initialize()
        {
            Show();

            // Configure window icon
            Icon = Misc.LoadIcon(App.Current.SoftwareIconName, IconSize.Dialog);

            // Populate the menu items from pluggable tools
            List <ITool> tools = new List <ITool> ();

            App.Current.EventsBroker.Publish <QueryToolsEvent> (
                new QueryToolsEvent {
                Tools = tools
            }
                );

            Menu     menu   = (this.UIManager.GetWidget("/menubar1/ToolsAction") as MenuItem).Submenu as Menu;
            MenuItem before = this.UIManager.GetWidget("/menubar1/ToolsAction/DatabasesManagerAction") as MenuItem;
            int      idx    = 1;

            // Find position of the database manager
            foreach (Widget child in menu.Children)
            {
                if (child == before)
                {
                    break;
                }
                idx++;
            }

            // Get the default action group
            ActionGroup ag = this.UIManager.ActionGroups [0];
            uint        mergeId;

            mergeId = this.UIManager.NewMergeId();

            // Insert our tools
            foreach (ITool tool in tools)
            {
                if (tool.MenubarLabel != null)
                {
                    // Use the class name as the action name to avoid collisions
                    string     actionName = tool.ToString().Substring(tool.ToString().LastIndexOf('.') + 1) + "Action";
                    Gtk.Action itemAction = new Gtk.Action(actionName, tool.MenubarLabel, null, null);
                    itemAction.Sensitive  = true;
                    itemAction.ShortLabel = tool.MenubarLabel;
                    itemAction.Activated += async(sender, e) => {
                        await App.Current.StateController.MoveTo(tool.UIFlow.First().Key, null);
                    };

                    this.UIManager.AddUi(mergeId, "/menubar1/ToolsAction", actionName, actionName, UIManagerItemType.Menuitem, false);
                    ag.Add(itemAction, tool.MenubarAccelerator);

                    // Ugly hack, given that we cannot add a menu item at a specific position
                    // we remove it and finally add it back again.
                    MenuItem item = (this.UIManager.GetWidget("/menubar1/ToolsAction/" + actionName) as MenuItem);
                    menu.Remove(item);
                    menu.Insert(item, idx++);
                }
            }
            this.UIManager.EnsureUpdate();
            renderingstatebarview1.SetViewModel(App.Current.JobsManager);

            ConnectSignals();

            FileMenuEntry = new MenuExtensionEntry("/menubar1/FileAction", 3);
            ToolMenuEntry = new MenuExtensionEntry("/menubar1/ToolsAction", 6);
        }
示例#2
0
 protected void RegisterMenuItem(MenuItem item, Menu menu, MenuExtensionEntry menuEntry)
 {
     MenuItems.Add(item);
     menu.Insert(item, menuEntry.LastPosition);
     menuEntry.UpdateLastPosition();
 }