| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu_controller_vie
ws.h" | 5 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu_controller_vie
ws.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_editor.h" | 9 #include "chrome/browser/bookmarks/bookmark_editor.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_folder_editor_controller.h" | |
| 11 #include "chrome/browser/bookmarks/bookmark_model.h" | 10 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 12 #include "chrome/browser/bookmarks/bookmark_utils.h" | 11 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 13 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 12 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 14 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_list.h" | 16 #include "chrome/browser/ui/browser_list.h" |
| 18 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 19 #include "content/browser/tab_contents/page_navigator.h" | 18 #include "content/browser/tab_contents/page_navigator.h" |
| 20 #include "content/browser/user_metrics.h" | 19 #include "content/browser/user_metrics.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 case IDC_BOOKMARK_BAR_RENAME_FOLDER: | 122 case IDC_BOOKMARK_BAR_RENAME_FOLDER: |
| 124 case IDC_BOOKMARK_BAR_EDIT: | 123 case IDC_BOOKMARK_BAR_EDIT: |
| 125 UserMetrics::RecordAction( | 124 UserMetrics::RecordAction( |
| 126 UserMetricsAction("BookmarkBar_ContextMenu_Edit")); | 125 UserMetricsAction("BookmarkBar_ContextMenu_Edit")); |
| 127 | 126 |
| 128 if (selection_.size() != 1) { | 127 if (selection_.size() != 1) { |
| 129 NOTREACHED(); | 128 NOTREACHED(); |
| 130 return; | 129 return; |
| 131 } | 130 } |
| 132 | 131 |
| 133 if (selection_[0]->is_url()) { | 132 BookmarkEditor::Show( |
| 134 BookmarkEditor::Show(parent_widget_->GetNativeWindow(), profile_, | 133 parent_widget_->GetNativeWindow(), |
| 135 BookmarkEditor::EditDetails::EditNode(selection_[0]), | 134 profile_, |
| 136 BookmarkEditor::SHOW_TREE); | 135 BookmarkEditor::EditDetails::EditNode(selection_[0]), |
| 137 } else { | 136 BookmarkEditor::SHOW_TREE); |
| 138 BookmarkFolderEditorController::Show(profile_, | |
| 139 parent_widget_->GetNativeWindow(), selection_[0], -1, | |
| 140 BookmarkFolderEditorController::EXISTING_BOOKMARK); | |
| 141 } | |
| 142 break; | 137 break; |
| 143 | 138 |
| 144 case IDC_BOOKMARK_BAR_REMOVE: { | 139 case IDC_BOOKMARK_BAR_REMOVE: { |
| 145 UserMetrics::RecordAction( | 140 UserMetrics::RecordAction( |
| 146 UserMetricsAction("BookmarkBar_ContextMenu_Remove")); | 141 UserMetricsAction("BookmarkBar_ContextMenu_Remove")); |
| 147 | 142 |
| 148 delegate_->WillRemoveBookmarks(selection_); | 143 delegate_->WillRemoveBookmarks(selection_); |
| 149 for (size_t i = 0; i < selection_.size(); ++i) { | 144 for (size_t i = 0; i < selection_.size(); ++i) { |
| 150 model->Remove(selection_[i]->parent(), | 145 model->Remove(selection_[i]->parent(), |
| 151 selection_[i]->parent()->GetIndexOf(selection_[i])); | 146 selection_[i]->parent()->GetIndexOf(selection_[i])); |
| 152 } | 147 } |
| 153 delegate_->DidRemoveBookmarks(); | 148 delegate_->DidRemoveBookmarks(); |
| 154 selection_.clear(); | 149 selection_.clear(); |
| 155 break; | 150 break; |
| 156 } | 151 } |
| 157 | 152 |
| 158 case IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK: { | 153 case IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK: { |
| 159 UserMetrics::RecordAction( | 154 UserMetrics::RecordAction( |
| 160 UserMetricsAction("BookmarkBar_ContextMenu_Add")); | 155 UserMetricsAction("BookmarkBar_ContextMenu_Add")); |
| 161 | 156 |
| 162 // TODO: this should honor the index from GetParentForNewNodes. | 157 int index; |
| 158 const BookmarkNode* parent = |
| 159 bookmark_utils::GetParentForNewNodes(parent_, selection_, &index); |
| 163 BookmarkEditor::Show( | 160 BookmarkEditor::Show( |
| 164 parent_widget_->GetNativeWindow(), profile_, | 161 parent_widget_->GetNativeWindow(), |
| 165 BookmarkEditor::EditDetails::AddNodeInFolder( | 162 profile_, |
| 166 bookmark_utils::GetParentForNewNodes(parent_, selection_, NULL)), | 163 BookmarkEditor::EditDetails::AddNodeInFolder(parent, index), |
| 167 BookmarkEditor::SHOW_TREE); | 164 BookmarkEditor::SHOW_TREE); |
| 168 break; | 165 break; |
| 169 } | 166 } |
| 170 | 167 |
| 171 case IDC_BOOKMARK_BAR_NEW_FOLDER: { | 168 case IDC_BOOKMARK_BAR_NEW_FOLDER: { |
| 172 UserMetrics::RecordAction( | 169 UserMetrics::RecordAction( |
| 173 UserMetricsAction("BookmarkBar_ContextMenu_NewFolder")); | 170 UserMetricsAction("BookmarkBar_ContextMenu_NewFolder")); |
| 171 |
| 174 int index; | 172 int index; |
| 175 const BookmarkNode* parent = | 173 const BookmarkNode* parent = |
| 176 bookmark_utils::GetParentForNewNodes(parent_, selection_, &index); | 174 bookmark_utils::GetParentForNewNodes(parent_, selection_, &index); |
| 177 BookmarkFolderEditorController::Show(profile_, | 175 BookmarkEditor::Show( |
| 178 parent_widget_->GetNativeWindow(), parent, index, | 176 parent_widget_->GetNativeWindow(), |
| 179 BookmarkFolderEditorController::NEW_BOOKMARK); | 177 profile_, |
| 178 BookmarkEditor::EditDetails::AddFolder(parent, index), |
| 179 BookmarkEditor::SHOW_TREE); |
| 180 break; | 180 break; |
| 181 } | 181 } |
| 182 | 182 |
| 183 case IDC_BOOKMARK_BAR_ALWAYS_SHOW: | 183 case IDC_BOOKMARK_BAR_ALWAYS_SHOW: |
| 184 bookmark_utils::ToggleWhenVisible(profile_); | 184 bookmark_utils::ToggleWhenVisible(profile_); |
| 185 break; | 185 break; |
| 186 | 186 |
| 187 case IDC_BOOKMARK_MANAGER: { | 187 case IDC_BOOKMARK_MANAGER: { |
| 188 UserMetrics::RecordAction(UserMetricsAction("ShowBookmarkManager")); | 188 UserMetrics::RecordAction(UserMetricsAction("ShowBookmarkManager")); |
| 189 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); | 189 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 return model; | 297 return model; |
| 298 } | 298 } |
| 299 | 299 |
| 300 bool BookmarkContextMenuControllerViews::HasURLs() const { | 300 bool BookmarkContextMenuControllerViews::HasURLs() const { |
| 301 for (size_t i = 0; i < selection_.size(); ++i) { | 301 for (size_t i = 0; i < selection_.size(); ++i) { |
| 302 if (bookmark_utils::NodeHasURLs(selection_[i])) | 302 if (bookmark_utils::NodeHasURLs(selection_[i])) |
| 303 return true; | 303 return true; |
| 304 } | 304 } |
| 305 return false; | 305 return false; |
| 306 } | 306 } |
| OLD | NEW |