allow_setting_secondary_label_via_simplemenumodel.patch 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: deepak1556 <[email protected]>
  3. Date: Thu, 21 May 2020 13:58:01 -0700
  4. Subject: Allow setting secondary label via SimpleMenuModel
  5. Builds on https://chromium-review.googlesource.com/c/chromium/src/+/2208976
  6. diff --git a/ui/base/models/simple_menu_model.cc b/ui/base/models/simple_menu_model.cc
  7. index ffafdacb3e0171f81d22fa1736012b92e9df2ba9..dad79e82221c15b887cfde9a35ff7447989da62a 100644
  8. --- a/ui/base/models/simple_menu_model.cc
  9. +++ b/ui/base/models/simple_menu_model.cc
  10. @@ -53,6 +53,11 @@ std::u16string SimpleMenuModel::Delegate::GetLabelForCommandId(
  11. return std::u16string();
  12. }
  13. +std::u16string SimpleMenuModel::Delegate::GetSecondaryLabelForCommandId(
  14. + int command_id) const {
  15. + return std::u16string();
  16. +}
  17. +
  18. ImageModel SimpleMenuModel::Delegate::GetIconForCommandId(
  19. int command_id) const {
  20. return ImageModel();
  21. @@ -338,6 +343,11 @@ void SimpleMenuModel::SetLabel(size_t index, const std::u16string& label) {
  22. MenuItemsChanged();
  23. }
  24. +void SimpleMenuModel::SetSecondaryLabel(size_t index, const std::u16string& secondary_label) {
  25. + items_[ValidateItemIndex(index)].secondary_label = secondary_label;
  26. + MenuItemsChanged();
  27. +}
  28. +
  29. void SimpleMenuModel::SetMinorText(size_t index,
  30. const std::u16string& minor_text) {
  31. items_[ValidateItemIndex(index)].minor_text = minor_text;
  32. @@ -428,6 +438,12 @@ std::u16string SimpleMenuModel::GetLabelAt(size_t index) const {
  33. return items_[ValidateItemIndex(index)].label;
  34. }
  35. +std::u16string SimpleMenuModel::GetSecondaryLabelAt(size_t index) const {
  36. + if (IsItemDynamicAt(index))
  37. + return delegate_->GetSecondaryLabelForCommandId(GetCommandIdAt(index));
  38. + return items_[ValidateItemIndex(index)].secondary_label;
  39. +}
  40. +
  41. std::u16string SimpleMenuModel::GetMinorTextAt(size_t index) const {
  42. return items_[ValidateItemIndex(index)].minor_text;
  43. }
  44. diff --git a/ui/base/models/simple_menu_model.h b/ui/base/models/simple_menu_model.h
  45. index 1539464b1942db2a5e493022109a1c8dc247dc5a..b3979cbccf8eb2f0145e050e11ecbb6303c38d46 100644
  46. --- a/ui/base/models/simple_menu_model.h
  47. +++ b/ui/base/models/simple_menu_model.h
  48. @@ -55,6 +55,7 @@ class COMPONENT_EXPORT(UI_BASE) SimpleMenuModel : public MenuModel {
  49. // Some command ids have labels and icons that change over time.
  50. virtual bool IsItemForCommandIdDynamic(int command_id) const;
  51. virtual std::u16string GetLabelForCommandId(int command_id) const;
  52. + virtual std::u16string GetSecondaryLabelForCommandId(int command_id) const;
  53. // Gets the icon for the item with the specified id.
  54. virtual ImageModel GetIconForCommandId(int command_id) const;
  55. @@ -174,6 +175,9 @@ class COMPONENT_EXPORT(UI_BASE) SimpleMenuModel : public MenuModel {
  56. // Sets the label for the item at |index|.
  57. void SetLabel(size_t index, const std::u16string& label);
  58. + // Sets the secondary_label for the item at |index|.
  59. + void SetSecondaryLabel(size_t index, const std::u16string& secondary_label);
  60. +
  61. // Sets the minor text for the item at |index|.
  62. void SetMinorText(size_t index, const std::u16string& minor_text);
  63. @@ -216,6 +220,7 @@ class COMPONENT_EXPORT(UI_BASE) SimpleMenuModel : public MenuModel {
  64. ui::MenuSeparatorType GetSeparatorTypeAt(size_t index) const override;
  65. int GetCommandIdAt(size_t index) const override;
  66. std::u16string GetLabelAt(size_t index) const override;
  67. + std::u16string GetSecondaryLabelAt(size_t index) const override;
  68. std::u16string GetMinorTextAt(size_t index) const override;
  69. ImageModel GetMinorIconAt(size_t index) const override;
  70. bool IsItemDynamicAt(size_t index) const override;
  71. @@ -255,6 +260,7 @@ class COMPONENT_EXPORT(UI_BASE) SimpleMenuModel : public MenuModel {
  72. int command_id = 0;
  73. ItemType type = TYPE_COMMAND;
  74. std::u16string label;
  75. + std::u16string secondary_label;
  76. std::u16string minor_text;
  77. ImageModel minor_icon;
  78. ImageModel icon;