| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. |
| 4 |
| 5 #include "chrome/browser/page_menu_model.h" |
| 6 |
| 7 #include "app/l10n_util.h" |
| 8 #include "base/compiler_specific.h" |
| 9 #include "chrome/app/chrome_dll_resource.h" |
| 10 #include "chrome/browser/browser.h" |
| 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/encoding_menu_controller.h" |
| 13 #include "chrome/browser/tab_contents/tab_contents.h" |
| 14 #include "grit/generated_resources.h" |
| 15 |
| 16 PageMenuModel::PageMenuModel(menus::SimpleMenuModel::Delegate* delegate, |
| 17 Browser* browser) |
| 18 : menus::SimpleMenuModel(delegate), browser_(browser) { |
| 19 Build(); |
| 20 } |
| 21 |
| 22 void PageMenuModel::Build() { |
| 23 AddItemWithStringId(IDC_CREATE_SHORTCUTS, IDS_CREATE_SHORTCUTS); |
| 24 AddSeparator(); |
| 25 AddItemWithStringId(IDC_CUT, IDS_CUT); |
| 26 AddItemWithStringId(IDC_COPY, IDS_COPY); |
| 27 AddItemWithStringId(IDC_PASTE, IDS_PASTE); |
| 28 AddSeparator(); |
| 29 AddItemWithStringId(IDC_FIND, IDS_FIND); |
| 30 AddItemWithStringId(IDC_SAVE_PAGE, IDS_SAVE_PAGE); |
| 31 AddItemWithStringId(IDC_PRINT, IDS_PRINT); |
| 32 AddSeparator(); |
| 33 |
| 34 zoom_menu_model_.reset(new ZoomMenuModel(delegate())); |
| 35 AddSubMenuWithStringId(IDS_ZOOM_MENU, zoom_menu_model_.get()); |
| 36 |
| 37 encoding_menu_model_.reset(new EncodingMenuModel(browser_)); |
| 38 AddSubMenuWithStringId(IDS_ENCODING_MENU, encoding_menu_model_.get()); |
| 39 |
| 40 #if !defined(OS_CHROMEOS) |
| 41 AddSeparator(); |
| 42 devtools_menu_model_.reset(new DevToolsMenuModel(delegate())); |
| 43 AddSubMenuWithStringId(IDS_DEVELOPER_MENU, devtools_menu_model_.get()); |
| 44 |
| 45 AddSeparator(); |
| 46 AddItemWithStringId(IDC_REPORT_BUG, IDS_REPORT_BUG); |
| 47 #else |
| 48 NOTIMPLEMENTED(); |
| 49 #endif |
| 50 } |
| 51 |
| 52 //////////////////////////////////////////////////////////////////////////////// |
| 53 // EncodingMenuModel |
| 54 |
| 55 EncodingMenuModel::EncodingMenuModel(Browser* browser) |
| 56 : ALLOW_THIS_IN_INITIALIZER_LIST(menus::SimpleMenuModel(this)), |
| 57 browser_(browser) { |
| 58 Build(); |
| 59 } |
| 60 |
| 61 void EncodingMenuModel::Build() { |
| 62 EncodingMenuController::EncodingMenuItemList encoding_menu_items; |
| 63 EncodingMenuController encoding_menu_controller; |
| 64 encoding_menu_controller.GetEncodingMenuItems(browser_->profile(), |
| 65 &encoding_menu_items); |
| 66 |
| 67 int group_id = 0; |
| 68 EncodingMenuController::EncodingMenuItemList::iterator it = |
| 69 encoding_menu_items.begin(); |
| 70 for (; it != encoding_menu_items.end(); ++it) { |
| 71 int id = it->first; |
| 72 string16& label = it->second; |
| 73 if (id == 0) { |
| 74 AddSeparator(); |
| 75 } else { |
| 76 if (id == IDC_ENCODING_AUTO_DETECT) { |
| 77 AddCheckItem(id, label); |
| 78 } else { |
| 79 // Use the id of the first radio command as the id of the group. |
| 80 if (group_id <= 0) |
| 81 group_id = id; |
| 82 AddRadioItem(id, label, group_id); |
| 83 } |
| 84 } |
| 85 } |
| 86 } |
| 87 |
| 88 bool EncodingMenuModel::IsCommandIdChecked(int command_id) const { |
| 89 TabContents* current_tab = browser_->GetSelectedTabContents(); |
| 90 EncodingMenuController controller; |
| 91 return controller.IsItemChecked(browser_->profile(), |
| 92 current_tab->encoding(), command_id); |
| 93 } |
| 94 |
| 95 bool EncodingMenuModel::IsCommandIdEnabled(int command_id) const { |
| 96 return browser_->command_updater()->IsCommandEnabled(command_id); |
| 97 } |
| 98 |
| 99 bool EncodingMenuModel::GetAcceleratorForCommandId( |
| 100 int command_id, |
| 101 menus::Accelerator* accelerator) { |
| 102 return false; |
| 103 } |
| 104 |
| 105 void EncodingMenuModel::ExecuteCommand(int command_id) { |
| 106 browser_->ExecuteCommand(command_id); |
| 107 } |
| 108 |
| 109 //////////////////////////////////////////////////////////////////////////////// |
| 110 // ZoomMenuModel |
| 111 |
| 112 ZoomMenuModel::ZoomMenuModel(menus::SimpleMenuModel::Delegate* delegate) |
| 113 : SimpleMenuModel(delegate) { |
| 114 Build(); |
| 115 } |
| 116 |
| 117 void ZoomMenuModel::Build() { |
| 118 AddItemWithStringId(IDC_ZOOM_PLUS, IDS_ZOOM_PLUS); |
| 119 AddItemWithStringId(IDC_ZOOM_NORMAL, IDS_ZOOM_NORMAL); |
| 120 AddItemWithStringId(IDC_ZOOM_MINUS, IDS_ZOOM_MINUS); |
| 121 } |
| 122 |
| 123 //////////////////////////////////////////////////////////////////////////////// |
| 124 // DevToolsMenuModel |
| 125 |
| 126 DevToolsMenuModel::DevToolsMenuModel(menus::SimpleMenuModel::Delegate* delegate) |
| 127 : SimpleMenuModel(delegate) { |
| 128 Build(); |
| 129 } |
| 130 |
| 131 void DevToolsMenuModel::Build() { |
| 132 AddItemWithStringId(IDC_VIEW_SOURCE, IDS_VIEW_SOURCE); |
| 133 if (g_browser_process->have_inspector_files()) { |
| 134 AddItemWithStringId(IDC_DEV_TOOLS, IDS_DEV_TOOLS); |
| 135 AddItemWithStringId(IDC_DEV_TOOLS_CONSOLE, IDS_DEV_TOOLS_CONSOLE); |
| 136 } |
| 137 AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER); |
| 138 } |
| OLD | NEW |