tomboy r1744 - in trunk: . Tomboy



Author: sharm
Date: Mon Jan  7 16:43:25 2008
New Revision: 1744
URL: http://svn.gnome.org/viewvc/tomboy?rev=1744&view=rev

Log:
* Tomboy/ActionManager.cs: Add ActionManager.GetPlaceholderChildren
  method, which retrieves the widgets for all child elements under
  the specified placeholder XML element in the UIManager XML.
* Tomboy/Tray.cs: Fix reordering of menu items placed in the
  TrayNewNotePlaceholder element in the UIManager XML.  Fixes bug
  #507798.  Does not account for menu items added under other
  placeholders, or menu items added in other fashions (so it doesn't
  work with the Tasks addin which adds items programatically).

Modified:
   trunk/ChangeLog
   trunk/Tomboy/ActionManager.cs
   trunk/Tomboy/Tray.cs

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	(original)
+++ trunk/ChangeLog	Mon Jan  7 16:43:25 2008
@@ -1,5 +1,16 @@
 2008-01-07  Sandy Armstrong <sanfordarmstrong gmail com> 
 
+	* Tomboy/ActionManager.cs: Add ActionManager.GetPlaceholderChildren method,
+	  which retrieves the widgets for all child elements under the specified
+	  placeholder XML element in the UIManager XML.
+	* Tomboy/Tray.cs: Fix reordering of menu items placed in the
+	  TrayNewNotePlaceholder element in the UIManager XML.  Fixes bug #507798.
+	   Does not account for menu items added under other placeholders, or menu
+	  items added in other fashions (so it doesn't work with the Tasks addin
+	  which adds items programatically).
+
+2008-01-07  Sandy Armstrong <sanfordarmstrong gmail com> 
+
 	* Tomboy/Tomboy.cs: If dbus is disabled, execute command line options
 	  *after* initializing the ActionManager and ApplicationAddins.  Opening
 	  the search UI before this is done causes Tomboy to hit null reference

Modified: trunk/Tomboy/ActionManager.cs
==============================================================================
--- trunk/Tomboy/ActionManager.cs	(original)
+++ trunk/Tomboy/ActionManager.cs	Mon Jan  7 16:43:25 2008
@@ -30,7 +30,11 @@
  */
 
 using System;
+using System.IO;
+using System.Text;
+using System.Xml;
 using System.Collections;
+using System.Collections.Generic;
 using Mono.Unix;
 
 namespace Tomboy
@@ -52,6 +56,47 @@
 			ui.AddUiFromResource ("UIManagerLayout.xml");
 			Gtk.Window.DefaultIconName = "tomboy";
 		}
+		
+		/// <summary>
+		/// Get all widgets represents by XML elements that are children
+		/// of the placeholder element specified by path.
+		/// </summary>
+		/// <param name="path">
+		/// A <see cref="System.String"/> representing the path to
+		/// the placeholder of interest.
+		/// </param>
+		/// <returns>
+		/// A <see cref="IList`1"/> of Gtk.Widget objects corresponding
+		/// to the XML child elements of the placeholder element.
+		/// </returns>
+		public IList<Gtk.Widget> GetPlaceholderChildren (string path)
+		{
+			List<Gtk.Widget> children = new List<Gtk.Widget> ();
+			// Wrap the UIManager XML in a root element
+			// so that it's real parseable XML.
+			string xml = "<root>" + ui.Ui + "</root>";
+			
+			using (StringReader reader = new StringReader (xml)) {
+				XmlDocument doc = new XmlDocument ();
+				doc.Load (reader);
+				
+				// Get the element name
+				string placeholderName = path.Substring (path.LastIndexOf ("/") + 1);
+				
+				// Find the placeholder specified in the path
+				foreach (XmlNode placeholderNode in doc.GetElementsByTagName ("placeholder")) {
+					if (placeholderNode.Attributes ["name"].InnerXml == placeholderName) {
+						// Return each child element's widget
+						foreach (XmlNode widgetNode in placeholderNode.ChildNodes) {
+							string widgetName = widgetNode.Attributes ["name"].InnerXml;
+							children.Add (GetWidget (path + "/" + widgetName));
+						}
+					}
+				}
+			}
+			
+			return children;
+		}
 
 		private void PopulateActionGroups ()
 		{

Modified: trunk/Tomboy/Tray.cs
==============================================================================
--- trunk/Tomboy/Tray.cs	(original)
+++ trunk/Tomboy/Tray.cs	Mon Jan  7 16:43:25 2008
@@ -302,7 +302,25 @@
 			Gtk.MenuItem searchNotesItem = Tomboy.ActionManager.GetWidget (
 			                                       "/TrayIconMenu/ShowSearchAllNotes") as Gtk.MenuItem;
 			recent_menu.ReorderChild (newNoteItem, 0);
-			recent_menu.ReorderChild (searchNotesItem, 1);
+			int insertion_point = 1; // If menu opens downward
+			
+			// Find all child widgets under the TrayNewNotePlaceholder
+			// element.  Make sure those added by add-ins are
+			// properly accounted for and reordered.
+			List<Gtk.Widget> newNotePlaceholderWidgets = new List<Gtk.Widget> ();
+			IList<Gtk.Widget> allChildWidgets =
+				Tomboy.ActionManager.GetPlaceholderChildren ("/TrayIconMenu/TrayNewNotePlaceholder");
+			foreach (Gtk.Widget child in allChildWidgets) {
+				if (child is Gtk.MenuItem &&
+				    child != newNoteItem) {
+					newNotePlaceholderWidgets.Add (child);
+					recent_menu.ReorderChild (child, insertion_point);
+					insertion_point++;
+				}
+			}
+			
+			recent_menu.ReorderChild (searchNotesItem, insertion_point);
+			insertion_point++;
 
 			DateTime days_ago = DateTime.Today.AddDays (-3);
 			
@@ -335,8 +353,8 @@
 
 				if (show) {
 					item = new NoteMenuItem (note, true);
-					// Add this widget to the menu (+2 to add after new+search)
-					recent_menu.Insert (item, list_size + 2);
+					// Add this widget to the menu (+insertion_point to add after new+search+...)
+					recent_menu.Insert (item, list_size + insertion_point);
 					// Keep track of this item so we can remove it later
 					recent_notes.Add (item);
 
@@ -348,9 +366,9 @@
 			if (start != null) {
 				item = new NoteMenuItem (start, false);
 				if (menuOpensUpward)
-					recent_menu.Insert (item, list_size + 2);
+					recent_menu.Insert (item, list_size + insertion_point);
 				else
-					recent_menu.Insert (item, 2);
+					recent_menu.Insert (item, insertion_point);
 				recent_notes.Add (item);
 
 				list_size++;
@@ -363,13 +381,15 @@
 					        Preferences.KEYBINDING_OPEN_START_HERE);
 			}
 
-			int insertion_point = 2; // If menu opens downard
 
 			// FIXME: Rearrange this stuff to have less wasteful reordering
 			if (menuOpensUpward) {
 				// Relocate common items to bottom of menu
-				recent_menu.ReorderChild (searchNotesItem, list_size + 1);
-				recent_menu.ReorderChild (newNoteItem, list_size + 1);
+				insertion_point -= 1;
+				recent_menu.ReorderChild (searchNotesItem, list_size + insertion_point);
+				foreach (Gtk.Widget widget in newNotePlaceholderWidgets)
+					recent_menu.ReorderChild (widget, list_size + insertion_point);
+				recent_menu.ReorderChild (newNoteItem, list_size + insertion_point);
 				insertion_point = list_size;
 			}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]