Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: chrome/browser/bookmarks/bookmark_context_menu_controller.cc

Issue 1730015: Windows/Views: delete native bookmark manager code. (Closed)
Patch Set: Patch with fixed file perms. Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/bookmarks/bookmark_folder_editor_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/bookmarks/bookmark_context_menu_controller.h" 5 #include "chrome/browser/bookmarks/bookmark_context_menu_controller.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.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" 10 #include "chrome/browser/bookmarks/bookmark_folder_editor_controller.h"
11 #include "chrome/browser/bookmarks/bookmark_manager.h"
12 #include "chrome/browser/bookmarks/bookmark_model.h" 11 #include "chrome/browser/bookmarks/bookmark_model.h"
13 #include "chrome/browser/bookmarks/bookmark_utils.h" 12 #include "chrome/browser/bookmarks/bookmark_utils.h"
14 #include "chrome/browser/browser.h" 13 #include "chrome/browser/browser.h"
15 #include "chrome/browser/browser_list.h" 14 #include "chrome/browser/browser_list.h"
16 #include "chrome/browser/metrics/user_metrics.h" 15 #include "chrome/browser/metrics/user_metrics.h"
17 #include "chrome/browser/pref_service.h" 16 #include "chrome/browser/pref_service.h"
18 #include "chrome/browser/profile.h" 17 #include "chrome/browser/profile.h"
19 #include "chrome/browser/tab_contents/page_navigator.h" 18 #include "chrome/browser/tab_contents/page_navigator.h"
20 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
21 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
22 21
23 namespace { 22 namespace {
24 23
25 // Returns true if the specified node is of type URL, or has a descendant 24 // Returns true if the specified node is of type URL, or has a descendant
26 // of type URL. 25 // of type URL.
27 bool NodeHasURLs(const BookmarkNode* node) { 26 bool NodeHasURLs(const BookmarkNode* node) {
28 if (node->is_url()) 27 if (node->is_url())
29 return true; 28 return true;
30 29
31 for (int i = 0; i < node->GetChildCount(); ++i) { 30 for (int i = 0; i < node->GetChildCount(); ++i) {
32 if (NodeHasURLs(node->GetChild(i))) 31 if (NodeHasURLs(node->GetChild(i)))
33 return true; 32 return true;
34 } 33 }
35 return false; 34 return false;
36 } 35 }
37 36
38 // SelectOnCreationHandler ----------------------------------------------------
39
40 // Used when adding a new bookmark. If a new bookmark is created it is selected
41 // in the bookmark manager.
42 class SelectOnCreationHandler : public BookmarkEditor::Handler {
43 public:
44 explicit SelectOnCreationHandler(Profile* profile) : profile_(profile) {
45 }
46
47 virtual void NodeCreated(const BookmarkNode* new_node) {
48 // TODO(viettrungluu): I don't know if this is really needed, but it'll be
49 // deleted soon.
50 #if defined(OS_WIN)
51 BookmarkManager::SelectInTree(profile_, new_node);
52 #endif
53 }
54
55 private:
56 Profile* profile_;
57
58 DISALLOW_COPY_AND_ASSIGN(SelectOnCreationHandler);
59 };
60
61 } // namespace 37 } // namespace
62 38
63 BookmarkContextMenuController::BookmarkContextMenuController( 39 BookmarkContextMenuController::BookmarkContextMenuController(
64 gfx::NativeWindow parent_window, 40 gfx::NativeWindow parent_window,
65 BookmarkContextMenuControllerDelegate* delegate, 41 BookmarkContextMenuControllerDelegate* delegate,
66 Profile* profile, 42 Profile* profile,
67 PageNavigator* navigator, 43 PageNavigator* navigator,
68 const BookmarkNode* parent, 44 const BookmarkNode* parent,
69 const std::vector<const BookmarkNode*>& selection, 45 const std::vector<const BookmarkNode*>& selection,
70 ConfigurationType configuration) 46 ConfigurationType configuration)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 81 }
106 AddSeparator(); 82 AddSeparator();
107 } 83 }
108 84
109 if (selection_.size() == 1 && selection_[0]->is_folder()) { 85 if (selection_.size() == 1 && selection_[0]->is_folder()) {
110 AddItem(IDS_BOOKMARK_BAR_RENAME_FOLDER); 86 AddItem(IDS_BOOKMARK_BAR_RENAME_FOLDER);
111 } else { 87 } else {
112 AddItem(IDS_BOOKMARK_BAR_EDIT); 88 AddItem(IDS_BOOKMARK_BAR_EDIT);
113 } 89 }
114 90
115 // TODO(viettrungluu): I don't know if this is really needed, but it'll be
116 // deleted soon.
117 #if defined(OS_WIN)
118 if (configuration_ == BOOKMARK_MANAGER_TABLE_OTHER ||
119 configuration_ == BOOKMARK_MANAGER_ORGANIZE_MENU_OTHER) {
120 AddItem(IDS_BOOKMARK_MANAGER_SHOW_IN_FOLDER);
121 }
122 #endif
123
124 AddSeparator(); 91 AddSeparator();
125 AddItem(IDS_CUT); 92 AddItem(IDS_CUT);
126 AddItem(IDS_COPY); 93 AddItem(IDS_COPY);
127 AddItem(IDS_PASTE); 94 AddItem(IDS_PASTE);
128 95
129 AddSeparator(); 96 AddSeparator();
130 AddItem(IDS_BOOKMARK_BAR_REMOVE); 97 AddItem(IDS_BOOKMARK_BAR_REMOVE);
131 98
132 if (configuration_ == BOOKMARK_MANAGER_ORGANIZE_MENU) { 99 if (configuration_ == BOOKMARK_MANAGER_ORGANIZE_MENU) {
133 AddSeparator(); 100 AddSeparator();
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 } 196 }
230 selection_.clear(); 197 selection_.clear();
231 break; 198 break;
232 } 199 }
233 200
234 case IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK: { 201 case IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK: {
235 UserMetrics::RecordAction( 202 UserMetrics::RecordAction(
236 UserMetricsAction("BookmarkBar_ContextMenu_Add"), 203 UserMetricsAction("BookmarkBar_ContextMenu_Add"),
237 profile_); 204 profile_);
238 205
239 BookmarkEditor::Configuration editor_config; 206 BookmarkEditor::Configuration editor_config =
240 BookmarkEditor::Handler* handler = NULL; 207 (configuration_ == BOOKMARK_BAR) ? BookmarkEditor::SHOW_TREE :
241 if (configuration_ == BOOKMARK_BAR) { 208 BookmarkEditor::NO_TREE;
242 editor_config = BookmarkEditor::SHOW_TREE;
243 } else {
244 editor_config = BookmarkEditor::NO_TREE;
245 // This is owned by the BookmarkEditorView.
246 handler = new SelectOnCreationHandler(profile_);
247 }
248 // TODO: this should honor the index from GetParentForNewNodes. 209 // TODO: this should honor the index from GetParentForNewNodes.
249 BookmarkEditor::Show( 210 BookmarkEditor::Show(
250 parent_window_, profile_, 211 parent_window_, profile_,
251 bookmark_utils::GetParentForNewNodes(parent_, selection_, NULL), 212 bookmark_utils::GetParentForNewNodes(parent_, selection_, NULL),
252 BookmarkEditor::EditDetails(), editor_config, 213 BookmarkEditor::EditDetails(), editor_config, NULL);
253 handler);
254 break; 214 break;
255 } 215 }
256 216
257 case IDS_BOOMARK_BAR_NEW_FOLDER: { 217 case IDS_BOOMARK_BAR_NEW_FOLDER: {
258 UserMetrics::RecordAction( 218 UserMetrics::RecordAction(
259 UserMetricsAction("BookmarkBar_ContextMenu_NewFolder"), 219 UserMetricsAction("BookmarkBar_ContextMenu_NewFolder"),
260 profile_); 220 profile_);
261 int index; 221 int index;
262 const BookmarkNode* parent = 222 const BookmarkNode* parent =
263 bookmark_utils::GetParentForNewNodes(parent_, selection_, &index); 223 bookmark_utils::GetParentForNewNodes(parent_, selection_, &index);
264 uint32 details = BookmarkFolderEditorController::IS_NEW; 224 uint32 details = BookmarkFolderEditorController::IS_NEW;
265 if (configuration_ != BOOKMARK_BAR) 225 if (configuration_ != BOOKMARK_BAR)
266 details |= BookmarkFolderEditorController::SHOW_IN_MANAGER; 226 details |= BookmarkFolderEditorController::SHOW_IN_MANAGER;
267 BookmarkFolderEditorController::Show(profile_, parent_window_, parent, 227 BookmarkFolderEditorController::Show(profile_, parent_window_, parent,
268 index, details); 228 index, details);
269 break; 229 break;
270 } 230 }
271 231
272 case IDS_BOOMARK_BAR_ALWAYS_SHOW: 232 case IDS_BOOMARK_BAR_ALWAYS_SHOW:
273 bookmark_utils::ToggleWhenVisible(profile_); 233 bookmark_utils::ToggleWhenVisible(profile_);
274 break; 234 break;
275 235
276 // TODO(viettrungluu): I don't know if this is really needed, but it'll be
277 // deleted soon.
278 #if defined(OS_WIN)
279 case IDS_BOOKMARK_MANAGER_SHOW_IN_FOLDER:
280 UserMetrics::RecordAction(
281 UserMetricsAction("BookmarkBar_ContextMenu_ShowInFolder"),
282 profile_);
283
284 if (selection_.size() != 1) {
285 NOTREACHED();
286 break;
287 }
288
289 BookmarkManager::SelectInTree(profile_, selection_[0]);
290 break;
291 #endif
292
293 case IDS_BOOKMARK_MANAGER: 236 case IDS_BOOKMARK_MANAGER:
294 UserMetrics::RecordAction(UserMetricsAction("ShowBookmarkManager"), 237 UserMetrics::RecordAction(UserMetricsAction("ShowBookmarkManager"),
295 profile_); 238 profile_);
296 { 239 {
297 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); 240 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
298 if (browser) 241 if (browser)
299 browser->OpenBookmarkManager(); 242 browser->OpenBookmarkManager();
300 else 243 else
301 NOTREACHED(); 244 NOTREACHED();
302 } 245 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 case IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW: 298 case IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW:
356 return HasURLs(); 299 return HasURLs();
357 300
358 case IDS_BOOKMARK_BAR_RENAME_FOLDER: 301 case IDS_BOOKMARK_BAR_RENAME_FOLDER:
359 case IDS_BOOKMARK_BAR_EDIT: 302 case IDS_BOOKMARK_BAR_EDIT:
360 return selection_.size() == 1 && !is_root_node; 303 return selection_.size() == 1 && !is_root_node;
361 304
362 case IDS_BOOKMARK_BAR_REMOVE: 305 case IDS_BOOKMARK_BAR_REMOVE:
363 return !selection_.empty() && !is_root_node; 306 return !selection_.empty() && !is_root_node;
364 307
365 // TODO(viettrungluu): I don't know if this is really needed, but it'll be
366 // deleted soon.
367 #if defined(OS_WIN)
368 case IDS_BOOKMARK_MANAGER_SHOW_IN_FOLDER:
369 return (configuration_ == BOOKMARK_MANAGER_TABLE_OTHER ||
370 configuration_ == BOOKMARK_MANAGER_ORGANIZE_MENU_OTHER) &&
371 selection_.size() == 1;
372 #endif
373
374 case IDS_BOOKMARK_MANAGER_SORT: 308 case IDS_BOOKMARK_MANAGER_SORT:
375 return parent_ && parent_ != model_->root_node(); 309 return parent_ && parent_ != model_->root_node();
376 310
377 case IDS_BOOMARK_BAR_NEW_FOLDER: 311 case IDS_BOOMARK_BAR_NEW_FOLDER:
378 case IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK: 312 case IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK:
379 return bookmark_utils::GetParentForNewNodes( 313 return bookmark_utils::GetParentForNewNodes(
380 parent_, selection_, NULL) != NULL; 314 parent_, selection_, NULL) != NULL;
381 315
382 case IDS_COPY: 316 case IDS_COPY:
383 case IDS_CUT: 317 case IDS_CUT:
(...skipping 13 matching lines...) Expand all
397 delegate_->CloseMenu(); 331 delegate_->CloseMenu();
398 } 332 }
399 333
400 bool BookmarkContextMenuController::HasURLs() const { 334 bool BookmarkContextMenuController::HasURLs() const {
401 for (size_t i = 0; i < selection_.size(); ++i) { 335 for (size_t i = 0; i < selection_.size(); ++i) {
402 if (NodeHasURLs(selection_[i])) 336 if (NodeHasURLs(selection_[i]))
403 return true; 337 return true;
404 } 338 }
405 return false; 339 return false;
406 } 340 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/bookmarks/bookmark_folder_editor_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698