| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.h" | 5 #include "chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 BookmarkBubbleGtk::BookmarkBubbleGtk(GtkWidget* anchor, | 86 BookmarkBubbleGtk::BookmarkBubbleGtk(GtkWidget* anchor, |
| 87 Profile* profile, | 87 Profile* profile, |
| 88 const GURL& url, | 88 const GURL& url, |
| 89 bool newly_bookmarked) | 89 bool newly_bookmarked) |
| 90 : url_(url), | 90 : url_(url), |
| 91 profile_(profile), | 91 profile_(profile), |
| 92 model_(profile->GetBookmarkModel()), |
| 92 theme_service_(GtkThemeService::GetFrom(profile_)), | 93 theme_service_(GtkThemeService::GetFrom(profile_)), |
| 93 anchor_(anchor), | 94 anchor_(anchor), |
| 94 content_(NULL), | 95 content_(NULL), |
| 95 name_entry_(NULL), | 96 name_entry_(NULL), |
| 96 folder_combo_(NULL), | 97 folder_combo_(NULL), |
| 97 bubble_(NULL), | 98 bubble_(NULL), |
| 98 factory_(this), | 99 factory_(this), |
| 99 newly_bookmarked_(newly_bookmarked), | 100 newly_bookmarked_(newly_bookmarked), |
| 100 apply_edits_(true), | 101 apply_edits_(true), |
| 101 remove_bookmark_(false) { | 102 remove_bookmark_(false) { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 197 |
| 197 BookmarkBubbleGtk::~BookmarkBubbleGtk() { | 198 BookmarkBubbleGtk::~BookmarkBubbleGtk() { |
| 198 DCHECK(!content_); // |content_| should have already been destroyed. | 199 DCHECK(!content_); // |content_| should have already been destroyed. |
| 199 | 200 |
| 200 DCHECK(g_bubble); | 201 DCHECK(g_bubble); |
| 201 g_bubble = NULL; | 202 g_bubble = NULL; |
| 202 | 203 |
| 203 if (apply_edits_) { | 204 if (apply_edits_) { |
| 204 ApplyEdits(); | 205 ApplyEdits(); |
| 205 } else if (remove_bookmark_) { | 206 } else if (remove_bookmark_) { |
| 206 BookmarkModel* model = profile_->GetBookmarkModel(); | 207 const BookmarkNode* node = model_->GetMostRecentlyAddedNodeForURL(url_); |
| 207 const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_); | |
| 208 if (node) | 208 if (node) |
| 209 model->Remove(node->parent(), node->parent()->GetIndexOf(node)); | 209 model_->Remove(node->parent(), node->parent()->GetIndexOf(node)); |
| 210 } | 210 } |
| 211 } | 211 } |
| 212 | 212 |
| 213 void BookmarkBubbleGtk::OnDestroy(GtkWidget* widget) { | 213 void BookmarkBubbleGtk::OnDestroy(GtkWidget* widget) { |
| 214 // We are self deleting, we have a destroy signal setup to catch when we | 214 // We are self deleting, we have a destroy signal setup to catch when we |
| 215 // destroyed (via the BubbleGtk being destroyed), and delete ourself. | 215 // destroyed (via the BubbleGtk being destroyed), and delete ourself. |
| 216 content_ = NULL; // We are being destroyed. | 216 content_ = NULL; // We are being destroyed. |
| 217 delete this; | 217 delete this; |
| 218 } | 218 } |
| 219 | 219 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 | 262 |
| 263 apply_edits_ = false; | 263 apply_edits_ = false; |
| 264 remove_bookmark_ = true; | 264 remove_bookmark_ = true; |
| 265 bubble_->Close(); | 265 bubble_->Close(); |
| 266 } | 266 } |
| 267 | 267 |
| 268 void BookmarkBubbleGtk::ApplyEdits() { | 268 void BookmarkBubbleGtk::ApplyEdits() { |
| 269 // Set this to make sure we don't attempt to apply edits again. | 269 // Set this to make sure we don't attempt to apply edits again. |
| 270 apply_edits_ = false; | 270 apply_edits_ = false; |
| 271 | 271 |
| 272 BookmarkModel* model = profile_->GetBookmarkModel(); | 272 const BookmarkNode* node = model_->GetMostRecentlyAddedNodeForURL(url_); |
| 273 const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_); | |
| 274 if (node) { | 273 if (node) { |
| 275 const string16 new_title( | 274 const string16 new_title( |
| 276 UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(name_entry_)))); | 275 UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(name_entry_)))); |
| 277 | 276 |
| 278 if (new_title != node->GetTitle()) { | 277 if (new_title != node->GetTitle()) { |
| 279 model->SetTitle(node, new_title); | 278 model_->SetTitle(node, new_title); |
| 280 UserMetrics::RecordAction( | 279 UserMetrics::RecordAction( |
| 281 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); | 280 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); |
| 282 } | 281 } |
| 283 | 282 |
| 284 int index = gtk_combo_box_get_active(GTK_COMBO_BOX(folder_combo_)); | 283 int index = gtk_combo_box_get_active(GTK_COMBO_BOX(folder_combo_)); |
| 285 | 284 |
| 286 // Last index means 'Choose another folder...' | 285 // Last index means 'Choose another folder...' |
| 287 if (index < folder_combo_model_->GetItemCount() - 1) { | 286 if (index < folder_combo_model_->GetItemCount() - 1) { |
| 288 const BookmarkNode* new_parent = folder_combo_model_->GetNodeAt(index); | 287 const BookmarkNode* new_parent = folder_combo_model_->GetNodeAt(index); |
| 289 if (new_parent != node->parent()) { | 288 if (new_parent != node->parent()) { |
| 290 UserMetrics::RecordAction( | 289 UserMetrics::RecordAction( |
| 291 UserMetricsAction("BookmarkBubble_ChangeParent")); | 290 UserMetricsAction("BookmarkBubble_ChangeParent")); |
| 292 model->Move(node, new_parent, new_parent->child_count()); | 291 model_->Move(node, new_parent, new_parent->child_count()); |
| 293 } | 292 } |
| 294 } | 293 } |
| 295 } | 294 } |
| 296 } | 295 } |
| 297 | 296 |
| 298 std::string BookmarkBubbleGtk::GetTitle() { | 297 std::string BookmarkBubbleGtk::GetTitle() { |
| 299 BookmarkModel* bookmark_model= profile_->GetBookmarkModel(); | 298 const BookmarkNode* node = model_->GetMostRecentlyAddedNodeForURL(url_); |
| 300 const BookmarkNode* node = | |
| 301 bookmark_model->GetMostRecentlyAddedNodeForURL(url_); | |
| 302 if (!node) { | 299 if (!node) { |
| 303 NOTREACHED(); | 300 NOTREACHED(); |
| 304 return std::string(); | 301 return std::string(); |
| 305 } | 302 } |
| 306 | 303 |
| 307 return UTF16ToUTF8(node->GetTitle()); | 304 return UTF16ToUTF8(node->GetTitle()); |
| 308 } | 305 } |
| 309 | 306 |
| 310 void BookmarkBubbleGtk::ShowEditor() { | 307 void BookmarkBubbleGtk::ShowEditor() { |
| 311 const BookmarkNode* node = | 308 const BookmarkNode* node = model_->GetMostRecentlyAddedNodeForURL(url_); |
| 312 profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url_); | |
| 313 | 309 |
| 314 // Commit any edits now. | 310 // Commit any edits now. |
| 315 ApplyEdits(); | 311 ApplyEdits(); |
| 316 | 312 |
| 317 // Closing might delete us, so we'll cache what we need on the stack. | 313 // Closing might delete us, so we'll cache what we need on the stack. |
| 318 Profile* profile = profile_; | 314 Profile* profile = profile_; |
| 319 GtkWindow* toplevel = GTK_WINDOW(gtk_widget_get_toplevel(anchor_)); | 315 GtkWindow* toplevel = GTK_WINDOW(gtk_widget_get_toplevel(anchor_)); |
| 320 | 316 |
| 321 // Close the bubble, deleting the C++ objects, etc. | 317 // Close the bubble, deleting the C++ objects, etc. |
| 322 bubble_->Close(); | 318 bubble_->Close(); |
| 323 | 319 |
| 324 if (node) { | 320 if (node) { |
| 325 BookmarkEditor::Show(toplevel, profile, | 321 BookmarkEditor::Show(toplevel, profile, |
| 326 BookmarkEditor::EditDetails::EditNode(node), | 322 BookmarkEditor::EditDetails::EditNode(node), |
| 327 BookmarkEditor::SHOW_TREE); | 323 BookmarkEditor::SHOW_TREE); |
| 328 } | 324 } |
| 329 } | 325 } |
| 330 | 326 |
| 331 void BookmarkBubbleGtk::InitFolderComboModel() { | 327 void BookmarkBubbleGtk::InitFolderComboModel() { |
| 332 const BookmarkNode* node = | 328 const BookmarkNode* node = model_->GetMostRecentlyAddedNodeForURL(url_); |
| 333 profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url_); | |
| 334 DCHECK(node); | 329 DCHECK(node); |
| 335 | 330 |
| 336 folder_combo_model_.reset(new RecentlyUsedFoldersComboModel( | 331 folder_combo_model_.reset(new RecentlyUsedFoldersComboModel(model_, node)); |
| 337 profile_->GetBookmarkModel(), node)); | |
| 338 | 332 |
| 339 // We always have nodes + 1 entries in the combo. The last entry will be | 333 // We always have nodes + 1 entries in the combo. The last entry will be |
| 340 // the 'Select another folder...' entry that opens the bookmark editor. | 334 // the 'Select another folder...' entry that opens the bookmark editor. |
| 341 for (int i = 0; i < folder_combo_model_->GetItemCount(); ++i) { | 335 for (int i = 0; i < folder_combo_model_->GetItemCount(); ++i) { |
| 342 gtk_combo_box_append_text(GTK_COMBO_BOX(folder_combo_), | 336 gtk_combo_box_append_text(GTK_COMBO_BOX(folder_combo_), |
| 343 UTF16ToUTF8(folder_combo_model_->GetItemAt(i)).c_str()); | 337 UTF16ToUTF8(folder_combo_model_->GetItemAt(i)).c_str()); |
| 344 } | 338 } |
| 345 | 339 |
| 346 gtk_combo_box_set_active(GTK_COMBO_BOX(folder_combo_), | 340 gtk_combo_box_set_active(GTK_COMBO_BOX(folder_combo_), |
| 347 folder_combo_model_->node_parent_index()); | 341 folder_combo_model_->node_parent_index()); |
| 348 } | 342 } |
| OLD | NEW |