Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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.h" | 5 #include "chrome/browser/bookmarks/bookmark_context_menu.h" |
| 6 | 6 |
| 7 #include "chrome/browser/bookmarks/bookmark_model.h" | 7 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_utils.h" | 8 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 9 #include "chrome/browser/browser.h" | 9 #include "chrome/browser/browser.h" |
| 10 #include "chrome/browser/browser_list.h" | 10 #include "chrome/browser/browser_list.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 ModelChanged(); | 158 ModelChanged(); |
| 159 } | 159 } |
| 160 | 160 |
| 161 virtual void BookmarkNodeChanged(BookmarkModel* model, BookmarkNode* node) { | 161 virtual void BookmarkNodeChanged(BookmarkModel* model, BookmarkNode* node) { |
| 162 ModelChanged(); | 162 ModelChanged(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, | 165 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, |
| 166 BookmarkNode* node) {} | 166 BookmarkNode* node) {} |
| 167 | 167 |
| 168 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, | |
| 169 BookmarkNode* node) { | |
| 170 ModelChanged(); | |
| 171 } | |
| 172 | |
| 168 void ModelChanged() { | 173 void ModelChanged() { |
| 169 window_->Close(); | 174 window_->Close(); |
| 170 } | 175 } |
| 171 | 176 |
| 172 Profile* profile_; | 177 Profile* profile_; |
| 173 BookmarkModel* model_; | 178 BookmarkModel* model_; |
| 174 // If is_new is true, this is the parent to create the new node under. | 179 // If is_new is true, this is the parent to create the new node under. |
| 175 // Otherwise this is the node to change the title of. | 180 // Otherwise this is the node to change the title of. |
| 176 BookmarkNode* node_; | 181 BookmarkNode* node_; |
| 177 | 182 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 configuration == BOOKMARK_MANAGER_ORGANIZE_MENU_OTHER) { | 288 configuration == BOOKMARK_MANAGER_ORGANIZE_MENU_OTHER) { |
| 284 menu_->AppendSeparator(); | 289 menu_->AppendSeparator(); |
| 285 menu_->AppendMenuItemWithLabel( | 290 menu_->AppendMenuItemWithLabel( |
| 286 IDS_CUT, l10n_util::GetString(IDS_CUT)); | 291 IDS_CUT, l10n_util::GetString(IDS_CUT)); |
| 287 menu_->AppendMenuItemWithLabel( | 292 menu_->AppendMenuItemWithLabel( |
| 288 IDS_COPY, l10n_util::GetString(IDS_COPY)); | 293 IDS_COPY, l10n_util::GetString(IDS_COPY)); |
| 289 menu_->AppendMenuItemWithLabel( | 294 menu_->AppendMenuItemWithLabel( |
| 290 IDS_PASTE, l10n_util::GetString(IDS_PASTE)); | 295 IDS_PASTE, l10n_util::GetString(IDS_PASTE)); |
| 291 } | 296 } |
| 292 | 297 |
| 298 if (configuration == BOOKMARK_MANAGER_ORGANIZE_MENU) { | |
| 299 menu_->AppendSeparator(); | |
| 300 menu_->AppendMenuItemWithLabel( | |
| 301 IDS_BOOKMARK_MANAGER_SORT, | |
| 302 l10n_util::GetString(IDS_BOOKMARK_MANAGER_SORT)); | |
| 303 } | |
| 304 | |
| 293 menu_->AppendSeparator(); | 305 menu_->AppendSeparator(); |
| 294 | 306 |
| 295 menu_->AppendMenuItemWithLabel( | 307 menu_->AppendMenuItemWithLabel( |
| 296 IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK, | 308 IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK, |
| 297 l10n_util::GetString(IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK)); | 309 l10n_util::GetString(IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK)); |
| 298 menu_->AppendMenuItemWithLabel( | 310 menu_->AppendMenuItemWithLabel( |
| 299 IDS_BOOMARK_BAR_NEW_FOLDER, | 311 IDS_BOOMARK_BAR_NEW_FOLDER, |
| 300 l10n_util::GetString(IDS_BOOMARK_BAR_NEW_FOLDER)); | 312 l10n_util::GetString(IDS_BOOMARK_BAR_NEW_FOLDER)); |
| 301 | 313 |
| 302 if (configuration == BOOKMARK_BAR) { | 314 if (configuration == BOOKMARK_BAR) { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 | 442 |
| 431 if (BookmarkManagerView::current()) | 443 if (BookmarkManagerView::current()) |
| 432 BookmarkManagerView::current()->SelectInTree(selection_[0]); | 444 BookmarkManagerView::current()->SelectInTree(selection_[0]); |
| 433 break; | 445 break; |
| 434 | 446 |
| 435 case IDS_BOOKMARK_MANAGER: | 447 case IDS_BOOKMARK_MANAGER: |
| 436 UserMetrics::RecordAction(L"ShowBookmarkManager", profile_); | 448 UserMetrics::RecordAction(L"ShowBookmarkManager", profile_); |
| 437 BookmarkManagerView::Show(profile_); | 449 BookmarkManagerView::Show(profile_); |
| 438 break; | 450 break; |
| 439 | 451 |
| 452 case IDS_BOOKMARK_MANAGER_SORT: | |
| 453 UserMetrics::RecordAction(L"BookmarkManager_Sort", profile_); | |
| 454 model_->SortChildren(parent_); | |
| 455 break; | |
| 456 | |
| 440 case IDS_COPY: | 457 case IDS_COPY: |
| 441 case IDS_CUT: | 458 case IDS_CUT: |
| 442 bookmark_utils::CopyToClipboard(profile_->GetBookmarkModel(), | 459 bookmark_utils::CopyToClipboard(profile_->GetBookmarkModel(), |
| 443 selection_, id == IDS_CUT); | 460 selection_, id == IDS_CUT); |
| 444 break; | 461 break; |
| 445 | 462 |
| 446 case IDS_PASTE: { | 463 case IDS_PASTE: { |
| 447 // Always paste to parent. | 464 // Always paste to parent. |
| 448 if (!parent_) | 465 if (!parent_) |
| 449 return; | 466 return; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 487 return selection_.size() == 1 && !is_root_node; | 504 return selection_.size() == 1 && !is_root_node; |
| 488 | 505 |
| 489 case IDS_BOOKMARK_BAR_REMOVE: | 506 case IDS_BOOKMARK_BAR_REMOVE: |
| 490 return !selection_.empty() && !is_root_node; | 507 return !selection_.empty() && !is_root_node; |
| 491 | 508 |
| 492 case IDS_BOOKMARK_MANAGER_SHOW_IN_FOLDER: | 509 case IDS_BOOKMARK_MANAGER_SHOW_IN_FOLDER: |
| 493 return (configuration_ == BOOKMARK_MANAGER_TABLE_OTHER || | 510 return (configuration_ == BOOKMARK_MANAGER_TABLE_OTHER || |
| 494 configuration_ == BOOKMARK_MANAGER_ORGANIZE_MENU_OTHER) && | 511 configuration_ == BOOKMARK_MANAGER_ORGANIZE_MENU_OTHER) && |
| 495 selection_.size() == 1; | 512 selection_.size() == 1; |
| 496 | 513 |
| 514 case IDS_BOOKMARK_MANAGER_SORT: | |
| 515 return parent_ && parent_->GetParent(); | |
|
ncarter (slow)
2009/02/27 21:22:34
If the GetParent() check is to protect against roo
sky
2009/02/27 21:42:06
Done.
| |
| 516 | |
| 497 case IDS_BOOMARK_BAR_NEW_FOLDER: | 517 case IDS_BOOMARK_BAR_NEW_FOLDER: |
| 498 case IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK: | 518 case IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK: |
| 499 return GetParentForNewNodes() != NULL; | 519 return GetParentForNewNodes() != NULL; |
| 500 | 520 |
| 501 case IDS_COPY: | 521 case IDS_COPY: |
| 502 case IDS_CUT: | 522 case IDS_CUT: |
| 503 return selection_.size() > 0 && !is_root_node; | 523 return selection_.size() > 0 && !is_root_node; |
| 504 | 524 |
| 505 case IDS_PASTE: | 525 case IDS_PASTE: |
| 506 // Always paste to parent. | 526 // Always paste to parent. |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 532 int index, | 552 int index, |
| 533 BookmarkNode* node) { | 553 BookmarkNode* node) { |
| 534 ModelChanged(); | 554 ModelChanged(); |
| 535 } | 555 } |
| 536 | 556 |
| 537 void BookmarkContextMenu::BookmarkNodeChanged(BookmarkModel* model, | 557 void BookmarkContextMenu::BookmarkNodeChanged(BookmarkModel* model, |
| 538 BookmarkNode* node) { | 558 BookmarkNode* node) { |
| 539 ModelChanged(); | 559 ModelChanged(); |
| 540 } | 560 } |
| 541 | 561 |
| 562 void BookmarkContextMenu::BookmarkNodeChildrenReordered(BookmarkModel* model, | |
| 563 BookmarkNode* node) { | |
| 564 ModelChanged(); | |
| 565 } | |
| 566 | |
| 542 void BookmarkContextMenu::ModelChanged() { | 567 void BookmarkContextMenu::ModelChanged() { |
| 543 menu_->Cancel(); | 568 menu_->Cancel(); |
| 544 } | 569 } |
| 545 | 570 |
| 546 BookmarkModel* BookmarkContextMenu::RemoveModelObserver() { | 571 BookmarkModel* BookmarkContextMenu::RemoveModelObserver() { |
| 547 BookmarkModel* model = model_; | 572 BookmarkModel* model = model_; |
| 548 model_->RemoveObserver(this); | 573 model_->RemoveObserver(this); |
| 549 model_ = NULL; | 574 model_ = NULL; |
| 550 return model; | 575 return model; |
| 551 } | 576 } |
| 552 | 577 |
| 553 bool BookmarkContextMenu::HasURLs() const { | 578 bool BookmarkContextMenu::HasURLs() const { |
| 554 for (size_t i = 0; i < selection_.size(); ++i) { | 579 for (size_t i = 0; i < selection_.size(); ++i) { |
| 555 if (NodeHasURLs(selection_[i])) | 580 if (NodeHasURLs(selection_[i])) |
| 556 return true; | 581 return true; |
| 557 } | 582 } |
| 558 return false; | 583 return false; |
| 559 } | 584 } |
| 560 | 585 |
| 561 BookmarkNode* BookmarkContextMenu::GetParentForNewNodes() const { | 586 BookmarkNode* BookmarkContextMenu::GetParentForNewNodes() const { |
| 562 return (selection_.size() == 1 && selection_[0]->is_folder()) ? | 587 return (selection_.size() == 1 && selection_[0]->is_folder()) ? |
| 563 selection_[0] : parent_; | 588 selection_[0] : parent_; |
| 564 } | 589 } |
| OLD | NEW |