From c63e7f9b6e5264ec81a995a43184650f97113089 Mon Sep 17 00:00:00 2001 From: Michael Fisher Date: Thu, 30 Aug 2012 19:08:23 -0500 Subject: [PATCH] Adapt Pannel Button Panel Button implementing the MenuButton::get() API to retrieve MenuItems. Fixed broken Panel Menu's 'Lock' ability due to GTK move --- src/gui/widgets/menu-button.cpp | 27 ++++++++++++++++++++------- src/gui/widgets/menu-button.hpp | 24 +++++++++++++++++++----- src/gui/widgets/panel-bar.cpp | 7 ++----- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/gui/widgets/menu-button.cpp b/src/gui/widgets/menu-button.cpp index 1ae2c0955..e6468ce4f 100644 --- a/src/gui/widgets/menu-button.cpp +++ b/src/gui/widgets/menu-button.cpp @@ -69,6 +69,16 @@ MenuButton::MenuButton(cuString& label, bool mnemonic) : setup_button(); } +Gtk::Widget* +MenuButton::get(uString slug) +{ + //TODO: if (slug == "Menu") return &get_menu(); + uString path (POPUP_PATH); + path.append("/"); + return uimanager->get_widget(path.append(slug)); +} + + Menu& MenuButton::get_menu() { @@ -82,23 +92,27 @@ MenuButton::get_menu() void MenuButton::append (uString &slug, uString &title, - sigc::slot &callback) + sigc::slot &callback, bool toggle) { - actions->add(Action::create(slug, title), callback); + if (!toggle) + actions->add(Action::create(slug, title,""), callback); + else + actions->add(ToggleAction::create(slug, title,"",false), callback); + uimanager->add_ui(uimanager->new_merge_id(), ustring("ui/").append(POPUP_SLUG), - title,slug, Gtk::UI_MANAGER_MENUITEM, + slug, slug, Gtk::UI_MANAGER_AUTO, false); uimanager->ensure_update(); } void MenuButton::append (const char *slug, const char* title, - sigc::slot& callback) + sigc::slot& callback, bool toggle) { uString uSlug (slug); uString uTitle (_(title)); - append (uSlug, uTitle, callback); + append (uSlug, uTitle, callback, toggle); } void @@ -114,10 +128,9 @@ MenuButton::appendSeparator() void MenuButton::popup() { - get_menu().popup( mem_fun(this, &MenuButton::on_menu_position), + get_menu().popup(mem_fun(this, &MenuButton::on_menu_position), 0, gtk_get_current_event_time()); set_active(); - dump_xml(); } void diff --git a/src/gui/widgets/menu-button.hpp b/src/gui/widgets/menu-button.hpp index 7de2a9227..84edb0ae8 100644 --- a/src/gui/widgets/menu-button.hpp +++ b/src/gui/widgets/menu-button.hpp @@ -67,9 +67,6 @@ public: * Label in it */ MenuButton(cuString& label, bool mnemonic=false); - - /* Testing Code */ - void dump_xml() { /* std::cout << uimanager->get_ui() << std::endl; */ } /** * Gets the menu which will be displayed when the button is clicked @@ -84,22 +81,39 @@ public: * @param slug Unique identifier in the UI Manager * @param title The title of the item * @param callback The signal handler when clicked + * @param toggle */ - void append (uString &slug, uString &title, sigc::slot& callback); + void append (uString &slug, uString &title, + sigc::slot& callback, bool toggle=false); /** * Append a Menu Item to the Menu * @param slug Unique identifier in the UI Manager * @param title The title of the item * @param callback The signal handler when clicked + * @param toggle */ - void append (const char *slug, const char* title, sigc::slot& callback); + void append (const char *slug, const char* title, + sigc::slot& callback, bool toggle=false); + /** * Append a Gtk::SeparatorMenuItem to the Menu */ void appendSeparator(); + + /** + * Get an object from the Menu + * + * @param slug The slug that created the object + * @return Widget* Returns a valid Gtk::Widget or NULL if not found + * @remarks Typically you'll 'get' a MenuItem of sorts. Use + * MenuButton::get_menu() to get the menu as a whole + */ + Gtk::Widget* get(uString slug); + + /** * Pops up the menu. */ diff --git a/src/gui/widgets/panel-bar.cpp b/src/gui/widgets/panel-bar.cpp index 9482e94fa..b05ac6f56 100644 --- a/src/gui/widgets/panel-bar.cpp +++ b/src/gui/widgets/panel-bar.cpp @@ -90,14 +90,11 @@ PanelBar::setup_panel_button() panelButton.append("Hide","_Hide", hide); slot lock = mem_fun(*this, &PanelBar::on_lock); - panelButton.append("Lock", "_Lock", lock); + panelButton.append("Lock", "_Lock", lock, true); - FIXME("Update for gtk3"); -#if 0 - lockItem = dynamic_cast(&list.back()); + lockItem = dynamic_cast(panelButton.get("Lock")); ENSURE(lockItem); lockItem->set_active(panel.is_locked()); -#endif slot hfunc = bind(mem_fun(*this, &PanelBar::on_split_panel),