bookmark_editor_view.cc revision 5e3f23d412006dc4db4e659864679f29341e113f
1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/ui/views/bookmarks/bookmark_editor_view.h"
6
7#include <string>
8
9#include "base/basictypes.h"
10#include "base/logging.h"
11#include "base/prefs/pref_service.h"
12#include "base/strings/string_util.h"
13#include "base/strings/utf_string_conversions.h"
14#include "chrome/browser/bookmarks/bookmark_model.h"
15#include "chrome/browser/bookmarks/bookmark_model_factory.h"
16#include "chrome/browser/bookmarks/bookmark_utils.h"
17#include "chrome/browser/history/history_service.h"
18#include "chrome/browser/net/url_fixer_upper.h"
19#include "chrome/browser/profiles/profile.h"
20#include "chrome/browser/ui/bookmarks/bookmark_utils.h"
21#include "components/user_prefs/user_prefs.h"
22#include "googleurl/src/gurl.h"
23#include "grit/chromium_strings.h"
24#include "grit/generated_resources.h"
25#include "grit/locale_settings.h"
26#include "ui/base/events/event.h"
27#include "ui/base/l10n/l10n_util.h"
28#include "ui/views/background.h"
29#include "ui/views/controls/button/label_button.h"
30#include "ui/views/controls/label.h"
31#include "ui/views/controls/menu/menu_runner.h"
32#include "ui/views/controls/textfield/textfield.h"
33#include "ui/views/controls/tree/tree_view.h"
34#include "ui/views/focus/focus_manager.h"
35#include "ui/views/layout/grid_layout.h"
36#include "ui/views/layout/layout_constants.h"
37#include "ui/views/widget/widget.h"
38#include "ui/views/window/dialog_client_view.h"
39
40using views::GridLayout;
41
42namespace {
43
44// Background color of text field when URL is invalid.
45const SkColor kErrorColor = SkColorSetRGB(0xFF, 0xBC, 0xBC);
46
47}  // namespace
48
49// static
50void BookmarkEditor::Show(gfx::NativeWindow parent_window,
51                          Profile* profile,
52                          const EditDetails& details,
53                          Configuration configuration) {
54  DCHECK(profile);
55  BookmarkEditorView* editor = new BookmarkEditorView(profile,
56      details.parent_node, details, configuration);
57  editor->Show(parent_window);
58}
59
60BookmarkEditorView::BookmarkEditorView(
61    Profile* profile,
62    const BookmarkNode* parent,
63    const EditDetails& details,
64    BookmarkEditor::Configuration configuration)
65    : profile_(profile),
66      tree_view_(NULL),
67      new_folder_button_(NULL),
68      url_label_(NULL),
69      url_tf_(NULL),
70      title_label_(NULL),
71      title_tf_(NULL),
72      parent_(parent),
73      details_(details),
74      running_menu_for_root_(false),
75      show_tree_(configuration == SHOW_TREE) {
76  DCHECK(profile);
77  Init();
78}
79
80BookmarkEditorView::~BookmarkEditorView() {
81  // The tree model is deleted before the view. Reset the model otherwise the
82  // tree will reference a deleted model.
83  if (tree_view_)
84    tree_view_->SetModel(NULL);
85  bb_model_->RemoveObserver(this);
86}
87
88string16 BookmarkEditorView::GetDialogButtonLabel(
89    ui::DialogButton button) const {
90  if (button == ui::DIALOG_BUTTON_OK)
91    return l10n_util::GetStringUTF16(IDS_SAVE);
92  return views::DialogDelegateView::GetDialogButtonLabel(button);
93}
94
95bool BookmarkEditorView::IsDialogButtonEnabled(ui::DialogButton button) const {
96  if (button == ui::DIALOG_BUTTON_OK) {
97    if (!bb_model_->loaded())
98      return false;
99
100    if (details_.GetNodeType() != BookmarkNode::FOLDER)
101      return GetInputURL().is_valid();
102  }
103  return true;
104}
105
106views::View* BookmarkEditorView::CreateExtraView() {
107  return new_folder_button_.get();
108}
109
110ui::ModalType BookmarkEditorView::GetModalType() const {
111  return ui::MODAL_TYPE_WINDOW;
112}
113
114bool BookmarkEditorView::CanResize() const {
115  return true;
116}
117
118string16 BookmarkEditorView::GetWindowTitle() const {
119  return l10n_util::GetStringUTF16(details_.GetWindowTitleId());
120}
121
122bool BookmarkEditorView::Accept() {
123  if (!IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)) {
124    if (details_.GetNodeType() != BookmarkNode::FOLDER) {
125      // The url is invalid, focus the url field.
126      url_tf_->SelectAll(true);
127      url_tf_->RequestFocus();
128    }
129    return false;
130  }
131  // Otherwise save changes and close the dialog box.
132  ApplyEdits();
133  return true;
134}
135
136gfx::Size BookmarkEditorView::GetPreferredSize() {
137  if (!show_tree_)
138    return views::View::GetPreferredSize();
139
140  return gfx::Size(views::Widget::GetLocalizedContentsSize(
141      IDS_EDITBOOKMARK_DIALOG_WIDTH_CHARS,
142      IDS_EDITBOOKMARK_DIALOG_HEIGHT_LINES));
143}
144
145void BookmarkEditorView::OnTreeViewSelectionChanged(
146    views::TreeView* tree_view) {
147}
148
149bool BookmarkEditorView::CanEdit(views::TreeView* tree_view,
150                                 ui::TreeModelNode* node) {
151  // Only allow editting of children of the bookmark bar node and other node.
152  EditorNode* bb_node = tree_model_->AsNode(node);
153  return (bb_node->parent() && bb_node->parent()->parent());
154}
155
156void BookmarkEditorView::ContentsChanged(views::Textfield* sender,
157                                         const string16& new_contents) {
158  UserInputChanged();
159}
160
161bool BookmarkEditorView::HandleKeyEvent(views::Textfield* sender,
162                                        const ui::KeyEvent& key_event) {
163    return false;
164}
165
166void BookmarkEditorView::ButtonPressed(views::Button* sender,
167                                       const ui::Event& event) {
168  DCHECK_EQ(new_folder_button_.get(), sender);
169  NewFolder();
170}
171
172bool BookmarkEditorView::IsCommandIdChecked(int command_id) const {
173  return false;
174}
175
176bool BookmarkEditorView::IsCommandIdEnabled(int command_id) const {
177  switch (command_id) {
178    case IDS_EDIT:
179    case IDS_DELETE:
180      return !running_menu_for_root_;
181    case IDS_BOOKMARK_EDITOR_NEW_FOLDER_MENU_ITEM:
182      return true;
183    default:
184      NOTREACHED();
185      return false;
186  }
187}
188
189bool BookmarkEditorView::GetAcceleratorForCommandId(
190    int command_id,
191    ui::Accelerator* accelerator) {
192  return GetWidget()->GetAccelerator(command_id, accelerator);
193}
194
195void BookmarkEditorView::ExecuteCommand(int command_id, int event_flags) {
196  DCHECK(tree_view_->GetSelectedNode());
197  if (command_id == IDS_EDIT) {
198    tree_view_->StartEditing(tree_view_->GetSelectedNode());
199  } else if (command_id == IDS_DELETE) {
200    EditorNode* node = tree_model_->AsNode(tree_view_->GetSelectedNode());
201    if (!node)
202      return;
203    if (node->value != 0) {
204      const BookmarkNode* b_node = bb_model_->GetNodeByID(node->value);
205      if (!b_node->empty() &&
206          !chrome::ConfirmDeleteBookmarkNode(b_node,
207            GetWidget()->GetNativeWindow())) {
208        // The folder is not empty and the user didn't confirm.
209        return;
210      }
211      deletes_.push_back(node->value);
212    }
213    tree_model_->Remove(node->parent(), node);
214  } else {
215    DCHECK_EQ(IDS_BOOKMARK_EDITOR_NEW_FOLDER_MENU_ITEM, command_id);
216    NewFolder();
217  }
218}
219
220void BookmarkEditorView::Show(gfx::NativeWindow parent) {
221  views::DialogDelegate::CreateDialogWidget(this, NULL, parent);
222  UserInputChanged();
223  if (show_tree_ && bb_model_->loaded())
224    ExpandAndSelect();
225  GetWidget()->Show();
226  // Select all the text in the name Textfield.
227  title_tf_->SelectAll(true);
228  // Give focus to the name Textfield.
229  title_tf_->RequestFocus();
230}
231
232void BookmarkEditorView::Close() {
233  DCHECK(GetWidget());
234  GetWidget()->Close();
235}
236
237void BookmarkEditorView::ShowContextMenuForView(views::View* source,
238                                                const gfx::Point& point) {
239  DCHECK_EQ(tree_view_, source);
240  if (!tree_view_->GetSelectedNode())
241    return;
242  running_menu_for_root_ =
243      (tree_model_->GetParent(tree_view_->GetSelectedNode()) ==
244       tree_model_->GetRoot());
245
246  context_menu_runner_.reset(new views::MenuRunner(GetMenuModel()));
247
248  if (context_menu_runner_->RunMenuAt(source->GetWidget()->GetTopLevelWidget(),
249        NULL, gfx::Rect(point, gfx::Size()), views::MenuItemView::TOPRIGHT,
250        views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) ==
251        views::MenuRunner::MENU_DELETED)
252    return;
253}
254
255void BookmarkEditorView::Init() {
256  bb_model_ = BookmarkModelFactory::GetForProfile(profile_);
257  DCHECK(bb_model_);
258  bb_model_->AddObserver(this);
259
260  title_label_ = new views::Label(
261      l10n_util::GetStringUTF16(IDS_BOOKMARK_EDITOR_NAME_LABEL));
262
263  string16 title;
264  GURL url;
265  if (details_.type == EditDetails::EXISTING_NODE) {
266    title = details_.existing_node->GetTitle();
267    url = details_.existing_node->url();
268  } else if (details_.type == EditDetails::NEW_FOLDER) {
269    title = l10n_util::GetStringUTF16(IDS_BOOKMARK_EDITOR_NEW_FOLDER_NAME);
270  } else if (details_.type == EditDetails::NEW_URL) {
271    url = details_.url;
272    title = details_.title;
273  }
274  title_tf_ = new views::Textfield;
275  title_tf_->SetText(title);
276  title_tf_->SetController(this);
277  title_tf_->SetAccessibleName(title_label_->text());
278
279  if (show_tree_) {
280    tree_view_ = new views::TreeView;
281    tree_view_->SetRootShown(false);
282    tree_view_->set_context_menu_controller(this);
283
284    new_folder_button_.reset(new views::LabelButton(this,
285        l10n_util::GetStringUTF16(IDS_BOOKMARK_EDITOR_NEW_FOLDER_BUTTON)));
286    new_folder_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON);
287    new_folder_button_->set_owned_by_client();
288    new_folder_button_->SetEnabled(false);
289  }
290
291  GridLayout* layout = GridLayout::CreatePanel(this);
292  SetLayoutManager(layout);
293
294  const int labels_column_set_id = 0;
295  const int single_column_view_set_id = 1;
296  const int buttons_column_set_id = 2;
297
298  views::ColumnSet* column_set = layout->AddColumnSet(labels_column_set_id);
299  column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
300                        GridLayout::USE_PREF, 0, 0);
301  column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
302  column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1,
303                        GridLayout::USE_PREF, 0, 0);
304
305  column_set = layout->AddColumnSet(single_column_view_set_id);
306  if (views::DialogDelegate::UseNewStyle()) {
307    column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
308                          GridLayout::USE_PREF, 0, 0);
309  } else {
310    column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
311                          GridLayout::FIXED, 300, 0);
312  }
313
314  column_set = layout->AddColumnSet(buttons_column_set_id);
315  column_set->AddColumn(GridLayout::FILL, GridLayout::LEADING, 0,
316                        GridLayout::USE_PREF, 0, 0);
317  column_set->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing);
318  column_set->AddColumn(GridLayout::FILL, GridLayout::LEADING, 0,
319                        GridLayout::USE_PREF, 0, 0);
320  column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
321  column_set->AddColumn(GridLayout::FILL, GridLayout::LEADING, 0,
322                        GridLayout::USE_PREF, 0, 0);
323  column_set->LinkColumnSizes(0, 2, 4, -1);
324
325  layout->StartRow(0, labels_column_set_id);
326  layout->AddView(title_label_);
327  layout->AddView(title_tf_);
328
329  if (details_.GetNodeType() != BookmarkNode::FOLDER) {
330    url_label_ = new views::Label(
331        l10n_util::GetStringUTF16(IDS_BOOKMARK_EDITOR_URL_LABEL));
332
333    url_tf_ = new views::Textfield;
334    PrefService* prefs =
335        profile_ ? user_prefs::UserPrefs::Get(profile_) : NULL;
336    url_tf_->SetText(chrome::FormatBookmarkURLForDisplay(url, prefs));
337    url_tf_->SetController(this);
338    url_tf_->SetAccessibleName(url_label_->text());
339
340    layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
341
342    layout->StartRow(0, labels_column_set_id);
343    layout->AddView(url_label_);
344    layout->AddView(url_tf_);
345  }
346
347  if (show_tree_) {
348    layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
349    layout->StartRow(1, single_column_view_set_id);
350    layout->AddView(tree_view_->CreateParentIfNecessary());
351  }
352
353  layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
354
355  if (!show_tree_ || bb_model_->loaded())
356    Reset();
357}
358
359void BookmarkEditorView::BookmarkNodeMoved(BookmarkModel* model,
360                                           const BookmarkNode* old_parent,
361                                           int old_index,
362                                           const BookmarkNode* new_parent,
363                                           int new_index) {
364  Reset();
365}
366
367void BookmarkEditorView::BookmarkNodeAdded(BookmarkModel* model,
368                                           const BookmarkNode* parent,
369                                           int index) {
370  Reset();
371}
372
373void BookmarkEditorView::BookmarkNodeRemoved(BookmarkModel* model,
374                                             const BookmarkNode* parent,
375                                             int index,
376                                             const BookmarkNode* node) {
377  if ((details_.type == EditDetails::EXISTING_NODE &&
378       details_.existing_node->HasAncestor(node)) ||
379      (parent_ && parent_->HasAncestor(node))) {
380    // The node, or its parent was removed. Close the dialog.
381    GetWidget()->Close();
382  } else {
383    Reset();
384  }
385}
386
387void BookmarkEditorView::BookmarkAllNodesRemoved(BookmarkModel* model) {
388  Reset();
389}
390
391void BookmarkEditorView::BookmarkNodeChildrenReordered(
392    BookmarkModel* model, const BookmarkNode* node) {
393  Reset();
394}
395
396void BookmarkEditorView::Reset() {
397  if (!show_tree_) {
398    if (parent())
399      UserInputChanged();
400    return;
401  }
402
403  new_folder_button_->SetEnabled(true);
404
405  // Do this first, otherwise when we invoke SetModel with the real one
406  // tree_view will try to invoke something on the model we just deleted.
407  tree_view_->SetModel(NULL);
408
409  EditorNode* root_node = CreateRootNode();
410  tree_model_.reset(new EditorTreeModel(root_node));
411
412  tree_view_->SetModel(tree_model_.get());
413  tree_view_->SetController(this);
414
415  context_menu_runner_.reset();
416
417  if (parent())
418    ExpandAndSelect();
419}
420
421GURL BookmarkEditorView::GetInputURL() const {
422  if (details_.GetNodeType() == BookmarkNode::FOLDER)
423    return GURL();
424  return URLFixerUpper::FixupURL(UTF16ToUTF8(url_tf_->text()), std::string());
425}
426
427void BookmarkEditorView::UserInputChanged() {
428  if (details_.GetNodeType() != BookmarkNode::FOLDER) {
429    const GURL url(GetInputURL());
430    if (!url.is_valid())
431      url_tf_->SetBackgroundColor(kErrorColor);
432    else
433      url_tf_->UseDefaultBackgroundColor();
434  }
435  GetDialogClientView()->UpdateDialogButtons();
436}
437
438void BookmarkEditorView::NewFolder() {
439  // Create a new entry parented to the selected item, or the bookmark
440  // bar if nothing is selected.
441  EditorNode* parent = tree_model_->AsNode(tree_view_->GetSelectedNode());
442  if (!parent) {
443    NOTREACHED();
444    return;
445  }
446
447  tree_view_->StartEditing(AddNewFolder(parent));
448}
449
450BookmarkEditorView::EditorNode* BookmarkEditorView::AddNewFolder(
451    EditorNode* parent) {
452  EditorNode* new_node = new EditorNode(
453      l10n_util::GetStringUTF16(IDS_BOOKMARK_EDITOR_NEW_FOLDER_NAME), 0);
454  // |new_node| is now owned by |parent|.
455  tree_model_->Add(parent, new_node, parent->child_count());
456  return new_node;
457}
458
459void BookmarkEditorView::ExpandAndSelect() {
460  BookmarkExpandedStateTracker::Nodes expanded_nodes =
461      bb_model_->expanded_state_tracker()->GetExpandedNodes();
462  for (BookmarkExpandedStateTracker::Nodes::const_iterator i(
463       expanded_nodes.begin()); i != expanded_nodes.end(); ++i) {
464    EditorNode* editor_node =
465        FindNodeWithID(tree_model_->GetRoot(), (*i)->id());
466    if (editor_node)
467      tree_view_->Expand(editor_node);
468  }
469
470  const BookmarkNode* to_select = parent_;
471  if (details_.type == EditDetails::EXISTING_NODE)
472    to_select = details_.existing_node->parent();
473  int64 folder_id_to_select = to_select->id();
474  EditorNode* b_node =
475      FindNodeWithID(tree_model_->GetRoot(), folder_id_to_select);
476  if (!b_node)
477    b_node = tree_model_->GetRoot()->GetChild(0);  // Bookmark bar node.
478
479  tree_view_->SetSelectedNode(b_node);
480}
481
482BookmarkEditorView::EditorNode* BookmarkEditorView::CreateRootNode() {
483  EditorNode* root_node = new EditorNode(string16(), 0);
484  const BookmarkNode* bb_root_node = bb_model_->root_node();
485  CreateNodes(bb_root_node, root_node);
486  DCHECK(root_node->child_count() >= 2 && root_node->child_count() <= 3);
487  DCHECK_EQ(BookmarkNode::BOOKMARK_BAR, bb_root_node->GetChild(0)->type());
488  DCHECK_EQ(BookmarkNode::OTHER_NODE, bb_root_node->GetChild(1)->type());
489  if (root_node->child_count() == 3)
490    DCHECK_EQ(BookmarkNode::MOBILE, bb_root_node->GetChild(2)->type());
491  return root_node;
492}
493
494void BookmarkEditorView::CreateNodes(const BookmarkNode* bb_node,
495                                     BookmarkEditorView::EditorNode* b_node) {
496  for (int i = 0; i < bb_node->child_count(); ++i) {
497    const BookmarkNode* child_bb_node = bb_node->GetChild(i);
498    if (child_bb_node->IsVisible() && child_bb_node->is_folder()) {
499      EditorNode* new_b_node = new EditorNode(child_bb_node->GetTitle(),
500                                              child_bb_node->id());
501      b_node->Add(new_b_node, b_node->child_count());
502      CreateNodes(child_bb_node, new_b_node);
503    }
504  }
505}
506
507BookmarkEditorView::EditorNode* BookmarkEditorView::FindNodeWithID(
508    BookmarkEditorView::EditorNode* node,
509    int64 id) {
510  if (node->value == id)
511    return node;
512  for (int i = 0; i < node->child_count(); ++i) {
513    EditorNode* result = FindNodeWithID(node->GetChild(i), id);
514    if (result)
515      return result;
516  }
517  return NULL;
518}
519
520void BookmarkEditorView::ApplyEdits() {
521  DCHECK(bb_model_->loaded());
522
523  if (tree_view_)
524    tree_view_->CommitEdit();
525
526  EditorNode* parent = show_tree_ ?
527      tree_model_->AsNode(tree_view_->GetSelectedNode()) : NULL;
528  if (show_tree_ && !parent) {
529    NOTREACHED();
530    return;
531  }
532  ApplyEdits(parent);
533}
534
535void BookmarkEditorView::ApplyEdits(EditorNode* parent) {
536  DCHECK(!show_tree_ || parent);
537
538  // We're going to apply edits to the bookmark bar model, which will call us
539  // back. Normally when a structural edit occurs we reset the tree model.
540  // We don't want to do that here, so we remove ourselves as an observer.
541  bb_model_->RemoveObserver(this);
542
543  GURL new_url(GetInputURL());
544  string16 new_title(title_tf_->text());
545
546  if (!show_tree_) {
547    bookmark_utils::ApplyEditsWithNoFolderChange(
548        bb_model_, parent_, details_, new_title, new_url);
549    return;
550  }
551
552  // Create the new folders and update the titles.
553  const BookmarkNode* new_parent = NULL;
554  ApplyNameChangesAndCreateNewFolders(
555      bb_model_->root_node(), tree_model_->GetRoot(), parent, &new_parent);
556
557  bookmark_utils::ApplyEditsWithPossibleFolderChange(
558      bb_model_, new_parent, details_, new_title, new_url);
559
560  BookmarkExpandedStateTracker::Nodes expanded_nodes;
561  UpdateExpandedNodes(tree_model_->GetRoot(), &expanded_nodes);
562  bb_model_->expanded_state_tracker()->SetExpandedNodes(expanded_nodes);
563
564  // Remove the folders that were removed. This has to be done after all the
565  // other changes have been committed.
566  bookmark_utils::DeleteBookmarkFolders(bb_model_, deletes_);
567}
568
569void BookmarkEditorView::ApplyNameChangesAndCreateNewFolders(
570    const BookmarkNode* bb_node,
571    BookmarkEditorView::EditorNode* b_node,
572    BookmarkEditorView::EditorNode* parent_b_node,
573    const BookmarkNode** parent_bb_node) {
574  if (parent_b_node == b_node)
575    *parent_bb_node = bb_node;
576  for (int i = 0; i < b_node->child_count(); ++i) {
577    EditorNode* child_b_node = b_node->GetChild(i);
578    const BookmarkNode* child_bb_node = NULL;
579    if (child_b_node->value == 0) {
580      // New folder.
581      child_bb_node = bb_model_->AddFolder(bb_node,
582          bb_node->child_count(), child_b_node->GetTitle());
583      child_b_node->value = child_bb_node->id();
584    } else {
585      // Existing node, reset the title (BookmarkModel ignores changes if the
586      // title is the same).
587      for (int j = 0; j < bb_node->child_count(); ++j) {
588        const BookmarkNode* node = bb_node->GetChild(j);
589        if (node->is_folder() && node->id() == child_b_node->value) {
590          child_bb_node = node;
591          break;
592        }
593      }
594      DCHECK(child_bb_node);
595      bb_model_->SetTitle(child_bb_node, child_b_node->GetTitle());
596    }
597    ApplyNameChangesAndCreateNewFolders(child_bb_node, child_b_node,
598                                        parent_b_node, parent_bb_node);
599  }
600}
601
602void BookmarkEditorView::UpdateExpandedNodes(
603    EditorNode* editor_node,
604    BookmarkExpandedStateTracker::Nodes* expanded_nodes) {
605  if (!tree_view_->IsExpanded(editor_node))
606    return;
607
608  if (editor_node->value != 0)  // The root is 0
609    expanded_nodes->insert(bb_model_->GetNodeByID(editor_node->value));
610  for (int i = 0; i < editor_node->child_count(); ++i)
611    UpdateExpandedNodes(editor_node->GetChild(i), expanded_nodes);
612}
613
614ui::SimpleMenuModel* BookmarkEditorView::GetMenuModel() {
615  if (!context_menu_model_.get()) {
616    context_menu_model_.reset(new ui::SimpleMenuModel(this));
617    context_menu_model_->AddItemWithStringId(IDS_EDIT, IDS_EDIT);
618    context_menu_model_->AddItemWithStringId(IDS_DELETE, IDS_DELETE);
619    context_menu_model_->AddItemWithStringId(
620        IDS_BOOKMARK_EDITOR_NEW_FOLDER_MENU_ITEM,
621        IDS_BOOKMARK_EDITOR_NEW_FOLDER_MENU_ITEM);
622  }
623  return context_menu_model_.get();
624}
625
626void BookmarkEditorView::EditorTreeModel::SetTitle(ui::TreeModelNode* node,
627                                                   const string16& title) {
628  if (!title.empty())
629    ui::TreeNodeModel<EditorNode>::SetTitle(node, title);
630}
631