[gnome-globalmenu] Reliably detect the menubars created after the module is loaded.



commit aa9aa5972b3396b9f261708d3e8d0eefb8626407
Author: Yu Feng <rainwoodman gmail com>
Date:   Wed Nov 11 17:16:59 2009 -0500

    Reliably detect the menubars created after the module is loaded.
    
    Before this patch we depends on the superriden map function.

 globalmenu-plugin/gtk-widget.vala        |    8 ++++++++
 globalmenu-plugin/tests/test-module.vala |   10 ++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/globalmenu-plugin/gtk-widget.vala b/globalmenu-plugin/gtk-widget.vala
index ea600fa..bcfb618 100644
--- a/globalmenu-plugin/gtk-widget.vala
+++ b/globalmenu-plugin/gtk-widget.vala
@@ -17,7 +17,15 @@ internal class Widget {
 		ParentSetFunc super = (ParentSetFunc) Superrider.peek_super(typeof(Gtk.Widget), OffsetParentSet);
 		if(super != null) super(widget, old_parent);
 
+		/* Detect menu bar */
+		if(widget is Gtk.MenuBar) {
+			var factory = MenuBarInfoFactory.get();
+			factory.create(widget as Gtk.MenuBar);
+			message("menubar detected %p", widget);
+		}
+
 		if(widget is Gtk.MenuBar || widget is Gtk.Menu) return;
+
 		var parent = widget.parent;
 		Gtk.MenuBar menubar = null;
 		if(parent != null) {
diff --git a/globalmenu-plugin/tests/test-module.vala b/globalmenu-plugin/tests/test-module.vala
index ecdc8ed..fcdf9ba 100644
--- a/globalmenu-plugin/tests/test-module.vala
+++ b/globalmenu-plugin/tests/test-module.vala
@@ -6,6 +6,7 @@ namespace GnomenuGtk {
 		Gtk.MenuBar menubar = new Gtk.MenuBar();
 		Gtk.MenuItem item = new MenuItem.with_label("test1");
 		Gtk.Menu submenu = new Gtk.Menu();
+		Gtk.Box box = new Gtk.VBox(false, 0);
 
 		TestUnload () {
 			base("/GnomenuGTK/Unload");
@@ -14,18 +15,19 @@ namespace GnomenuGtk {
 				menubar.append(item);
 				menubar.append(new MenuItem.with_label("test2"));
 				menubar.append(new MenuItem.with_label("test3"));
-				Gtk.Box box = new Gtk.VBox(false, 0);
+				Gtk.Button button0 = new Button.with_label("add menu");
 				Gtk.Button button1 = new Button.with_label("Load");
 				Gtk.Button button2 = new Button.with_label("UnLoad");
 				Gtk.Button button3 = new Button.with_label("add item");
 				Gtk.Button button4 = new Button.with_label("change label");
 				window.add(box);
-				box.add(menubar);
+				box.add(button0);
 				box.add(button1);
 				box.add(button2);
 				box.add(button3);
 				box.add(button4);
 				window.show_all();
+				button0.clicked += add_menu;
 				button1.clicked += load_module;
 				button2.clicked += unload_module;
 				button3.clicked += add_item;
@@ -34,6 +36,10 @@ namespace GnomenuGtk {
 			});
 
 		}
+		private void add_menu() {
+			menubar.show_all();
+			box.add(menubar);
+		}
 		private void add_item() {
 			submenu.append(new MenuItem.with_label("added item"));
 			submenu.show_all();



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