diff options
-rw-r--r-- | app/menus/simple_menu_model.cc | 61 | ||||
-rw-r--r-- | app/menus/simple_menu_model.h | 17 | ||||
-rw-r--r-- | chrome/browser/app_menu_model.cc | 4 | ||||
-rw-r--r-- | chrome/browser/views/toolbar_view.cc | 12 | ||||
-rw-r--r-- | chrome/browser/views/toolbar_view.h | 3 |
5 files changed, 89 insertions, 8 deletions
diff --git a/app/menus/simple_menu_model.cc b/app/menus/simple_menu_model.cc index 66ef4c4..53fe4c1 100644 --- a/app/menus/simple_menu_model.cc +++ b/app/menus/simple_menu_model.cc @@ -60,6 +60,67 @@ void SimpleMenuModel::AddSubMenuWithStringId(int string_id, MenuModel* model) { AddSubMenu(l10n_util::GetStringUTF16(string_id), model); } +void SimpleMenuModel::InsertItemAt( + int index, int command_id, const string16& label) { + Item item = { command_id, label, TYPE_COMMAND, -1, NULL }; + items_.insert(items_.begin() + FlipIndex(index), item); +} + +void SimpleMenuModel::InsertItemWithStringIdAt( + int index, int command_id, int string_id) { + InsertItemAt(index, command_id, l10n_util::GetStringUTF16(string_id)); +} + +void SimpleMenuModel::InsertSeparatorAt(int index) { + Item item = { -1, string16(), TYPE_SEPARATOR, -1, NULL }; + items_.insert(items_.begin() + FlipIndex(index), item); +} + +void SimpleMenuModel::InsertCheckItemAt( + int index, int command_id, const string16& label) { + Item item = { command_id, label, TYPE_CHECK, -1, NULL }; + items_.insert(items_.begin() + FlipIndex(index), item); +} + +void SimpleMenuModel::InsertCheckItemWithStringIdAt( + int index, int command_id, int string_id) { + InsertCheckItemAt( + FlipIndex(index), command_id, l10n_util::GetStringUTF16(string_id)); +} + +void SimpleMenuModel::InsertRadioItemAt( + int index, int command_id, const string16& label, int group_id) { + Item item = { command_id, label, TYPE_RADIO, group_id, NULL }; + items_.insert(items_.begin() + FlipIndex(index), item); +} + +void SimpleMenuModel::InsertRadioItemWithStringIdAt( + int index, int command_id, int string_id, int group_id) { + InsertRadioItemAt( + index, command_id, l10n_util::GetStringUTF16(string_id), group_id); +} + +void SimpleMenuModel::InsertSubMenuAt( + int index, const string16& label, MenuModel* model) { + Item item = { -1, label, TYPE_SUBMENU, -1, model }; + items_.insert(items_.begin() + FlipIndex(index), item); +} + +void SimpleMenuModel::InsertSubMenuWithStringIdAt( + int index, int string_id, MenuModel* model) { + InsertSubMenuAt(index, l10n_util::GetStringUTF16(string_id), model); +} + +int SimpleMenuModel::GetIndexOfCommandId(int command_id) { + std::vector<Item>::iterator itr; + for (itr = items_.begin(); itr != items_.end(); itr++) { + if ((*itr).command_id == command_id) { + return FlipIndex(static_cast<int>(std::distance(items_.begin(), itr))); + } + } + return -1; +} + //////////////////////////////////////////////////////////////////////////////// // SimpleMenuModel, MenuModel implementation: diff --git a/app/menus/simple_menu_model.h b/app/menus/simple_menu_model.h index e093bb2..882e227 100644 --- a/app/menus/simple_menu_model.h +++ b/app/menus/simple_menu_model.h @@ -62,6 +62,23 @@ class SimpleMenuModel : public MenuModel { void AddSubMenu(const string16& label, MenuModel* model); void AddSubMenuWithStringId(int string_id, MenuModel* model); + // Methods for inserting items into the model. + void InsertItemAt(int index, int command_id, const string16& label); + void InsertItemWithStringIdAt(int index, int command_id, int string_id); + void InsertSeparatorAt(int index); + void InsertCheckItemAt(int index, int command_id, const string16& label); + void InsertCheckItemWithStringIdAt(int index, int command_id, int string_id); + void InsertRadioItemAt( + int index, int command_id, const string16& label, int group_id); + void InsertRadioItemWithStringIdAt( + int index, int command_id, int string_id, int group_id); + void InsertSubMenuAt(int index, const string16& label, MenuModel* model); + void InsertSubMenuWithStringIdAt(int index, int string_id, MenuModel* model); + + // Returns the index of the item that has the given |command_id|. Returns + // -1 if not found. + int GetIndexOfCommandId(int command_id); + // Overridden from MenuModel: virtual bool HasIcons() const; virtual int GetItemCount() const; diff --git a/chrome/browser/app_menu_model.cc b/chrome/browser/app_menu_model.cc index e6d242e..7ecaa57 100644 --- a/chrome/browser/app_menu_model.cc +++ b/chrome/browser/app_menu_model.cc @@ -15,10 +15,6 @@ #include "grit/chromium_strings.h" #include "grit/generated_resources.h" -// TODO(akalin): Now that AppMenuModel handles the sync item -// dynamically, we don't need to refresh the menu on Windows/Linux. -// Remove that code and make sure it works. - AppMenuModel::AppMenuModel(menus::SimpleMenuModel::Delegate* delegate, Browser* browser) : menus::SimpleMenuModel(delegate), diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc index 1ff6636..ead67d3 100644 --- a/chrome/browser/views/toolbar_view.cc +++ b/chrome/browser/views/toolbar_view.cc @@ -121,6 +121,9 @@ void ToolbarView::Init(Profile* profile) { show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); SetProfile(profile); + if (!app_menu_model_.get()) { + SetAppMenuModel(new AppMenuModel(this, browser_)); + } } void ToolbarView::SetProfile(Profile* profile) { @@ -139,6 +142,11 @@ void ToolbarView::Update(TabContents* tab, bool should_restore_state) { browser_actions_->RefreshBrowserActionViews(); } +void ToolbarView::SetAppMenuModel(AppMenuModel* model) { + app_menu_model_.reset(model); + app_menu_menu_.reset(new views::Menu2(app_menu_model_.get())); +} + //////////////////////////////////////////////////////////////////////////////// // ToolbarView, AccessibleToolbarView overrides: @@ -713,9 +721,5 @@ void ToolbarView::RunPageMenu(const gfx::Point& pt) { } void ToolbarView::RunAppMenu(const gfx::Point& pt) { - // We always rebuild the app menu so that we can get the current state of - // the sync system. - app_menu_model_.reset(new AppMenuModel(this, browser_)); - app_menu_menu_.reset(new views::Menu2(app_menu_model_.get())); app_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); } diff --git a/chrome/browser/views/toolbar_view.h b/chrome/browser/views/toolbar_view.h index f8ffd50..c9baae5 100644 --- a/chrome/browser/views/toolbar_view.h +++ b/chrome/browser/views/toolbar_view.h @@ -59,6 +59,9 @@ class ToolbarView : public AccessibleToolbarView, // (such as user editing) as well. void Update(TabContents* tab, bool should_restore_state); + // Sets the app menu model. + void SetAppMenuModel(AppMenuModel* model); + // Accessors... Browser* browser() const { return browser_; } BrowserActionsContainer* browser_actions() const { return browser_actions_; } |