mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
refactor: GetSublabelAt => GetSecondaryLabelAt
This commit is contained in:
@@ -95,3 +95,4 @@ upload_list_add_loadsync_method.patch
|
||||
breakpad_allow_getting_string_values_for_crash_keys.patch
|
||||
crash_allow_disabling_compression_on_linux.patch
|
||||
fix_hunspell_crash.patch
|
||||
allow_setting_secondary_label_via_simplemenumodel.patch
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: deepak1556 <hop2deep@gmail.com>
|
||||
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/base/models/simple_menu_model.cc b/ui/base/models/simple_menu_model.cc
|
||||
index 88053e9d501413d18b6a6ae36b76668431db7ee9..481a04c4835d246cfa20edfc4f1dd10ce93fcdb8 100644
|
||||
--- a/ui/base/models/simple_menu_model.cc
|
||||
+++ b/ui/base/models/simple_menu_model.cc
|
||||
@@ -49,6 +49,11 @@ base::string16 SimpleMenuModel::Delegate::GetLabelForCommandId(
|
||||
return base::string16();
|
||||
}
|
||||
|
||||
+base::string16 SimpleMenuModel::Delegate::GetSecondaryLabelForCommandId(
|
||||
+ int command_id) const {
|
||||
+ return base::string16();
|
||||
+}
|
||||
+
|
||||
ImageModel SimpleMenuModel::Delegate::GetIconForCommandId(
|
||||
int command_id) const {
|
||||
return ImageModel();
|
||||
@@ -291,6 +296,11 @@ void SimpleMenuModel::SetLabel(int index, const base::string16& label) {
|
||||
MenuItemsChanged();
|
||||
}
|
||||
|
||||
+void SimpleMenuModel::SetSecondaryLabel(int index, const base::string16& secondary_label) {
|
||||
+ items_[ValidateItemIndex(index)].secondary_label = secondary_label;
|
||||
+ MenuItemsChanged();
|
||||
+}
|
||||
+
|
||||
void SimpleMenuModel::SetMinorText(int index,
|
||||
const base::string16& minor_text) {
|
||||
items_[ValidateItemIndex(index)].minor_text = minor_text;
|
||||
@@ -364,6 +374,12 @@ base::string16 SimpleMenuModel::GetLabelAt(int index) const {
|
||||
return items_[ValidateItemIndex(index)].label;
|
||||
}
|
||||
|
||||
+base::string16 SimpleMenuModel::GetSecondaryLabelAt(int index) const {
|
||||
+ if (IsItemDynamicAt(index))
|
||||
+ return delegate_->GetSecondaryLabelForCommandId(GetCommandIdAt(index));
|
||||
+ return items_[ValidateItemIndex(index)].secondary_label;
|
||||
+}
|
||||
+
|
||||
base::string16 SimpleMenuModel::GetMinorTextAt(int index) const {
|
||||
return items_[ValidateItemIndex(index)].minor_text;
|
||||
}
|
||||
diff --git a/ui/base/models/simple_menu_model.h b/ui/base/models/simple_menu_model.h
|
||||
index 2b06f3f4a03227ac7898fc3563ab04518d24a313..df1e65a5f580290e9d395cf8958c156cb6d27875 100644
|
||||
--- a/ui/base/models/simple_menu_model.h
|
||||
+++ b/ui/base/models/simple_menu_model.h
|
||||
@@ -43,6 +43,7 @@ class UI_BASE_EXPORT SimpleMenuModel : public MenuModel {
|
||||
// Some command ids have labels and icons that change over time.
|
||||
virtual bool IsItemForCommandIdDynamic(int command_id) const;
|
||||
virtual base::string16 GetLabelForCommandId(int command_id) const;
|
||||
+ virtual base::string16 GetSecondaryLabelForCommandId(int command_id) const;
|
||||
// Gets the icon for the item with the specified id.
|
||||
virtual ImageModel GetIconForCommandId(int command_id) const;
|
||||
|
||||
@@ -146,6 +147,9 @@ class UI_BASE_EXPORT SimpleMenuModel : public MenuModel {
|
||||
// Sets the label for the item at |index|.
|
||||
void SetLabel(int index, const base::string16& label);
|
||||
|
||||
+ // Sets the secondary_label for the item at |index|.
|
||||
+ void SetSecondaryLabel(int index, const base::string16& secondary_label);
|
||||
+
|
||||
// Sets the minor text for the item at |index|.
|
||||
void SetMinorText(int index, const base::string16& minor_text);
|
||||
|
||||
@@ -172,6 +176,7 @@ class UI_BASE_EXPORT SimpleMenuModel : public MenuModel {
|
||||
ui::MenuSeparatorType GetSeparatorTypeAt(int index) const override;
|
||||
int GetCommandIdAt(int index) const override;
|
||||
base::string16 GetLabelAt(int index) const override;
|
||||
+ base::string16 GetSecondaryLabelAt(int index) const override;
|
||||
base::string16 GetMinorTextAt(int index) const override;
|
||||
ImageModel GetMinorIconAt(int index) const override;
|
||||
bool IsItemDynamicAt(int index) const override;
|
||||
@@ -206,6 +211,7 @@ class UI_BASE_EXPORT SimpleMenuModel : public MenuModel {
|
||||
int command_id = 0;
|
||||
ItemType type = TYPE_COMMAND;
|
||||
base::string16 label;
|
||||
+ base::string16 secondary_label;
|
||||
base::string16 minor_text;
|
||||
ImageModel minor_icon;
|
||||
ImageModel icon;
|
||||
@@ -147,7 +147,7 @@ void Menu::SetIcon(int index, const gfx::Image& image) {
|
||||
}
|
||||
|
||||
void Menu::SetSublabel(int index, const base::string16& sublabel) {
|
||||
model_->SetSublabel(index, sublabel);
|
||||
model_->SetSecondaryLabel(index, sublabel);
|
||||
}
|
||||
|
||||
void Menu::SetToolTip(int index, const base::string16& toolTip) {
|
||||
@@ -179,7 +179,7 @@ base::string16 Menu::GetLabelAt(int index) const {
|
||||
}
|
||||
|
||||
base::string16 Menu::GetSublabelAt(int index) const {
|
||||
return model_->GetSublabelAt(index);
|
||||
return model_->GetSecondaryLabelAt(index);
|
||||
}
|
||||
|
||||
base::string16 Menu::GetToolTipAt(int index) const {
|
||||
|
||||
@@ -41,12 +41,13 @@ base::string16 ElectronMenuModel::GetRoleAt(int index) {
|
||||
return iter == std::end(roles_) ? base::string16() : iter->second;
|
||||
}
|
||||
|
||||
void ElectronMenuModel::SetSublabel(int index, const base::string16& sublabel) {
|
||||
void ElectronMenuModel::SetSecondaryLabel(int index,
|
||||
const base::string16& sublabel) {
|
||||
int command_id = GetCommandIdAt(index);
|
||||
sublabels_[command_id] = sublabel;
|
||||
}
|
||||
|
||||
base::string16 ElectronMenuModel::GetSublabelAt(int index) const {
|
||||
base::string16 ElectronMenuModel::GetSecondaryLabelAt(int index) const {
|
||||
int command_id = GetCommandIdAt(index);
|
||||
const auto iter = sublabels_.find(command_id);
|
||||
return iter == std::end(sublabels_) ? base::string16() : iter->second;
|
||||
|
||||
@@ -57,8 +57,8 @@ class ElectronMenuModel : public ui::SimpleMenuModel {
|
||||
base::string16 GetToolTipAt(int index);
|
||||
void SetRole(int index, const base::string16& role);
|
||||
base::string16 GetRoleAt(int index);
|
||||
void SetSublabel(int index, const base::string16& sublabel);
|
||||
base::string16 GetSublabelAt(int index) const override;
|
||||
void SetSecondaryLabel(int index, const base::string16& sublabel);
|
||||
base::string16 GetSecondaryLabelAt(int index) const override;
|
||||
bool GetAcceleratorAtWithParams(int index,
|
||||
bool use_default_accelerator,
|
||||
ui::Accelerator* accelerator) const;
|
||||
|
||||
Reference in New Issue
Block a user