bookmark_editor_view.cc revision 868fa2fe829687343ffae624259930155e16dbd8
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 = profile_ ? 335 components::UserPrefs::Get(profile_) : 336 NULL; 337 url_tf_->SetText(chrome::FormatBookmarkURLForDisplay(url, prefs)); 338 url_tf_->SetController(this); 339 url_tf_->SetAccessibleName(url_label_->text()); 340 341 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 342 343 layout->StartRow(0, labels_column_set_id); 344 layout->AddView(url_label_); 345 layout->AddView(url_tf_); 346 } 347 348 if (show_tree_) { 349 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 350 layout->StartRow(1, single_column_view_set_id); 351 layout->AddView(tree_view_->CreateParentIfNecessary()); 352 } 353 354 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 355 356 if (!show_tree_ || bb_model_->loaded()) 357 Reset(); 358} 359 360void BookmarkEditorView::BookmarkNodeMoved(BookmarkModel* model, 361 const BookmarkNode* old_parent, 362 int old_index, 363 const BookmarkNode* new_parent, 364 int new_index) { 365 Reset(); 366} 367 368void BookmarkEditorView::BookmarkNodeAdded(BookmarkModel* model, 369 const BookmarkNode* parent, 370 int index) { 371 Reset(); 372} 373 374void BookmarkEditorView::BookmarkNodeRemoved(BookmarkModel* model, 375 const BookmarkNode* parent, 376 int index, 377 const BookmarkNode* node) { 378 if ((details_.type == EditDetails::EXISTING_NODE && 379 details_.existing_node->HasAncestor(node)) || 380 (parent_ && parent_->HasAncestor(node))) { 381 // The node, or its parent was removed. Close the dialog. 382 GetWidget()->Close(); 383 } else { 384 Reset(); 385 } 386} 387 388void BookmarkEditorView::BookmarkAllNodesRemoved(BookmarkModel* model) { 389 Reset(); 390} 391 392void BookmarkEditorView::BookmarkNodeChildrenReordered( 393 BookmarkModel* model, const BookmarkNode* node) { 394 Reset(); 395} 396 397void BookmarkEditorView::Reset() { 398 if (!show_tree_) { 399 if (parent()) 400 UserInputChanged(); 401 return; 402 } 403 404 new_folder_button_->SetEnabled(true); 405 406 // Do this first, otherwise when we invoke SetModel with the real one 407 // tree_view will try to invoke something on the model we just deleted. 408 tree_view_->SetModel(NULL); 409 410 EditorNode* root_node = CreateRootNode(); 411 tree_model_.reset(new EditorTreeModel(root_node)); 412 413 tree_view_->SetModel(tree_model_.get()); 414 tree_view_->SetController(this); 415 416 context_menu_runner_.reset(); 417 418 if (parent()) 419 ExpandAndSelect(); 420} 421 422GURL BookmarkEditorView::GetInputURL() const { 423 if (details_.GetNodeType() == BookmarkNode::FOLDER) 424 return GURL(); 425 return URLFixerUpper::FixupURL(UTF16ToUTF8(url_tf_->text()), std::string()); 426} 427 428void BookmarkEditorView::UserInputChanged() { 429 if (details_.GetNodeType() != BookmarkNode::FOLDER) { 430 const GURL url(GetInputURL()); 431 if (!url.is_valid()) 432 url_tf_->SetBackgroundColor(kErrorColor); 433 else 434 url_tf_->UseDefaultBackgroundColor(); 435 } 436 GetDialogClientView()->UpdateDialogButtons(); 437} 438 439void BookmarkEditorView::NewFolder() { 440 // Create a new entry parented to the selected item, or the bookmark 441 // bar if nothing is selected. 442 EditorNode* parent = tree_model_->AsNode(tree_view_->GetSelectedNode()); 443 if (!parent) { 444 NOTREACHED(); 445 return; 446 } 447 448 tree_view_->StartEditing(AddNewFolder(parent)); 449} 450 451BookmarkEditorView::EditorNode* BookmarkEditorView::AddNewFolder( 452 EditorNode* parent) { 453 EditorNode* new_node = new EditorNode( 454 l10n_util::GetStringUTF16(IDS_BOOKMARK_EDITOR_NEW_FOLDER_NAME), 0); 455 // |new_node| is now owned by |parent|. 456 tree_model_->Add(parent, new_node, parent->child_count()); 457 return new_node; 458} 459 460void BookmarkEditorView::ExpandAndSelect() { 461 BookmarkExpandedStateTracker::Nodes expanded_nodes = 462 bb_model_->expanded_state_tracker()->GetExpandedNodes(); 463 for (BookmarkExpandedStateTracker::Nodes::const_iterator i( 464 expanded_nodes.begin()); i != expanded_nodes.end(); ++i) { 465 EditorNode* editor_node = 466 FindNodeWithID(tree_model_->GetRoot(), (*i)->id()); 467 if (editor_node) 468 tree_view_->Expand(editor_node); 469 } 470 471 const BookmarkNode* to_select = parent_; 472 if (details_.type == EditDetails::EXISTING_NODE) 473 to_select = details_.existing_node->parent(); 474 int64 folder_id_to_select = to_select->id(); 475 EditorNode* b_node = 476 FindNodeWithID(tree_model_->GetRoot(), folder_id_to_select); 477 if (!b_node) 478 b_node = tree_model_->GetRoot()->GetChild(0); // Bookmark bar node. 479 480 tree_view_->SetSelectedNode(b_node); 481} 482 483BookmarkEditorView::EditorNode* BookmarkEditorView::CreateRootNode() { 484 EditorNode* root_node = new EditorNode(string16(), 0); 485 const BookmarkNode* bb_root_node = bb_model_->root_node(); 486 CreateNodes(bb_root_node, root_node); 487 DCHECK(root_node->child_count() >= 2 && root_node->child_count() <= 3); 488 DCHECK_EQ(BookmarkNode::BOOKMARK_BAR, bb_root_node->GetChild(0)->type()); 489 DCHECK_EQ(BookmarkNode::OTHER_NODE, bb_root_node->GetChild(1)->type()); 490 if (root_node->child_count() == 3) 491 DCHECK_EQ(BookmarkNode::MOBILE, bb_root_node->GetChild(2)->type()); 492 return root_node; 493} 494 495void BookmarkEditorView::CreateNodes(const BookmarkNode* bb_node, 496 BookmarkEditorView::EditorNode* b_node) { 497 for (int i = 0; i < bb_node->child_count(); ++i) { 498 const BookmarkNode* child_bb_node = bb_node->GetChild(i); 499 if (child_bb_node->IsVisible() && child_bb_node->is_folder()) { 500 EditorNode* new_b_node = new EditorNode(child_bb_node->GetTitle(), 501 child_bb_node->id()); 502 b_node->Add(new_b_node, b_node->child_count()); 503 CreateNodes(child_bb_node, new_b_node); 504 } 505 } 506} 507 508BookmarkEditorView::EditorNode* BookmarkEditorView::FindNodeWithID( 509 BookmarkEditorView::EditorNode* node, 510 int64 id) { 511 if (node->value == id) 512 return node; 513 for (int i = 0; i < node->child_count(); ++i) { 514 EditorNode* result = FindNodeWithID(node->GetChild(i), id); 515 if (result) 516 return result; 517 } 518 return NULL; 519} 520 521void BookmarkEditorView::ApplyEdits() { 522 DCHECK(bb_model_->loaded()); 523 524 if (tree_view_) 525 tree_view_->CommitEdit(); 526 527 EditorNode* parent = show_tree_ ? 528 tree_model_->AsNode(tree_view_->GetSelectedNode()) : NULL; 529 if (show_tree_ && !parent) { 530 NOTREACHED(); 531 return; 532 } 533 ApplyEdits(parent); 534} 535 536void BookmarkEditorView::ApplyEdits(EditorNode* parent) { 537 DCHECK(!show_tree_ || parent); 538 539 // We're going to apply edits to the bookmark bar model, which will call us 540 // back. Normally when a structural edit occurs we reset the tree model. 541 // We don't want to do that here, so we remove ourselves as an observer. 542 bb_model_->RemoveObserver(this); 543 544 GURL new_url(GetInputURL()); 545 string16 new_title(title_tf_->text()); 546 547 if (!show_tree_) { 548 bookmark_utils::ApplyEditsWithNoFolderChange( 549 bb_model_, parent_, details_, new_title, new_url); 550 return; 551 } 552 553 // Create the new folders and update the titles. 554 const BookmarkNode* new_parent = NULL; 555 ApplyNameChangesAndCreateNewFolders( 556 bb_model_->root_node(), tree_model_->GetRoot(), parent, &new_parent); 557 558 bookmark_utils::ApplyEditsWithPossibleFolderChange( 559 bb_model_, new_parent, details_, new_title, new_url); 560 561 BookmarkExpandedStateTracker::Nodes expanded_nodes; 562 UpdateExpandedNodes(tree_model_->GetRoot(), &expanded_nodes); 563 bb_model_->expanded_state_tracker()->SetExpandedNodes(expanded_nodes); 564 565 // Remove the folders that were removed. This has to be done after all the 566 // other changes have been committed. 567 bookmark_utils::DeleteBookmarkFolders(bb_model_, deletes_); 568} 569 570void BookmarkEditorView::ApplyNameChangesAndCreateNewFolders( 571 const BookmarkNode* bb_node, 572 BookmarkEditorView::EditorNode* b_node, 573 BookmarkEditorView::EditorNode* parent_b_node, 574 const BookmarkNode** parent_bb_node) { 575 if (parent_b_node == b_node) 576 *parent_bb_node = bb_node; 577 for (int i = 0; i < b_node->child_count(); ++i) { 578 EditorNode* child_b_node = b_node->GetChild(i); 579 const BookmarkNode* child_bb_node = NULL; 580 if (child_b_node->value == 0) { 581 // New folder. 582 child_bb_node = bb_model_->AddFolder(bb_node, 583 bb_node->child_count(), child_b_node->GetTitle()); 584 child_b_node->value = child_bb_node->id(); 585 } else { 586 // Existing node, reset the title (BookmarkModel ignores changes if the 587 // title is the same). 588 for (int j = 0; j < bb_node->child_count(); ++j) { 589 const BookmarkNode* node = bb_node->GetChild(j); 590 if (node->is_folder() && node->id() == child_b_node->value) { 591 child_bb_node = node; 592 break; 593 } 594 } 595 DCHECK(child_bb_node); 596 bb_model_->SetTitle(child_bb_node, child_b_node->GetTitle()); 597 } 598 ApplyNameChangesAndCreateNewFolders(child_bb_node, child_b_node, 599 parent_b_node, parent_bb_node); 600 } 601} 602 603void BookmarkEditorView::UpdateExpandedNodes( 604 EditorNode* editor_node, 605 BookmarkExpandedStateTracker::Nodes* expanded_nodes) { 606 if (!tree_view_->IsExpanded(editor_node)) 607 return; 608 609 if (editor_node->value != 0) // The root is 0 610 expanded_nodes->insert(bb_model_->GetNodeByID(editor_node->value)); 611 for (int i = 0; i < editor_node->child_count(); ++i) 612 UpdateExpandedNodes(editor_node->GetChild(i), expanded_nodes); 613} 614 615ui::SimpleMenuModel* BookmarkEditorView::GetMenuModel() { 616 if (!context_menu_model_.get()) { 617 context_menu_model_.reset(new ui::SimpleMenuModel(this)); 618 context_menu_model_->AddItemWithStringId(IDS_EDIT, IDS_EDIT); 619 context_menu_model_->AddItemWithStringId(IDS_DELETE, IDS_DELETE); 620 context_menu_model_->AddItemWithStringId( 621 IDS_BOOKMARK_EDITOR_NEW_FOLDER_MENU_ITEM, 622 IDS_BOOKMARK_EDITOR_NEW_FOLDER_MENU_ITEM); 623 } 624 return context_menu_model_.get(); 625} 626 627void BookmarkEditorView::EditorTreeModel::SetTitle(ui::TreeModelNode* node, 628 const string16& title) { 629 if (!title.empty()) 630 ui::TreeNodeModel<EditorNode>::SetTitle(node, title); 631} 632