Skip to content

Commit

Permalink
Reliably detect the menubars created after the module is loaded.
Browse files Browse the repository at this point in the history
Before this patch we depends on the superriden map function.
  • Loading branch information
rainwoodman committed Nov 11, 2009
1 parent 69f0fc2 commit aa9aa59
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 8 additions & 0 deletions globalmenu-plugin/gtk-widget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 8 additions & 2 deletions globalmenu-plugin/tests/test-module.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
Expand All @@ -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();
Expand Down

0 comments on commit aa9aa59

Please sign in to comment.