diff options
author | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-29 19:06:56 +0000 |
---|---|---|
committer | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-29 19:06:56 +0000 |
commit | 211d0260056c82843c27945c25bfe3ed59abacc3 (patch) | |
tree | d99fb5d68871675b635fbbdb49039348bed15fc9 /chrome | |
parent | a529471238e60a75410d07ed652870b6e4b4478a (diff) | |
download | chromium_src-211d0260056c82843c27945c25bfe3ed59abacc3.zip chromium_src-211d0260056c82843c27945c25bfe3ed59abacc3.tar.gz chromium_src-211d0260056c82843c27945c25bfe3ed59abacc3.tar.bz2 |
The button menu items on GTK menus honor the enabled state of the command.
BUG=None
TEST=Verify that wrench menu zoom controls are disabled when showing PDF using the Chrome PDF plugin anf enabled otherwise.
Review URL: http://codereview.chromium.org/3032038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54162 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/gtk/menu_gtk.cc | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/chrome/browser/gtk/menu_gtk.cc b/chrome/browser/gtk/menu_gtk.cc index 5bdebea..f170a1b 100644 --- a/chrome/browser/gtk/menu_gtk.cc +++ b/chrome/browser/gtk/menu_gtk.cc @@ -80,24 +80,25 @@ void OnSubmenuShowButtonMenuItem(GtkWidget* widget, GtkButton* button) { int index = GPOINTER_TO_INT(g_object_get_data( G_OBJECT(button), "button-model-id")); - std::string label = - ConvertAcceleratorsFromWindowsStyle( - UTF16ToUTF8(model->GetLabelAt(index))); - gtk_button_set_label(GTK_BUTTON(button), label.c_str()); -} - -void SetupDynamicLabelMenuButton(GtkWidget* button, - GtkWidget* menu, - menus::ButtonMenuItemModel* model, - int index) { if (model->IsLabelDynamicAt(index)) { - g_object_set_data(G_OBJECT(button), "button-model", - model); - g_object_set_data(G_OBJECT(button), "button-model-id", - GINT_TO_POINTER(index)); - g_signal_connect(menu, "show", G_CALLBACK(OnSubmenuShowButtonMenuItem), - button); + std::string label = + ConvertAcceleratorsFromWindowsStyle( + UTF16ToUTF8(model->GetLabelAt(index))); + gtk_button_set_label(GTK_BUTTON(button), label.c_str()); } + gtk_widget_set_sensitive(GTK_WIDGET(button), model->IsEnabledAt(index)); +} + +void SetupButtonShowHandler(GtkWidget* button, + GtkWidget* menu, + menus::ButtonMenuItemModel* model, + int index) { + g_object_set_data(G_OBJECT(button), "button-model", + model); + g_object_set_data(G_OBJECT(button), "button-model-id", + GINT_TO_POINTER(index)); + g_signal_connect(menu, "show", G_CALLBACK(OnSubmenuShowButtonMenuItem), + button); } void OnSubmenuShowButtonImage(GtkWidget* widget, GtkButton* button) { @@ -401,7 +402,7 @@ GtkWidget* MenuGtk::BuildButtomMenuItem(menus::ButtonMenuItemModel* model, UTF16ToUTF8(model->GetLabelAt(i))).c_str()); } - SetupDynamicLabelMenuButton(button, menu, model, i); + SetupButtonShowHandler(button, menu, model, i); break; } case menus::ButtonMenuItemModel::TYPE_BUTTON_LABEL: { @@ -412,7 +413,7 @@ GtkWidget* MenuGtk::BuildButtomMenuItem(menus::ButtonMenuItemModel* model, GTK_BUTTON(button), RemoveWindowsStyleAccelerators( UTF16ToUTF8(model->GetLabelAt(i))).c_str()); - SetupDynamicLabelMenuButton(button, menu, model, i); + SetupButtonShowHandler(button, menu, model, i); break; } } @@ -465,7 +466,7 @@ void MenuGtk::OnMenuButtonPressed(GtkMenuItem* menu_item, int command_id, menus::ButtonMenuItemModel* model = reinterpret_cast<menus::ButtonMenuItemModel*>( g_object_get_data(G_OBJECT(menu_item), "button-model")); - if (model) { + if (model && model->IsCommandIdEnabled(command_id)) { if (menu->delegate_) menu->delegate_->CommandWillBeExecuted(); |