| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bookmarks/bookmark_context_menu_controller.h" | 5 #include "chrome/browser/ui/bookmarks/bookmark_context_menu_controller.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 break; | 239 break; |
| 240 } | 240 } |
| 241 | 241 |
| 242 case IDC_BOOKMARK_BAR_ALWAYS_SHOW: | 242 case IDC_BOOKMARK_BAR_ALWAYS_SHOW: |
| 243 chrome::ToggleBookmarkBarWhenVisible(profile_); | 243 chrome::ToggleBookmarkBarWhenVisible(profile_); |
| 244 break; | 244 break; |
| 245 | 245 |
| 246 case IDC_BOOKMARK_BAR_SHOW_APPS_SHORTCUT: { | 246 case IDC_BOOKMARK_BAR_SHOW_APPS_SHORTCUT: { |
| 247 PrefService* prefs = profile_->GetPrefs(); | 247 PrefService* prefs = profile_->GetPrefs(); |
| 248 prefs->SetBoolean( | 248 prefs->SetBoolean( |
| 249 prefs::kShowAppsShortcutInBookmarkBar, | 249 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, |
| 250 !prefs->GetBoolean(prefs::kShowAppsShortcutInBookmarkBar)); | 250 !prefs->GetBoolean(bookmarks::prefs::kShowAppsShortcutInBookmarkBar)); |
| 251 break; | 251 break; |
| 252 } | 252 } |
| 253 | 253 |
| 254 case IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS: { | 254 case IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS: { |
| 255 PrefService* prefs = profile_->GetPrefs(); | 255 PrefService* prefs = profile_->GetPrefs(); |
| 256 prefs->SetBoolean( | 256 prefs->SetBoolean( |
| 257 prefs::kShowManagedBookmarksInBookmarkBar, | 257 bookmarks::prefs::kShowManagedBookmarksInBookmarkBar, |
| 258 !prefs->GetBoolean(prefs::kShowManagedBookmarksInBookmarkBar)); | 258 !prefs->GetBoolean( |
| 259 bookmarks::prefs::kShowManagedBookmarksInBookmarkBar)); |
| 259 break; | 260 break; |
| 260 } | 261 } |
| 261 | 262 |
| 262 case IDC_BOOKMARK_MANAGER: { | 263 case IDC_BOOKMARK_MANAGER: { |
| 263 content::RecordAction(UserMetricsAction("ShowBookmarkManager")); | 264 content::RecordAction(UserMetricsAction("ShowBookmarkManager")); |
| 264 if (selection_.size() != 1) | 265 if (selection_.size() != 1) |
| 265 chrome::ShowBookmarkManager(browser_); | 266 chrome::ShowBookmarkManager(browser_); |
| 266 else if (selection_[0]->is_folder()) | 267 else if (selection_[0]->is_folder()) |
| 267 chrome::ShowBookmarkManagerForNode(browser_, selection_[0]->id()); | 268 chrome::ShowBookmarkManagerForNode(browser_, selection_[0]->id()); |
| 268 else if (parent_) | 269 else if (parent_) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 client->managed_node()->GetTitle()); | 324 client->managed_node()->GetTitle()); |
| 324 } | 325 } |
| 325 | 326 |
| 326 NOTREACHED(); | 327 NOTREACHED(); |
| 327 return base::string16(); | 328 return base::string16(); |
| 328 } | 329 } |
| 329 | 330 |
| 330 bool BookmarkContextMenuController::IsCommandIdChecked(int command_id) const { | 331 bool BookmarkContextMenuController::IsCommandIdChecked(int command_id) const { |
| 331 PrefService* prefs = profile_->GetPrefs(); | 332 PrefService* prefs = profile_->GetPrefs(); |
| 332 if (command_id == IDC_BOOKMARK_BAR_ALWAYS_SHOW) | 333 if (command_id == IDC_BOOKMARK_BAR_ALWAYS_SHOW) |
| 333 return prefs->GetBoolean(prefs::kShowBookmarkBar); | 334 return prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar); |
| 334 if (command_id == IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS) | 335 if (command_id == IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS) |
| 335 return prefs->GetBoolean(prefs::kShowManagedBookmarksInBookmarkBar); | 336 return prefs->GetBoolean( |
| 337 bookmarks::prefs::kShowManagedBookmarksInBookmarkBar); |
| 336 | 338 |
| 337 DCHECK_EQ(IDC_BOOKMARK_BAR_SHOW_APPS_SHORTCUT, command_id); | 339 DCHECK_EQ(IDC_BOOKMARK_BAR_SHOW_APPS_SHORTCUT, command_id); |
| 338 return prefs->GetBoolean(prefs::kShowAppsShortcutInBookmarkBar); | 340 return prefs->GetBoolean(bookmarks::prefs::kShowAppsShortcutInBookmarkBar); |
| 339 } | 341 } |
| 340 | 342 |
| 341 bool BookmarkContextMenuController::IsCommandIdEnabled(int command_id) const { | 343 bool BookmarkContextMenuController::IsCommandIdEnabled(int command_id) const { |
| 342 PrefService* prefs = profile_->GetPrefs(); | 344 PrefService* prefs = profile_->GetPrefs(); |
| 343 | 345 |
| 344 bool is_root_node = selection_.size() == 1 && | 346 bool is_root_node = selection_.size() == 1 && |
| 345 selection_[0]->parent() == model_->root_node(); | 347 selection_[0]->parent() == model_->root_node(); |
| 346 bool can_edit = prefs->GetBoolean(prefs::kEditBookmarksEnabled) && | 348 bool can_edit = prefs->GetBoolean(bookmarks::prefs::kEditBookmarksEnabled) && |
| 347 bookmarks::CanAllBeEditedByUser(model_->client(), selection_); | 349 bookmarks::CanAllBeEditedByUser(model_->client(), selection_); |
| 348 IncognitoModePrefs::Availability incognito_avail = | 350 IncognitoModePrefs::Availability incognito_avail = |
| 349 IncognitoModePrefs::GetAvailability(prefs); | 351 IncognitoModePrefs::GetAvailability(prefs); |
| 350 | 352 |
| 351 switch (command_id) { | 353 switch (command_id) { |
| 352 case IDC_BOOKMARK_BAR_OPEN_INCOGNITO: | 354 case IDC_BOOKMARK_BAR_OPEN_INCOGNITO: |
| 353 return !profile_->IsOffTheRecord() && | 355 return !profile_->IsOffTheRecord() && |
| 354 incognito_avail != IncognitoModePrefs::DISABLED; | 356 incognito_avail != IncognitoModePrefs::DISABLED; |
| 355 | 357 |
| 356 case IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO: | 358 case IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 381 | 383 |
| 382 case IDC_BOOKMARK_BAR_REMOVE: | 384 case IDC_BOOKMARK_BAR_REMOVE: |
| 383 return !selection_.empty() && !is_root_node && can_edit; | 385 return !selection_.empty() && !is_root_node && can_edit; |
| 384 | 386 |
| 385 case IDC_BOOKMARK_BAR_NEW_FOLDER: | 387 case IDC_BOOKMARK_BAR_NEW_FOLDER: |
| 386 case IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK: | 388 case IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK: |
| 387 return can_edit && model_->client()->CanBeEditedByUser(parent_) && | 389 return can_edit && model_->client()->CanBeEditedByUser(parent_) && |
| 388 bookmarks::GetParentForNewNodes(parent_, selection_, NULL) != NULL; | 390 bookmarks::GetParentForNewNodes(parent_, selection_, NULL) != NULL; |
| 389 | 391 |
| 390 case IDC_BOOKMARK_BAR_ALWAYS_SHOW: | 392 case IDC_BOOKMARK_BAR_ALWAYS_SHOW: |
| 391 return !prefs->IsManagedPreference(prefs::kShowBookmarkBar); | 393 return !prefs->IsManagedPreference(bookmarks::prefs::kShowBookmarkBar); |
| 392 | 394 |
| 393 case IDC_BOOKMARK_BAR_SHOW_APPS_SHORTCUT: | 395 case IDC_BOOKMARK_BAR_SHOW_APPS_SHORTCUT: |
| 394 return !prefs->IsManagedPreference(prefs::kShowAppsShortcutInBookmarkBar); | 396 return !prefs->IsManagedPreference( |
| 397 bookmarks::prefs::kShowAppsShortcutInBookmarkBar); |
| 395 | 398 |
| 396 case IDC_COPY: | 399 case IDC_COPY: |
| 397 case IDC_CUT: | 400 case IDC_CUT: |
| 398 return !selection_.empty() && !is_root_node && | 401 return !selection_.empty() && !is_root_node && |
| 399 (command_id == IDC_COPY || can_edit); | 402 (command_id == IDC_COPY || can_edit); |
| 400 | 403 |
| 401 case IDC_PASTE: | 404 case IDC_PASTE: |
| 402 // Paste to selection from the Bookmark Bar, to parent_ everywhere else | 405 // Paste to selection from the Bookmark Bar, to parent_ everywhere else |
| 403 return can_edit && | 406 return can_edit && |
| 404 ((!selection_.empty() && | 407 ((!selection_.empty() && |
| (...skipping 18 matching lines...) Expand all Loading... |
| 423 bool BookmarkContextMenuController::GetAcceleratorForCommandId( | 426 bool BookmarkContextMenuController::GetAcceleratorForCommandId( |
| 424 int command_id, | 427 int command_id, |
| 425 ui::Accelerator* accelerator) { | 428 ui::Accelerator* accelerator) { |
| 426 return false; | 429 return false; |
| 427 } | 430 } |
| 428 | 431 |
| 429 void BookmarkContextMenuController::BookmarkModelChanged() { | 432 void BookmarkContextMenuController::BookmarkModelChanged() { |
| 430 if (delegate_) | 433 if (delegate_) |
| 431 delegate_->CloseMenu(); | 434 delegate_->CloseMenu(); |
| 432 } | 435 } |
| OLD | NEW |