/// <summary> /// Add a tab form to the tab control. Optionally select the tab if SelectTab is true. /// </summary> public void AddTab(string TabText, string ImageResource, Widget Contents, bool SelectTab) { Label tabLabel = new Label(); // If the tab text passed in is a filename then only show the filename (no path) // on the tab. The ToolTipText will still have the full path and name. if (TabText.Contains(Path.DirectorySeparatorChar.ToString())) { tabLabel.Text = Path.GetFileNameWithoutExtension(TabText); } else { tabLabel.Text = TabText; } HBox headerBox = new HBox(); Button closeBtn = new Button(); Image closeImg = new Image(new Gdk.Pixbuf(null, "ApsimNG.Resources.Close.png", 12, 12)); closeBtn.Image = closeImg; closeBtn.Relief = ReliefStyle.None; closeBtn.Clicked += OnCloseBtnClick; headerBox.PackStart(tabLabel); headerBox.PackEnd(closeBtn); headerBox.ButtonPressEvent += on_eventbox1_button_press_event; //headerBox.ShowAll(); // Wrap the whole thing inside an event box, so we can respond to a right-button click EventBox eventbox = new EventBox(); eventbox.ButtonPressEvent += on_eventbox1_button_press_event; eventbox.Add(headerBox); eventbox.ShowAll(); notebook1.CurrentPage = notebook1.AppendPageMenu(Contents, eventbox, new Label(tabLabel.Text)); }
/// <summary>Add a tab form to the tab control. Optionally select the tab if SelectTab is true.</summary> /// <param name="text">Text for tab.</param> /// <param name="image">Image for tab.</param> /// <param name="control">Control for tab.</param> /// <param name="onLeftTabControl">If true a tab will be added to the left hand tab control.</param> public void AddTab(string text, Gtk.Image image, Widget control, bool onLeftTabControl) { Label tabLabel = new Label(); // If the tab text passed in is a filename then only show the filename (no path) // on the tab. The ToolTipText will still have the full path and name. if (text.Contains(Path.DirectorySeparatorChar.ToString())) { tabLabel.Text = Path.GetFileNameWithoutExtension(text); } else { tabLabel.Text = text; } HBox headerBox = new HBox(); Button closeBtn = new Button(); string imageName = Utility.Configuration.Settings.DarkTheme ? "Close.dark.svg" : "Close.light.svg"; Gtk.Image closeImg = new Gtk.Image(new Gdk.Pixbuf(null, $"ApsimNG.Resources.TreeViewImages.{imageName}", 12, 12)); closeBtn.Image = closeImg; closeBtn.Relief = ReliefStyle.None; closeBtn.Clicked += OnCloseBtnClick; headerBox.PackStart(tabLabel, true, true, 0); headerBox.PackEnd(closeBtn, true, true, 0); // Wrap the whole thing inside an event box, so we can respond to a right-button or center-button click EventBox eventbox = new EventBox(); eventbox.HasTooltip = text.Contains(Path.DirectorySeparatorChar.ToString()); eventbox.TooltipText = text; eventbox.ButtonPressEvent += OnEventbox1ButtonPress; eventbox.Add(headerBox); Notebook notebook = onLeftTabControl ? notebook1 : notebook2; // Attach an icon to the context menu Widget iconLabel = LabelWithIcon(tabLabel.Text, null); notebook.CurrentPage = notebook.AppendPageMenu(control, eventbox, iconLabel); // For reasons that I do not understand at all, with Release builds we must delay calling ShowAll until // after the page has been added. This is not the case with Debug builds. eventbox.ShowAll(); }