diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-05 00:35:09 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-05 00:35:09 +0000 |
commit | 140aea057fa118579380f685f362f2533862b03f (patch) | |
tree | 627c15d8adda34f2c602589e0bac815bbdc7d4d9 /chrome/browser/bookmarks/bookmark_utils.cc | |
parent | 57e3074163dc21bc3bc8cd37dc05f191532d836a (diff) | |
download | chromium_src-140aea057fa118579380f685f362f2533862b03f.zip chromium_src-140aea057fa118579380f685f362f2533862b03f.tar.gz chromium_src-140aea057fa118579380f685f362f2533862b03f.tar.bz2 |
Port the folder selector portion of the BookmarkEditor to GTK.
Mirrors the BookmarkEditorView method, where the contents of BookmarkModel
are copied to a temporary model so changes can be discarded if the user hits
Cancel. In the GTK version, we copy not into another BookmarkModel, but into
a GtkTreeStore, which serves as a model to the GtkTreeView on screen.
Also ports the unit tests.
http://crbug.com/11250
Review URL: http://codereview.chromium.org/99361
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15257 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/bookmarks/bookmark_utils.cc')
-rw-r--r-- | chrome/browser/bookmarks/bookmark_utils.cc | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/chrome/browser/bookmarks/bookmark_utils.cc b/chrome/browser/bookmarks/bookmark_utils.cc index e20e545..6832778 100644 --- a/chrome/browser/bookmarks/bookmark_utils.cc +++ b/chrome/browser/bookmarks/bookmark_utils.cc @@ -32,6 +32,8 @@ #include "chrome/common/temp_scaffolding_stubs.h" #endif +using base::Time; + namespace { // A PageNavigator implementation that creates a new Browser. This is used when @@ -531,6 +533,82 @@ bool DoesBookmarkContainText(BookmarkNode* node, const std::wstring& text) { return (node->is_url() && DoesBookmarkContainWords(node, words)); } +void ApplyEditsWithNoGroupChange(BookmarkModel* model, + BookmarkNode* parent, + BookmarkNode* node, + const std::wstring& new_title, + const GURL& new_url, + BookmarkEditor::Handler* handler) { + BookmarkNode* old_parent = node ? node->GetParent() : NULL; + const int old_index = old_parent ? old_parent->IndexOfChild(node) : -1; + + if (!node) { + node = + model->AddURL(parent, parent->GetChildCount(), new_title, new_url); + + if (handler) + handler->NodeCreated(node); + return; + } + + // If we're not showing the tree we only need to modify the node. + if (old_index == -1) { + NOTREACHED(); + return; + } + + if (new_url != node->GetURL()) { + model->AddURLWithCreationTime(old_parent, old_index, new_title, + new_url, node->date_added()); + model->Remove(old_parent, old_index + 1); + } else { + model->SetTitle(node, new_title); + } +} + +void ApplyEditsWithPossibleGroupChange(BookmarkModel* model, + BookmarkNode* new_parent, + BookmarkNode* node, + const std::wstring& new_title, + const GURL& new_url, + BookmarkEditor::Handler* handler) { + BookmarkNode* old_parent = node ? node->GetParent() : NULL; + const int old_index = old_parent ? old_parent->IndexOfChild(node) : -1; + + if (node) { + Time date_added = node->date_added(); + if (new_parent == node->GetParent()) { + // The parent is the same. + if (new_url != node->GetURL()) { + model->Remove(old_parent, old_index); + BookmarkNode* new_node = + model->AddURL(old_parent, old_index, new_title, new_url); + new_node->set_date_added(date_added); + } else { + model->SetTitle(node, new_title); + } + } else if (new_url != node->GetURL()) { + // The parent and URL changed. + model->Remove(old_parent, old_index); + BookmarkNode* new_node = + model->AddURL(new_parent, new_parent->GetChildCount(), new_title, + new_url); + new_node->set_date_added(date_added); + } else { + // The parent and title changed. Move the node and change the title. + model->Move(node, new_parent, new_parent->GetChildCount()); + model->SetTitle(node, new_title); + } + } else { + // We're adding a new URL. + node = + model->AddURL(new_parent, new_parent->GetChildCount(), new_title, + new_url); + if (handler) + handler->NodeCreated(node); + } +} + // Formerly in BookmarkBarView void ToggleWhenVisible(Profile* profile) { PrefService* prefs = profile->GetPrefs(); |