summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-16 22:28:44 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-16 22:28:44 +0000
commitec12ffe60e6d1e26833fb5c518fd6c85ab0c12bb (patch)
treec5f53581aa406dc819f4a758abc1e794099fa29b /chrome
parent54fe13676dcdfa8a711b0ffd9a9d96a194da834d (diff)
downloadchromium_src-ec12ffe60e6d1e26833fb5c518fd6c85ab0c12bb.zip
chromium_src-ec12ffe60e6d1e26833fb5c518fd6c85ab0c12bb.tar.gz
chromium_src-ec12ffe60e6d1e26833fb5c518fd6c85ab0c12bb.tar.bz2
Makes canceling 'bookmark all tabs' delete the folder. Or rather,
makes it so that bookmark all tabs only creates the folder if the user presses ok. I wasn't happy adding another random arg to BookmarkEditor::Show, so I added in a structure an enum. This makes it clearer what Show should do. I also fixed the following: . On gtk we wouldn't always pick the right parent for nodes. . The context menu item is now enabled on views/gtk. And this now breaks the mac side. I'll straighten that out right after landing this. BUG=24367 TEST=Make sure 'bookmark all tabs' works, as well as the bookmark editor work. (get to the bookmark editor by creating a new bookmark, then clicking edit, or right clicking a bookmark on the bookmark bar and choosing edit). Review URL: http://codereview.chromium.org/271115 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29343 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/bookmarks/bookmark_context_menu_controller.cc6
-rw-r--r--chrome/browser/bookmarks/bookmark_editor.h60
-rw-r--r--chrome/browser/bookmarks/bookmark_utils.cc113
-rw-r--r--chrome/browser/bookmarks/bookmark_utils.h11
-rw-r--r--chrome/browser/browser.cc14
-rw-r--r--chrome/browser/cocoa/bookmark_bar_controller.mm4
-rw-r--r--chrome/browser/cocoa/bookmark_editor_controller.mm19
-rw-r--r--chrome/browser/gtk/bookmark_bubble_gtk.cc3
-rw-r--r--chrome/browser/gtk/bookmark_context_menu_gtk.cc8
-rw-r--r--chrome/browser/gtk/bookmark_editor_gtk.cc63
-rw-r--r--chrome/browser/gtk/bookmark_editor_gtk.h9
-rw-r--r--chrome/browser/gtk/bookmark_editor_gtk_unittest.cc27
-rw-r--r--chrome/browser/gtk/bookmark_manager_gtk.cc4
-rw-r--r--chrome/browser/gtk/bookmark_tree_model.cc17
-rw-r--r--chrome/browser/gtk/bookmark_tree_model.h9
-rw-r--r--chrome/browser/sync/glue/change_processor.cc3
-rw-r--r--chrome/browser/views/bookmark_bubble_view.cc3
-rw-r--r--chrome/browser/views/bookmark_editor_view.cc43
-rw-r--r--chrome/browser/views/bookmark_editor_view.h13
-rw-r--r--chrome/browser/views/bookmark_editor_view_unittest.cc109
-rw-r--r--chrome/browser/views/tabs/tab.cc2
-rw-r--r--chrome/test/live_sync/bookmark_model_verifier.cc5
-rw-r--r--chrome/test/live_sync/two_client_live_bookmarks_sync_test.cc8
23 files changed, 317 insertions, 236 deletions
diff --git a/chrome/browser/bookmarks/bookmark_context_menu_controller.cc b/chrome/browser/bookmarks/bookmark_context_menu_controller.cc
index 15791a8..0e62277 100644
--- a/chrome/browser/bookmarks/bookmark_context_menu_controller.cc
+++ b/chrome/browser/bookmarks/bookmark_context_menu_controller.cc
@@ -316,7 +316,8 @@ void BookmarkContextMenuController::ExecuteCommand(int id) {
editor_config = BookmarkEditor::SHOW_TREE;
else
editor_config = BookmarkEditor::NO_TREE;
- BookmarkEditor::Show(parent_window_, profile_, parent_, selection_[0],
+ BookmarkEditor::Show(parent_window_, profile_, parent_,
+ BookmarkEditor::EditDetails(selection_[0]),
editor_config, NULL);
} else {
EditFolderController::Show(profile_, parent_window_, selection_[0],
@@ -349,7 +350,8 @@ void BookmarkContextMenuController::ExecuteCommand(int id) {
handler = new SelectOnCreationHandler(profile_);
}
BookmarkEditor::Show(parent_window_, profile_, GetParentForNewNodes(),
- NULL, editor_config, handler);
+ BookmarkEditor::EditDetails(), editor_config,
+ handler);
break;
}
diff --git a/chrome/browser/bookmarks/bookmark_editor.h b/chrome/browser/bookmarks/bookmark_editor.h
index 0b98406..e935311 100644
--- a/chrome/browser/bookmarks/bookmark_editor.h
+++ b/chrome/browser/bookmarks/bookmark_editor.h
@@ -5,9 +5,14 @@
#ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_EDITOR_H_
#define CHROME_BROWSER_BOOKMARKS_BOOKMARK_EDITOR_H_
+#include <string>
+#include <utility>
+#include <vector>
+
#include "app/gfx/native_widget_types.h"
class BookmarkNode;
+class GURL;
class Profile;
// Small, cross platform interface that shows the correct platform specific
@@ -28,20 +33,53 @@ class BookmarkEditor {
NO_TREE
};
- // Shows the platform specific BookmarkEditor subclass editing |node|. |node|
- // may be one of three values:
- // . NULL, in which a case a new entry is created initially parented to
- // |parent|.
- // . non-null and a url.
- // . non-null and a folder. In this case the url field is not shown and an
- // entry for the node is not shown in the tree.
- // If |show_tree| is false the tree is not shown. BookmarkEditor takes
- // ownership of |handler| and deletes it when done. |handler| may be
- // null. See description of Handler for details.
+ // Describes what the user is editing.
+ struct EditDetails {
+ enum Type {
+ // The user is editing an existing node in the model. The node the user
+ // is editing is set in |existing_node|.
+ EXISTING_NODE,
+
+ // A new bookmark should be created if the user accepts the edit.
+ // |existing_node| is null in this case.
+ NEW_URL,
+
+ // A new folder bookmark should be created if the user accepts the edit.
+ // The contents of the folder should be that of |urls|.
+ // |existing_node| is null in this case.
+ NEW_FOLDER
+ };
+
+ EditDetails() : type(NEW_URL), existing_node(NULL) {}
+
+ explicit EditDetails(const BookmarkNode* node)
+ : type(EXISTING_NODE),
+ existing_node(node) {
+ }
+
+ // See description of enum value for details.
+ Type type;
+
+ // If type == EXISTING_NODE this gives the existing node.
+ const BookmarkNode* existing_node;
+
+ // If type == NEW_FOLDER, this is the urls/title pairs to add to the
+ // folder.
+ std::vector<std::pair<GURL, std::wstring> > urls;
+ };
+
+ // Shows the bookmark editor. The bookmark editor allows editing an
+ // existing node or creating a new bookmark node (as determined by
+ // |details.type|). If |configuration| is SHOW_TREE, a tree is shown allowing
+ // the user to choose the parent of the node.
+ // |parent| gives the initial parent to select in the tree for the node.
+ // |parent| is only used if |details.existing_node| is null.
+ // BookmarkEditor takes ownership of |handler| and deletes it when done.
+ // |handler| may be null. See description of Handler for details.
static void Show(gfx::NativeWindow parent_window,
Profile* profile,
const BookmarkNode* parent,
- const BookmarkNode* node,
+ const EditDetails& details,
Configuration configuration,
Handler* handler);
};
diff --git a/chrome/browser/bookmarks/bookmark_utils.cc b/chrome/browser/bookmarks/bookmark_utils.cc
index a8f5860..b11d0b9 100644
--- a/chrome/browser/bookmarks/bookmark_utils.cc
+++ b/chrome/browser/bookmarks/bookmark_utils.cc
@@ -505,22 +505,44 @@ bool DoesBookmarkContainText(const BookmarkNode* node,
return (node->is_url() && DoesBookmarkContainWords(node, words, languages));
}
-const BookmarkNode* ApplyEditsWithNoGroupChange(BookmarkModel* model,
- const BookmarkNode* parent, const BookmarkNode* node,
+static const BookmarkNode* CreateNewNode(BookmarkModel* model,
+ const BookmarkNode* parent, const BookmarkEditor::EditDetails& details,
const std::wstring& new_title, const GURL& new_url,
BookmarkEditor::Handler* handler) {
- const BookmarkNode* old_parent = node ? node->GetParent() : NULL;
- const int old_index = old_parent ? old_parent->IndexOfChild(node) : -1;
+ const BookmarkNode* node;
+ if (details.type == BookmarkEditor::EditDetails::NEW_URL) {
+ node = model->AddURL(parent, parent->GetChildCount(), new_title, new_url);
+ } else if (details.type == BookmarkEditor::EditDetails::NEW_FOLDER) {
+ node = model->AddGroup(parent, parent->GetChildCount(), new_title);
+ for (size_t i = 0; i < details.urls.size(); ++i) {
+ model->AddURL(node, node->GetChildCount(), details.urls[i].second,
+ details.urls[i].first);
+ }
+ // TODO(sky): update parent modified time.
+ } else {
+ NOTREACHED();
+ return NULL;
+ }
- if (!node) {
- node =
- model->AddURL(parent, parent->GetChildCount(), new_title, new_url);
+ if (handler)
+ handler->NodeCreated(node);
+ return node;
+}
- if (handler)
- handler->NodeCreated(node);
- return node;
+const BookmarkNode* ApplyEditsWithNoGroupChange(BookmarkModel* model,
+ const BookmarkNode* parent, const BookmarkEditor::EditDetails& details,
+ const std::wstring& new_title, const GURL& new_url,
+ BookmarkEditor::Handler* handler) {
+ if (details.type == BookmarkEditor::EditDetails::NEW_URL ||
+ details.type == BookmarkEditor::EditDetails::NEW_FOLDER) {
+ return CreateNewNode(model, parent, details, new_title, new_url, handler);
}
+ const BookmarkNode* node = details.existing_node;
+ DCHECK(node);
+ const BookmarkNode* old_parent = node->GetParent();
+ int old_index = old_parent ? old_parent->IndexOfChild(node) : -1;
+
// If we're not showing the tree we only need to modify the node.
if (old_index == -1) {
NOTREACHED();
@@ -528,6 +550,7 @@ const BookmarkNode* ApplyEditsWithNoGroupChange(BookmarkModel* model,
}
if (new_url != node->GetURL()) {
+ // TODO(sky): need SetURL on the model.
const BookmarkNode* new_node = model->AddURLWithCreationTime(old_parent,
old_index, new_title, new_url, node->date_added());
model->Remove(old_parent, old_index + 1);
@@ -539,40 +562,40 @@ const BookmarkNode* ApplyEditsWithNoGroupChange(BookmarkModel* model,
}
const BookmarkNode* ApplyEditsWithPossibleGroupChange(BookmarkModel* model,
- const BookmarkNode* new_parent, const BookmarkNode* node,
+ const BookmarkNode* new_parent, const BookmarkEditor::EditDetails& details,
const std::wstring& new_title, const GURL& new_url,
BookmarkEditor::Handler* handler) {
- const BookmarkNode* old_parent = node ? node->GetParent() : NULL;
- const int old_index = old_parent ? old_parent->IndexOfChild(node) : -1;
+ if (details.type == BookmarkEditor::EditDetails::NEW_URL ||
+ details.type == BookmarkEditor::EditDetails::NEW_FOLDER) {
+ return CreateNewNode(model, new_parent, details, new_title, new_url,
+ handler);
+ }
+
+ const BookmarkNode* node = details.existing_node;
+ DCHECK(node);
+ const BookmarkNode* old_parent = node->GetParent();
+ int old_index = old_parent->IndexOfChild(node);
const BookmarkNode* return_node = node;
- if (node) {
- Time date_added = node->date_added();
- if (new_parent == node->GetParent()) {
- // The parent is the same.
- if (node->is_url() && new_url != node->GetURL()) {
- model->Remove(old_parent, old_index);
- return_node = model->AddURLWithCreationTime(old_parent, old_index,
- new_title, new_url, date_added);
- } else {
- model->SetTitle(node, new_title);
- }
- } else if (node->is_url() && new_url != node->GetURL()) {
- // The parent and URL changed.
+
+ Time date_added = node->date_added();
+ if (new_parent == node->GetParent()) {
+ // The parent is the same.
+ if (node->is_url() && new_url != node->GetURL()) {
model->Remove(old_parent, old_index);
- return_node = model->AddURLWithCreationTime(new_parent,
- new_parent->GetChildCount(), new_title, new_url, date_added);
+ return_node = model->AddURLWithCreationTime(old_parent, old_index,
+ new_title, new_url, 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 if (node->is_url() && new_url != node->GetURL()) {
+ // The parent and URL changed.
+ model->Remove(old_parent, old_index);
+ return_node = model->AddURLWithCreationTime(new_parent,
+ new_parent->GetChildCount(), new_title, new_url, date_added);
} else {
- // We're adding a new URL.
- return_node =
- model->AddURL(new_parent, new_parent->GetChildCount(), new_title,
- new_url);
- if (handler)
- handler->NodeCreated(return_node);
+ // 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);
}
return return_node;
}
@@ -618,20 +641,14 @@ void GetURLAndTitleToBookmark(TabContents* tab_contents,
*title = UTF16ToWideHack(tab_contents->GetTitle());
}
-const BookmarkNode* CreateBookmarkForAllTabs(Browser* browser) {
- BookmarkModel* model = browser->profile()->GetBookmarkModel();
- DCHECK(model && model->IsLoaded());
- const BookmarkNode* parent = model->GetParentForNewNodes();
- const BookmarkNode* folder = model->AddGroup(
- parent, parent->GetChildCount(),
- l10n_util::GetString(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME));
+void GetURLsForOpenTabs(Browser* browser,
+ std::vector<std::pair<GURL, std::wstring> >* urls) {
for (int i = 0; i < browser->tab_count(); ++i) {
- GURL url;
- std::wstring title;
- GetURLAndTitleToBookmark(browser->GetTabContentsAt(i), &url, &title);
- model->AddURL(folder, folder->GetChildCount(), title, url);
+ std::pair<GURL, std::wstring> entry;
+ GetURLAndTitleToBookmark(browser->GetTabContentsAt(i), &(entry.first),
+ &(entry.second));
+ urls->push_back(entry);
}
- return folder;
}
} // namespace bookmark_utils
diff --git a/chrome/browser/bookmarks/bookmark_utils.h b/chrome/browser/bookmarks/bookmark_utils.h
index 0c5d53d..7117967 100644
--- a/chrome/browser/bookmarks/bookmark_utils.h
+++ b/chrome/browser/bookmarks/bookmark_utils.h
@@ -155,7 +155,7 @@ bool DoesBookmarkContainText(const BookmarkNode* node,
const BookmarkNode* ApplyEditsWithNoGroupChange(
BookmarkModel* model,
const BookmarkNode* parent,
- const BookmarkNode* node,
+ const BookmarkEditor::EditDetails& details,
const std::wstring& new_title,
const GURL& new_url,
BookmarkEditor::Handler* handler);
@@ -167,7 +167,7 @@ const BookmarkNode* ApplyEditsWithNoGroupChange(
const BookmarkNode* ApplyEditsWithPossibleGroupChange(
BookmarkModel* model,
const BookmarkNode* new_parent,
- const BookmarkNode* node,
+ const BookmarkEditor::EditDetails& details,
const std::wstring& new_title,
const GURL& new_url,
BookmarkEditor::Handler* handler);
@@ -187,9 +187,10 @@ void GetURLAndTitleToBookmark(TabContents* tab_contents,
GURL* url,
std::wstring* title);
-// Creates a new folder containing a bookmark for each of the tabs in
-// |browser|.
-const BookmarkNode* CreateBookmarkForAllTabs(Browser* browser);
+// Returns, by reference in |urls|, the url and title pairs for each open
+// tab in browser.
+void GetURLsForOpenTabs(Browser* browser,
+ std::vector<std::pair<GURL, std::wstring> >* urls);
// Number of bookmarks we'll open before prompting the user to see if they
// really want to open all.
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index 865f932..29ecb09 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -1654,13 +1654,17 @@ bool Browser::CanBookmarkAllTabs() const {
}
void Browser::BookmarkAllTabs() {
- const BookmarkNode* node = bookmark_utils::CreateBookmarkForAllTabs(this);
- if (!node)
- return;
+ BookmarkModel* model = profile()->GetBookmarkModel();
+ DCHECK(model && model->IsLoaded());
+
+ BookmarkEditor::EditDetails details;
+ details.type = BookmarkEditor::EditDetails::NEW_FOLDER;
+ bookmark_utils::GetURLsForOpenTabs(this, &(details.urls));
+ DCHECK(!details.urls.empty());
BookmarkEditor::Show(window()->GetNativeHandle(), profile_,
- node->GetParent(), node, BookmarkEditor::SHOW_TREE,
- NULL);
+ model->GetParentForNewNodes(), details,
+ BookmarkEditor::SHOW_TREE, NULL);
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/browser/cocoa/bookmark_bar_controller.mm b/chrome/browser/cocoa/bookmark_bar_controller.mm
index 1ff34b0..52ec734 100644
--- a/chrome/browser/cocoa/bookmark_bar_controller.mm
+++ b/chrome/browser/cocoa/bookmark_bar_controller.mm
@@ -435,7 +435,7 @@
BookmarkEditor::Show([[self view] window],
browser_->profile(),
node->GetParent(),
- node,
+ BookmarkEditor::EditDetails(node),
BookmarkEditor::SHOW_TREE,
nil);
}
@@ -486,7 +486,7 @@
BookmarkEditor::Show([[self view] window],
browser_->profile(),
parent,
- nil,
+ BookmarkEditor::EditDetails(),
BookmarkEditor::SHOW_TREE,
nil);
}
diff --git a/chrome/browser/cocoa/bookmark_editor_controller.mm b/chrome/browser/cocoa/bookmark_editor_controller.mm
index a5a3df6..3c45556 100644
--- a/chrome/browser/cocoa/bookmark_editor_controller.mm
+++ b/chrome/browser/cocoa/bookmark_editor_controller.mm
@@ -14,16 +14,21 @@
void BookmarkEditor::Show(gfx::NativeWindow parent_hwnd,
Profile* profile,
const BookmarkNode* parent,
- const BookmarkNode* node,
+ const EditDetails& details,
Configuration configuration,
Handler* handler) {
+ if (details.type == EditDetails::NEW_FOLDER) {
+ // TODO(sky): implement this.
+ NOTIMPLEMENTED();
+ return;
+ }
BookmarkEditorController* controller = [[BookmarkEditorController alloc]
- initWithParentWindow:parent_hwnd
- profile:profile
- parent:parent
- node:node
- configuration:configuration
- handler:handler];
+ initWithParentWindow:parent_hwnd
+ profile:profile
+ parent:parent
+ node:details.existing_node
+ configuration:configuration
+ handler:handler];
[controller runAsModalSheet];
}
diff --git a/chrome/browser/gtk/bookmark_bubble_gtk.cc b/chrome/browser/gtk/bookmark_bubble_gtk.cc
index c43a7a0..a17db56 100644
--- a/chrome/browser/gtk/bookmark_bubble_gtk.cc
+++ b/chrome/browser/gtk/bookmark_bubble_gtk.cc
@@ -369,7 +369,8 @@ void BookmarkBubbleGtk::ShowEditor() {
bubble_->Close();
if (node) {
- BookmarkEditor::Show(toplevel, profile, NULL, node,
+ BookmarkEditor::Show(toplevel, profile, NULL,
+ BookmarkEditor::EditDetails(node),
BookmarkEditor::SHOW_TREE, NULL);
}
}
diff --git a/chrome/browser/gtk/bookmark_context_menu_gtk.cc b/chrome/browser/gtk/bookmark_context_menu_gtk.cc
index 9c3f03c..b0b2819 100644
--- a/chrome/browser/gtk/bookmark_context_menu_gtk.cc
+++ b/chrome/browser/gtk/bookmark_context_menu_gtk.cc
@@ -338,7 +338,8 @@ void BookmarkContextMenuGtk::ExecuteCommand(int id) {
editor_config = BookmarkEditor::SHOW_TREE;
else
editor_config = BookmarkEditor::NO_TREE;
- BookmarkEditor::Show(wnd_, profile_, parent_, selection_[0],
+ BookmarkEditor::Show(wnd_, profile_, parent_,
+ BookmarkEditor::EditDetails(selection_[0]),
editor_config, NULL);
} else {
EditFolderController::Show(profile_, wnd_, selection_[0], false,
@@ -370,8 +371,9 @@ void BookmarkContextMenuGtk::ExecuteCommand(int id) {
// This is owned by the BookmarkEditorView.
handler = new SelectOnCreationHandler(profile_);
}
- BookmarkEditor::Show(wnd_, profile_, GetParentForNewNodes(), NULL,
- editor_config, handler);
+ BookmarkEditor::Show(wnd_, profile_, GetParentForNewNodes(),
+ BookmarkEditor::EditDetails(), editor_config,
+ handler);
break;
}
diff --git a/chrome/browser/gtk/bookmark_editor_gtk.cc b/chrome/browser/gtk/bookmark_editor_gtk.cc
index 9b95b66..6b32462 100644
--- a/chrome/browser/gtk/bookmark_editor_gtk.cc
+++ b/chrome/browser/gtk/bookmark_editor_gtk.cc
@@ -40,13 +40,13 @@ static const int kTreeHeight = 150;
void BookmarkEditor::Show(gfx::NativeWindow parent_hwnd,
Profile* profile,
const BookmarkNode* parent,
- const BookmarkNode* node,
+ const EditDetails& details,
Configuration configuration,
Handler* handler) {
DCHECK(profile);
BookmarkEditorGtk* editor =
- new BookmarkEditorGtk(parent_hwnd, profile, parent, node, configuration,
- handler);
+ new BookmarkEditorGtk(parent_hwnd, profile, parent, details,
+ configuration, handler);
editor->Show();
}
@@ -54,13 +54,13 @@ BookmarkEditorGtk::BookmarkEditorGtk(
GtkWindow* window,
Profile* profile,
const BookmarkNode* parent,
- const BookmarkNode* node,
+ const EditDetails& details,
BookmarkEditor::Configuration configuration,
BookmarkEditor::Handler* handler)
: profile_(profile),
dialog_(NULL),
parent_(parent),
- node_(node),
+ details_(details),
running_menu_for_root_(false),
show_tree_(configuration == SHOW_TREE),
handler_(handler) {
@@ -125,24 +125,32 @@ void BookmarkEditorGtk::Init(GtkWindow* parent_window) {
// |+-------------------------------------------------------------+|
// +---------------------------------------------------------------+
//
- // * The url and corresponding label are not shown if node_ is a folder.
+ // * The url and corresponding label are not shown if creating a new folder.
GtkWidget* content_area = GTK_DIALOG(dialog_)->vbox;
gtk_box_set_spacing(GTK_BOX(content_area), gtk_util::kContentAreaSpacing);
GtkWidget* vbox = gtk_vbox_new(FALSE, 12);
name_entry_ = gtk_entry_new();
- gtk_entry_set_text(GTK_ENTRY(name_entry_),
- node_ ? WideToUTF8(node_->GetTitle()).c_str() : "");
+ std::string title;
+ if (details_.type == EditDetails::EXISTING_NODE) {
+ title = WideToUTF8(details_.existing_node->GetTitle());
+ } else if (details_.type == EditDetails::NEW_FOLDER) {
+ title = WideToUTF8(
+ l10n_util::GetString(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME));
+ }
+ gtk_entry_set_text(GTK_ENTRY(name_entry_), title.c_str());
g_signal_connect(G_OBJECT(name_entry_), "changed",
G_CALLBACK(OnEntryChanged), this);
gtk_entry_set_activates_default(GTK_ENTRY(name_entry_), TRUE);
GtkWidget* table;
- if (!IsEditingFolder()) {
+ if (details_.type != EditDetails::NEW_FOLDER) {
url_entry_ = gtk_entry_new();
- gtk_entry_set_text(GTK_ENTRY(url_entry_),
- node_ ? node_->GetURL().spec().c_str() : "");
+ std::string url_spec;
+ if (details_.type == EditDetails::EXISTING_NODE)
+ url_spec = details_.existing_node->GetURL().spec();
+ gtk_entry_set_text(GTK_ENTRY(url_entry_), url_spec.c_str());
g_signal_connect(G_OBJECT(url_entry_), "changed",
G_CALLBACK(OnEntryChanged), this);
gtk_entry_set_activates_default(GTK_ENTRY(url_entry_), TRUE);
@@ -165,11 +173,14 @@ void BookmarkEditorGtk::Init(GtkWindow* parent_window) {
if (show_tree_) {
GtkTreeIter selected_iter;
- int64 selected_id = parent_ ? parent_->id() : 0;
- const BookmarkNode* node_to_ignore = IsEditingFolder() ? node_ : NULL;
+ int64 selected_id = 0;
+ if (details_.type == EditDetails::EXISTING_NODE)
+ selected_id = details_.existing_node->GetParent()->id();
+ else if (parent_)
+ selected_id = parent_->id();
tree_store_ = bookmark_utils::MakeFolderTreeStore();
- bookmark_utils::AddToTreeStore(bb_model_, selected_id, node_to_ignore,
- tree_store_, &selected_iter);
+ bookmark_utils::AddToTreeStore(bb_model_, selected_id, tree_store_,
+ &selected_iter);
tree_view_ = bookmark_utils::MakeTreeViewForStore(tree_store_);
gtk_widget_set_size_request(tree_view_, kTreeWidth, kTreeHeight);
tree_selection_ = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view_));
@@ -246,7 +257,8 @@ void BookmarkEditorGtk::BookmarkNodeRemoved(BookmarkModel* model,
const BookmarkNode* parent,
int index,
const BookmarkNode* node) {
- if ((node_ && node_->HasAncestor(node)) ||
+ if ((details_.type == EditDetails::EXISTING_NODE &&
+ details_.existing_node->HasAncestor(node)) ||
(parent_ && parent_->HasAncestor(node))) {
// The node, or its parent was removed. Close the dialog.
Close();
@@ -305,7 +317,7 @@ void BookmarkEditorGtk::ApplyEdits(GtkTreeIter* selected_parent) {
if (!show_tree_ || !selected_parent) {
bookmark_utils::ApplyEditsWithNoGroupChange(
- bb_model_, parent_, node_, new_title, new_url, handler_.get());
+ bb_model_, parent_, details_, new_title, new_url, handler_.get());
return;
}
@@ -321,7 +333,7 @@ void BookmarkEditorGtk::ApplyEdits(GtkTreeIter* selected_parent) {
}
bookmark_utils::ApplyEditsWithPossibleGroupChange(
- bb_model_, new_parent, node_, new_title, new_url, handler_.get());
+ bb_model_, new_parent, details_, new_title, new_url, handler_.get());
}
void BookmarkEditorGtk::AddNewGroup(GtkTreeIter* parent, GtkTreeIter* child) {
@@ -336,10 +348,6 @@ void BookmarkEditorGtk::AddNewGroup(GtkTreeIter* parent, GtkTreeIter* child) {
-1);
}
-bool BookmarkEditorGtk::IsEditingFolder() const {
- return node_ && node_->is_folder();
-}
-
// static
void BookmarkEditorGtk::OnSelectionChanged(GtkTreeSelection* selection,
BookmarkEditorGtk* dialog) {
@@ -352,9 +360,8 @@ void BookmarkEditorGtk::OnSelectionChanged(GtkTreeSelection* selection,
// static
void BookmarkEditorGtk::OnResponse(GtkDialog* dialog, int response_id,
BookmarkEditorGtk* window) {
- if (response_id == GTK_RESPONSE_ACCEPT) {
+ if (response_id == GTK_RESPONSE_ACCEPT)
window->ApplyEdits();
- }
window->Close();
}
@@ -382,9 +389,10 @@ void BookmarkEditorGtk::OnWindowDestroy(GtkWidget* widget,
void BookmarkEditorGtk::OnEntryChanged(GtkEditable* entry,
BookmarkEditorGtk* dialog) {
gboolean can_close = TRUE;
- if (dialog->IsEditingFolder()) {
+ if (dialog->details_.type == EditDetails::NEW_FOLDER) {
if (dialog->GetInputTitle().empty()) {
- gtk_widget_modify_base(dialog->name_entry_, GTK_STATE_NORMAL, &kErrorColor);
+ gtk_widget_modify_base(dialog->name_entry_, GTK_STATE_NORMAL,
+ &kErrorColor);
can_close = FALSE;
} else {
gtk_widget_modify_base(dialog->name_entry_, GTK_STATE_NORMAL, NULL);
@@ -392,7 +400,8 @@ void BookmarkEditorGtk::OnEntryChanged(GtkEditable* entry,
} else {
GURL url(dialog->GetInputURL());
if (!url.is_valid()) {
- gtk_widget_modify_base(dialog->url_entry_, GTK_STATE_NORMAL, &kErrorColor);
+ gtk_widget_modify_base(dialog->url_entry_, GTK_STATE_NORMAL,
+ &kErrorColor);
can_close = FALSE;
} else {
gtk_widget_modify_base(dialog->url_entry_, GTK_STATE_NORMAL, NULL);
diff --git a/chrome/browser/gtk/bookmark_editor_gtk.h b/chrome/browser/gtk/bookmark_editor_gtk.h
index 8d6efd9..d2ab6eb 100644
--- a/chrome/browser/gtk/bookmark_editor_gtk.h
+++ b/chrome/browser/gtk/bookmark_editor_gtk.h
@@ -33,7 +33,7 @@ class BookmarkEditorGtk : public BookmarkEditor,
BookmarkEditorGtk(GtkWindow* window,
Profile* profile,
const BookmarkNode* parent,
- const BookmarkNode* node,
+ const EditDetails& details,
BookmarkEditor::Configuration configuration,
BookmarkEditor::Handler* handler);
@@ -90,9 +90,6 @@ class BookmarkEditorGtk : public BookmarkEditor,
// new group.
void AddNewGroup(GtkTreeIter* parent, GtkTreeIter* child);
- // Returns true if editing a folder.
- bool IsEditingFolder() const;
-
static void OnSelectionChanged(GtkTreeSelection* treeselection,
BookmarkEditorGtk* dialog);
@@ -132,8 +129,8 @@ class BookmarkEditorGtk : public BookmarkEditor,
// Initial parent to select. Is only used if node_ is NULL.
const BookmarkNode* parent_;
- // Node being edited. Is NULL if creating a new node.
- const BookmarkNode* node_;
+ // Details about the node we're editing.
+ const EditDetails details_;
// Mode used to create nodes from.
BookmarkModel* bb_model_;
diff --git a/chrome/browser/gtk/bookmark_editor_gtk_unittest.cc b/chrome/browser/gtk/bookmark_editor_gtk_unittest.cc
index 7cb3a44..de03a51 100644
--- a/chrome/browser/gtk/bookmark_editor_gtk_unittest.cc
+++ b/chrome/browser/gtk/bookmark_editor_gtk_unittest.cc
@@ -88,7 +88,8 @@ class BookmarkEditorGtkTest : public testing::Test {
// Makes sure the tree model matches that of the bookmark bar model.
TEST_F(BookmarkEditorGtkTest, ModelsMatch) {
- BookmarkEditorGtk editor(NULL, profile_.get(), NULL, NULL,
+ BookmarkEditorGtk editor(NULL, profile_.get(), NULL,
+ BookmarkEditor::EditDetails(),
BookmarkEditor::SHOW_TREE, NULL);
// The root should have two children, one for the bookmark bar node,
@@ -127,7 +128,8 @@ TEST_F(BookmarkEditorGtkTest, ModelsMatch) {
// Changes the title and makes sure parent/visual order doesn't change.
TEST_F(BookmarkEditorGtkTest, EditTitleKeepsPosition) {
- BookmarkEditorGtk editor(NULL, profile_.get(), NULL, GetNode("a"),
+ BookmarkEditorGtk editor(NULL, profile_.get(), NULL,
+ BookmarkEditor::EditDetails(GetNode("a")),
BookmarkEditor::SHOW_TREE, NULL);
gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a");
@@ -146,7 +148,8 @@ TEST_F(BookmarkEditorGtkTest, EditTitleKeepsPosition) {
// Changes the url and makes sure parent/visual order doesn't change.
TEST_F(BookmarkEditorGtkTest, EditURLKeepsPosition) {
Time node_time = GetNode("a")->date_added();
- BookmarkEditorGtk editor(NULL, profile_.get(), NULL, GetNode("a"),
+ BookmarkEditorGtk editor(NULL, profile_.get(), NULL,
+ BookmarkEditor::EditDetails(GetNode("a")),
BookmarkEditor::SHOW_TREE, NULL);
gtk_entry_set_text(GTK_ENTRY(editor.url_entry_),
GURL(base_path() + "new_a").spec().c_str());
@@ -166,7 +169,8 @@ TEST_F(BookmarkEditorGtkTest, EditURLKeepsPosition) {
// Moves 'a' to be a child of the other node.
TEST_F(BookmarkEditorGtkTest, ChangeParent) {
- BookmarkEditorGtk editor(NULL, profile_.get(), NULL, GetNode("a"),
+ BookmarkEditorGtk editor(NULL, profile_.get(), NULL,
+ BookmarkEditor::EditDetails(GetNode("a")),
BookmarkEditor::SHOW_TREE, NULL);
GtkTreeModel* store = GTK_TREE_MODEL(editor.tree_store_);
@@ -184,7 +188,8 @@ TEST_F(BookmarkEditorGtkTest, ChangeParent) {
// Moves 'a' to be a child of the other node and changes its url to new_a.
TEST_F(BookmarkEditorGtkTest, ChangeParentAndURL) {
Time node_time = GetNode("a")->date_added();
- BookmarkEditorGtk editor(NULL, profile_.get(), NULL, GetNode("a"),
+ BookmarkEditorGtk editor(NULL, profile_.get(), NULL,
+ BookmarkEditor::EditDetails(GetNode("a")),
BookmarkEditor::SHOW_TREE, NULL);
gtk_entry_set_text(GTK_ENTRY(editor.url_entry_),
@@ -204,7 +209,8 @@ TEST_F(BookmarkEditorGtkTest, ChangeParentAndURL) {
// Creates a new folder and moves a node to it.
TEST_F(BookmarkEditorGtkTest, MoveToNewParent) {
- BookmarkEditorGtk editor(NULL, profile_.get(), NULL, GetNode("a"),
+ BookmarkEditorGtk editor(NULL, profile_.get(), NULL,
+ BookmarkEditor::EditDetails(GetNode("a")),
BookmarkEditor::SHOW_TREE, NULL);
GtkTreeIter bookmark_bar_node;
@@ -251,7 +257,8 @@ TEST_F(BookmarkEditorGtkTest, MoveToNewParent) {
// Brings up the editor, creating a new URL on the bookmark bar.
TEST_F(BookmarkEditorGtkTest, NewURL) {
- BookmarkEditorGtk editor(NULL, profile_.get(), NULL, NULL,
+ BookmarkEditorGtk editor(NULL, profile_.get(), NULL,
+ BookmarkEditor::EditDetails(),
BookmarkEditor::SHOW_TREE, NULL);
gtk_entry_set_text(GTK_ENTRY(editor.url_entry_),
@@ -275,7 +282,8 @@ TEST_F(BookmarkEditorGtkTest, NewURL) {
// Brings up the editor with no tree and modifies the url.
TEST_F(BookmarkEditorGtkTest, ChangeURLNoTree) {
BookmarkEditorGtk editor(NULL, profile_.get(), NULL,
- model_->other_node()->GetChild(0),
+ BookmarkEditor::EditDetails(
+ model_->other_node()->GetChild(0)),
BookmarkEditor::NO_TREE, NULL);
gtk_entry_set_text(GTK_ENTRY(editor.url_entry_),
@@ -296,7 +304,8 @@ TEST_F(BookmarkEditorGtkTest, ChangeURLNoTree) {
// Brings up the editor with no tree and modifies only the title.
TEST_F(BookmarkEditorGtkTest, ChangeTitleNoTree) {
BookmarkEditorGtk editor(NULL, profile_.get(), NULL,
- model_->other_node()->GetChild(0),
+ BookmarkEditor::EditDetails(
+ model_->other_node()->GetChild(0)),
BookmarkEditor::NO_TREE, NULL);
gtk_entry_set_text(GTK_ENTRY(editor.name_entry_), "new_a");
diff --git a/chrome/browser/gtk/bookmark_manager_gtk.cc b/chrome/browser/gtk/bookmark_manager_gtk.cc
index 96ae1ae..a1ad0d6 100644
--- a/chrome/browser/gtk/bookmark_manager_gtk.cc
+++ b/chrome/browser/gtk/bookmark_manager_gtk.cc
@@ -224,7 +224,7 @@ void BookmarkManagerGtk::BookmarkNodeAdded(BookmarkModel* model,
if (node->is_folder()) {
GtkTreeIter iter = { 0, };
if (RecursiveFind(GTK_TREE_MODEL(left_store_), &iter, parent->id()))
- bookmark_utils::AddToTreeStoreAt(node, 0, NULL, left_store_, NULL, &iter);
+ bookmark_utils::AddToTreeStoreAt(node, 0, left_store_, NULL, &iter);
}
}
@@ -615,7 +615,7 @@ void BookmarkManagerGtk::ResetOrganizeMenu(bool left) {
void BookmarkManagerGtk::BuildLeftStore() {
GtkTreeIter select_iter;
bookmark_utils::AddToTreeStore(model_,
- model_->GetBookmarkBarNode()->id(), NULL, left_store_, &select_iter);
+ model_->GetBookmarkBarNode()->id(), left_store_, &select_iter);
gtk_tree_selection_select_iter(left_selection(), &select_iter);
// TODO(estade): is there a decent stock icon we can use here?
diff --git a/chrome/browser/gtk/bookmark_tree_model.cc b/chrome/browser/gtk/bookmark_tree_model.cc
index e8e52ca..3c23740 100644
--- a/chrome/browser/gtk/bookmark_tree_model.cc
+++ b/chrome/browser/gtk/bookmark_tree_model.cc
@@ -98,12 +98,11 @@ GtkTreeStore* MakeFolderTreeStore() {
}
void AddToTreeStore(BookmarkModel* model, int64 selected_id,
- const BookmarkNode* node_to_ignore, GtkTreeStore* store,
- GtkTreeIter* selected_iter) {
+ GtkTreeStore* store, GtkTreeIter* selected_iter) {
const BookmarkNode* root_node = model->root_node();
for (int i = 0; i < root_node->GetChildCount(); ++i) {
- AddToTreeStoreAt(root_node->GetChild(i), selected_id, node_to_ignore, store,
- selected_iter, NULL);
+ AddToTreeStoreAt(root_node->GetChild(i), selected_id, store, selected_iter,
+ NULL);
}
}
@@ -138,9 +137,9 @@ GtkCellRenderer* GetCellRendererText(GtkTreeView* tree_view) {
}
void AddToTreeStoreAt(const BookmarkNode* node, int64 selected_id,
- const BookmarkNode* node_to_ignore, GtkTreeStore* store,
- GtkTreeIter* selected_iter, GtkTreeIter* parent) {
- if (!node->is_folder() || node == node_to_ignore)
+ GtkTreeStore* store, GtkTreeIter* selected_iter,
+ GtkTreeIter* parent) {
+ if (!node->is_folder())
return;
GtkTreeIter iter;
@@ -153,8 +152,8 @@ void AddToTreeStoreAt(const BookmarkNode* node, int64 selected_id,
}
for (int i = 0; i < node->GetChildCount(); ++i) {
- AddToTreeStoreAt(node->GetChild(i), selected_id, node_to_ignore, store,
- selected_iter, &iter);
+ AddToTreeStoreAt(node->GetChild(i), selected_id, store, selected_iter,
+ &iter);
}
}
diff --git a/chrome/browser/gtk/bookmark_tree_model.h b/chrome/browser/gtk/bookmark_tree_model.h
index 01da71f..80b1984 100644
--- a/chrome/browser/gtk/bookmark_tree_model.h
+++ b/chrome/browser/gtk/bookmark_tree_model.h
@@ -41,17 +41,14 @@ GtkTreeStore* MakeFolderTreeStore();
// |recursive| indicates whether to recurse into sub-directories (if false,
// the tree store will effectively be a list). |only_folders| indicates whether
// to include bookmarks in the tree, or to only show folders.
-// If |node_to_ignore| is non-null, a node in the tree store is not created for
-// it.
void AddToTreeStore(BookmarkModel* model, int64 selected_id,
- const BookmarkNode* node_to_ignore, GtkTreeStore* store,
- GtkTreeIter* selected_iter);
+ GtkTreeStore* store, GtkTreeIter* selected_iter);
// As above, but inserts just the tree rooted at |node| as a child of |parent|.
// If |parent| is NULL, add it at the top level.
void AddToTreeStoreAt(const BookmarkNode* node, int64 selected_id,
- const BookmarkNode* node_to_ignore, GtkTreeStore* store,
- GtkTreeIter* selected_iter, GtkTreeIter* parent);
+ GtkTreeStore* store, GtkTreeIter* selected_iter,
+ GtkTreeIter* parent);
// Makes a tree view for the store. This will take ownership of |store| and the
// returned widget has a floating reference.
diff --git a/chrome/browser/sync/glue/change_processor.cc b/chrome/browser/sync/glue/change_processor.cc
index 696df04..f5669cb 100644
--- a/chrome/browser/sync/glue/change_processor.cc
+++ b/chrome/browser/sync/glue/change_processor.cc
@@ -457,7 +457,8 @@ const BookmarkNode* ChangeProcessor::CreateOrUpdateBookmarkNode(
// that can happen if both a local user change and server change occur
// within a sufficiently small time interval.
const BookmarkNode* old_dst = dst;
- dst = bookmark_utils::ApplyEditsWithNoGroupChange(model, parent, dst,
+ dst = bookmark_utils::ApplyEditsWithNoGroupChange(model, parent,
+ BookmarkEditor::EditDetails(dst),
UTF16ToWide(src->GetTitle()),
src->GetIsFolder() ? GURL() : GURL(src->GetURL()),
NULL); // NULL because we don't need a BookmarkEditor::Handler.
diff --git a/chrome/browser/views/bookmark_bubble_view.cc b/chrome/browser/views/bookmark_bubble_view.cc
index 183498f..9c4465b 100644
--- a/chrome/browser/views/bookmark_bubble_view.cc
+++ b/chrome/browser/views/bookmark_bubble_view.cc
@@ -420,7 +420,8 @@ void BookmarkBubbleView::ShowEditor() {
Close();
if (node) {
- BookmarkEditor::Show(parent, profile_, NULL, node,
+ BookmarkEditor::Show(parent, profile_, NULL,
+ BookmarkEditor::EditDetails(node),
BookmarkEditor::SHOW_TREE, NULL);
}
}
diff --git a/chrome/browser/views/bookmark_editor_view.cc b/chrome/browser/views/bookmark_editor_view.cc
index 42d6447..852649b 100644
--- a/chrome/browser/views/bookmark_editor_view.cc
+++ b/chrome/browser/views/bookmark_editor_view.cc
@@ -49,26 +49,26 @@ static const int kNewGroupButtonID = 1002;
void BookmarkEditor::Show(HWND parent_hwnd,
Profile* profile,
const BookmarkNode* parent,
- const BookmarkNode* node,
+ const EditDetails& details,
Configuration configuration,
Handler* handler) {
DCHECK(profile);
BookmarkEditorView* editor =
- new BookmarkEditorView(profile, parent, node, configuration, handler);
+ new BookmarkEditorView(profile, parent, details, configuration, handler);
editor->Show(parent_hwnd);
}
BookmarkEditorView::BookmarkEditorView(
Profile* profile,
const BookmarkNode* parent,
- const BookmarkNode* node,
+ const EditDetails& details,
BookmarkEditor::Configuration configuration,
BookmarkEditor::Handler* handler)
: profile_(profile),
tree_view_(NULL),
new_group_button_(NULL),
parent_(parent),
- node_(node),
+ details_(details),
running_menu_for_root_(false),
show_tree_(configuration == SHOW_TREE),
handler_(handler) {
@@ -87,7 +87,7 @@ BookmarkEditorView::~BookmarkEditorView() {
bool BookmarkEditorView::IsDialogButtonEnabled(
MessageBoxFlags::DialogButton button) const {
if (button == MessageBoxFlags::DIALOGBUTTON_OK) {
- if (IsEditingFolder())
+ if (details_.type == EditDetails::NEW_FOLDER)
return !title_tf_.text().empty();
const GURL url(GetInputURL());
@@ -263,19 +263,24 @@ void BookmarkEditorView::Init() {
url_tf_.SetParentOwned(false);
title_tf_.SetParentOwned(false);
- title_tf_.SetText(node_ ? node_->GetTitle() : std::wstring());
+ std::wstring title;
+ if (details_.type == EditDetails::EXISTING_NODE)
+ title = details_.existing_node->GetTitle();
+ else if (details_.type == EditDetails::NEW_FOLDER)
+ title = l10n_util::GetString(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME);
+ title_tf_.SetText(title);
title_tf_.SetController(this);
std::wstring url_text;
- if (node_ && !IsEditingFolder()) {
+ if (details_.type == EditDetails::EXISTING_NODE) {
std::wstring languages = profile_
? profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)
: std::wstring();
// The following URL is user-editable. We specify omit_username_password=
// false and unescape=false to show the original URL except IDN.
url_text =
- net::FormatUrl(node_->GetURL(), languages, false, UnescapeRule::NONE,
- NULL, NULL);
+ net::FormatUrl(details_.existing_node->GetURL(), languages, false,
+ UnescapeRule::NONE, NULL, NULL);
}
url_tf_.SetText(url_text);
url_tf_.SetController(this);
@@ -327,7 +332,7 @@ void BookmarkEditorView::Init() {
new Label(l10n_util::GetString(IDS_BOOMARK_EDITOR_NAME_LABEL)));
layout->AddView(&title_tf_);
- if (!IsEditingFolder()) {
+ if (details_.type != EditDetails::NEW_FOLDER) {
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
layout->StartRow(0, labels_column_set_id);
@@ -366,7 +371,8 @@ void BookmarkEditorView::BookmarkNodeRemoved(BookmarkModel* model,
const BookmarkNode* parent,
int index,
const BookmarkNode* node) {
- if ((node_ && node_->HasAncestor(node)) ||
+ if ((details_.type == EditDetails::EXISTING_NODE &&
+ details_.existing_node->HasAncestor(node)) ||
(parent_ && parent_->HasAncestor(node))) {
// The node, or its parent was removed. Close the dialog.
window()->Close();
@@ -447,14 +453,12 @@ BookmarkEditorView::EditorNode* BookmarkEditorView::AddNewGroup(
return new_node;
}
-bool BookmarkEditorView::IsEditingFolder() const {
- return node_ && node_->is_folder();
-}
-
void BookmarkEditorView::ExpandAndSelect() {
tree_view_->ExpandAll();
- const BookmarkNode* to_select = node_ ? node_->GetParent() : parent_;
+ const BookmarkNode* to_select = parent_;
+ if (details_.type == EditDetails::EXISTING_NODE)
+ to_select = details_.existing_node->GetParent();
int64 group_id_to_select = to_select->id();
EditorNode* b_node =
FindNodeWithID(tree_model_->GetRoot(), group_id_to_select);
@@ -478,8 +482,7 @@ void BookmarkEditorView::CreateNodes(const BookmarkNode* bb_node,
BookmarkEditorView::EditorNode* b_node) {
for (int i = 0; i < bb_node->GetChildCount(); ++i) {
const BookmarkNode* child_bb_node = bb_node->GetChild(i);
- if (child_bb_node->is_folder() &&
- (!IsEditingFolder() || child_bb_node != node_)) {
+ if (child_bb_node->is_folder()) {
EditorNode* new_b_node = new EditorNode(child_bb_node->GetTitle(),
child_bb_node->id());
b_node->Add(b_node->GetChildCount(), new_b_node);
@@ -526,7 +529,7 @@ void BookmarkEditorView::ApplyEdits(EditorNode* parent) {
if (!show_tree_) {
bookmark_utils::ApplyEditsWithNoGroupChange(
- bb_model_, parent_, node_, new_title, new_url, handler_.get());
+ bb_model_, parent_, details_, new_title, new_url, handler_.get());
return;
}
@@ -536,7 +539,7 @@ void BookmarkEditorView::ApplyEdits(EditorNode* parent) {
bb_model_->root_node(), tree_model_->GetRoot(), parent, &new_parent);
bookmark_utils::ApplyEditsWithPossibleGroupChange(
- bb_model_, new_parent, node_, new_title, new_url, handler_.get());
+ bb_model_, new_parent, details_, new_title, new_url, handler_.get());
}
void BookmarkEditorView::ApplyNameChangesAndCreateNewGroups(
diff --git a/chrome/browser/views/bookmark_editor_view.h b/chrome/browser/views/bookmark_editor_view.h
index 571c9ff..f2d6498 100644
--- a/chrome/browser/views/bookmark_editor_view.h
+++ b/chrome/browser/views/bookmark_editor_view.h
@@ -69,7 +69,7 @@ class BookmarkEditorView : public BookmarkEditor,
BookmarkEditorView(Profile* profile,
const BookmarkNode* parent,
- const BookmarkNode* node,
+ const EditDetails& details,
BookmarkEditor::Configuration configuration,
BookmarkEditor::Handler* handler);
@@ -167,7 +167,7 @@ class BookmarkEditorView : public BookmarkEditor,
EditorNode* CreateRootNode();
// Adds and creates a child node in b_node for all children of bb_node that
- // are groups, except for |node_| if editing a folder.
+ // are groups.
void CreateNodes(const BookmarkNode* bb_node, EditorNode* b_node);
// Returns the node with the specified id, or NULL if one can't be found.
@@ -215,9 +215,6 @@ class BookmarkEditorView : public BookmarkEditor,
// internally by NewGroup and broken into a separate method for testing.
EditorNode* AddNewGroup(EditorNode* parent);
- // Returns true if editing a folder.
- bool IsEditingFolder() const;
-
// Profile the entry is from.
Profile* profile_;
@@ -236,11 +233,11 @@ class BookmarkEditorView : public BookmarkEditor,
// Used for editing the title.
views::Textfield title_tf_;
- // Initial parent to select. Is only used if node_ is NULL.
+ // Initial parent to select. Is only used if |details_.existing_node| is
+ // NULL.
const BookmarkNode* parent_;
- // Node being edited. Is NULL if creating a new node.
- const BookmarkNode* node_;
+ const EditDetails details_;
// The context menu.
scoped_ptr<views::SimpleMenuModel> context_menu_contents_;
diff --git a/chrome/browser/views/bookmark_editor_view_unittest.cc b/chrome/browser/views/bookmark_editor_view_unittest.cc
index 789e1ee1..f697500 100644
--- a/chrome/browser/views/bookmark_editor_view_unittest.cc
+++ b/chrome/browser/views/bookmark_editor_view_unittest.cc
@@ -55,11 +55,11 @@ class BookmarkEditorViewTest : public testing::Test {
void CreateEditor(Profile* profile,
const BookmarkNode* parent,
- const BookmarkNode* node,
+ const BookmarkEditor::EditDetails& details,
BookmarkEditor::Configuration configuration,
BookmarkEditor::Handler* handler) {
- editor_.reset(new BookmarkEditorView(profile, parent, node, configuration,
- handler));
+ editor_.reset(new BookmarkEditorView(profile, parent, details,
+ configuration, handler));
}
void SetTitleText(const std::wstring& title) {
@@ -121,8 +121,8 @@ class BookmarkEditorViewTest : public testing::Test {
// Makes sure the tree model matches that of the bookmark bar model.
TEST_F(BookmarkEditorViewTest, ModelsMatch) {
- CreateEditor(profile_.get(), NULL, NULL, BookmarkEditorView::SHOW_TREE,
- NULL);
+ CreateEditor(profile_.get(), NULL, BookmarkEditor::EditDetails(),
+ BookmarkEditorView::SHOW_TREE, NULL);
BookmarkEditorView::EditorNode* editor_root = editor_tree_model()->GetRoot();
// The root should have two children, one for the bookmark bar node,
// the other for the 'other bookmarks' folder.
@@ -146,7 +146,7 @@ TEST_F(BookmarkEditorViewTest, ModelsMatch) {
// Changes the title and makes sure parent/visual order doesn't change.
TEST_F(BookmarkEditorViewTest, EditTitleKeepsPosition) {
- CreateEditor(profile_.get(), NULL, GetNode("a"),
+ CreateEditor(profile_.get(), NULL, BookmarkEditor::EditDetails(GetNode("a")),
BookmarkEditorView::SHOW_TREE, NULL);
SetTitleText(L"new_a");
@@ -163,7 +163,7 @@ TEST_F(BookmarkEditorViewTest, EditTitleKeepsPosition) {
TEST_F(BookmarkEditorViewTest, EditURLKeepsPosition) {
Time node_time = Time::Now() + TimeDelta::FromDays(2);
GetMutableNode("a")->set_date_added(node_time);
- CreateEditor(profile_.get(), NULL, GetNode("a"),
+ CreateEditor(profile_.get(), NULL, BookmarkEditor::EditDetails(GetNode("a")),
BookmarkEditorView::SHOW_TREE, NULL);
SetURLText(UTF8ToWide(GURL(base_path() + "new_a").spec()));
@@ -180,7 +180,7 @@ TEST_F(BookmarkEditorViewTest, EditURLKeepsPosition) {
// Moves 'a' to be a child of the other node.
TEST_F(BookmarkEditorViewTest, ChangeParent) {
- CreateEditor(profile_.get(), NULL, GetNode("a"),
+ CreateEditor(profile_.get(), NULL, BookmarkEditor::EditDetails(GetNode("a")),
BookmarkEditorView::SHOW_TREE, NULL);
ApplyEdits(editor_tree_model()->GetRoot()->GetChild(1));
@@ -194,7 +194,7 @@ TEST_F(BookmarkEditorViewTest, ChangeParent) {
TEST_F(BookmarkEditorViewTest, ChangeParentAndURL) {
Time node_time = Time::Now() + TimeDelta::FromDays(2);
GetMutableNode("a")->set_date_added(node_time);
- CreateEditor(profile_.get(), NULL, GetNode("a"),
+ CreateEditor(profile_.get(), NULL, BookmarkEditor::EditDetails(GetNode("a")),
BookmarkEditorView::SHOW_TREE, NULL);
SetURLText(UTF8ToWide(GURL(base_path() + "new_a").spec()));
@@ -209,7 +209,7 @@ TEST_F(BookmarkEditorViewTest, ChangeParentAndURL) {
// Creates a new folder and moves a node to it.
TEST_F(BookmarkEditorViewTest, MoveToNewParent) {
- CreateEditor(profile_.get(), NULL, GetNode("a"),
+ CreateEditor(profile_.get(), NULL, BookmarkEditor::EditDetails(GetNode("a")),
BookmarkEditorView::SHOW_TREE, NULL);
// Create two nodes: "F21" as a child of "F2" and "F211" as a child of "F21".
@@ -242,8 +242,8 @@ TEST_F(BookmarkEditorViewTest, MoveToNewParent) {
// Brings up the editor, creating a new URL on the bookmark bar.
TEST_F(BookmarkEditorViewTest, NewURL) {
- CreateEditor(profile_.get(), NULL, NULL, BookmarkEditorView::SHOW_TREE,
- NULL);
+ CreateEditor(profile_.get(), NULL, BookmarkEditor::EditDetails(),
+ BookmarkEditorView::SHOW_TREE, NULL);
SetURLText(UTF8ToWide(GURL(base_path() + "a").spec()));
SetTitleText(L"new_a");
@@ -262,7 +262,8 @@ TEST_F(BookmarkEditorViewTest, NewURL) {
// Brings up the editor with no tree and modifies the url.
TEST_F(BookmarkEditorViewTest, ChangeURLNoTree) {
- CreateEditor(profile_.get(), NULL, model_->other_node()->GetChild(0),
+ CreateEditor(profile_.get(), NULL,
+ BookmarkEditor::EditDetails(model_->other_node()->GetChild(0)),
BookmarkEditorView::NO_TREE, NULL);
SetURLText(UTF8ToWide(GURL(base_path() + "a").spec()));
@@ -281,7 +282,8 @@ TEST_F(BookmarkEditorViewTest, ChangeURLNoTree) {
// Brings up the editor with no tree and modifies only the title.
TEST_F(BookmarkEditorViewTest, ChangeTitleNoTree) {
- CreateEditor(profile_.get(), NULL, model_->other_node()->GetChild(0),
+ CreateEditor(profile_.get(), NULL,
+ BookmarkEditor::EditDetails(model_->other_node()->GetChild(0)),
BookmarkEditorView::NO_TREE, NULL);
SetTitleText(L"new_a");
@@ -296,62 +298,59 @@ TEST_F(BookmarkEditorViewTest, ChangeTitleNoTree) {
EXPECT_EQ(L"new_a", new_node->GetTitle());
}
-// Modifies the title of a folder.
-TEST_F(BookmarkEditorViewTest, ModifyFolderTitle) {
- int64 start_id = model_->GetBookmarkBarNode()->GetChild(2)->id();
- CreateEditor(profile_.get(), NULL, model_->GetBookmarkBarNode()->GetChild(2),
- BookmarkEditorView::SHOW_TREE, NULL);
+// Creates a new folder.
+TEST_F(BookmarkEditorViewTest, NewFolder) {
+ BookmarkEditor::EditDetails details;
+ details.urls.push_back(std::make_pair(GURL(base_path() + "x"), L"z"));
+ details.type = BookmarkEditor::EditDetails::NEW_FOLDER;
+ CreateEditor(profile_.get(), model_->GetBookmarkBarNode(),
+ details, BookmarkEditorView::SHOW_TREE, NULL);
// The url field shouldn't be visible.
EXPECT_FALSE(URLTFHasParent());
SetTitleText(L"new_F");
- // Make sure the tree isn't showing the folder we're editing.
- EXPECT_EQ(1, editor_tree_model()->GetRoot()->GetChild(0)->GetChildCount());
-
ApplyEdits(editor_tree_model()->GetRoot()->GetChild(0));
- // Make sure the folder we edited is still there.
- ASSERT_EQ(3, model_->GetBookmarkBarNode()->GetChildCount());
- EXPECT_EQ(start_id, model_->GetBookmarkBarNode()->GetChild(2)->id());
- EXPECT_TRUE(model_->GetBookmarkBarNode()->GetChild(2)->is_folder());
- EXPECT_EQ(L"new_F", model_->GetBookmarkBarNode()->GetChild(2)->GetTitle());
+ // Make sure the folder was created.
+ ASSERT_EQ(4, model_->GetBookmarkBarNode()->GetChildCount());
+ const BookmarkNode* new_node =
+ model_->GetBookmarkBarNode()->GetChild(3);
+ EXPECT_EQ(BookmarkNode::FOLDER, new_node->GetType());
+ EXPECT_EQ(L"new_F", new_node->GetTitle());
+ // The node should have one child.
+ ASSERT_EQ(1, new_node->GetChildCount());
+ const BookmarkNode* new_child = new_node->GetChild(0);
+ // Make sure the child url/title match.
+ EXPECT_EQ(BookmarkNode::URL, new_child->GetType());
+ EXPECT_EQ(details.urls[0].second, new_child->GetTitle());
+ EXPECT_TRUE(details.urls[0].first == new_child->GetURL());
}
-// Moves a folder.
+// Creates a new folder and selects a different folder for the folder to appear
+// in then the editor is initially created showing.
TEST_F(BookmarkEditorViewTest, MoveFolder) {
- const BookmarkNode* node = model_->GetBookmarkBarNode()->GetChild(2);
- int64 start_id = node->id();
- CreateEditor(profile_.get(), NULL, node, BookmarkEditorView::SHOW_TREE, NULL);
+ BookmarkEditor::EditDetails details;
+ details.urls.push_back(std::make_pair(GURL(base_path() + "x"), L"z"));
+ details.type = BookmarkEditor::EditDetails::NEW_FOLDER;
+ CreateEditor(profile_.get(), model_->GetBookmarkBarNode(),
+ details, BookmarkEditorView::SHOW_TREE, NULL);
SetTitleText(L"new_F");
- // Moves to the 'other' folder.
+ // Create the folder in the 'other' folder.
ApplyEdits(editor_tree_model()->GetRoot()->GetChild(1));
// Make sure the folder we edited is still there.
ASSERT_EQ(3, model_->other_node()->GetChildCount());
- EXPECT_EQ(node, model_->other_node()->GetChild(2));
- EXPECT_TRUE(node->is_folder());
- EXPECT_EQ(L"new_F", node->GetTitle());
-}
-
-// Moves a folder under a new folder.
-TEST_F(BookmarkEditorViewTest, MoveFolderNewParent) {
- const BookmarkNode* node = model_->GetBookmarkBarNode()->GetChild(2);
- CreateEditor(profile_.get(), NULL, node, BookmarkEditorView::SHOW_TREE, NULL);
-
- BookmarkEditorView::EditorNode* other =
- editor_tree_model()->GetRoot()->GetChild(1);
- BookmarkEditorView::EditorNode* new_f = AddNewGroup(other);
- new_f->SetTitle(L"new_f");
-
- ApplyEdits(new_f);
-
- // Make sure the folder we edited is still there.
- ASSERT_EQ(3, model_->other_node()->GetChildCount());
- const BookmarkNode* new_folder = model_->other_node()->GetChild(2);
- EXPECT_EQ(L"new_f", new_folder->GetTitle());
- ASSERT_EQ(1, new_folder->GetChildCount());
- ASSERT_EQ(node, new_folder->GetChild(0));
+ const BookmarkNode* new_node = model_->other_node()->GetChild(2);
+ EXPECT_EQ(BookmarkNode::FOLDER, new_node->GetType());
+ EXPECT_EQ(L"new_F", new_node->GetTitle());
+ // The node should have one child.
+ ASSERT_EQ(1, new_node->GetChildCount());
+ const BookmarkNode* new_child = new_node->GetChild(0);
+ // Make sure the child url/title match.
+ EXPECT_EQ(BookmarkNode::URL, new_child->GetType());
+ EXPECT_EQ(details.urls[0].second, new_child->GetTitle());
+ EXPECT_TRUE(details.urls[0].first == new_child->GetURL());
}
diff --git a/chrome/browser/views/tabs/tab.cc b/chrome/browser/views/tabs/tab.cc
index 9ff31b0..f69ced8 100644
--- a/chrome/browser/views/tabs/tab.cc
+++ b/chrome/browser/views/tabs/tab.cc
@@ -98,10 +98,8 @@ class Tab::TabContextMenuContents : public views::SimpleMenuModel,
IDS_TAB_CXMENU_CLOSETABSOPENEDBY);
AddSeparator();
AddItemWithStringId(TabStripModel::CommandRestoreTab, IDS_RESTORE_TAB);
-#if defined(OS_WIN)
AddItemWithStringId(TabStripModel::CommandBookmarkAllTabs,
IDS_TAB_CXMENU_BOOKMARK_ALL_TABS);
-#endif
menu_.reset(new views::Menu2(this));
}
diff --git a/chrome/test/live_sync/bookmark_model_verifier.cc b/chrome/test/live_sync/bookmark_model_verifier.cc
index 517a3cc..a827f10 100644
--- a/chrome/test/live_sync/bookmark_model_verifier.cc
+++ b/chrome/test/live_sync/bookmark_model_verifier.cc
@@ -237,9 +237,10 @@ const BookmarkNode* BookmarkModelVerifier::SetURL(BookmarkModel* model,
const BookmarkNode* v_node = NULL;
FindNodeInVerifier(model, node, &v_node);
const BookmarkNode* result = bookmark_utils::ApplyEditsWithNoGroupChange(
- model, node->GetParent(), node, node->GetTitle(), new_url, NULL);
+ model, node->GetParent(), BookmarkEditor::EditDetails(node),
+ node->GetTitle(), new_url, NULL);
bookmark_utils::ApplyEditsWithNoGroupChange(verifier_, v_node->GetParent(),
- v_node, v_node->GetTitle(), new_url, NULL);
+ BookmarkEditor::EditDetails(v_node), v_node->GetTitle(), new_url, NULL);
return result;
}
diff --git a/chrome/test/live_sync/two_client_live_bookmarks_sync_test.cc b/chrome/test/live_sync/two_client_live_bookmarks_sync_test.cc
index 78cedd9..368605a 100644
--- a/chrome/test/live_sync/two_client_live_bookmarks_sync_test.cc
+++ b/chrome/test/live_sync/two_client_live_bookmarks_sync_test.cc
@@ -389,10 +389,10 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveBookmarksSyncTest,
{
const BookmarkNode* google_one = GetByUniqueURL(model_one, initial_url);
const BookmarkNode* google_two = GetByUniqueURL(model_two, initial_url);
- bookmark_utils::ApplyEditsWithNoGroupChange(model_one, bbn_one, google_one,
- title, second_url, NULL);
- bookmark_utils::ApplyEditsWithNoGroupChange(model_two, bbn_two, google_two,
- title, third_url, NULL);
+ bookmark_utils::ApplyEditsWithNoGroupChange(model_one, bbn_one,
+ BookmarkEditor::EditDetails(google_one), title, second_url, NULL);
+ bookmark_utils::ApplyEditsWithNoGroupChange(model_two, bbn_two,
+ BookmarkEditor::EditDetails(google_two), title, third_url, NULL);
}
ASSERT_TRUE(client1()->AwaitMutualSyncCycleCompletionWithConflict(client2()));
BookmarkModelVerifier::ExpectModelsMatch(model_one, model_two);