/// <summary> /// Constructs a demo object with the appropriate gui. /// </summary> public DemoWindow() : base("Moonfire Games' Gtk Demo") { // Create a window SetDefaultSize(1000, 800); DeleteEvent += OnWindowDelete; demoComponents = new DemoComponents(); // Create a user action manager. var actionManager = new ActionManager(this); actionManager.Add(GetType().Assembly); demoConfiguratorsTab = new DemoConfiguratorsTab(this); actionManager.Add(demoConfiguratorsTab); demoActions = new DemoActions(actionManager); // Load the layout from the file system. layout = new ActionLayout(new FileInfo("ActionLayout1.xml")); actionManager.SetLayout(layout); // Load the keybinding from a file. keybindings = new ActionKeybindings(new FileInfo("ActionKeybindings1.xml")); actionManager.SetKeybindings(keybindings); // Create the window frame var box = new VBox(); Add(box); // Create the components we need before the menu. notebook = new Notebook(); actionManager.Add(new SwitchPageAction(notebook, 0, "Components")); actionManager.Add(new SwitchPageAction(notebook, 1, "Text Editor")); actionManager.Add(new SwitchPageAction(notebook, 2, "Actions")); actionManager.Add(new SwitchPageAction(notebook, 3, "Configurators")); // Create a notebook notebook.BorderWidth = 5; notebook.AppendPage(demoComponents, new Label("Components")); notebook.AppendPage(demoActions, new Label("Actions")); notebook.AppendPage(demoConfiguratorsTab, new Label("Configurators")); // Add the status bar statusbar = new Statusbar(); statusbar.Push(0, "Welcome!"); statusbar.HasResizeGrip = true; // Create the menu menubar = new MenuBar(); // Back everything into place. box.PackStart(CreateGuiMenu(), false, false, 0); box.PackStart(notebook, true, true, 0); box.PackStart(statusbar, false, false, 0); }
/// <summary> /// Initializes a new instance of the <see cref="ActionMenuItem"/> class. /// </summary> /// <param name="manager">The manager.</param> /// <param name="action">The action.</param> public ActionMenuItem( ActionManager manager, Action action) { // Saves the properties. if (manager == null) { throw new ArgumentNullException("manager"); } if (action == null) { throw new ArgumentNullException("action"); } // Attach to the action. this.action = action; action.ConnectProxy(this); // The default menu can't handle the chained accelerators, so we // remove the contents of the menu item and recreate it using a // HBox with a custom label for both. var newChild = new HBox(false, 0); displayLabel = new Label(action.Label); displayLabel.UseUnderline = true; displayLabel.Xalign = 0.0f; displayLabel.Show(); newChild.PackStart(displayLabel); // Get the keybinding label. HierarchicalPath acceleratorPath = manager.GetPrimaryAcceleratorPath(action); if (acceleratorPath != null) { // Get a formatted version of the accelerator path. string display = ActionKeybindings.FormatAcceleratorPath(acceleratorPath); keybindingLabel = new Label(display); keybindingLabel.UseUnderline = false; keybindingLabel.Xalign = 1.0f; keybindingLabel.Show(); newChild.PackStart(keybindingLabel); } // Lay out the contents in the HBox. newChild.Show(); // Remove the old child item and add this. Remove(Child); Add(newChild); // Figure out if we have an icon. if (!String.IsNullOrEmpty(action.StockId)) { IconSet iconSet = Style.LookupIconSet(action.StockId); Pixbuf image = iconSet.RenderIcon( Style, DefaultDirection, State, IconSize.Menu, this, null); var iconImage = new Image(image); Image = iconImage; } }