changeset 7:d92d11bd4808

* Refactor out "label with close button" creation to new method (useful for warfoundry:ticket:125) * Change close from deleting to removing page (fixes warfoundry:ticket:96) no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Fri, 28 Aug 2009 18:45:06 +0000
parents 49307b998555
children 14ce41d2f9bd
files NotebookUtil.cs
diffstat 1 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/NotebookUtil.cs	Wed Jul 22 20:58:19 2009 +0000
+++ b/NotebookUtil.cs	Fri Aug 28 18:45:06 2009 +0000
@@ -27,6 +27,26 @@
 		/// </returns>
 		public static int AddPageToNotebookWithCloseButton(Notebook notebook, Widget page, string title)
 		{
+			return notebook.AppendPage(page, CreateNotebookTabLabelWithClose(notebook, page, title)); 
+		}
+		
+		/// <summary>
+		/// Creates a widget to be used as the label for a notebook tab with text and a close button
+		/// </summary>
+		/// <param name="notebook">
+		/// The <see cref="Notebook"/> the page is on
+		/// </param>
+		/// <param name="page">
+		/// The <see cref="Widget"/> that is the content of the page
+		/// </param>
+		/// <param name="title">
+		/// The text to display on the tab
+		/// </param>
+		/// <returns>
+		/// A <see cref="Widget"/> that can be used as a tab label that contains the label with the title text and a close button
+		/// </returns>
+		public static Widget CreateNotebookTabLabelWithClose(Notebook notebook, Widget page,String title)
+		{
 			HBox hbox = new HBox();
 			hbox.PackStart(new Label(title));			
 			Button close = new Button();
@@ -40,12 +60,11 @@
 			close.BorderWidth = 0;
 			close.Name = "NotebookTab.CloseButton";			
 			close.Clicked += delegate {
-			    hbox.Destroy();
-			    page.Destroy();
+				notebook.Remove(page);
 			};
 			hbox.PackStart(close);			
-			hbox.ShowAll();			
-			return notebook.AppendPage(page, hbox); 
+			hbox.ShowAll();	
+			return hbox;
 		}
 	}
 }