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 | |
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
-rw-r--r-- | app/menus/button_menu_item_model.cc | 6 | ||||
-rw-r--r-- | app/menus/button_menu_item_model.h | 3 | ||||
-rw-r--r-- | chrome/browser/gtk/menu_gtk.cc | 39 |
3 files changed, 28 insertions, 20 deletions
diff --git a/app/menus/button_menu_item_model.cc b/app/menus/button_menu_item_model.cc index 94949e4..3e09253 100644 --- a/app/menus/button_menu_item_model.cc +++ b/app/menus/button_menu_item_model.cc @@ -103,8 +103,12 @@ void ButtonMenuItemModel::ActivatedCommand(int command_id) { } bool ButtonMenuItemModel::IsEnabledAt(int index) const { + return IsCommandIdEnabled(items_[index].command_id); +} + +bool ButtonMenuItemModel::IsCommandIdEnabled(int command_id) const { if (delegate_) - return delegate_->IsCommandIdEnabled(items_[index].command_id); + return delegate_->IsCommandIdEnabled(command_id); return true; } diff --git a/app/menus/button_menu_item_model.h b/app/menus/button_menu_item_model.h index 38f8cf9..606e286 100644 --- a/app/menus/button_menu_item_model.h +++ b/app/menus/button_menu_item_model.h @@ -84,6 +84,9 @@ class ButtonMenuItemModel { // Returns the enabled state of the button at |index|. bool IsEnabledAt(int index) const; + // Returns the enabled state of the command specified by |command_id|. + bool IsCommandIdEnabled(int command_id) const; + const string16& label() const { return item_label_; } private: 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(); |