summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/bookmarks/bookmark_context_menu.cc29
-rw-r--r--chrome/browser/bookmarks/bookmark_manager.h25
-rw-r--r--chrome/browser/bookmarks/bookmark_utils.cc7
-rw-r--r--chrome/browser/bookmarks/bookmark_utils.h3
-rw-r--r--chrome/browser/browser_prefs.cc3
-rw-r--r--chrome/browser/gtk/bookmark_bar_gtk.cc13
-rw-r--r--chrome/browser/gtk/bookmark_editor_gtk.cc25
-rw-r--r--chrome/browser/gtk/bookmark_manager_gtk.cc212
-rw-r--r--chrome/browser/gtk/bookmark_manager_gtk.h79
-rw-r--r--chrome/browser/gtk/bookmark_tree_model.cc42
-rw-r--r--chrome/browser/gtk/bookmark_tree_model.h26
-rw-r--r--chrome/browser/views/bookmark_manager_view.cc20
-rw-r--r--chrome/browser/views/bookmark_manager_view.h3
-rw-r--r--chrome/chrome.gyp3
14 files changed, 434 insertions, 56 deletions
diff --git a/chrome/browser/bookmarks/bookmark_context_menu.cc b/chrome/browser/bookmarks/bookmark_context_menu.cc
index 35389f4..3b1247d 100644
--- a/chrome/browser/bookmarks/bookmark_context_menu.cc
+++ b/chrome/browser/bookmarks/bookmark_context_menu.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,6 +7,7 @@
#include "app/l10n_util.h"
#include "base/compiler_specific.h"
#include "chrome/browser/bookmarks/bookmark_editor.h"
+#include "chrome/browser/bookmarks/bookmark_manager.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/bookmarks/bookmark_utils.h"
#include "chrome/browser/browser.h"
@@ -22,7 +23,6 @@
// TODO(port): Port these files.
#if defined(OS_WIN)
#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/browser/views/bookmark_manager_view.h"
#include "views/window/window.h"
#endif
@@ -106,12 +106,10 @@ class EditFolderController : public InputWindowDialog::Delegate,
ALLOW_UNUSED BookmarkNode* node =
model_->AddGroup(node_, node_->GetChildCount(), text);
if (show_in_manager_) {
-#if defined(OS_WIN)
- BookmarkManagerView* manager = BookmarkManagerView::current();
- if (manager && manager->profile() == profile_)
- manager->SelectInTree(node);
+#if defined(OS_WIN) || defined(OS_LINUX)
+ BookmarkManager::SelectInTree(profile_, node);
#else
- NOTIMPLEMENTED() << "BookmarkManagerView not yet implemented";
+ NOTIMPLEMENTED() << "BookmarkManager not yet implemented";
#endif
}
} else {
@@ -195,11 +193,7 @@ class SelectOnCreationHandler : public BookmarkEditor::Handler {
}
virtual void NodeCreated(BookmarkNode* new_node) {
- BookmarkManagerView* manager = BookmarkManagerView::current();
- if (!manager || manager->profile() != profile_)
- return; // Manager no longer showing, or showing a different profile.
-
- manager->SelectInTree(new_node);
+ BookmarkManager::SelectInTree(profile_, new_node);
}
private:
@@ -336,7 +330,7 @@ void BookmarkContextMenu::ExecuteCommand(int id) {
}
if (selection_[0]->is_url()) {
-#if defined(OS_WIN)
+#if defined(OS_WIN) || defined(OS_LINUX)
BookmarkEditor::Configuration editor_config;
if (configuration_ == BOOKMARK_BAR)
editor_config = BookmarkEditor::SHOW_TREE;
@@ -407,9 +401,8 @@ void BookmarkContextMenu::ExecuteCommand(int id) {
return;
}
-#if defined(OS_WIN)
- if (BookmarkManagerView::current())
- BookmarkManagerView::current()->SelectInTree(selection_[0]);
+#if defined(OS_WIN) || defined(OS_LINUX)
+ BookmarkManager::SelectInTree(profile_, selection_[0]);
#else
NOTIMPLEMENTED() << "Bookmark Manager not implemented";
#endif
@@ -417,8 +410,8 @@ void BookmarkContextMenu::ExecuteCommand(int id) {
case IDS_BOOKMARK_MANAGER:
UserMetrics::RecordAction(L"ShowBookmarkManager", profile_);
-#if defined(OS_WIN)
- BookmarkManagerView::Show(profile_);
+#if defined(OS_WIN) || defined(OS_LINUX)
+ BookmarkManager::Show(profile_);
#else
NOTIMPLEMENTED() << "Bookmark Manager not implemented";
#endif
diff --git a/chrome/browser/bookmarks/bookmark_manager.h b/chrome/browser/bookmarks/bookmark_manager.h
new file mode 100644
index 0000000..28a210b
--- /dev/null
+++ b/chrome/browser/bookmarks/bookmark_manager.h
@@ -0,0 +1,25 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_MANAGER_H_
+#define CHROME_BROWSER_BOOKMARKS_BOOKMARK_MANAGER_H_
+
+class BookmarkNode;
+class PrefService;
+class Profile;
+
+// Cross-platform API for interacting with BookmarkManager views.
+// Implemented alongside the platform-specific view classes.
+class BookmarkManager {
+ public:
+ // Select |node| in the tree view of the bookmark manager, but only if the
+ // manager is showing and is for |profile|.
+ static void SelectInTree(Profile* profile, BookmarkNode* node);
+
+ // Show the bookmark manager for |profile|. Only one bookmark manager shows
+ // at a time, so if another one is showing, this does nothing.
+ static void Show(Profile* profile);
+};
+
+#endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_MANAGER_H_
diff --git a/chrome/browser/bookmarks/bookmark_utils.cc b/chrome/browser/bookmarks/bookmark_utils.cc
index c3e6dd3..d951df9 100644
--- a/chrome/browser/bookmarks/bookmark_utils.cc
+++ b/chrome/browser/bookmarks/bookmark_utils.cc
@@ -608,6 +608,13 @@ 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);
diff --git a/chrome/browser/bookmarks/bookmark_utils.h b/chrome/browser/bookmarks/bookmark_utils.h
index e161a81..2a7cbda 100644
--- a/chrome/browser/bookmarks/bookmark_utils.h
+++ b/chrome/browser/bookmarks/bookmark_utils.h
@@ -163,6 +163,9 @@ void ApplyEditsWithPossibleGroupChange(BookmarkModel* model,
// all tabs. This is a preference modifier, not a visual modifier.
void ToggleWhenVisible(Profile* profile);
+// Register local state prefs for bookmark bar view.
+void RegisterPrefs(PrefService* prefs);
+
// Register user prefs for BookmarkBar, BookmarkView, ...
void RegisterUserPrefs(PrefService* prefs);
diff --git a/chrome/browser/browser_prefs.cc b/chrome/browser/browser_prefs.cc
index 014c7b6..bfca089 100644
--- a/chrome/browser/browser_prefs.cc
+++ b/chrome/browser/browser_prefs.cc
@@ -26,7 +26,6 @@
#if defined(OS_WIN) // TODO(port): whittle this down as we port
#include "chrome/browser/task_manager.h"
#include "chrome/browser/views/blocked_popup_container.h"
-#include "chrome/browser/views/bookmark_manager_view.h"
#include "chrome/browser/views/frame/browser_view.h"
#include "chrome/browser/views/keyword_editor_view.h"
#include "chrome/browser/views/page_info_window.h"
@@ -45,8 +44,8 @@ void RegisterAllPrefs(PrefService* user_prefs, PrefService* local_state) {
SafeBrowsingService::RegisterPrefs(local_state);
browser_shutdown::RegisterPrefs(local_state);
chrome_browser_net::RegisterPrefs(local_state);
+ bookmark_utils::RegisterPrefs(local_state);
#if defined(OS_WIN) // TODO(port): whittle this down as we port
- BookmarkManagerView::RegisterPrefs(local_state);
BrowserView::RegisterBrowserViewPrefs(local_state);
PageInfoWindow::RegisterPrefs(local_state);
TaskManager::RegisterPrefs(local_state);
diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc
index 577105a..4a9e904 100644
--- a/chrome/browser/gtk/bookmark_bar_gtk.cc
+++ b/chrome/browser/gtk/bookmark_bar_gtk.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/bookmarks/bookmark_utils.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/gtk/bookmark_menu_controller_gtk.h"
+#include "chrome/browser/gtk/bookmark_tree_model.h"
#include "chrome/browser/gtk/custom_button.h"
#include "chrome/browser/gtk/dnd_registry.h"
#include "chrome/browser/gtk/gtk_chrome_button.h"
@@ -408,18 +409,12 @@ void BookmarkBarGtk::ConfigureButtonForNode(BookmarkNode* node,
gtk_image_new_from_pixbuf(pixbuf));
g_object_unref(pixbuf);
} else {
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- static GdkPixbuf* default_bookmark_icon = rb.GetPixbufNamed(
- IDR_DEFAULT_FAVICON);
- gtk_button_set_image(GTK_BUTTON(button),
- gtk_image_new_from_pixbuf(default_bookmark_icon));
+ gtk_button_set_image(GTK_BUTTON(button),
+ gtk_image_new_from_pixbuf(bookmark_utils::GetFolderIcon()));
}
} else {
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- static GdkPixbuf* default_bookmark_icon = rb.GetPixbufNamed(
- IDR_BOOKMARK_BAR_FOLDER);
gtk_button_set_image(GTK_BUTTON(button),
- gtk_image_new_from_pixbuf(default_bookmark_icon));
+ gtk_image_new_from_pixbuf(bookmark_utils::GetDefaultFavicon()));
}
SetButtonTextColors(button);
diff --git a/chrome/browser/gtk/bookmark_editor_gtk.cc b/chrome/browser/gtk/bookmark_editor_gtk.cc
index e8a3a93..8aa6c05 100644
--- a/chrome/browser/gtk/bookmark_editor_gtk.cc
+++ b/chrome/browser/gtk/bookmark_editor_gtk.cc
@@ -168,17 +168,25 @@ void BookmarkEditorGtk::Init(GtkWindow* parent_window) {
if (show_tree_) {
GtkTreeIter selected_iter;
int selected_id = node_ ? node_->GetParent()->id() : 0;
- bookmark_utils::BuildTreeStoreFrom(bb_model_, selected_id, &tree_store_,
- &selected_iter);
+ tree_store_ = bookmark_utils::MakeFolderTreeStore();
+ bookmark_utils::AddToTreeStore(bb_model_, selected_id,
+ tree_store_, &selected_iter);
- // TODO(erg): Figure out how to place icons here.
+ GtkTreeViewColumn* icon_column =
+ gtk_tree_view_column_new_with_attributes(
+ "", gtk_cell_renderer_pixbuf_new(), "pixbuf",
+ bookmark_utils::FOLDER_ICON, NULL);
GtkTreeViewColumn* name_column =
gtk_tree_view_column_new_with_attributes(
- "Folder", gtk_cell_renderer_text_new(), "text", 0, NULL);
+ "", gtk_cell_renderer_text_new(), "text",
+ bookmark_utils::FOLDER_NAME, NULL);
tree_view_ = gtk_tree_view_new_with_model(GTK_TREE_MODEL(tree_store_));
+ // Let |tree_view| own the store.
+ g_object_unref(tree_store_);
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree_view_), FALSE);
- gtk_tree_view_insert_column(GTK_TREE_VIEW(tree_view_), name_column, -1);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view_), icon_column);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view_), name_column);
gtk_widget_set_size_request(tree_view_, kTreeWidth, kTreeHeight);
tree_selection_ = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view_));
@@ -330,8 +338,11 @@ void BookmarkEditorGtk::AddNewGroup(GtkTreeIter* parent, GtkTreeIter* child) {
gtk_tree_store_append(tree_store_, child, parent);
gtk_tree_store_set(
tree_store_, child,
- 0, l10n_util::GetStringUTF8(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME).c_str(),
- 1, 0,
+ bookmark_utils::FOLDER_ICON,
+ bookmark_utils::GetFolderIcon(),
+ bookmark_utils::FOLDER_NAME,
+ l10n_util::GetStringUTF8(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME).c_str(),
+ bookmark_utils::ITEM_ID, 0,
-1);
}
diff --git a/chrome/browser/gtk/bookmark_manager_gtk.cc b/chrome/browser/gtk/bookmark_manager_gtk.cc
new file mode 100644
index 0000000..f8f1c15
--- /dev/null
+++ b/chrome/browser/gtk/bookmark_manager_gtk.cc
@@ -0,0 +1,212 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/gtk/bookmark_manager_gtk.h"
+
+#include "app/l10n_util.h"
+#include "chrome/browser/bookmarks/bookmark_manager.h"
+#include "chrome/browser/gtk/bookmark_tree_model.h"
+#include "chrome/browser/profile.h"
+#include "grit/generated_resources.h"
+
+namespace {
+
+// Padding between "Search:" and the entry field, in pixels.
+const int kSearchPadding = 5;
+
+// We only have one manager open at a time.
+BookmarkManagerGtk* manager = NULL;
+
+gboolean OnWindowDelete(GtkWidget* widget, GdkEvent* event, gpointer unused) {
+ gtk_widget_destroy(widget);
+ return FALSE;
+}
+
+void OnWindowDestroy(GtkWidget* widget,
+ BookmarkManagerGtk* bookmark_manager) {
+ DCHECK_EQ(bookmark_manager, manager);
+ delete manager;
+ manager = NULL;
+}
+
+} // namespace
+
+// BookmarkManager -------------------------------------------------------------
+
+void BookmarkManager::SelectInTree(Profile* profile, BookmarkNode* node) {
+ if (manager && manager->profile() == profile)
+ BookmarkManagerGtk::SelectInTree(node);
+}
+
+void BookmarkManager::Show(Profile* profile) {
+ BookmarkManagerGtk::Show(profile);
+}
+
+// BookmarkManagerGtk, public --------------------------------------------------
+
+void BookmarkManagerGtk::SelectInTree(BookmarkNode* node) {
+ // TODO(estade): Implement.
+}
+
+// static
+void BookmarkManagerGtk::Show(Profile* profile) {
+ if (!profile->GetBookmarkModel())
+ return;
+ if (!manager)
+ manager = new BookmarkManagerGtk(profile);
+}
+
+void BookmarkManagerGtk::BookmarkManagerGtk::Loaded(BookmarkModel* model) {
+ BuildLeftStore();
+ BuildRightStore();
+}
+
+void BookmarkManagerGtk::BookmarkModelBeingDeleted(BookmarkModel* model) {
+ gtk_widget_destroy(window_);
+}
+
+// BookmarkManagerGtk, private -------------------------------------------------
+
+BookmarkManagerGtk::BookmarkManagerGtk(Profile* profile)
+ : profile_(profile),
+ model_(profile->GetBookmarkModel()) {
+ InitWidgets();
+ g_signal_connect(window_, "destroy",
+ G_CALLBACK(OnWindowDestroy), this);
+ g_signal_connect(window_, "delete-event",
+ G_CALLBACK(OnWindowDelete), NULL);
+
+ model_->AddObserver(this);
+ if (model_->IsLoaded())
+ Loaded(model_);
+
+ gtk_widget_show_all(window_);
+}
+
+BookmarkManagerGtk::~BookmarkManagerGtk() {
+}
+
+void BookmarkManagerGtk::InitWidgets() {
+ GtkToolItem* organize = gtk_tool_button_new(NULL,
+ l10n_util::GetStringUTF8(IDS_BOOKMARK_MANAGER_ORGANIZE_MENU).c_str());
+ GtkToolItem* tools = gtk_tool_button_new(NULL,
+ l10n_util::GetStringUTF8(IDS_BOOKMARK_MANAGER_TOOLS_MENU).c_str());
+
+ GtkToolItem* spacer = gtk_separator_tool_item_new();
+ gtk_separator_tool_item_set_draw(GTK_SEPARATOR_TOOL_ITEM(spacer), FALSE);
+ gtk_tool_item_set_expand(spacer, TRUE);
+
+ GtkWidget* search_label = gtk_label_new(
+ l10n_util::GetStringUTF8(IDS_BOOKMARK_MANAGER_SEARCH_TITLE).c_str());
+ GtkWidget* search_entry = gtk_entry_new();
+ GtkWidget* search_hbox = gtk_hbox_new(FALSE, kSearchPadding);
+ gtk_box_pack_start(GTK_BOX(search_hbox), search_label, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(search_hbox), search_entry, FALSE, FALSE, 0);
+ GtkToolItem* search = gtk_tool_item_new();
+ gtk_container_add(GTK_CONTAINER(search), search_hbox);
+
+ GtkWidget* toolbar = gtk_toolbar_new();
+ gtk_toolbar_insert(GTK_TOOLBAR(toolbar), organize, 0);
+ gtk_toolbar_insert(GTK_TOOLBAR(toolbar), tools, 1);
+ gtk_toolbar_insert(GTK_TOOLBAR(toolbar), spacer, 2);
+ gtk_toolbar_insert(GTK_TOOLBAR(toolbar), search, 3);
+
+ GtkWidget* left_pane = MakeLeftPane();
+ GtkWidget* right_pane = MakeRightPane();
+
+ GtkWidget* paned = gtk_hpaned_new();
+ // Set the initial position of the pane divider.
+ // TODO(estade): we should set this to one third of the width of the window
+ // when it first shows (depending on the WM, this may or may not be the value
+ // we set below in gtk_window_set_size()).
+ gtk_paned_set_position(GTK_PANED(paned), 200);
+ gtk_paned_pack1(GTK_PANED(paned), left_pane, FALSE, FALSE);
+ gtk_paned_pack2(GTK_PANED(paned), right_pane, TRUE, FALSE);
+
+ GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(vbox), paned, TRUE, TRUE, 0);
+
+ window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title(GTK_WINDOW(window_),
+ l10n_util::GetStringUTF8(IDS_BOOKMARK_MANAGER_TITLE).c_str());
+ // TODO(estade): use dimensions based on
+ // IDS_BOOKMARK_MANAGER_DIALOG_WIDTH_CHARS and
+ // IDS_BOOKMARK_MANAGER_DIALOG_HEIGHT_LINES.
+ gtk_window_set_default_size(GTK_WINDOW(window_), 640, 480);
+ gtk_container_add(GTK_CONTAINER(window_), vbox);
+}
+
+GtkWidget* BookmarkManagerGtk::MakeLeftPane() {
+ left_store_ = bookmark_utils::MakeFolderTreeStore();
+
+ GtkTreeViewColumn* icon_column = gtk_tree_view_column_new_with_attributes(
+ "", gtk_cell_renderer_pixbuf_new(), "pixbuf", bookmark_utils::FOLDER_ICON,
+ NULL);
+ GtkTreeViewColumn* name_column = gtk_tree_view_column_new_with_attributes(
+ "", gtk_cell_renderer_text_new(), "text", bookmark_utils::FOLDER_NAME,
+ NULL);
+
+ GtkWidget* tree_view =
+ gtk_tree_view_new_with_model(GTK_TREE_MODEL(left_store_));
+ // Let |tree_view| own the store.
+ g_object_unref(left_store_);
+ gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree_view), FALSE);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), icon_column);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), name_column);
+
+ GtkWidget* scrolled = gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_container_add(GTK_CONTAINER(scrolled), tree_view);
+
+ GtkWidget* frame = gtk_frame_new(NULL);
+ gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN);
+ gtk_container_add(GTK_CONTAINER(frame), scrolled);
+
+ return frame;
+}
+
+GtkWidget* BookmarkManagerGtk::MakeRightPane() {
+ right_store_ = gtk_list_store_new(RIGHT_PANE_NUM,
+ G_TYPE_STRING, G_TYPE_STRING);
+
+ GtkTreeViewColumn* title_column = gtk_tree_view_column_new_with_attributes(
+ l10n_util::GetStringUTF8(IDS_BOOKMARK_TABLE_TITLE).c_str(),
+ gtk_cell_renderer_text_new(), "text", RIGHT_PANE_TITLE, NULL);
+ GtkTreeViewColumn* url_column = gtk_tree_view_column_new_with_attributes(
+ l10n_util::GetStringUTF8(IDS_BOOKMARK_TABLE_URL).c_str(),
+ gtk_cell_renderer_text_new(), "text", RIGHT_PANE_URL, NULL);
+
+ GtkWidget* tree_view =
+ gtk_tree_view_new_with_model(GTK_TREE_MODEL(right_store_));
+ // Let |tree_view| own the store.
+ g_object_unref(right_store_);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), title_column);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), url_column);
+
+ GtkWidget* scrolled = gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_container_add(GTK_CONTAINER(scrolled), tree_view);
+
+ GtkWidget* frame = gtk_frame_new(NULL);
+ gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN);
+ gtk_container_add(GTK_CONTAINER(frame), scrolled);
+
+ return frame;
+}
+
+void BookmarkManagerGtk::BuildLeftStore() {
+ bookmark_utils::AddToTreeStore(model_, 0, left_store_, NULL);
+ // TODO(estade): Add recently bookmarked node and search node.
+}
+
+void BookmarkManagerGtk::BuildRightStore() {
+ // TODO(estade): Implement.
+ GtkTreeIter iter;
+ gtk_list_store_append(right_store_, &iter);
+ gtk_list_store_set(right_store_, &iter, RIGHT_PANE_TITLE, "Not implemented",
+ -1);
+}
diff --git a/chrome/browser/gtk/bookmark_manager_gtk.h b/chrome/browser/gtk/bookmark_manager_gtk.h
new file mode 100644
index 0000000..6bbf0fd
--- /dev/null
+++ b/chrome/browser/gtk/bookmark_manager_gtk.h
@@ -0,0 +1,79 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.TIT
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_GTK_BOOKMARK_MANAGER_GTK_H_
+#define CHROME_BROWSER_GTK_BOOKMARK_MANAGER_GTK_H_
+
+#include <gtk/gtk.h>
+
+#include "chrome/browser/bookmarks/bookmark_model.h"
+
+class BookmarkModel;
+class Profile;
+
+class BookmarkManagerGtk : public BookmarkModelObserver {
+ public:
+ virtual ~BookmarkManagerGtk();
+
+ Profile* profile() { return profile_; }
+
+ // Show the node in the tree.
+ static void SelectInTree(BookmarkNode* node);
+
+ // Shows the bookmark manager. Only one bookmark manager exists.
+ static void Show(Profile* profile);
+
+ // BookmarkModelObserver implementation.
+ virtual void Loaded(BookmarkModel* model);
+ virtual void BookmarkModelBeingDeleted(BookmarkModel* model);
+ // TODO(estade): Implement these.
+ virtual void BookmarkNodeMoved(BookmarkModel* model,
+ BookmarkNode* old_parent,
+ int old_index,
+ BookmarkNode* new_parent,
+ int new_index) {}
+ virtual void BookmarkNodeAdded(BookmarkModel* model,
+ BookmarkNode* parent,
+ int index) {}
+ virtual void BookmarkNodeRemoved(BookmarkModel* model,
+ BookmarkNode* parent,
+ int index) {}
+ virtual void BookmarkNodeRemoved(BookmarkModel* model,
+ BookmarkNode* parent,
+ int old_index,
+ BookmarkNode* node) {}
+ virtual void BookmarkNodeChanged(BookmarkModel* model,
+ BookmarkNode* node) {}
+ virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
+ BookmarkNode* node) {}
+ virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
+ BookmarkNode* node) {}
+
+ private:
+ explicit BookmarkManagerGtk(Profile* profile);
+
+ void InitWidgets();
+ GtkWidget* MakeLeftPane();
+ GtkWidget* MakeRightPane();
+
+ // Pack the data from the bookmark model into the stores. This does not
+ // create the stores, which is done in Make{Left,Right}Pane(). These should
+ // only be called once (when the bookmark model is loaded).
+ void BuildLeftStore();
+ void BuildRightStore();
+
+ GtkWidget* window_;
+ Profile* profile_;
+ BookmarkModel* model_;
+
+ enum {
+ RIGHT_PANE_TITLE,
+ RIGHT_PANE_URL,
+ RIGHT_PANE_NUM
+ };
+ GtkTreeStore* left_store_;
+ GtkListStore* right_store_;
+};
+
+#endif // CHROME_BROWSER_GTK_BOOKMARK_MANAGER_GTK_H_
diff --git a/chrome/browser/gtk/bookmark_tree_model.cc b/chrome/browser/gtk/bookmark_tree_model.cc
index 309a9a1..244a138 100644
--- a/chrome/browser/gtk/bookmark_tree_model.cc
+++ b/chrome/browser/gtk/bookmark_tree_model.cc
@@ -6,8 +6,12 @@
#include <gtk/gtk.h>
+#include "app/resource_bundle.h"
#include "base/string_util.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
+#include "grit/app_resources.h"
+#include "grit/generated_resources.h"
+#include "grit/theme_resources.h"
namespace {
@@ -22,9 +26,13 @@ void RecursiveInsert(BookmarkNode* node, int selected_id,
BookmarkNode* child = node->GetChild(i);
if (child->is_folder()) {
gtk_tree_store_append(store, &iter, parent);
+ // TODO(estade): we should show the folder open when it's expanded.
gtk_tree_store_set(store, &iter,
- 0, WideToUTF8(child->GetTitle()).c_str(),
- 1, child->id(),
+ bookmark_utils::FOLDER_ICON,
+ bookmark_utils::GetFolderIcon(),
+ bookmark_utils::FOLDER_NAME,
+ WideToUTF8(child->GetTitle()).c_str(),
+ bookmark_utils::ITEM_ID, child->id(),
-1);
if (selected_id && child->id() == selected_id) {
// Save the iterator. Since we're using a GtkTreeStore, we're
@@ -84,10 +92,14 @@ void RecursiveResolve(BookmarkModel* bb_model, BookmarkNode* bb_node,
namespace bookmark_utils {
-void BuildTreeStoreFrom(BookmarkModel* model, int selected_id,
- GtkTreeStore** store, GtkTreeIter* selected_iter) {
- *store = gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_INT);
- RecursiveInsert(model->root_node(), selected_id, *store, selected_iter, NULL);
+GtkTreeStore* MakeFolderTreeStore() {
+ return gtk_tree_store_new(FOLDER_STORE_NUM_COLUMNS, GDK_TYPE_PIXBUF,
+ G_TYPE_STRING, G_TYPE_INT);
+}
+
+void AddToTreeStore(BookmarkModel* model, int selected_id,
+ GtkTreeStore* store, GtkTreeIter* selected_iter) {
+ RecursiveInsert(model->root_node(), selected_id, store, selected_iter, NULL);
}
BookmarkNode* CommitTreeStoreDifferencesBetween(
@@ -134,7 +146,7 @@ BookmarkNode* CommitTreeStoreDifferencesBetween(
int GetIdFromTreeIter(GtkTreeModel* model, GtkTreeIter* iter) {
GValue value = { 0, };
int ret_val = -1;
- gtk_tree_model_get_value(model, iter, 1, &value);
+ gtk_tree_model_get_value(model, iter, ITEM_ID, &value);
if (G_VALUE_HOLDS_INT(&value))
ret_val = g_value_get_int(&value);
else
@@ -146,7 +158,7 @@ int GetIdFromTreeIter(GtkTreeModel* model, GtkTreeIter* iter) {
std::wstring GetTitleFromTreeIter(GtkTreeModel* model, GtkTreeIter* iter) {
GValue value = { 0, };
std::wstring ret_val;
- gtk_tree_model_get_value(model, iter, 0, &value);
+ gtk_tree_model_get_value(model, iter, FOLDER_NAME, &value);
if (G_VALUE_HOLDS_STRING(&value)) {
const gchar* utf8str = g_value_get_string(&value);
ret_val = UTF8ToWide(utf8str);
@@ -158,4 +170,18 @@ std::wstring GetTitleFromTreeIter(GtkTreeModel* model, GtkTreeIter* iter) {
return ret_val;
}
+GdkPixbuf* GetFolderIcon() {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ static GdkPixbuf* default_folder_icon = rb.GetPixbufNamed(
+ IDR_BOOKMARK_BAR_FOLDER);
+ return default_folder_icon;
+}
+
+GdkPixbuf* GetDefaultFavicon() {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ static GdkPixbuf* default_bookmark_icon = rb.GetPixbufNamed(
+ IDR_DEFAULT_FAVICON);
+ return default_bookmark_icon;
+}
+
} // namespace bookmark_utils
diff --git a/chrome/browser/gtk/bookmark_tree_model.h b/chrome/browser/gtk/bookmark_tree_model.h
index d86165a..733adad 100644
--- a/chrome/browser/gtk/bookmark_tree_model.h
+++ b/chrome/browser/gtk/bookmark_tree_model.h
@@ -13,17 +13,31 @@ class BookmarkNode;
typedef struct _GtkTreeIter GtkTreeIter;
typedef struct _GtkTreeModel GtkTreeModel;
typedef struct _GtkTreeStore GtkTreeStore;
+typedef struct _GdkPixbuf GdkPixbuf;
namespace bookmark_utils {
-// Copies the tree of folders from the BookmarkModel into a GtkTreeStore. We
+enum FolderTreeStoreColumns {
+ FOLDER_ICON,
+ FOLDER_NAME,
+ ITEM_ID,
+ FOLDER_STORE_NUM_COLUMNS
+};
+
+// Make a tree store that has two columns: name and id.
+GtkTreeStore* MakeFolderTreeStore();
+
+// Copies the tree of folders rooted at |node| into a GtkTreeStore. We
// want the user to be able to modify the tree of folders, but to be able to
// click Cancel and discard their modifications. |selected_id| is the
// node->id() of the BookmarkNode that should selected on
// node->screen. |selected_iter| is an out value that points to the
// node->representation of the node associated with |selected_id| in |store|.
-void BuildTreeStoreFrom(BookmarkModel* model, int selected_id,
- GtkTreeStore** store, GtkTreeIter* selected_iter);
+// |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.
+void AddToTreeStore(BookmarkModel* model, int selected_id,
+ GtkTreeStore* store, GtkTreeIter* selected_iter);
// Commits changes to a GtkTreeStore built from BuildTreeStoreFrom() back
// into the BookmarkModel it was generated from. Returns the BookmarkNode that
@@ -38,6 +52,12 @@ int GetIdFromTreeIter(GtkTreeModel* model, GtkTreeIter* iter);
// Returns the title field of the row pointed to by |iter|.
std::wstring GetTitleFromTreeIter(GtkTreeModel* model, GtkTreeIter* iter);
+// Get a pointer to the folder icon. The returned pointer should not be freed.
+GdkPixbuf* GetFolderIcon();
+
+// As above.
+GdkPixbuf* GetDefaultFavicon();
+
} // namespace bookmark_utils
#endif // CHROME_BROWSER_GTK_BOOKMARK_TREE_MODEL_H_
diff --git a/chrome/browser/views/bookmark_manager_view.cc b/chrome/browser/views/bookmark_manager_view.cc
index a6f0819..4673c71 100644
--- a/chrome/browser/views/bookmark_manager_view.cc
+++ b/chrome/browser/views/bookmark_manager_view.cc
@@ -12,6 +12,7 @@
#include "base/thread.h"
#include "chrome/browser/bookmarks/bookmark_folder_tree_model.h"
#include "chrome/browser/bookmarks/bookmark_html_writer.h"
+#include "chrome/browser/bookmarks/bookmark_manager.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/bookmarks/bookmark_table_model.h"
#include "chrome/browser/bookmarks/bookmark_utils.h"
@@ -36,7 +37,6 @@
#include "views/widget/widget.h"
#include "views/window/window.h"
-
// If non-null, there is an open editor and this is the window it is contained
// in it.
static views::Window* open_window = NULL;
@@ -143,6 +143,19 @@ void ShowBookmarkManagerView(Profile* profile) {
} // namespace browser
+// BookmarkManager -------------------------------------------------------------
+
+void BookmarkManager::SelectInTree(Profile* profile, BookmarkNode* node) {
+ if (manager && manager->profile() == profile)
+ manager->SelectInTree(node);
+}
+
+void BookmarkManager::Show(Profile* profile) {
+ BookmarkManagerView::Show(profile);
+}
+
+// -----------------------------------------------------------------------------
+
BookmarkManagerView::BookmarkManagerView(Profile* profile)
: profile_(profile->GetOriginalProfile()),
table_view_(NULL),
@@ -232,11 +245,6 @@ BookmarkManagerView::~BookmarkManagerView() {
open_window = NULL;
}
-// static
-void BookmarkManagerView::RegisterPrefs(PrefService* prefs) {
- prefs->RegisterDictionaryPref(prefs::kBookmarkManagerPlacement);
- prefs->RegisterIntegerPref(prefs::kBookmarkManagerSplitLocation, -1);
-}
// static
void BookmarkManagerView::Show(Profile* profile) {
diff --git a/chrome/browser/views/bookmark_manager_view.h b/chrome/browser/views/bookmark_manager_view.h
index 12706fd..8419a0d 100644
--- a/chrome/browser/views/bookmark_manager_view.h
+++ b/chrome/browser/views/bookmark_manager_view.h
@@ -22,7 +22,6 @@ class BookmarkFolderTreeModel;
class BookmarkFolderTreeView;
class BookmarkTableModel;
class BookmarkTableView;
-class PrefService;
class Profile;
namespace views {
@@ -55,8 +54,6 @@ class BookmarkManagerView : public views::View,
explicit BookmarkManagerView(Profile* profile);
virtual ~BookmarkManagerView();
- static void RegisterPrefs(PrefService* prefs);
-
// Shows the bookmark manager. Only one bookmark manager exists.
static void Show(Profile* profile);
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 2d00a51..6997459 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -605,6 +605,7 @@
'browser/bookmarks/bookmark_index.h',
'browser/bookmarks/bookmark_html_writer.cc',
'browser/bookmarks/bookmark_html_writer.h',
+ 'browser/bookmarks/bookmark_manager.h',
'browser/bookmarks/bookmark_model.cc',
'browser/bookmarks/bookmark_model.h',
'browser/bookmarks/bookmark_service.h',
@@ -879,6 +880,8 @@
'browser/gtk/bookmark_bubble_gtk.h',
'browser/gtk/bookmark_editor_gtk.cc',
'browser/gtk/bookmark_editor_gtk.h',
+ 'browser/gtk/bookmark_manager_gtk.cc',
+ 'browser/gtk/bookmark_manager_gtk.h',
'browser/gtk/bookmark_menu_controller_gtk.cc',
'browser/gtk/bookmark_menu_controller_gtk.h',
'browser/gtk/bookmark_tree_model.cc',