Chromium Code Reviews| Index: chrome/browser/media_galleries/media_galleries_dialog_controller.cc |
| diff --git a/chrome/browser/media_galleries/media_galleries_dialog_controller.cc b/chrome/browser/media_galleries/media_galleries_dialog_controller.cc |
| index e4202eb976fd7a6f45bfd004678d2f049835b53a..8bfa54ab13703b330fdbd560f3265883d25b1222 100644 |
| --- a/chrome/browser/media_galleries/media_galleries_dialog_controller.cc |
| +++ b/chrome/browser/media_galleries/media_galleries_dialog_controller.cc |
| @@ -22,6 +22,7 @@ |
| #include "content/public/browser/web_contents_view.h" |
| #include "grit/generated_resources.h" |
| #include "ui/base/l10n/l10n_util.h" |
| +#include "ui/base/models/simple_menu_model.h" |
| #include "ui/base/text/bytes_formatting.h" |
| using extensions::APIPermission; |
| @@ -44,6 +45,40 @@ bool GalleriesVectorComparator( |
| } // namespace |
| +class GalleryContextMenuModel : public ui::SimpleMenuModel::Delegate { |
| + public: |
| + explicit GalleryContextMenuModel(MediaGalleriesDialogController* controller) |
| + : controller_(controller), id_(kInvalidMediaGalleryPrefId) {} |
| + virtual ~GalleryContextMenuModel() {} |
| + |
| + void set_media_gallery_pref_id(MediaGalleryPrefId id) { |
| + id_ = id; |
| + } |
| + |
| + virtual bool IsCommandIdChecked(int command_id) const OVERRIDE { |
| + return false; |
| + } |
| + virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE { |
| + return true; |
| + } |
| + virtual bool IsCommandIdVisible(int command_id) const OVERRIDE { |
| + return true; |
| + } |
| + |
| + virtual bool GetAcceleratorForCommandId( |
| + int command_id, ui::Accelerator* accelerator) OVERRIDE { |
| + return false; |
| + } |
| + |
| + virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE { |
| + controller_->DidForgetGallery(id_); |
| + } |
| + |
| + private: |
| + MediaGalleriesDialogController* controller_; |
| + MediaGalleryPrefId id_; |
| +}; |
| + |
| MediaGalleriesDialogController::MediaGalleriesDialogController( |
| content::WebContents* web_contents, |
| const Extension& extension, |
| @@ -60,6 +95,12 @@ MediaGalleriesDialogController::MediaGalleriesDialogController( |
| preferences_->EnsureInitialized( |
| base::Bind(&MediaGalleriesDialogController::OnPreferencesInitialized, |
| base::Unretained(this))); |
| + |
| + gallery_menu_model_.reset(new GalleryContextMenuModel(this)); |
| + ui::SimpleMenuModel* menu_model = |
| + new ui::SimpleMenuModel(gallery_menu_model_.get()); |
| + menu_model->AddItem(1, GetDeleteMenuCommand()); |
|
vandebo (ex-Chrome)
2013/10/29 14:55:17
Now that this is in the controller, you don't need
Greg Billock
2013/10/29 17:04:06
Done.
|
| + context_menu_model_.reset(menu_model); |
| } |
| void MediaGalleriesDialogController::OnPreferencesInitialized() { |
| @@ -116,6 +157,10 @@ string16 MediaGalleriesDialogController::GetUnattachedLocationsHeader() const { |
| return l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_UNATTACHED_LOCATIONS); |
| } |
| +string16 MediaGalleriesDialogController::GetDeleteMenuCommand() const { |
| + return l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_DELETE); |
| +} |
| + |
| // TODO(gbillock): Call this something a bit more connected to the |
| // messaging in the dialog. |
| bool MediaGalleriesDialogController::HasPermittedGalleries() const { |
| @@ -218,6 +263,12 @@ void MediaGalleriesDialogController::DidToggleNewGallery( |
| } |
| } |
| +void MediaGalleriesDialogController::DidForgetGallery( |
| + MediaGalleryPrefId pref_id) { |
| + DCHECK(preferences_); |
| + preferences_->ForgetGalleryById(pref_id); |
| +} |
| + |
| void MediaGalleriesDialogController::DialogFinished(bool accepted) { |
| // The dialog has finished, so there is no need to watch for more updates |
| // from |preferences_|. Do this here and not in the dtor since this is the |
| @@ -412,6 +463,12 @@ void MediaGalleriesDialogController::UpdateGalleriesOnDeviceEvent( |
| dialog_->UpdateGalleries(); |
| } |
| +ui::MenuModel* MediaGalleriesDialogController::GetContextMenuModel( |
| + MediaGalleryPrefId id) { |
| + gallery_menu_model_->set_media_gallery_pref_id(id); |
| + return context_menu_model_.get(); |
| +} |
| + |
| // MediaGalleries dialog ------------------------------------------------------- |
| MediaGalleriesDialog::~MediaGalleriesDialog() {} |