summaryrefslogtreecommitdiffstats
path: root/chrome/browser/bookmarks
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-08 20:56:54 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-08 20:56:54 +0000
commitb3ac5c830a92eecabb94160169e72415d59a5509 (patch)
tree516d1fe562c060b0a6a04a2796c3909b2646b601 /chrome/browser/bookmarks
parent378c3fdf56d3f6328632f0e994a678c9387c78d3 (diff)
downloadchromium_src-b3ac5c830a92eecabb94160169e72415d59a5509.zip
chromium_src-b3ac5c830a92eecabb94160169e72415d59a5509.tar.gz
chromium_src-b3ac5c830a92eecabb94160169e72415d59a5509.tar.bz2
Adds the ability to create a bookmark folder populated with a bookmark
for each open tab. I've currently wired this up on windows, will wire up rest of platforms in a separate cl. BUG=2935 TEST=on Windows open multiple tabs, right click on a tab and choose 'Bookmark all tabs'. You should then get the bookmark editor with no url field. Accepting the dialog should result in creating a new folder with a bookmark for each of the open tabs. Review URL: http://codereview.chromium.org/270021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28446 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/bookmarks')
-rw-r--r--chrome/browser/bookmarks/bookmark_editor.h11
-rw-r--r--chrome/browser/bookmarks/bookmark_utils.cc37
-rw-r--r--chrome/browser/bookmarks/bookmark_utils.h13
3 files changed, 54 insertions, 7 deletions
diff --git a/chrome/browser/bookmarks/bookmark_editor.h b/chrome/browser/bookmarks/bookmark_editor.h
index b7dc15b..982c314 100644
--- a/chrome/browser/bookmarks/bookmark_editor.h
+++ b/chrome/browser/bookmarks/bookmark_editor.h
@@ -28,9 +28,14 @@ class BookmarkEditor {
NO_TREE
};
- // Shows the platform specific BookmarkEditor subclass editing |node|. If
- // |node| is NULL a new entry is created initially parented to |parent|. If
- // |show_tree| is false the tree is not shown. BookmarkEditor takes
+ // 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.
static void Show(gfx::NativeView parent_window,
diff --git a/chrome/browser/bookmarks/bookmark_utils.cc b/chrome/browser/bookmarks/bookmark_utils.cc
index 945e22a..95cfe64 100644
--- a/chrome/browser/bookmarks/bookmark_utils.cc
+++ b/chrome/browser/bookmarks/bookmark_utils.cc
@@ -549,14 +549,14 @@ const BookmarkNode* ApplyEditsWithPossibleGroupChange(BookmarkModel* model,
Time date_added = node->date_added();
if (new_parent == node->GetParent()) {
// The parent is the same.
- if (new_url != node->GetURL()) {
+ 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 (new_url != node->GetURL()) {
+ } 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,
@@ -594,13 +594,11 @@ void ToggleWhenVisible(Profile* profile) {
NotificationService::NoDetails());
}
-// static
void RegisterPrefs(PrefService* prefs) {
prefs->RegisterDictionaryPref(prefs::kBookmarkManagerPlacement);
prefs->RegisterIntegerPref(prefs::kBookmarkManagerSplitLocation, -1);
}
-// static
void RegisterUserPrefs(PrefService* prefs) {
// Formerly in BookmarkBarView
prefs->RegisterBooleanPref(prefs::kShowBookmarkBar, false);
@@ -613,4 +611,35 @@ void RegisterUserPrefs(PrefService* prefs) {
prefs->RegisterIntegerPref(prefs::kBookmarkTablePathWidth, -1);
}
+bool GetURLAndTitleToBookmark(TabContents* tab_contents,
+ GURL* url,
+ std::wstring* title) {
+ if (!tab_contents->ShouldDisplayURL())
+ return false;
+ *url = tab_contents->GetURL();
+ if (url->is_empty() || !url->is_valid())
+ return false;
+ *title = UTF16ToWideHack(tab_contents->GetTitle());
+ return true;
+}
+
+const BookmarkNode* CreateBookmarkForAllTabs(Browser* browser) {
+ BookmarkModel* model = browser->profile()->GetBookmarkModel();
+ if (!model || !model->IsLoaded())
+ return NULL;
+
+ const BookmarkNode* parent = model->GetParentForNewNodes();
+ const BookmarkNode* folder = model->AddGroup(
+ parent, parent->GetChildCount(),
+ l10n_util::GetString(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME));
+ for (int i = 0; i < browser->tab_count(); ++i) {
+ GURL url;
+ std::wstring title;
+ if (GetURLAndTitleToBookmark(browser->GetTabContentsAt(i), &url, &title)) {
+ model->AddURL(folder, folder->GetChildCount(), title, url);
+ }
+ }
+ return folder;
+}
+
} // namespace bookmark_utils
diff --git a/chrome/browser/bookmarks/bookmark_utils.h b/chrome/browser/bookmarks/bookmark_utils.h
index 0c4ecab..d45ecad 100644
--- a/chrome/browser/bookmarks/bookmark_utils.h
+++ b/chrome/browser/bookmarks/bookmark_utils.h
@@ -16,9 +16,11 @@
class BookmarkModel;
class BookmarkNode;
+class Browser;
class PageNavigator;
class PrefService;
class Profile;
+class TabContents;
namespace views {
class DropTargetEvent;
@@ -180,6 +182,17 @@ void RegisterPrefs(PrefService* prefs);
// Register user prefs for BookmarkBar, BookmarkView, ...
void RegisterUserPrefs(PrefService* prefs);
+// Gets the url and title to use in creating a bookmark for the specified
+// TabContents. Returns false if a bookmark shouldn't be created for the
+// specified TabContents.
+bool GetURLAndTitleToBookmark(TabContents* tab_contents,
+ GURL* url,
+ std::wstring* title);
+
+// Creates a new folder containing a bookmark for each of the tabs in
+// |browser|. This returns null if the bookmark model isn't loaded.
+const BookmarkNode* CreateBookmarkForAllTabs(Browser* browser);
+
// Number of bookmarks we'll open before prompting the user to see if they
// really want to open all.
//