/// <summary> /// Adds a button to the end of the button list. /// Each button has an icon and a text, and changes /// CurrentPage when clicked. /// </summary> /// <param name="icon">Icon to show at the left of the button</param> /// <param name="text">Text to show at the right of the button</param> /// <param name = "tooltiptext">Text to add to the button as tooltip</param> public void AddButton(Pixbuf icon, string text, string tooltiptext) { // If there are other buttons, add the new button to their buttonGroup RadioButton otherbutton = null; string styleName = "toggletabbutton_only"; if (buttoncontainer.Children.Any ()) { otherbutton = buttoncontainer.Children.First () as RadioButton; styleName = "toggletabbutton_right"; } var button = new RadioButton (otherbutton); button.Name = styleName; button.DrawIndicator = false; var bin = new HBox (); var box = new HBox (); box.Spacing = 12; box.Add (new Gtk.Image (icon)); box.Add (new Label (text)); bin.PackStart (box, false, false, 10); button.Add (bin); // Restyle the widget that was the last (if any) int pos = buttoncontainer.Children.Length - 1; if (pos >= 0) { Widget previousLast = buttoncontainer.Children.Last (); previousLast.Name = pos == 0 ? "toggletabbutton_left" : "toggletabbutton_center"; previousLast.ResetRcStyles (); } if (tooltiptext != null) { button.TooltipText = tooltiptext; } buttoncontainer.Add (button); pos++; button.Toggled += (sender, e) => { if (button.Active) { SwitchPage (pos); } }; button.ShowAll (); }
public void AddPage (BaseContextPage page) { Hyena.Log.DebugFormat ("Adding context page {0}", page.Id); // TODO delay adding the page.Widget until the page is first activated, // that way we don't even create those objects unless used var frame = new Hyena.Widgets.RoundedFrame (); frame.Add (page.Widget); frame.Show (); // TODO implement DnD? /*if (page is ITrackContextPage) { Gtk.Drag.DestSet (frame, DestDefaults.Highlight | DestDefaults.Motion, new TargetEntry [] { Banshee.Gui.DragDrop.DragDropTarget.UriList }, Gdk.DragAction.Default); frame.DragDataReceived += delegate(object o, DragDataReceivedArgs args) { }; }*/ page.Widget.Show (); notebook.AppendPage (frame, null); pane_pages[page] = frame; // Setup the tab-like button that switches the notebook to this page var tab_image = new Image (IconThemeUtils.LoadIcon (22, page.IconNames)); var toggle_button = new RadioButton (radio_group) { Child = tab_image, DrawIndicator = false, Relief = ReliefStyle.None }; TooltipSetter.Set (tooltip_host, toggle_button, page.Name); toggle_button.Clicked += (s, e) => { if (pane_pages.ContainsKey (page)) { if (page.State == ContextState.Loaded) { notebook.CurrentPage = notebook.PageNum (pane_pages[page]); } SetActivePage (page); } }; toggle_button.ShowAll (); vbox.PackStart (toggle_button, false, false, 0); pane_tabs[page] = toggle_button; pages.Add (page); if (initialized && pages.Count == 1) { SetActivePage (page); toggle_button.Active = true; } UpdateVisibility (); }