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

Side by Side Diff: chrome/browser/views/bookmark_context_menu_controller_views.cc

Issue 1730015: Windows/Views: delete native bookmark manager code. (Closed)
Patch Set: Patch with fixed file perms. Created 10 years, 7 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
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/views/bookmark_context_menu_controller_views.h" 5 #include "chrome/browser/views/bookmark_context_menu_controller_views.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 #if defined(OS_WIN)
49 BookmarkManager::SelectInTree(profile_, new_node);
50 #endif
51 }
52
53 private:
54 Profile* profile_;
55
56 DISALLOW_COPY_AND_ASSIGN(SelectOnCreationHandler);
57 };
58
59 } // namespace 37 } // namespace
60 38
61 BookmarkContextMenuControllerViews::BookmarkContextMenuControllerViews( 39 BookmarkContextMenuControllerViews::BookmarkContextMenuControllerViews(
62 gfx::NativeWindow parent_window, 40 gfx::NativeWindow parent_window,
63 BookmarkContextMenuControllerViewsDelegate* delegate, 41 BookmarkContextMenuControllerViewsDelegate* delegate,
64 Profile* profile, 42 Profile* profile,
65 PageNavigator* navigator, 43 PageNavigator* navigator,
66 const BookmarkNode* parent, 44 const BookmarkNode* parent,
67 const std::vector<const BookmarkNode*>& selection, 45 const std::vector<const BookmarkNode*>& selection,
68 ConfigurationType configuration) 46 ConfigurationType configuration)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 78 }
101 delegate_->AddSeparator(); 79 delegate_->AddSeparator();
102 } 80 }
103 81
104 if (selection_.size() == 1 && selection_[0]->is_folder()) { 82 if (selection_.size() == 1 && selection_[0]->is_folder()) {
105 delegate_->AddItem(IDS_BOOKMARK_BAR_RENAME_FOLDER); 83 delegate_->AddItem(IDS_BOOKMARK_BAR_RENAME_FOLDER);
106 } else { 84 } else {
107 delegate_->AddItem(IDS_BOOKMARK_BAR_EDIT); 85 delegate_->AddItem(IDS_BOOKMARK_BAR_EDIT);
108 } 86 }
109 87
110 #if defined(OS_WIN)
111 if (configuration_ == BOOKMARK_MANAGER_TABLE ||
112 configuration_ == BOOKMARK_MANAGER_TABLE_OTHER ||
113 configuration_ == BOOKMARK_MANAGER_ORGANIZE_MENU ||
114 configuration_ == BOOKMARK_MANAGER_ORGANIZE_MENU_OTHER) {
115 delegate_->AddItem(IDS_BOOKMARK_MANAGER_SHOW_IN_FOLDER);
116 }
117 #endif
118
119 delegate_->AddSeparator(); 88 delegate_->AddSeparator();
120 delegate_->AddItem(IDS_CUT); 89 delegate_->AddItem(IDS_CUT);
121 delegate_->AddItem(IDS_COPY); 90 delegate_->AddItem(IDS_COPY);
122 delegate_->AddItem(IDS_PASTE); 91 delegate_->AddItem(IDS_PASTE);
123 92
124 delegate_->AddSeparator(); 93 delegate_->AddSeparator();
125 delegate_->AddItem(IDS_BOOKMARK_BAR_REMOVE); 94 delegate_->AddItem(IDS_BOOKMARK_BAR_REMOVE);
126 95
127 if (configuration_ == BOOKMARK_MANAGER_ORGANIZE_MENU) { 96 if (configuration_ == BOOKMARK_MANAGER_ORGANIZE_MENU) {
128 delegate_->AddSeparator(); 97 delegate_->AddSeparator();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 } 175 }
207 delegate_->DidRemoveBookmarks(); 176 delegate_->DidRemoveBookmarks();
208 selection_.clear(); 177 selection_.clear();
209 break; 178 break;
210 } 179 }
211 180
212 case IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK: { 181 case IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK: {
213 UserMetrics::RecordAction( 182 UserMetrics::RecordAction(
214 UserMetricsAction("BookmarkBar_ContextMenu_Add"), profile_); 183 UserMetricsAction("BookmarkBar_ContextMenu_Add"), profile_);
215 184
216 BookmarkEditor::Configuration editor_config; 185 BookmarkEditor::Configuration editor_config =
217 BookmarkEditor::Handler* handler = NULL; 186 (configuration_ == BOOKMARK_BAR) ? BookmarkEditor::SHOW_TREE :
218 if (configuration_ == BOOKMARK_BAR) { 187 BookmarkEditor::NO_TREE;
219 editor_config = BookmarkEditor::SHOW_TREE;
220 } else {
221 editor_config = BookmarkEditor::NO_TREE;
222 // This is owned by the BookmarkEditorView.
223 handler = new SelectOnCreationHandler(profile_);
224 }
225 // TODO: this should honor the index from GetParentForNewNodes. 188 // TODO: this should honor the index from GetParentForNewNodes.
226 BookmarkEditor::Show( 189 BookmarkEditor::Show(
227 parent_window_, profile_, 190 parent_window_, profile_,
228 bookmark_utils::GetParentForNewNodes(parent_, selection_, NULL), 191 bookmark_utils::GetParentForNewNodes(parent_, selection_, NULL),
229 BookmarkEditor::EditDetails(), editor_config, handler); 192 BookmarkEditor::EditDetails(), editor_config, NULL);
230 break; 193 break;
231 } 194 }
232 195
233 case IDS_BOOMARK_BAR_NEW_FOLDER: { 196 case IDS_BOOMARK_BAR_NEW_FOLDER: {
234 UserMetrics::RecordAction( 197 UserMetrics::RecordAction(
235 UserMetricsAction("BookmarkBar_ContextMenu_NewFolder"), 198 UserMetricsAction("BookmarkBar_ContextMenu_NewFolder"),
236 profile_); 199 profile_);
237 int index; 200 int index;
238 const BookmarkNode* parent = 201 const BookmarkNode* parent =
239 bookmark_utils::GetParentForNewNodes(parent_, selection_, &index); 202 bookmark_utils::GetParentForNewNodes(parent_, selection_, &index);
240 uint32 details = BookmarkFolderEditorController::IS_NEW; 203 uint32 details = BookmarkFolderEditorController::IS_NEW;
241 if (configuration_ != BOOKMARK_BAR) 204 if (configuration_ != BOOKMARK_BAR)
242 details |= BookmarkFolderEditorController::SHOW_IN_MANAGER; 205 details |= BookmarkFolderEditorController::SHOW_IN_MANAGER;
243 BookmarkFolderEditorController::Show(profile_, parent_window_, parent, 206 BookmarkFolderEditorController::Show(profile_, parent_window_, parent,
244 index, details); 207 index, details);
245 break; 208 break;
246 } 209 }
247 210
248 case IDS_BOOMARK_BAR_ALWAYS_SHOW: 211 case IDS_BOOMARK_BAR_ALWAYS_SHOW:
249 bookmark_utils::ToggleWhenVisible(profile_); 212 bookmark_utils::ToggleWhenVisible(profile_);
250 break; 213 break;
251 214
252 #if defined(OS_WIN)
253 case IDS_BOOKMARK_MANAGER_SHOW_IN_FOLDER:
254 UserMetrics::RecordAction(
255 UserMetricsAction("BookmarkBar_ContextMenu_ShowInFolder"),
256 profile_);
257
258 if (selection_.size() != 1) {
259 NOTREACHED();
260 return;
261 }
262
263 BookmarkManager::SelectInTree(profile_, selection_[0]);
264 break;
265 #endif
266
267 case IDS_BOOKMARK_MANAGER: 215 case IDS_BOOKMARK_MANAGER:
268 UserMetrics::RecordAction(UserMetricsAction("ShowBookmarkManager"), 216 UserMetrics::RecordAction(UserMetricsAction("ShowBookmarkManager"),
269 profile_); 217 profile_);
270 { 218 {
271 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); 219 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
272 if (browser) 220 if (browser)
273 browser->OpenBookmarkManager(); 221 browser->OpenBookmarkManager();
274 else 222 else
275 NOTREACHED(); 223 NOTREACHED();
276 } 224 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 case IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW: 276 case IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW:
329 return HasURLs(); 277 return HasURLs();
330 278
331 case IDS_BOOKMARK_BAR_RENAME_FOLDER: 279 case IDS_BOOKMARK_BAR_RENAME_FOLDER:
332 case IDS_BOOKMARK_BAR_EDIT: 280 case IDS_BOOKMARK_BAR_EDIT:
333 return selection_.size() == 1 && !is_root_node; 281 return selection_.size() == 1 && !is_root_node;
334 282
335 case IDS_BOOKMARK_BAR_REMOVE: 283 case IDS_BOOKMARK_BAR_REMOVE:
336 return !selection_.empty() && !is_root_node; 284 return !selection_.empty() && !is_root_node;
337 285
338 #if defined(OS_WIN)
339 case IDS_BOOKMARK_MANAGER_SHOW_IN_FOLDER:
340 return (configuration_ == BOOKMARK_MANAGER_TABLE_OTHER ||
341 configuration_ == BOOKMARK_MANAGER_ORGANIZE_MENU_OTHER) &&
342 selection_.size() == 1;
343 #endif
344
345 case IDS_BOOKMARK_MANAGER_SORT: 286 case IDS_BOOKMARK_MANAGER_SORT:
346 return parent_ && parent_ != model_->root_node(); 287 return parent_ && parent_ != model_->root_node();
347 288
348 case IDS_BOOMARK_BAR_NEW_FOLDER: 289 case IDS_BOOMARK_BAR_NEW_FOLDER:
349 case IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK: 290 case IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK:
350 return bookmark_utils::GetParentForNewNodes( 291 return bookmark_utils::GetParentForNewNodes(
351 parent_, selection_, NULL) != NULL; 292 parent_, selection_, NULL) != NULL;
352 293
353 case IDS_COPY: 294 case IDS_COPY:
354 case IDS_CUT: 295 case IDS_CUT:
(...skipping 19 matching lines...) Expand all
374 return model; 315 return model;
375 } 316 }
376 317
377 bool BookmarkContextMenuControllerViews::HasURLs() const { 318 bool BookmarkContextMenuControllerViews::HasURLs() const {
378 for (size_t i = 0; i < selection_.size(); ++i) { 319 for (size_t i = 0; i < selection_.size(); ++i) {
379 if (NodeHasURLs(selection_[i])) 320 if (NodeHasURLs(selection_[i]))
380 return true; 321 return true;
381 } 322 }
382 return false; 323 return false;
383 } 324 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/browser_window_gtk.cc ('k') | chrome/browser/views/bookmark_folder_tree_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698