1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
- From: deepak1556 <[email protected]>
- Date: Thu, 21 May 2020 13:58:01 -0700
- Subject: Allow setting secondary label via SimpleMenuModel
- Builds on https://chromium-review.googlesource.com/c/chromium/src/+/2208976
- diff --git a/ui/menus/simple_menu_model.cc b/ui/menus/simple_menu_model.cc
- index 9f56505d9502c685f66ab082b60eaae4011e76b7..35ee633305f6dd5910e1c19dcc8c9df064757c57 100644
- --- a/ui/menus/simple_menu_model.cc
- +++ b/ui/menus/simple_menu_model.cc
- @@ -54,6 +54,11 @@ std::u16string SimpleMenuModel::Delegate::GetLabelForCommandId(
- return std::u16string();
- }
-
- +std::u16string SimpleMenuModel::Delegate::GetSecondaryLabelForCommandId(
- + int command_id) const {
- + return std::u16string();
- +}
- +
- ImageModel SimpleMenuModel::Delegate::GetIconForCommandId(
- int command_id) const {
- return ImageModel();
- @@ -347,6 +352,11 @@ void SimpleMenuModel::SetAcceleratorAt(size_t index,
- MenuItemsChanged();
- }
-
- +void SimpleMenuModel::SetSecondaryLabel(size_t index, const std::u16string& secondary_label) {
- + items_[ValidateItemIndex(index)].secondary_label = secondary_label;
- + MenuItemsChanged();
- +}
- +
- void SimpleMenuModel::SetMinorText(size_t index,
- const std::u16string& minor_text) {
- items_[ValidateItemIndex(index)].minor_text = minor_text;
- @@ -453,6 +463,12 @@ std::u16string SimpleMenuModel::GetLabelAt(size_t index) const {
- return items_[ValidateItemIndex(index)].label;
- }
-
- +std::u16string SimpleMenuModel::GetSecondaryLabelAt(size_t index) const {
- + if (IsItemDynamicAt(index))
- + return delegate_->GetSecondaryLabelForCommandId(GetCommandIdAt(index));
- + return items_[ValidateItemIndex(index)].secondary_label;
- +}
- +
- std::u16string SimpleMenuModel::GetMinorTextAt(size_t index) const {
- return items_[ValidateItemIndex(index)].minor_text;
- }
- diff --git a/ui/menus/simple_menu_model.h b/ui/menus/simple_menu_model.h
- index 596663d62632e4331f8aad421298d1fcdc9ab05e..469778f0c13e6d3fd30023af9b19c4a4cb7969be 100644
- --- a/ui/menus/simple_menu_model.h
- +++ b/ui/menus/simple_menu_model.h
- @@ -99,6 +99,7 @@ class COMPONENT_EXPORT(UI_MENUS) SimpleMenuModel : public MenuModel {
- // Some command ids have labels and icons that change over time.
- virtual bool IsItemForCommandIdDynamic(int command_id) const;
- virtual std::u16string GetLabelForCommandId(int command_id) const;
- + virtual std::u16string GetSecondaryLabelForCommandId(int command_id) const;
- // Gets the icon for the item with the specified id.
- virtual ImageModel GetIconForCommandId(int command_id) const;
-
- @@ -224,6 +225,9 @@ class COMPONENT_EXPORT(UI_MENUS) SimpleMenuModel : public MenuModel {
- // former is set).
- void SetAcceleratorAt(size_t index, const ui::Accelerator& accelerator);
-
- + // Sets the secondary_label for the item at |index|.
- + void SetSecondaryLabel(size_t index, const std::u16string& secondary_label);
- +
- // Sets the minor text for the item at |index|.
- void SetMinorText(size_t index, const std::u16string& minor_text);
-
- @@ -274,6 +278,7 @@ class COMPONENT_EXPORT(UI_MENUS) SimpleMenuModel : public MenuModel {
- ui::MenuSeparatorType GetSeparatorTypeAt(size_t index) const override;
- int GetCommandIdAt(size_t index) const override;
- std::u16string GetLabelAt(size_t index) const override;
- + std::u16string GetSecondaryLabelAt(size_t index) const override;
- std::u16string GetMinorTextAt(size_t index) const override;
- ImageModel GetMinorIconAt(size_t index) const override;
- bool IsItemDynamicAt(size_t index) const override;
- @@ -321,6 +326,7 @@ class COMPONENT_EXPORT(UI_MENUS) SimpleMenuModel : public MenuModel {
- ItemType type = TYPE_COMMAND;
- std::u16string label;
- ui::Accelerator accelerator;
- + std::u16string secondary_label;
- std::u16string minor_text;
- ImageModel minor_icon;
- ImageModel icon;
|