summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/bookmark_bubble_gtk.cc
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-03 19:16:59 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-03 19:16:59 +0000
commita1e071118b7ed757f2c975a8fe188fdbe80fcdd1 (patch)
treebbceb7d5265f89f5f9598658860ca775e0bdded6 /chrome/browser/gtk/bookmark_bubble_gtk.cc
parent85408b7c5c652979acaf6e39d750b7e0aac579eb (diff)
downloadchromium_src-a1e071118b7ed757f2c975a8fe188fdbe80fcdd1.zip
chromium_src-a1e071118b7ed757f2c975a8fe188fdbe80fcdd1.tar.gz
chromium_src-a1e071118b7ed757f2c975a8fe188fdbe80fcdd1.tar.bz2
Implement more of the BookmarkBubble, connecting it to the bookmark system.
This allows you to edit the bookmark title, and remove the bookmark. BUG=11738 TEST=Click the bookmark star, you should be able to edit the bookmark title and remove the bookmark. Review URL: http://codereview.chromium.org/119079 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17514 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/bookmark_bubble_gtk.cc')
-rw-r--r--chrome/browser/gtk/bookmark_bubble_gtk.cc155
1 files changed, 119 insertions, 36 deletions
diff --git a/chrome/browser/gtk/bookmark_bubble_gtk.cc b/chrome/browser/gtk/bookmark_bubble_gtk.cc
index 310f00b..040a8f8 100644
--- a/chrome/browser/gtk/bookmark_bubble_gtk.cc
+++ b/chrome/browser/gtk/bookmark_bubble_gtk.cc
@@ -10,8 +10,13 @@
#include "app/resource_bundle.h"
#include "base/basictypes.h"
#include "base/logging.h"
+#include "chrome/browser/bookmarks/bookmark_editor.h"
+#include "chrome/browser/bookmarks/bookmark_model.h"
+#include "chrome/browser/bookmarks/bookmark_utils.h"
#include "chrome/browser/gtk/gtk_chrome_link_button.h"
#include "chrome/browser/gtk/info_bubble_gtk.h"
+#include "chrome/browser/metrics/user_metrics.h"
+#include "chrome/browser/profile.h"
#include "grit/generated_resources.h"
namespace {
@@ -20,16 +25,6 @@ namespace {
// keeps track of the currently open bubble, or NULL if none is open.
BookmarkBubbleGtk* g_bubble = NULL;
-// TODO(deanm): Just a temporary state to keep track of the last entry in the
-// combo box. This makes sure we are catching the closing events right and
-// saving the state.
-gint g_last_active = 0;
-
-void HandleCloseButton(GtkWidget* widget,
- gpointer user_data) {
- reinterpret_cast<InfoBubbleGtk*>(user_data)->Close();
-}
-
} // namespace
// static
@@ -50,8 +45,6 @@ void BookmarkBubbleGtk::Show(GtkWindow* transient_toplevel,
void BookmarkBubbleGtk::InfoBubbleClosing(InfoBubbleGtk* info_bubble,
bool closed_by_escape) {
- // Possibly commit any bookmark changes here...
- g_last_active = gtk_combo_box_get_active(GTK_COMBO_BOX(combo_));
}
BookmarkBubbleGtk::BookmarkBubbleGtk(GtkWindow* transient_toplevel,
@@ -59,10 +52,15 @@ BookmarkBubbleGtk::BookmarkBubbleGtk(GtkWindow* transient_toplevel,
Profile* profile,
const GURL& url,
bool newly_bookmarked)
- : profile_(profile),
- newly_bookmarked_(newly_bookmarked),
+ : url_(url),
+ profile_(profile),
content_(NULL),
- combo_(NULL) {
+ name_entry_(NULL),
+ folder_combo_(NULL),
+ bubble_(NULL),
+ newly_bookmarked_(newly_bookmarked),
+ apply_edits_(true),
+ remove_bookmark_(false) {
GtkWidget* label = gtk_label_new(l10n_util::GetStringUTF8(
newly_bookmarked_ ? IDS_BOOMARK_BUBBLE_PAGE_BOOKMARKED :
IDS_BOOMARK_BUBBLE_PAGE_BOOKMARK).c_str());
@@ -77,6 +75,10 @@ BookmarkBubbleGtk::BookmarkBubbleGtk(GtkWindow* transient_toplevel,
GtkWidget* close_button = gtk_button_new_with_label(
l10n_util::GetStringUTF8(IDS_CLOSE).c_str());
+ // Our content is arrange in 3 rows. |top| contains a left justified
+ // message, and a right justified remove link button. |table| is the middle
+ // portion with the name entry and the folder combo. |bottom| is the final
+ // row with a spacer, and the edit... and close buttons on the right.
GtkWidget* content = gtk_vbox_new(FALSE, 5);
GtkWidget* top = gtk_hbox_new(FALSE, 0);
@@ -86,16 +88,23 @@ BookmarkBubbleGtk::BookmarkBubbleGtk(GtkWindow* transient_toplevel,
gtk_box_pack_start(GTK_BOX(top), remove_button,
FALSE, FALSE, 0);
- // Use a combo box just to make sure popup windows work in the bubble content
- // and we're not fighting with the bubble for the grab.
- combo_ = gtk_combo_box_new_text();
- gtk_combo_box_append_text(GTK_COMBO_BOX(combo_), "entry 1");
- gtk_combo_box_append_text(GTK_COMBO_BOX(combo_), "entry 2");
- gtk_combo_box_append_text(GTK_COMBO_BOX(combo_), "entry 3");
- gtk_combo_box_set_active(GTK_COMBO_BOX(combo_), g_last_active);
-
- GtkWidget* name_entry = gtk_entry_new();
-
+ // 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);
+
+ // Create the edit entry for updating the bookmark name / title.
+ name_entry_ = gtk_entry_new();
+ gtk_entry_set_text(GTK_ENTRY(name_entry_), GetTitle().c_str());
+
+ // We use a table to allow the labels to line up with each other, along
+ // with the entry and folder combo lining up.
GtkWidget* table = gtk_table_new(2, 2, FALSE);
gtk_table_set_row_spacings(GTK_TABLE(table), 5);
gtk_table_set_col_spacings(GTK_TABLE(table), 10);
@@ -103,16 +112,18 @@ BookmarkBubbleGtk::BookmarkBubbleGtk(GtkWindow* transient_toplevel,
name_label,
0, 1, 0, 1);
gtk_table_attach_defaults(GTK_TABLE(table),
- name_entry,
+ name_entry_,
1, 2, 0, 1);
gtk_table_attach_defaults(GTK_TABLE(table),
folder_label,
0, 1, 1, 2);
gtk_table_attach_defaults(GTK_TABLE(table),
- combo_,
+ folder_combo_,
1, 2, 1, 2);
GtkWidget* bottom = gtk_hbox_new(FALSE, 0);
+ // We want the buttons on the right, so just use an expanding label to fill
+ // all of the extra space on the right.
gtk_box_pack_start(GTK_BOX(bottom), gtk_label_new(""),
TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(bottom), edit_button,
@@ -126,19 +137,21 @@ 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);
- g_signal_connect(content, "destroy",
- G_CALLBACK(&HandleDestroyThunk), this);
-
- // TODO(deanm): In the future we might want to hang on to the returned
- // InfoBubble so that we can call Close() on it.
- InfoBubbleGtk* bubble = InfoBubbleGtk::Show(transient_toplevel,
- rect, content, this);
- if (!bubble) {
+ bubble_ = InfoBubbleGtk::Show(transient_toplevel,
+ rect, content, this);
+ if (!bubble_) {
NOTREACHED();
+ return;
}
+ g_signal_connect(content, "destroy",
+ G_CALLBACK(&HandleDestroyThunk), this);
+ g_signal_connect(name_entry_, "activate",
+ G_CALLBACK(&HandleNameActivateThunk), this);
g_signal_connect(close_button, "clicked",
- G_CALLBACK(&HandleCloseButton), bubble);
+ G_CALLBACK(&HandleCloseButtonThunk), this);
+ g_signal_connect(remove_button, "clicked",
+ G_CALLBACK(&HandleRemoveButtonThunk), this);
}
BookmarkBubbleGtk::~BookmarkBubbleGtk() {
@@ -146,6 +159,15 @@ BookmarkBubbleGtk::~BookmarkBubbleGtk() {
DCHECK(g_bubble);
g_bubble = NULL;
+
+ if (apply_edits_) {
+ ApplyEdits();
+ } else if (remove_bookmark_) {
+ BookmarkModel* model = profile_->GetBookmarkModel();
+ BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_);
+ if (node)
+ model->Remove(node->GetParent(), node->GetParent()->IndexOfChild(node));
+ }
}
gboolean BookmarkBubbleGtk::HandleDestroy() {
@@ -155,3 +177,64 @@ gboolean BookmarkBubbleGtk::HandleDestroy() {
delete this;
return FALSE; // Propagate.
}
+
+void BookmarkBubbleGtk::HandleNameActivate() {
+ bubble_->Close();
+}
+
+void BookmarkBubbleGtk::HandleCloseButton() {
+ bubble_->Close();
+}
+
+void BookmarkBubbleGtk::HandleRemoveButton() {
+ UserMetrics::RecordAction(L"BookmarkBubble_Unstar", profile_);
+
+ apply_edits_ = false;
+ remove_bookmark_ = true;
+ bubble_->Close();
+}
+
+void BookmarkBubbleGtk::ApplyEdits() {
+ // Set this to make sure we don't attempt to apply edits again.
+ apply_edits_ = false;
+
+ BookmarkModel* model = profile_->GetBookmarkModel();
+ BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_);
+ if (node) {
+ // NOTE: Would be nice to save a strlen and use gtk_entry_get_text_length,
+ // but it is fairly new and not always in our GTK version.
+ const std::wstring new_title(
+ UTF8ToWide(gtk_entry_get_text(GTK_ENTRY(name_entry_))));
+
+ if (new_title != node->GetTitle()) {
+ model->SetTitle(node, new_title);
+ UserMetrics::RecordAction(L"BookmarkBubble_ChangeTitleInBubble",
+ 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());
+ if (new_parent != node->GetParent()) {
+ UserMetrics::RecordAction(L"BookmarkBubble_ChangeParent", profile_);
+ model->Move(node, new_parent, new_parent->GetChildCount());
+ }
+ }
+#endif
+ }
+}
+
+std::string BookmarkBubbleGtk::GetTitle() {
+ BookmarkModel* bookmark_model= profile_->GetBookmarkModel();
+ BookmarkNode* node = bookmark_model->GetMostRecentlyAddedNodeForURL(url_);
+ if (!node) {
+ NOTREACHED();
+ return std::string();
+ }
+
+ return WideToUTF8(node->GetTitle());
+}