summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-08 17:26:01 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-08 17:26:01 +0000
commitb71a24d4c87b70586acb34eae882c8532fe86aba (patch)
tree961c542d97b9c46172e42135822f652fd9c4e6f7 /chrome/browser
parentc8ad40c6b02751c1cc942abe4ecaffbf68bfa611 (diff)
downloadchromium_src-b71a24d4c87b70586acb34eae882c8532fe86aba.zip
chromium_src-b71a24d4c87b70586acb34eae882c8532fe86aba.tar.gz
chromium_src-b71a24d4c87b70586acb34eae882c8532fe86aba.tar.bz2
GTK bookmark manager: organize menu and aesthetic improvements.
Review URL: http://codereview.chromium.org/118388 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17868 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/bookmarks/bookmark_context_menu.h9
-rw-r--r--chrome/browser/bookmarks/bookmark_utils.cc3
-rw-r--r--chrome/browser/gtk/bookmark_manager_gtk.cc131
-rw-r--r--chrome/browser/gtk/bookmark_manager_gtk.h14
-rw-r--r--chrome/browser/gtk/menu_gtk.cc11
-rw-r--r--chrome/browser/gtk/menu_gtk.h5
6 files changed, 123 insertions, 50 deletions
diff --git a/chrome/browser/bookmarks/bookmark_context_menu.h b/chrome/browser/bookmarks/bookmark_context_menu.h
index 75f72f4..4bc1e35 100644
--- a/chrome/browser/bookmarks/bookmark_context_menu.h
+++ b/chrome/browser/bookmarks/bookmark_context_menu.h
@@ -73,8 +73,17 @@ class BookmarkContextMenu : public BookmarkModelObserver,
#elif defined(OS_LINUX)
// Pops up this menu. This call doesn't block.
void PopupAsContext(guint32 event_time);
+
+ // Returns the menu.
+ GtkWidget* menu() const { return menu_->widget(); }
#endif
+ void set_parent(BookmarkNode* parent) { parent_ = parent; }
+
+ void set_selection(const std::vector<BookmarkNode*>& selection) {
+ selection_ = selection;
+ }
+
// Menu::Delegate / MenuGtk::Delegate methods.
virtual void ExecuteCommand(int id);
virtual bool IsItemChecked(int id) const;
diff --git a/chrome/browser/bookmarks/bookmark_utils.cc b/chrome/browser/bookmarks/bookmark_utils.cc
index d951df9..88456c4 100644
--- a/chrome/browser/bookmarks/bookmark_utils.cc
+++ b/chrome/browser/bookmarks/bookmark_utils.cc
@@ -364,7 +364,6 @@ void CopyToClipboard(BookmarkModel* model,
#else
// TODO(port): Clipboard integration. Don't we have clipboard
// implemented somewhere else?
- NOTIMPLEMENTED();
#endif
if (remove_nodes) {
@@ -396,7 +395,6 @@ void PasteFromClipboard(BookmarkModel* model,
bookmark_utils::CloneDragData(model, bookmark_data.elements, parent, index);
#else
// TODO(port): Clipboard integration.
- NOTIMPLEMENTED();
#endif
}
@@ -414,7 +412,6 @@ bool CanPasteFromClipboard(BookmarkNode* node) {
return bookmark_data.Read(data_wrapper);
#else
// TODO(port): Clipboard integration.
- NOTIMPLEMENTED();
return false;
#endif
}
diff --git a/chrome/browser/gtk/bookmark_manager_gtk.cc b/chrome/browser/gtk/bookmark_manager_gtk.cc
index fb529cf..7c864c6 100644
--- a/chrome/browser/gtk/bookmark_manager_gtk.cc
+++ b/chrome/browser/gtk/bookmark_manager_gtk.cc
@@ -28,6 +28,20 @@ void OnWindowDestroy(GtkWidget* widget,
manager = NULL;
}
+void SetMenuBarStyle() {
+ static bool style_was_set = false;
+
+ if (style_was_set)
+ return;
+ style_was_set = true;
+
+ gtk_rc_parse_string(
+ "style \"chrome-bm-menubar\" {"
+ " GtkMenuBar::shadow-type = GTK_SHADOW_NONE"
+ "}"
+ "widget \"*chrome-bm-menubar\" style \"chrome-bm-menubar\"");
+}
+
} // namespace
// BookmarkManager -------------------------------------------------------------
@@ -53,6 +67,8 @@ void BookmarkManagerGtk::Show(Profile* profile) {
return;
if (!manager)
manager = new BookmarkManagerGtk(profile);
+ else
+ gtk_window_present(GTK_WINDOW(manager->window_));
}
void BookmarkManagerGtk::BookmarkManagerGtk::Loaded(BookmarkModel* model) {
@@ -87,29 +103,40 @@ BookmarkManagerGtk::~BookmarkManagerGtk() {
}
void BookmarkManagerGtk::InitWidgets() {
- GtkToolItem* organize = gtk_tool_button_new(NULL,
+ 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);
+
+ std::vector<BookmarkNode*> nodes;
+ organize_menu_.reset(new BookmarkContextMenu(window_, profile_, NULL, NULL,
+ NULL, nodes, BookmarkContextMenu::BOOKMARK_MANAGER_ORGANIZE_MENU));
+
+ GtkWidget* organize = gtk_menu_item_new_with_label(
l10n_util::GetStringUTF8(IDS_BOOKMARK_MANAGER_ORGANIZE_MENU).c_str());
- GtkToolItem* tools = gtk_tool_button_new(NULL,
+ gtk_menu_item_set_submenu(GTK_MENU_ITEM(organize), organize_menu_->menu());
+
+ GtkWidget* tools = gtk_menu_item_new_with_label(
l10n_util::GetStringUTF8(IDS_BOOKMARK_MANAGER_TOOLS_MENU).c_str());
+ // TODO(estade): create the tools menu.
- 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* menu_bar = gtk_menu_bar_new();
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), organize);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), tools);
+ SetMenuBarStyle();
+ gtk_widget_set_name(menu_bar, "chrome-bm-menubar");
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* hbox = gtk_hbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(hbox), menu_bar, FALSE, FALSE, 0);
+ gtk_box_pack_end(GTK_BOX(hbox), search_entry, FALSE, FALSE, 0);
+ gtk_box_pack_end(GTK_BOX(hbox), search_label, FALSE, FALSE, kSearchPadding);
GtkWidget* left_pane = MakeLeftPane();
GtkWidget* right_pane = MakeRightPane();
@@ -124,16 +151,8 @@ void BookmarkManagerGtk::InitWidgets() {
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), hbox, 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);
}
@@ -157,13 +176,11 @@ GtkWidget* BookmarkManagerGtk::MakeLeftPane() {
GtkWidget* scrolled = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled),
+ GTK_SHADOW_ETCHED_IN);
gtk_container_add(GTK_CONTAINER(scrolled), left_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;
+ return scrolled;
}
GtkWidget* BookmarkManagerGtk::MakeRightPane() {
@@ -191,6 +208,8 @@ GtkWidget* BookmarkManagerGtk::MakeRightPane() {
gtk_tree_view_append_column(GTK_TREE_VIEW(right_tree_view_), url_column);
g_signal_connect(left_selection(), "changed",
G_CALLBACK(OnLeftSelectionChanged), this);
+ g_signal_connect(right_selection(), "changed",
+ G_CALLBACK(OnRightSelectionChanged), this);
gtk_tree_view_enable_model_drag_source(GTK_TREE_VIEW(right_tree_view_),
GDK_BUTTON1_MASK,
@@ -209,13 +228,11 @@ GtkWidget* BookmarkManagerGtk::MakeRightPane() {
GtkWidget* scrolled = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled),
+ GTK_SHADOW_ETCHED_IN);
gtk_container_add(GTK_CONTAINER(scrolled), right_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;
+ return scrolled;
}
void BookmarkManagerGtk::BuildLeftStore() {
@@ -231,7 +248,7 @@ void BookmarkManagerGtk::BuildRightStore() {
if (!update_right_store_)
return;
- BookmarkNode* node = GetSelectedNode(left_selection());
+ BookmarkNode* node = GetFolder();
// TODO(estade): eventually we may hit a fake node here (recently bookmarked
// or search), but until then we require that node != NULL.
DCHECK(node);
@@ -256,13 +273,29 @@ BookmarkNode* BookmarkManagerGtk::GetNodeAt(GtkTreeModel* model,
return model_->GetNodeByID(id);
}
-BookmarkNode* BookmarkManagerGtk::GetSelectedNode(GtkTreeSelection* selection) {
+BookmarkNode* BookmarkManagerGtk::GetFolder() {
GtkTreeModel* model;
GtkTreeIter iter;
- gtk_tree_selection_get_selected(selection, &model, &iter);
+ gtk_tree_selection_get_selected(left_selection(), &model, &iter);
return GetNodeAt(model, &iter);
}
+std::vector<BookmarkNode*> BookmarkManagerGtk::GetRightSelection() {
+ GtkTreeModel* model;
+ GList* paths = gtk_tree_selection_get_selected_rows(right_selection(),
+ &model);
+ std::vector<BookmarkNode*> nodes;
+ for (GList* item = paths; item; item = item->next) {
+ GtkTreeIter iter;
+ gtk_tree_model_get_iter(model, &iter,
+ reinterpret_cast<GtkTreePath*>(item->data));
+ nodes.push_back(GetNodeAt(model, &iter));
+ }
+ g_list_free(paths);
+
+ return nodes;
+}
+
void BookmarkManagerGtk::AppendNodeToRightStore(BookmarkNode* node,
GtkTreeIter* iter) {
GdkPixbuf* pixbuf = bookmark_utils::GetPixbufForNode(node, model_);
@@ -281,18 +314,34 @@ void BookmarkManagerGtk::ToggleUpdatesToRightStore() {
BuildRightStore();
}
+// static
void BookmarkManagerGtk::OnLeftSelectionChanged(GtkTreeSelection* selection,
BookmarkManagerGtk* bookmark_manager) {
+ // Update the context menu.
+ BookmarkNode* parent = bookmark_manager->GetFolder();
+ bookmark_manager->organize_menu_->set_parent(parent);
+ std::vector<BookmarkNode*> nodes;
+ nodes.push_back(parent);
+ bookmark_manager->organize_menu_->set_selection(nodes);
+
bookmark_manager->BuildRightStore();
}
// static
+void BookmarkManagerGtk::OnRightSelectionChanged(GtkTreeSelection* selection,
+ BookmarkManagerGtk* bookmark_manager) {
+ // Update the context menu.
+ bookmark_manager->organize_menu_->set_selection(
+ bookmark_manager->GetRightSelection());
+}
+
+// static
void BookmarkManagerGtk::OnTreeViewDragGet(
GtkWidget* tree_view,
GdkDragContext* context, GtkSelectionData* selection_data,
guint target_type, guint time, BookmarkManagerGtk* bookmark_manager) {
- BookmarkNode* node =
- bookmark_manager->GetSelectedNode(bookmark_manager->right_selection());
+ // TODO(estade): support multiple target drag.
+ BookmarkNode* node = bookmark_manager->GetRightSelection().at(0);
bookmark_utils::WriteBookmarkToSelection(node, selection_data, target_type,
bookmark_manager->profile_);
}
@@ -350,7 +399,7 @@ void BookmarkManagerGtk::OnTreeViewDragReceived(
}
int idx = !path ? 0 :
gtk_tree_path_get_indices(path)[gtk_tree_path_get_depth(path) - 1];
- BookmarkNode* parent = bm->GetSelectedNode(bm->left_selection());
+ BookmarkNode* parent = bm->GetFolder();
bm->ToggleUpdatesToRightStore();
for (std::vector<BookmarkNode*>::iterator it = nodes.begin();
diff --git a/chrome/browser/gtk/bookmark_manager_gtk.h b/chrome/browser/gtk/bookmark_manager_gtk.h
index a30c087..bb3028d 100644
--- a/chrome/browser/gtk/bookmark_manager_gtk.h
+++ b/chrome/browser/gtk/bookmark_manager_gtk.h
@@ -6,7 +6,9 @@
#define CHROME_BROWSER_GTK_BOOKMARK_MANAGER_GTK_H_
#include <gtk/gtk.h>
+#include <vector>
+#include "chrome/browser/bookmarks/bookmark_context_menu.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
class BookmarkModel;
@@ -68,8 +70,11 @@ class BookmarkManagerGtk : public BookmarkModelObserver {
// Get the node from |model| at |iter|.
BookmarkNode* GetNodeAt(GtkTreeModel* model, GtkTreeIter* iter);
- // Get the node selected in one of the tree views.
- BookmarkNode* GetSelectedNode(GtkTreeSelection*);
+ // Get the node that is selected in the left tree view.
+ BookmarkNode* GetFolder();
+
+ // Get the nodes that are selected in the right tree view.
+ std::vector<BookmarkNode*> GetRightSelection();
// Stick node in the store that backs the right-side tree view.
void AppendNodeToRightStore(BookmarkNode* node, GtkTreeIter* iter);
@@ -89,6 +94,9 @@ class BookmarkManagerGtk : public BookmarkModelObserver {
static void OnLeftSelectionChanged(GtkTreeSelection* selection,
BookmarkManagerGtk* bookmark_manager);
+ static void OnRightSelectionChanged(GtkTreeSelection* selection,
+ BookmarkManagerGtk* bookmark_manager);
+
static void OnTreeViewDragGet(GtkWidget* tree_view, GdkDragContext* context,
GtkSelectionData* selection_data,
guint target_type, guint time,
@@ -115,6 +123,8 @@ class BookmarkManagerGtk : public BookmarkModelObserver {
GtkTreeStore* left_store_;
GtkListStore* right_store_;
bool update_right_store_;
+
+ scoped_ptr<BookmarkContextMenu> organize_menu_;
};
#endif // CHROME_BROWSER_GTK_BOOKMARK_MANAGER_GTK_H_
diff --git a/chrome/browser/gtk/menu_gtk.cc b/chrome/browser/gtk/menu_gtk.cc
index 1636f67..f259b39 100644
--- a/chrome/browser/gtk/menu_gtk.cc
+++ b/chrome/browser/gtk/menu_gtk.cc
@@ -40,6 +40,7 @@ MenuGtk::~MenuGtk() {
}
void MenuGtk::ConnectSignalHandlers() {
+ g_signal_connect(menu_.get(), "show", G_CALLBACK(OnMenuShow), this);
g_signal_connect(menu_.get(), "hide", G_CALLBACK(OnMenuHidden), this);
}
@@ -81,8 +82,6 @@ void MenuGtk::Popup(GtkWidget* widget, GdkEvent* event) {
}
void MenuGtk::Popup(GtkWidget* widget, gint button_type, guint32 timestamp) {
- gtk_container_foreach(GTK_CONTAINER(menu_.get()), SetMenuItemInfo, this);
-
gtk_menu_popup(GTK_MENU(menu_.get()), NULL, NULL,
MenuPositionFunc,
widget,
@@ -90,8 +89,6 @@ void MenuGtk::Popup(GtkWidget* widget, gint button_type, guint32 timestamp) {
}
void MenuGtk::PopupAsContext(guint32 event_time) {
- gtk_container_foreach(GTK_CONTAINER(menu_.get()), SetMenuItemInfo, this);
-
// TODO(estade): |button| value of 3 (6th argument) is not strictly true,
// but does it matter?
gtk_menu_popup(GTK_MENU(menu_.get()), NULL, NULL, NULL, NULL, 3, event_time);
@@ -284,6 +281,12 @@ void MenuGtk::MenuPositionFunc(GtkMenu* menu,
}
// static
+void MenuGtk::OnMenuShow(GtkWidget* widget, MenuGtk* menu) {
+ gtk_container_foreach(GTK_CONTAINER(menu->menu_.get()),
+ SetMenuItemInfo, menu);
+}
+
+// static
void MenuGtk::OnMenuHidden(GtkWidget* widget, MenuGtk* menu) {
menu->delegate_->StoppedShowing();
}
diff --git a/chrome/browser/gtk/menu_gtk.h b/chrome/browser/gtk/menu_gtk.h
index 4bf51cd..975580d 100644
--- a/chrome/browser/gtk/menu_gtk.h
+++ b/chrome/browser/gtk/menu_gtk.h
@@ -91,6 +91,8 @@ class MenuGtk {
gboolean* push_in,
void* void_widget);
+ GtkWidget* widget() const { return menu_.get(); }
+
private:
// A recursive function that transforms a MenuCreateMaterial tree into a set
// of GtkMenuItems.
@@ -121,6 +123,9 @@ class MenuGtk {
// Sets the check mark and enabled/disabled state on our menu items.
static void SetMenuItemInfo(GtkWidget* widget, void* raw_menu);
+ // Updates all the menu items' state.
+ static void OnMenuShow(GtkWidget* widget, MenuGtk* menu);
+
// Sets the activating widget back to a normal appearance.
static void OnMenuHidden(GtkWidget* widget, MenuGtk* menu);