| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 const EditDetails& details, | 65 const EditDetails& details, |
| 66 BookmarkEditor::Configuration configuration) | 66 BookmarkEditor::Configuration configuration) |
| 67 : profile_(profile), | 67 : profile_(profile), |
| 68 tree_view_(NULL), | 68 tree_view_(NULL), |
| 69 url_label_(NULL), | 69 url_label_(NULL), |
| 70 url_tf_(NULL), | 70 url_tf_(NULL), |
| 71 title_label_(NULL), | 71 title_label_(NULL), |
| 72 title_tf_(NULL), | 72 title_tf_(NULL), |
| 73 parent_(parent), | 73 parent_(parent), |
| 74 details_(details), | 74 details_(details), |
| 75 bb_model_(BookmarkModelFactory::GetForProfile(profile)), |
| 75 running_menu_for_root_(false), | 76 running_menu_for_root_(false), |
| 76 show_tree_(configuration == SHOW_TREE) { | 77 show_tree_(configuration == SHOW_TREE) { |
| 77 DCHECK(profile); | 78 DCHECK(profile); |
| 79 DCHECK(bb_model_); |
| 80 DCHECK(bb_model_->client()->CanBeEditedByUser(parent)); |
| 78 Init(); | 81 Init(); |
| 79 } | 82 } |
| 80 | 83 |
| 81 BookmarkEditorView::~BookmarkEditorView() { | 84 BookmarkEditorView::~BookmarkEditorView() { |
| 82 // The tree model is deleted before the view. Reset the model otherwise the | 85 // The tree model is deleted before the view. Reset the model otherwise the |
| 83 // tree will reference a deleted model. | 86 // tree will reference a deleted model. |
| 84 if (tree_view_) | 87 if (tree_view_) |
| 85 tree_view_->SetModel(NULL); | 88 tree_view_->SetModel(NULL); |
| 86 bb_model_->RemoveObserver(this); | 89 bb_model_->RemoveObserver(this); |
| 87 } | 90 } |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 gfx::Rect(point, gfx::Size()), | 258 gfx::Rect(point, gfx::Size()), |
| 256 views::MENU_ANCHOR_TOPRIGHT, | 259 views::MENU_ANCHOR_TOPRIGHT, |
| 257 source_type, | 260 source_type, |
| 258 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == | 261 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == |
| 259 views::MenuRunner::MENU_DELETED) { | 262 views::MenuRunner::MENU_DELETED) { |
| 260 return; | 263 return; |
| 261 } | 264 } |
| 262 } | 265 } |
| 263 | 266 |
| 264 void BookmarkEditorView::Init() { | 267 void BookmarkEditorView::Init() { |
| 265 bb_model_ = BookmarkModelFactory::GetForProfile(profile_); | |
| 266 DCHECK(bb_model_); | |
| 267 bb_model_->AddObserver(this); | 268 bb_model_->AddObserver(this); |
| 268 | 269 |
| 269 title_label_ = new views::Label( | 270 title_label_ = new views::Label( |
| 270 l10n_util::GetStringUTF16(IDS_BOOKMARK_EDITOR_NAME_LABEL)); | 271 l10n_util::GetStringUTF16(IDS_BOOKMARK_EDITOR_NAME_LABEL)); |
| 271 | 272 |
| 272 base::string16 title; | 273 base::string16 title; |
| 273 GURL url; | 274 GURL url; |
| 274 if (details_.type == EditDetails::EXISTING_NODE) { | 275 if (details_.type == EditDetails::EXISTING_NODE) { |
| 275 title = details_.existing_node->GetTitle(); | 276 title = details_.existing_node->GetTitle(); |
| 276 url = details_.existing_node->url(); | 277 url = details_.existing_node->url(); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 DCHECK_EQ(BookmarkNode::OTHER_NODE, bb_root_node->GetChild(1)->type()); | 501 DCHECK_EQ(BookmarkNode::OTHER_NODE, bb_root_node->GetChild(1)->type()); |
| 501 if (root_node->child_count() >= 3) | 502 if (root_node->child_count() >= 3) |
| 502 DCHECK_EQ(BookmarkNode::MOBILE, bb_root_node->GetChild(2)->type()); | 503 DCHECK_EQ(BookmarkNode::MOBILE, bb_root_node->GetChild(2)->type()); |
| 503 return root_node; | 504 return root_node; |
| 504 } | 505 } |
| 505 | 506 |
| 506 void BookmarkEditorView::CreateNodes(const BookmarkNode* bb_node, | 507 void BookmarkEditorView::CreateNodes(const BookmarkNode* bb_node, |
| 507 BookmarkEditorView::EditorNode* b_node) { | 508 BookmarkEditorView::EditorNode* b_node) { |
| 508 for (int i = 0; i < bb_node->child_count(); ++i) { | 509 for (int i = 0; i < bb_node->child_count(); ++i) { |
| 509 const BookmarkNode* child_bb_node = bb_node->GetChild(i); | 510 const BookmarkNode* child_bb_node = bb_node->GetChild(i); |
| 510 if (child_bb_node->IsVisible() && child_bb_node->is_folder()) { | 511 if (child_bb_node->IsVisible() && child_bb_node->is_folder() && |
| 512 bb_model_->client()->CanBeEditedByUser(child_bb_node)) { |
| 511 EditorNode* new_b_node = new EditorNode(child_bb_node->GetTitle(), | 513 EditorNode* new_b_node = new EditorNode(child_bb_node->GetTitle(), |
| 512 child_bb_node->id()); | 514 child_bb_node->id()); |
| 513 b_node->Add(new_b_node, b_node->child_count()); | 515 b_node->Add(new_b_node, b_node->child_count()); |
| 514 CreateNodes(child_bb_node, new_b_node); | 516 CreateNodes(child_bb_node, new_b_node); |
| 515 } | 517 } |
| 516 } | 518 } |
| 517 } | 519 } |
| 518 | 520 |
| 519 BookmarkEditorView::EditorNode* BookmarkEditorView::FindNodeWithID( | 521 BookmarkEditorView::EditorNode* BookmarkEditorView::FindNodeWithID( |
| 520 BookmarkEditorView::EditorNode* node, | 522 BookmarkEditorView::EditorNode* node, |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 } | 637 } |
| 636 return context_menu_model_.get(); | 638 return context_menu_model_.get(); |
| 637 } | 639 } |
| 638 | 640 |
| 639 void BookmarkEditorView::EditorTreeModel::SetTitle( | 641 void BookmarkEditorView::EditorTreeModel::SetTitle( |
| 640 ui::TreeModelNode* node, | 642 ui::TreeModelNode* node, |
| 641 const base::string16& title) { | 643 const base::string16& title) { |
| 642 if (!title.empty()) | 644 if (!title.empty()) |
| 643 ui::TreeNodeModel<EditorNode>::SetTitle(node, title); | 645 ui::TreeNodeModel<EditorNode>::SetTitle(node, title); |
| 644 } | 646 } |
| OLD | NEW |