Index: ui/base/models/simple_menu_model.cc |
diff --git a/ui/base/models/simple_menu_model.cc b/ui/base/models/simple_menu_model.cc |
index 4d5213262739f62e0ab63e4a6252e685d00c0174..227d5029afbad25fe7f6bab00532a1c288d60891 100644 |
--- a/ui/base/models/simple_menu_model.cc |
+++ b/ui/base/models/simple_menu_model.cc |
@@ -16,6 +16,7 @@ const int kSeparatorId = -1; |
struct SimpleMenuModel::Item { |
int command_id; |
string16 label; |
+ string16 sublabel; |
gfx::Image icon; |
ItemType type; |
int group_id; |
@@ -40,6 +41,11 @@ string16 SimpleMenuModel::Delegate::GetLabelForCommandId(int command_id) const { |
return string16(); |
} |
+string16 SimpleMenuModel::Delegate::GetSublabelForCommandId( |
+ int command_id) const { |
+ return string16(); |
+} |
+ |
bool SimpleMenuModel::Delegate::GetIconForCommandId( |
int command_id, gfx::Image* image_skia) const { |
return false; |
@@ -72,8 +78,8 @@ SimpleMenuModel::~SimpleMenuModel() { |
} |
void SimpleMenuModel::AddItem(int command_id, const string16& label) { |
- Item item = { command_id, label, gfx::Image(), TYPE_COMMAND, -1, NULL, |
- NULL, NORMAL_SEPARATOR }; |
+ Item item = { command_id, label, string16(), gfx::Image(), |
+ TYPE_COMMAND, -1, NULL, NULL, NORMAL_SEPARATOR }; |
AppendItem(item); |
} |
@@ -82,8 +88,8 @@ void SimpleMenuModel::AddItemWithStringId(int command_id, int string_id) { |
} |
void SimpleMenuModel::AddCheckItem(int command_id, const string16& label) { |
- Item item = { command_id, label, gfx::Image(), TYPE_CHECK, -1, NULL, |
- NULL, NORMAL_SEPARATOR }; |
+ Item item = { command_id, label, string16(), gfx::Image(), |
+ TYPE_CHECK, -1, NULL, NULL, NORMAL_SEPARATOR }; |
AppendItem(item); |
} |
@@ -93,8 +99,8 @@ void SimpleMenuModel::AddCheckItemWithStringId(int command_id, int string_id) { |
void SimpleMenuModel::AddRadioItem(int command_id, const string16& label, |
int group_id) { |
- Item item = { command_id, label, gfx::Image(), TYPE_RADIO, group_id, NULL, |
- NULL, NORMAL_SEPARATOR }; |
+ Item item = { command_id, label, string16(), gfx::Image(), |
+ TYPE_RADIO, group_id, NULL, NULL, NORMAL_SEPARATOR }; |
AppendItem(item); |
} |
@@ -118,8 +124,8 @@ void SimpleMenuModel::AddSeparator(MenuSeparatorType separator_type) { |
if (separator_type != NORMAL_SEPARATOR) |
NOTIMPLEMENTED(); |
#endif |
- Item item = { kSeparatorId, string16(), gfx::Image(), TYPE_SEPARATOR, |
- -1, NULL, NULL , separator_type }; |
+ Item item = { kSeparatorId, string16(), string16(), gfx::Image(), |
+ TYPE_SEPARATOR, -1, NULL, NULL , separator_type }; |
AppendItem(item); |
} |
@@ -130,15 +136,15 @@ void SimpleMenuModel::RemoveTrailingSeparators() { |
void SimpleMenuModel::AddButtonItem(int command_id, |
ButtonMenuItemModel* model) { |
- Item item = { command_id, string16(), gfx::Image(), TYPE_BUTTON_ITEM, -1, |
- NULL, model, NORMAL_SEPARATOR }; |
+ Item item = { command_id, string16(), string16(), gfx::Image(), |
+ TYPE_BUTTON_ITEM, -1, NULL, model, NORMAL_SEPARATOR }; |
AppendItem(item); |
} |
void SimpleMenuModel::AddSubMenu(int command_id, const string16& label, |
MenuModel* model) { |
- Item item = { command_id, label, gfx::Image(), TYPE_SUBMENU, -1, model, |
- NULL, NORMAL_SEPARATOR }; |
+ Item item = { command_id, label, string16(), gfx::Image(), |
+ TYPE_SUBMENU, -1, model, NULL, NORMAL_SEPARATOR }; |
AppendItem(item); |
} |
@@ -149,8 +155,8 @@ void SimpleMenuModel::AddSubMenuWithStringId(int command_id, |
void SimpleMenuModel::InsertItemAt( |
int index, int command_id, const string16& label) { |
- Item item = { command_id, label, gfx::Image(), TYPE_COMMAND, -1, NULL, |
- NULL, NORMAL_SEPARATOR }; |
+ Item item = { command_id, label, string16(), gfx::Image(), |
+ TYPE_COMMAND, -1, NULL, NULL, NORMAL_SEPARATOR }; |
InsertItemAtIndex(item, index); |
} |
@@ -166,15 +172,15 @@ void SimpleMenuModel::InsertSeparatorAt(int index, |
NOTIMPLEMENTED(); |
} |
#endif |
- Item item = { kSeparatorId, string16(), gfx::Image(), TYPE_SEPARATOR, |
- -1, NULL, NULL, separator_type }; |
+ Item item = { kSeparatorId, string16(), string16(), gfx::Image(), |
+ TYPE_SEPARATOR, -1, NULL, NULL, separator_type }; |
InsertItemAtIndex(item, index); |
} |
void SimpleMenuModel::InsertCheckItemAt( |
int index, int command_id, const string16& label) { |
- Item item = { command_id, label, gfx::Image(), TYPE_CHECK, -1, NULL, |
- NULL, NORMAL_SEPARATOR }; |
+ Item item = { command_id, label, string16(), gfx::Image(), |
+ TYPE_CHECK, -1, NULL, NULL, NORMAL_SEPARATOR }; |
InsertItemAtIndex(item, index); |
} |
@@ -185,8 +191,8 @@ void SimpleMenuModel::InsertCheckItemWithStringIdAt( |
void SimpleMenuModel::InsertRadioItemAt( |
int index, int command_id, const string16& label, int group_id) { |
- Item item = { command_id, label, gfx::Image(), TYPE_RADIO, group_id, NULL, |
- NULL, NORMAL_SEPARATOR }; |
+ Item item = { command_id, label, string16(), gfx::Image(), |
+ TYPE_RADIO, group_id, NULL, NULL, NORMAL_SEPARATOR }; |
InsertItemAtIndex(item, index); |
} |
@@ -198,8 +204,8 @@ void SimpleMenuModel::InsertRadioItemWithStringIdAt( |
void SimpleMenuModel::InsertSubMenuAt( |
int index, int command_id, const string16& label, MenuModel* model) { |
- Item item = { command_id, label, gfx::Image(), TYPE_SUBMENU, -1, model, |
- NULL, NORMAL_SEPARATOR }; |
+ Item item = { command_id, label, string16(), gfx::Image(), |
+ TYPE_SUBMENU, -1, model, NULL, NORMAL_SEPARATOR }; |
InsertItemAtIndex(item, index); |
} |
@@ -213,6 +219,10 @@ void SimpleMenuModel::SetIcon(int index, const gfx::Image& icon) { |
items_[ValidateItemIndex(index)].icon = icon; |
} |
+void SimpleMenuModel::SetSublabel(int index, const string16& sublabel) { |
+ items_[ValidateItemIndex(index)].sublabel = sublabel; |
+} |
+ |
void SimpleMenuModel::Clear() { |
items_.clear(); |
} |
@@ -259,6 +269,12 @@ string16 SimpleMenuModel::GetLabelAt(int index) const { |
return items_[ValidateItemIndex(index)].label; |
} |
+string16 SimpleMenuModel::GetSublabelAt(int index) const { |
+ if (IsItemDynamicAt(index)) |
+ return delegate_->GetSublabelForCommandId(GetCommandIdAt(index)); |
+ return items_[ValidateItemIndex(index)].sublabel; |
+} |
+ |
bool SimpleMenuModel::IsItemDynamicAt(int index) const { |
if (delegate_) |
return delegate_->IsItemForCommandIdDynamic(GetCommandIdAt(index)); |