Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Side by Side Diff: chrome/browser/gtk/bookmark_bubble_gtk.cc

Issue 335032: Add a check for NULL in PopulateFolderCombo. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/gtk/bookmark_bubble_gtk.h" 5 #include "chrome/browser/gtk/bookmark_bubble_gtk.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "app/gfx/gtk_util.h" 9 #include "app/gfx/gtk_util.h"
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
(...skipping 18 matching lines...) Expand all
29 // We basically have a singleton, since a bubble is sort of app-modal. This 29 // We basically have a singleton, since a bubble is sort of app-modal. This
30 // keeps track of the currently open bubble, or NULL if none is open. 30 // keeps track of the currently open bubble, or NULL if none is open.
31 BookmarkBubbleGtk* g_bubble = NULL; 31 BookmarkBubbleGtk* g_bubble = NULL;
32 32
33 // Max number of most recently used folders. 33 // Max number of most recently used folders.
34 const size_t kMaxMRUFolders = 5; 34 const size_t kMaxMRUFolders = 5;
35 35
36 std::vector<const BookmarkNode*> PopulateFolderCombo(BookmarkModel* model, 36 std::vector<const BookmarkNode*> PopulateFolderCombo(BookmarkModel* model,
37 const GURL& url, 37 const GURL& url,
38 GtkWidget* folder_combo) { 38 GtkWidget* folder_combo) {
39 const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url);
40 const BookmarkNode* parent = node->GetParent();
41 const BookmarkNode* bookmark_bar = model->GetBookmarkBarNode(); 39 const BookmarkNode* bookmark_bar = model->GetBookmarkBarNode();
42 const BookmarkNode* other = model->other_node(); 40 const BookmarkNode* other = model->other_node();
41 const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url);
42 const BookmarkNode* parent = node ? node->GetParent() : NULL;
43 43
44 // Use + 2 to account for bookmark bar and other node. 44 // Use + 2 to account for bookmark bar and other node.
45 std::vector<const BookmarkNode*> recent_nodes = 45 std::vector<const BookmarkNode*> recent_nodes =
46 bookmark_utils::GetMostRecentlyModifiedGroups(model, kMaxMRUFolders + 2); 46 bookmark_utils::GetMostRecentlyModifiedGroups(model, kMaxMRUFolders + 2);
47 47
48 std::vector<const BookmarkNode*> nodes; 48 std::vector<const BookmarkNode*> nodes;
49 // Make the parent the first item, unless it's the bookmark bar or other node. 49 // Make the parent the first item, unless it's the bookmark bar or other node.
50 if (parent != bookmark_bar && parent != other) 50 if (parent && parent != bookmark_bar && parent != other)
51 nodes.push_back(parent); 51 nodes.push_back(parent);
52 52
53 for (size_t i = 0; i < recent_nodes.size(); ++i) { 53 for (size_t i = 0; i < recent_nodes.size(); ++i) {
54 if (recent_nodes[i] != parent && 54 if (recent_nodes[i] != parent &&
55 recent_nodes[i] != bookmark_bar && 55 recent_nodes[i] != bookmark_bar &&
56 recent_nodes[i] != other) { 56 recent_nodes[i] != other) {
57 nodes.push_back(recent_nodes[i]); 57 nodes.push_back(recent_nodes[i]);
58 } 58 }
59 // Make sure we only have kMaxMRUFolders in the first chunk. 59 // Make sure we only have kMaxMRUFolders in the first chunk.
60 if (nodes.size() == kMaxMRUFolders) 60 if (nodes.size() == kMaxMRUFolders)
61 break; 61 break;
62 } 62 }
63 63
64 // And put the bookmark bar and other nodes at the end of the list. 64 // And put the bookmark bar and other nodes at the end of the list.
65 nodes.push_back(bookmark_bar); 65 nodes.push_back(bookmark_bar);
66 nodes.push_back(other); 66 nodes.push_back(other);
67 67
68 // We always have nodes + 1 entries in the combo. The last entry will be 68 // We always have nodes + 1 entries in the combo. The last entry will be
69 // the 'Select another folder...' entry that opens the bookmark editor. 69 // the 'Select another folder...' entry that opens the bookmark editor.
70 for (size_t i = 0; i < nodes.size(); ++i) { 70 for (size_t i = 0; i < nodes.size(); ++i) {
71 gtk_combo_box_append_text(GTK_COMBO_BOX(folder_combo), 71 gtk_combo_box_append_text(GTK_COMBO_BOX(folder_combo),
72 WideToUTF8(nodes[i]->GetTitle()).c_str()); 72 WideToUTF8(nodes[i]->GetTitle()).c_str());
73 } 73 }
74 gtk_combo_box_append_text(GTK_COMBO_BOX(folder_combo), 74 gtk_combo_box_append_text(GTK_COMBO_BOX(folder_combo),
75 l10n_util::GetStringUTF8( 75 l10n_util::GetStringUTF8(
76 IDS_BOOMARK_BUBBLE_CHOOSER_ANOTHER_FOLDER).c_str()); 76 IDS_BOOMARK_BUBBLE_CHOOSER_ANOTHER_FOLDER).c_str());
77 77
78 int parent_index = static_cast<int>( 78 gint parent_index = 0;
79 std::find(nodes.begin(), nodes.end(), parent) - nodes.begin()); 79 if (parent) {
80 parent_index = static_cast<gint>(
81 std::find(nodes.begin(), nodes.end(), parent) - nodes.begin());
82 }
80 gtk_combo_box_set_active(GTK_COMBO_BOX(folder_combo), parent_index); 83 gtk_combo_box_set_active(GTK_COMBO_BOX(folder_combo), parent_index);
81 84
82 return nodes; 85 return nodes;
83 } 86 }
84 87
85 } // namespace 88 } // namespace
86 89
87 // static 90 // static
88 void BookmarkBubbleGtk::Show(GtkWindow* toplevel_window, 91 void BookmarkBubbleGtk::Show(GtkWindow* toplevel_window,
89 const gfx::Rect& rect, 92 const gfx::Rect& rect,
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 370
368 // Close the bubble, deleting the C++ objects, etc. 371 // Close the bubble, deleting the C++ objects, etc.
369 bubble_->Close(); 372 bubble_->Close();
370 373
371 if (node) { 374 if (node) {
372 BookmarkEditor::Show(toplevel, profile, NULL, 375 BookmarkEditor::Show(toplevel, profile, NULL,
373 BookmarkEditor::EditDetails(node), 376 BookmarkEditor::EditDetails(node),
374 BookmarkEditor::SHOW_TREE, NULL); 377 BookmarkEditor::SHOW_TREE, NULL);
375 } 378 }
376 } 379 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698