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

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

Issue 149140: Have the ApplyEdit* bookmark utilities return the BookmarkNode pointer... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/bookmarks/bookmark_utils.h ('k') | no next file » | 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) 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_utils.h" 5 #include "chrome/browser/bookmarks/bookmark_utils.h"
6 6
7 #include "app/drag_drop_types.h" 7 #include "app/drag_drop_types.h"
8 #include "app/l10n_util.h" 8 #include "app/l10n_util.h"
9 // TODO(port): Port these files. 9 // TODO(port): Port these files.
10 #if defined(OS_WIN) 10 #if defined(OS_WIN)
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 const std::wstring& languages) { 506 const std::wstring& languages) {
507 std::vector<std::wstring> words; 507 std::vector<std::wstring> words;
508 QueryParser parser; 508 QueryParser parser;
509 parser.ExtractQueryWords(l10n_util::ToLower(text), &words); 509 parser.ExtractQueryWords(l10n_util::ToLower(text), &words);
510 if (words.empty()) 510 if (words.empty())
511 return false; 511 return false;
512 512
513 return (node->is_url() && DoesBookmarkContainWords(node, words, languages)); 513 return (node->is_url() && DoesBookmarkContainWords(node, words, languages));
514 } 514 }
515 515
516 void ApplyEditsWithNoGroupChange(BookmarkModel* model, 516 const BookmarkNode* ApplyEditsWithNoGroupChange(BookmarkModel* model,
517 const BookmarkNode* parent, 517 const BookmarkNode* parent, const BookmarkNode* node,
518 const BookmarkNode* node, 518 const std::wstring& new_title, const GURL& new_url,
519 const std::wstring& new_title, 519 BookmarkEditor::Handler* handler) {
520 const GURL& new_url,
521 BookmarkEditor::Handler* handler) {
522 const BookmarkNode* old_parent = node ? node->GetParent() : NULL; 520 const BookmarkNode* old_parent = node ? node->GetParent() : NULL;
523 const int old_index = old_parent ? old_parent->IndexOfChild(node) : -1; 521 const int old_index = old_parent ? old_parent->IndexOfChild(node) : -1;
524 522
525 if (!node) { 523 if (!node) {
526 node = 524 node =
527 model->AddURL(parent, parent->GetChildCount(), new_title, new_url); 525 model->AddURL(parent, parent->GetChildCount(), new_title, new_url);
528 526
529 if (handler) 527 if (handler)
530 handler->NodeCreated(node); 528 handler->NodeCreated(node);
531 return; 529 return node;
532 } 530 }
533 531
534 // If we're not showing the tree we only need to modify the node. 532 // If we're not showing the tree we only need to modify the node.
535 if (old_index == -1) { 533 if (old_index == -1) {
536 NOTREACHED(); 534 NOTREACHED();
537 return; 535 return node;
538 } 536 }
539 537
540 if (new_url != node->GetURL()) { 538 if (new_url != node->GetURL()) {
541 model->AddURLWithCreationTime(old_parent, old_index, new_title, 539 const BookmarkNode* new_node = model->AddURLWithCreationTime(old_parent,
542 new_url, node->date_added()); 540 old_index, new_title, new_url, node->date_added());
543 model->Remove(old_parent, old_index + 1); 541 model->Remove(old_parent, old_index + 1);
542 return new_node;
544 } else { 543 } else {
545 model->SetTitle(node, new_title); 544 model->SetTitle(node, new_title);
546 } 545 }
546 return node;
547 } 547 }
548 548
549 void ApplyEditsWithPossibleGroupChange(BookmarkModel* model, 549 const BookmarkNode* ApplyEditsWithPossibleGroupChange(BookmarkModel* model,
550 const BookmarkNode* new_parent, 550 const BookmarkNode* new_parent, const BookmarkNode* node,
551 const BookmarkNode* node, 551 const std::wstring& new_title, const GURL& new_url,
552 const std::wstring& new_title, 552 BookmarkEditor::Handler* handler) {
553 const GURL& new_url,
554 BookmarkEditor::Handler* handler) {
555 const BookmarkNode* old_parent = node ? node->GetParent() : NULL; 553 const BookmarkNode* old_parent = node ? node->GetParent() : NULL;
556 const int old_index = old_parent ? old_parent->IndexOfChild(node) : -1; 554 const int old_index = old_parent ? old_parent->IndexOfChild(node) : -1;
557 555 const BookmarkNode* return_node = node;
558 if (node) { 556 if (node) {
559 Time date_added = node->date_added(); 557 Time date_added = node->date_added();
560 if (new_parent == node->GetParent()) { 558 if (new_parent == node->GetParent()) {
561 // The parent is the same. 559 // The parent is the same.
562 if (new_url != node->GetURL()) { 560 if (new_url != node->GetURL()) {
563 model->Remove(old_parent, old_index); 561 model->Remove(old_parent, old_index);
564 model->AddURLWithCreationTime(old_parent, old_index, 562 return_node = model->AddURLWithCreationTime(old_parent, old_index,
565 new_title, new_url, date_added); 563 new_title, new_url, date_added);
566 } else { 564 } else {
567 model->SetTitle(node, new_title); 565 model->SetTitle(node, new_title);
568 } 566 }
569 } else if (new_url != node->GetURL()) { 567 } else if (new_url != node->GetURL()) {
570 // The parent and URL changed. 568 // The parent and URL changed.
571 model->Remove(old_parent, old_index); 569 model->Remove(old_parent, old_index);
572 model->AddURLWithCreationTime(new_parent, new_parent->GetChildCount(), 570 return_node = model->AddURLWithCreationTime(new_parent,
573 new_title, new_url, date_added); 571 new_parent->GetChildCount(), new_title, new_url, date_added);
574 } else { 572 } else {
575 // The parent and title changed. Move the node and change the title. 573 // The parent and title changed. Move the node and change the title.
576 model->Move(node, new_parent, new_parent->GetChildCount()); 574 model->Move(node, new_parent, new_parent->GetChildCount());
577 model->SetTitle(node, new_title); 575 model->SetTitle(node, new_title);
578 } 576 }
579 } else { 577 } else {
580 // We're adding a new URL. 578 // We're adding a new URL.
581 node = 579 return_node =
582 model->AddURL(new_parent, new_parent->GetChildCount(), new_title, 580 model->AddURL(new_parent, new_parent->GetChildCount(), new_title,
583 new_url); 581 new_url);
584 if (handler) 582 if (handler)
585 handler->NodeCreated(node); 583 handler->NodeCreated(return_node);
586 } 584 }
585 return return_node;
587 } 586 }
588 587
589 // Formerly in BookmarkBarView 588 // Formerly in BookmarkBarView
590 void ToggleWhenVisible(Profile* profile) { 589 void ToggleWhenVisible(Profile* profile) {
591 PrefService* prefs = profile->GetPrefs(); 590 PrefService* prefs = profile->GetPrefs();
592 const bool always_show = !prefs->GetBoolean(prefs::kShowBookmarkBar); 591 const bool always_show = !prefs->GetBoolean(prefs::kShowBookmarkBar);
593 592
594 // The user changed when the bookmark bar is shown, update the preferences. 593 // The user changed when the bookmark bar is shown, update the preferences.
595 prefs->SetBoolean(prefs::kShowBookmarkBar, always_show); 594 prefs->SetBoolean(prefs::kShowBookmarkBar, always_show);
596 prefs->ScheduleSavePersistentPrefs(); 595 prefs->ScheduleSavePersistentPrefs();
(...skipping 19 matching lines...) Expand all
616 615
617 // Formerly in BookmarkTableView 616 // Formerly in BookmarkTableView
618 prefs->RegisterIntegerPref(prefs::kBookmarkTableNameWidth1, -1); 617 prefs->RegisterIntegerPref(prefs::kBookmarkTableNameWidth1, -1);
619 prefs->RegisterIntegerPref(prefs::kBookmarkTableURLWidth1, -1); 618 prefs->RegisterIntegerPref(prefs::kBookmarkTableURLWidth1, -1);
620 prefs->RegisterIntegerPref(prefs::kBookmarkTableNameWidth2, -1); 619 prefs->RegisterIntegerPref(prefs::kBookmarkTableNameWidth2, -1);
621 prefs->RegisterIntegerPref(prefs::kBookmarkTableURLWidth2, -1); 620 prefs->RegisterIntegerPref(prefs::kBookmarkTableURLWidth2, -1);
622 prefs->RegisterIntegerPref(prefs::kBookmarkTablePathWidth, -1); 621 prefs->RegisterIntegerPref(prefs::kBookmarkTablePathWidth, -1);
623 } 622 }
624 623
625 } // namespace bookmark_utils 624 } // namespace bookmark_utils
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698