/// <summary>Populate the main menu tool strip.</summary> /// <param name="menuDescriptions">Descriptions for each item.</param> public void Populate(List <MenuDescriptionArgs> menuDescriptions) { accelerators = new AccelGroup(); foreach (Widget child in toolStrip.Children) { toolStrip.Remove(child); child.Dispose(); } foreach (MenuDescriptionArgs description in menuDescriptions) { Gtk.Image image = null; Gdk.Pixbuf pixbuf = null; ManifestResourceInfo info = Assembly.GetExecutingAssembly().GetManifestResourceInfo(description.ResourceNameForImage); if (info != null) { pixbuf = new Gdk.Pixbuf(null, description.ResourceNameForImage, 20, 20); image = new Gtk.Image(pixbuf); } ToolItem item = new ToolItem(); item.Expand = true; if (description.OnClick == null) { Label toolbarlabel = new Label(); if (description.RightAligned) { toolbarlabel.Xalign = 1.0F; } toolbarlabel.Xpad = 10; toolbarlabel.Text = description.Name; toolbarlabel.TooltipText = description.ToolTip; toolbarlabel.Visible = !String.IsNullOrEmpty(toolbarlabel.Text); item.Add(toolbarlabel); toolStrip.Add(item); toolStrip.ShowAll(); } else { ToolButton button = new ToolButton(image, description.Name); button.Homogeneous = false; button.LabelWidget = new Label(description.Name); button.Clicked += description.OnClick; if (!string.IsNullOrWhiteSpace(description.ShortcutKey)) { Gtk.Accelerator.Parse(description.ShortcutKey, out uint key, out Gdk.ModifierType modifier); button.AddAccelerator("clicked", accelerators, key, modifier, AccelFlags.Visible); } item = button; } toolStrip.Add(item); } Window mainWindow = GetMainWindow(); if (mainWindow != null) { mainWindow.AddAccelGroup(accelerators); } toolStrip.ShowAll(); }