diff options
author | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-08 09:03:40 +0000 |
---|---|---|
committer | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-08 09:03:40 +0000 |
commit | a9e41c680f8d1ab6745e6bec0496d4f27d19d4ad (patch) | |
tree | 6fcdcd82f5a2de245f7e4818328f1bed102c9d65 /chrome/browser | |
parent | 36f52c000fd60e1754e4b64aad0b2890291b516e (diff) | |
download | chromium_src-a9e41c680f8d1ab6745e6bec0496d4f27d19d4ad.zip chromium_src-a9e41c680f8d1ab6745e6bec0496d4f27d19d4ad.tar.gz chromium_src-a9e41c680f8d1ab6745e6bec0496d4f27d19d4ad.tar.bz2 |
Hook up the Linux bookmark bubble to the bookmark editor.
Folder selection and the Edit... button should now work.
BUG=11738
Review URL: http://codereview.chromium.org/119174
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17850 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/gtk/bookmark_bubble_gtk.cc | 113 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_bubble_gtk.h | 26 |
2 files changed, 124 insertions, 15 deletions
diff --git a/chrome/browser/gtk/bookmark_bubble_gtk.cc b/chrome/browser/gtk/bookmark_bubble_gtk.cc index 040a8f8..adf0874 100644 --- a/chrome/browser/gtk/bookmark_bubble_gtk.cc +++ b/chrome/browser/gtk/bookmark_bubble_gtk.cc @@ -25,6 +25,58 @@ namespace { // keeps track of the currently open bubble, or NULL if none is open. BookmarkBubbleGtk* g_bubble = NULL; +// Max number of most recently used folders. +const size_t kMaxMRUFolders = 5; + +std::vector<BookmarkNode*> PopulateFolderCombo(BookmarkModel* model, + const GURL& url, + GtkWidget* folder_combo) { + BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url); + BookmarkNode* parent = node->GetParent(); + BookmarkNode* bookmark_bar = model->GetBookmarkBarNode(); + BookmarkNode* other = model->other_node(); + + // Use + 2 to account for bookmark bar and other node. + std::vector<BookmarkNode*> recent_nodes = + bookmark_utils::GetMostRecentlyModifiedGroups(model, kMaxMRUFolders + 2); + + std::vector<BookmarkNode*> nodes; + // Make the parent the first item, unless it's the bookmark bar or other node. + if (parent != bookmark_bar && parent != other) + nodes.push_back(parent); + + for (size_t i = 0; i < recent_nodes.size(); ++i) { + if (recent_nodes[i] != parent && + recent_nodes[i] != bookmark_bar && + recent_nodes[i] != other) { + nodes.push_back(recent_nodes[i]); + } + // Make sure we only have kMaxMRUFolders in the first chunk. + if (nodes.size() == kMaxMRUFolders) + break; + } + + // And put the bookmark bar and other nodes at the end of the list. + nodes.push_back(bookmark_bar); + nodes.push_back(other); + + // We always have nodes + 1 entries in the combo. The last entry will be + // the 'Select another folder...' entry that opens the bookmark editor. + for (size_t i = 0; i < nodes.size(); ++i) { + gtk_combo_box_append_text(GTK_COMBO_BOX(folder_combo), + WideToUTF8(nodes[i]->GetTitle()).c_str()); + } + gtk_combo_box_append_text(GTK_COMBO_BOX(folder_combo), + l10n_util::GetStringUTF8( + IDS_BOOMARK_BUBBLE_CHOOSER_ANOTHER_FOLDER).c_str()); + + int parent_index = static_cast<int>( + std::find(nodes.begin(), nodes.end(), parent) - nodes.begin()); + gtk_combo_box_set_active(GTK_COMBO_BOX(folder_combo), parent_index); + + return nodes; +} + } // namespace // static @@ -54,6 +106,7 @@ BookmarkBubbleGtk::BookmarkBubbleGtk(GtkWindow* transient_toplevel, bool newly_bookmarked) : url_(url), profile_(profile), + transient_toplevel_(transient_toplevel), content_(NULL), name_entry_(NULL), folder_combo_(NULL), @@ -91,13 +144,9 @@ BookmarkBubbleGtk::BookmarkBubbleGtk(GtkWindow* transient_toplevel, // TODO(deanm): We should show the bookmark bar folder along with the top // other choices and an entry to go into the bookmark editor. Since we don't // have the editor up yet on Linux, just show the bookmark bar for now. - BookmarkModel* model = profile_->GetBookmarkModel(); - BookmarkNode* bookmark_bar = model->GetBookmarkBarNode(); folder_combo_ = gtk_combo_box_new_text(); - gtk_combo_box_append_text(GTK_COMBO_BOX(folder_combo_), - WideToUTF8(bookmark_bar->GetTitle()).c_str()); - // We default to the bookmark bar, so make it the active selection. - gtk_combo_box_set_active(GTK_COMBO_BOX(folder_combo_), 0); + folder_nodes_ = PopulateFolderCombo(profile_->GetBookmarkModel(), + url_, folder_combo_); // Create the edit entry for updating the bookmark name / title. name_entry_ = gtk_entry_new(); @@ -137,7 +186,7 @@ BookmarkBubbleGtk::BookmarkBubbleGtk(GtkWindow* transient_toplevel, // We want the focus to start on the entry, not on the remove button. gtk_container_set_focus_child(GTK_CONTAINER(content), table); - bubble_ = InfoBubbleGtk::Show(transient_toplevel, + bubble_ = InfoBubbleGtk::Show(transient_toplevel_, rect, content, this); if (!bubble_) { NOTREACHED(); @@ -148,6 +197,10 @@ BookmarkBubbleGtk::BookmarkBubbleGtk(GtkWindow* transient_toplevel, G_CALLBACK(&HandleDestroyThunk), this); g_signal_connect(name_entry_, "activate", G_CALLBACK(&HandleNameActivateThunk), this); + g_signal_connect(folder_combo_, "changed", + G_CALLBACK(&HandleFolderChangedThunk), this); + g_signal_connect(edit_button, "clicked", + G_CALLBACK(&HandleEditButtonThunk), this); g_signal_connect(close_button, "clicked", G_CALLBACK(&HandleCloseButtonThunk), this); g_signal_connect(remove_button, "clicked", @@ -182,6 +235,19 @@ void BookmarkBubbleGtk::HandleNameActivate() { bubble_->Close(); } +void BookmarkBubbleGtk::HandleFolderChanged() { + size_t cur_folder = gtk_combo_box_get_active(GTK_COMBO_BOX(folder_combo_)); + if (cur_folder == folder_nodes_.size()) { + UserMetrics::RecordAction(L"BookmarkBubble_EditFromCombobox", profile_); + ShowEditor(); + } +} + +void BookmarkBubbleGtk::HandleEditButton() { + UserMetrics::RecordAction(L"BookmarkBubble_Edit", profile_); + ShowEditor(); +} + void BookmarkBubbleGtk::HandleCloseButton() { bubble_->Close(); } @@ -212,19 +278,16 @@ void BookmarkBubbleGtk::ApplyEdits() { profile_); } -// TODO(deanm): We need to get the Bookmark editor running on Linux. -#if 0 - // Last index means 'Choose another folder...' - if (parent_combobox_->selected_item() < - parent_model_.GetItemCount(parent_combobox_) - 1) { - BookmarkNode* new_parent = - parent_model_.GetNodeAt(parent_combobox_->selected_item()); + size_t cur_folder = gtk_combo_box_get_active(GTK_COMBO_BOX(folder_combo_)); + + // Last index ('Choose another folder...') is not in folder_nodes_. + if (cur_folder < folder_nodes_.size()) { + BookmarkNode* new_parent = folder_nodes_[cur_folder]; if (new_parent != node->GetParent()) { UserMetrics::RecordAction(L"BookmarkBubble_ChangeParent", profile_); model->Move(node, new_parent, new_parent->GetChildCount()); } } -#endif } } @@ -238,3 +301,23 @@ std::string BookmarkBubbleGtk::GetTitle() { return WideToUTF8(node->GetTitle()); } + +void BookmarkBubbleGtk::ShowEditor() { + BookmarkNode* node = + profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url_); + + // Commit any edits now. + ApplyEdits(); + + // Closing might delete us, so we'll cache what we want we need on the stack. + Profile* profile = profile_; + GtkWidget* toplevel = GTK_WIDGET(transient_toplevel_); + + // Close the bubble, deleting the C++ objects, etc. + bubble_->Close(); + + if (node) { + BookmarkEditor::Show(toplevel, profile, NULL, node, + BookmarkEditor::SHOW_TREE, NULL); + } +} diff --git a/chrome/browser/gtk/bookmark_bubble_gtk.h b/chrome/browser/gtk/bookmark_bubble_gtk.h index 3dd0291..dcce212 100644 --- a/chrome/browser/gtk/bookmark_bubble_gtk.h +++ b/chrome/browser/gtk/bookmark_bubble_gtk.h @@ -14,10 +14,13 @@ #include <gtk/gtk.h> +#include <vector> + #include "base/basictypes.h" #include "chrome/browser/gtk/info_bubble_gtk.h" #include "googleurl/src/gurl.h" +class BookmarkNode; class Profile; namespace gfx { class Rect; @@ -61,6 +64,20 @@ class BookmarkBubbleGtk : public InfoBubbleGtkDelegate { } void HandleNameActivate(); + static void HandleFolderChangedThunk(GtkWidget* widget, + gpointer user_data) { + return reinterpret_cast<BookmarkBubbleGtk*>(user_data)-> + HandleFolderChanged(); + } + void HandleFolderChanged(); + + static void HandleEditButtonThunk(GtkWidget* widget, + gpointer user_data) { + return reinterpret_cast<BookmarkBubbleGtk*>(user_data)-> + HandleEditButton(); + } + void HandleEditButton(); + static void HandleCloseButtonThunk(GtkWidget* widget, gpointer user_data) { return reinterpret_cast<BookmarkBubbleGtk*>(user_data)-> @@ -78,6 +95,9 @@ class BookmarkBubbleGtk : public InfoBubbleGtkDelegate { // Update the bookmark with any edits that have been made. void ApplyEdits(); + // Open the bookmark editor for the current url and close the bubble. + void ShowEditor(); + // Return the UTF8 encoded title for the current |url_|. std::string GetTitle(); @@ -86,6 +106,9 @@ class BookmarkBubbleGtk : public InfoBubbleGtkDelegate { // Our current profile (used to access the bookmark system). Profile* profile_; + // The toplevel window our dialogs should be transient for. + GtkWindow* transient_toplevel_; + // We let the InfoBubble own our content, and then we delete ourself // when the widget is destroyed (when the InfoBubble is destroyed). GtkWidget* content_; @@ -96,6 +119,9 @@ class BookmarkBubbleGtk : public InfoBubbleGtkDelegate { // The combo box for selecting the bookmark folder. GtkWidget* folder_combo_; + // The bookmark nodes in |folder_combo_|. + std::vector<BookmarkNode*> folder_nodes_; + InfoBubbleGtk* bubble_; // Whether the bubble is creating or editing an existing bookmark. |