Adapt Pannel Button

Panel Button implementing the MenuButton::get() API
to retrieve MenuItems.

Fixed broken Panel Menu's 'Lock' ability due to GTK move
This commit is contained in:
Michael Fisher 2012-08-30 19:08:23 -05:00 committed by Ichthyostega
parent a86f3bf497
commit c63e7f9b6e
3 changed files with 41 additions and 17 deletions

View file

@ -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<void> &callback)
sigc::slot<void> &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<void>& callback)
sigc::slot<void>& 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

View file

@ -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<void>& callback);
void append (uString &slug, uString &title,
sigc::slot<void>& 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<void>& callback);
void append (const char *slug, const char* title,
sigc::slot<void>& 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.
*/

View file

@ -90,14 +90,11 @@ PanelBar::setup_panel_button()
panelButton.append("Hide","_Hide", hide);
slot<void> 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<CheckMenuItem*>(&list.back());
lockItem = dynamic_cast<CheckMenuItem*>(panelButton.get("Lock"));
ENSURE(lockItem);
lockItem->set_active(panel.is_locked());
#endif
slot<void> hfunc =
bind(mem_fun(*this, &PanelBar::on_split_panel),