OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/views/bookmarks/bookmark_editor_view.h" | 5 #include "chrome/browser/ui/views/bookmarks/bookmark_editor_view.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 if (!b_node->empty() && | 243 if (!b_node->empty() && |
244 !chrome::ConfirmDeleteBookmarkNode(b_node, | 244 !chrome::ConfirmDeleteBookmarkNode(b_node, |
245 GetWidget()->GetNativeWindow())) { | 245 GetWidget()->GetNativeWindow())) { |
246 // The folder is not empty and the user didn't confirm. | 246 // The folder is not empty and the user didn't confirm. |
247 return; | 247 return; |
248 } | 248 } |
249 deletes_.push_back(node->value); | 249 deletes_.push_back(node->value); |
250 } | 250 } |
251 tree_model_->Remove(node->parent(), node); | 251 tree_model_->Remove(node->parent(), node); |
252 } else { | 252 } else { |
253 DCHECK(command_id == IDS_BOOKMARK_EDITOR_NEW_FOLDER_MENU_ITEM); | 253 DCHECK_EQ(IDS_BOOKMARK_EDITOR_NEW_FOLDER_MENU_ITEM, command_id); |
254 NewFolder(); | 254 NewFolder(); |
255 } | 255 } |
256 } | 256 } |
257 | 257 |
258 void BookmarkEditorView::Show(gfx::NativeWindow parent_window) { | 258 void BookmarkEditorView::Show(gfx::NativeWindow parent_window) { |
259 views::Widget::CreateWindowWithParent(this, parent_window); | 259 views::Widget::CreateWindowWithParent(this, parent_window); |
260 UserInputChanged(); | 260 UserInputChanged(); |
261 if (show_tree_ && bb_model_->IsLoaded()) | 261 if (show_tree_ && bb_model_->IsLoaded()) |
262 ExpandAndSelect(); | 262 ExpandAndSelect(); |
263 GetWidget()->Show(); | 263 GetWidget()->Show(); |
264 // Select all the text in the name Textfield. | 264 // Select all the text in the name Textfield. |
265 title_tf_->SelectAll(true); | 265 title_tf_->SelectAll(true); |
266 // Give focus to the name Textfield. | 266 // Give focus to the name Textfield. |
267 title_tf_->RequestFocus(); | 267 title_tf_->RequestFocus(); |
268 } | 268 } |
269 | 269 |
270 void BookmarkEditorView::Close() { | 270 void BookmarkEditorView::Close() { |
271 DCHECK(GetWidget()); | 271 DCHECK(GetWidget()); |
272 GetWidget()->Close(); | 272 GetWidget()->Close(); |
273 } | 273 } |
274 | 274 |
275 void BookmarkEditorView::ShowContextMenuForView(views::View* source, | 275 void BookmarkEditorView::ShowContextMenuForView(views::View* source, |
276 const gfx::Point& point) { | 276 const gfx::Point& point) { |
277 DCHECK(source == tree_view_); | 277 DCHECK_EQ(tree_view_, source); |
278 if (!tree_view_->GetSelectedNode()) | 278 if (!tree_view_->GetSelectedNode()) |
279 return; | 279 return; |
280 running_menu_for_root_ = | 280 running_menu_for_root_ = |
281 (tree_model_->GetParent(tree_view_->GetSelectedNode()) == | 281 (tree_model_->GetParent(tree_view_->GetSelectedNode()) == |
282 tree_model_->GetRoot()); | 282 tree_model_->GetRoot()); |
283 | 283 |
284 views::MenuModelAdapter adapter(GetMenuModel()); | 284 views::MenuModelAdapter adapter(GetMenuModel()); |
285 context_menu_runner_.reset(new views::MenuRunner(adapter.CreateMenu())); | 285 context_menu_runner_.reset(new views::MenuRunner(adapter.CreateMenu())); |
286 | 286 |
287 if (context_menu_runner_->RunMenuAt(source->GetWidget()->GetTopLevelWidget(), | 287 if (context_menu_runner_->RunMenuAt(source->GetWidget()->GetTopLevelWidget(), |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 b_node = tree_model_->GetRoot()->GetChild(0); // Bookmark bar node. | 517 b_node = tree_model_->GetRoot()->GetChild(0); // Bookmark bar node. |
518 | 518 |
519 tree_view_->SetSelectedNode(b_node); | 519 tree_view_->SetSelectedNode(b_node); |
520 } | 520 } |
521 | 521 |
522 BookmarkEditorView::EditorNode* BookmarkEditorView::CreateRootNode() { | 522 BookmarkEditorView::EditorNode* BookmarkEditorView::CreateRootNode() { |
523 EditorNode* root_node = new EditorNode(string16(), 0); | 523 EditorNode* root_node = new EditorNode(string16(), 0); |
524 const BookmarkNode* bb_root_node = bb_model_->root_node(); | 524 const BookmarkNode* bb_root_node = bb_model_->root_node(); |
525 CreateNodes(bb_root_node, root_node); | 525 CreateNodes(bb_root_node, root_node); |
526 DCHECK(root_node->child_count() >= 2 && root_node->child_count() <= 3); | 526 DCHECK(root_node->child_count() >= 2 && root_node->child_count() <= 3); |
527 DCHECK(bb_root_node->GetChild(0)->type() == BookmarkNode::BOOKMARK_BAR); | 527 DCHECK_EQ(BookmarkNode::BOOKMARK_BAR, bb_root_node->GetChild(0)->type()); |
528 DCHECK(bb_root_node->GetChild(1)->type() == BookmarkNode::OTHER_NODE); | 528 DCHECK_EQ(BookmarkNode::OTHER_NODE, bb_root_node->GetChild(1)->type()); |
529 if (root_node->child_count() == 3) | 529 if (root_node->child_count() == 3) |
530 DCHECK(bb_root_node->GetChild(2)->type() == BookmarkNode::MOBILE); | 530 DCHECK_EQ(BookmarkNode::MOBILE, bb_root_node->GetChild(2)->type()); |
531 return root_node; | 531 return root_node; |
532 } | 532 } |
533 | 533 |
534 void BookmarkEditorView::CreateNodes(const BookmarkNode* bb_node, | 534 void BookmarkEditorView::CreateNodes(const BookmarkNode* bb_node, |
535 BookmarkEditorView::EditorNode* b_node) { | 535 BookmarkEditorView::EditorNode* b_node) { |
536 for (int i = 0; i < bb_node->child_count(); ++i) { | 536 for (int i = 0; i < bb_node->child_count(); ++i) { |
537 const BookmarkNode* child_bb_node = bb_node->GetChild(i); | 537 const BookmarkNode* child_bb_node = bb_node->GetChild(i); |
538 if (child_bb_node->IsVisible() && child_bb_node->is_folder()) { | 538 if (child_bb_node->IsVisible() && child_bb_node->is_folder()) { |
539 EditorNode* new_b_node = new EditorNode(child_bb_node->GetTitle(), | 539 EditorNode* new_b_node = new EditorNode(child_bb_node->GetTitle(), |
540 child_bb_node->id()); | 540 child_bb_node->id()); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 IDS_BOOKMARK_EDITOR_NEW_FOLDER_MENU_ITEM); | 658 IDS_BOOKMARK_EDITOR_NEW_FOLDER_MENU_ITEM); |
659 } | 659 } |
660 return context_menu_model_.get(); | 660 return context_menu_model_.get(); |
661 } | 661 } |
662 | 662 |
663 void BookmarkEditorView::EditorTreeModel::SetTitle(ui::TreeModelNode* node, | 663 void BookmarkEditorView::EditorTreeModel::SetTitle(ui::TreeModelNode* node, |
664 const string16& title) { | 664 const string16& title) { |
665 if (!title.empty()) | 665 if (!title.empty()) |
666 ui::TreeNodeModel<EditorNode>::SetTitle(node, title); | 666 ui::TreeNodeModel<EditorNode>::SetTitle(node, title); |
667 } | 667 } |
OLD | NEW |