| 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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 if (context_menu_runner_->RunMenuAt(source->GetWidget()->GetTopLevelWidget(), | 259 if (context_menu_runner_->RunMenuAt(source->GetWidget()->GetTopLevelWidget(), |
| 260 NULL, | 260 NULL, |
| 261 gfx::Rect(point, gfx::Size()), | 261 gfx::Rect(point, gfx::Size()), |
| 262 views::MENU_ANCHOR_TOPRIGHT, | 262 views::MENU_ANCHOR_TOPRIGHT, |
| 263 source_type) == | 263 source_type) == |
| 264 views::MenuRunner::MENU_DELETED) { | 264 views::MenuRunner::MENU_DELETED) { |
| 265 return; | 265 return; |
| 266 } | 266 } |
| 267 } | 267 } |
| 268 | 268 |
| 269 const char* BookmarkEditorView::GetClassName() const { |
| 270 return "BookmarkEditorView"; |
| 271 } |
| 272 |
| 273 void BookmarkEditorView::BookmarkNodeMoved(BookmarkModel* model, |
| 274 const BookmarkNode* old_parent, |
| 275 int old_index, |
| 276 const BookmarkNode* new_parent, |
| 277 int new_index) { |
| 278 Reset(); |
| 279 } |
| 280 |
| 281 void BookmarkEditorView::BookmarkNodeAdded(BookmarkModel* model, |
| 282 const BookmarkNode* parent, |
| 283 int index) { |
| 284 Reset(); |
| 285 } |
| 286 |
| 287 void BookmarkEditorView::BookmarkNodeRemoved( |
| 288 BookmarkModel* model, |
| 289 const BookmarkNode* parent, |
| 290 int index, |
| 291 const BookmarkNode* node, |
| 292 const std::set<GURL>& removed_urls) { |
| 293 if ((details_.type == EditDetails::EXISTING_NODE && |
| 294 details_.existing_node->HasAncestor(node)) || |
| 295 (parent_ && parent_->HasAncestor(node))) { |
| 296 // The node, or its parent was removed. Close the dialog. |
| 297 GetWidget()->Close(); |
| 298 } else { |
| 299 Reset(); |
| 300 } |
| 301 } |
| 302 |
| 303 void BookmarkEditorView::BookmarkAllUserNodesRemoved( |
| 304 BookmarkModel* model, |
| 305 const std::set<GURL>& removed_urls) { |
| 306 Reset(); |
| 307 } |
| 308 |
| 309 void BookmarkEditorView::BookmarkNodeChildrenReordered( |
| 310 BookmarkModel* model, |
| 311 const BookmarkNode* node) { |
| 312 Reset(); |
| 313 } |
| 314 |
| 269 void BookmarkEditorView::Init() { | 315 void BookmarkEditorView::Init() { |
| 270 bb_model_->AddObserver(this); | 316 bb_model_->AddObserver(this); |
| 271 | 317 |
| 272 title_label_ = new views::Label( | 318 title_label_ = new views::Label( |
| 273 l10n_util::GetStringUTF16(IDS_BOOKMARK_EDITOR_NAME_LABEL)); | 319 l10n_util::GetStringUTF16(IDS_BOOKMARK_EDITOR_NAME_LABEL)); |
| 274 | 320 |
| 275 base::string16 title; | 321 base::string16 title; |
| 276 GURL url; | 322 GURL url; |
| 277 if (details_.type == EditDetails::EXISTING_NODE) { | 323 if (details_.type == EditDetails::EXISTING_NODE) { |
| 278 title = details_.existing_node->GetTitle(); | 324 title = details_.existing_node->GetTitle(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 layout->StartRow(1, single_column_view_set_id); | 404 layout->StartRow(1, single_column_view_set_id); |
| 359 layout->AddView(tree_view_->CreateParentIfNecessary()); | 405 layout->AddView(tree_view_->CreateParentIfNecessary()); |
| 360 } | 406 } |
| 361 | 407 |
| 362 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 408 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 363 | 409 |
| 364 if (!show_tree_ || bb_model_->loaded()) | 410 if (!show_tree_ || bb_model_->loaded()) |
| 365 Reset(); | 411 Reset(); |
| 366 } | 412 } |
| 367 | 413 |
| 368 void BookmarkEditorView::BookmarkNodeMoved(BookmarkModel* model, | |
| 369 const BookmarkNode* old_parent, | |
| 370 int old_index, | |
| 371 const BookmarkNode* new_parent, | |
| 372 int new_index) { | |
| 373 Reset(); | |
| 374 } | |
| 375 | |
| 376 void BookmarkEditorView::BookmarkNodeAdded(BookmarkModel* model, | |
| 377 const BookmarkNode* parent, | |
| 378 int index) { | |
| 379 Reset(); | |
| 380 } | |
| 381 | |
| 382 void BookmarkEditorView::BookmarkNodeRemoved( | |
| 383 BookmarkModel* model, | |
| 384 const BookmarkNode* parent, | |
| 385 int index, | |
| 386 const BookmarkNode* node, | |
| 387 const std::set<GURL>& removed_urls) { | |
| 388 if ((details_.type == EditDetails::EXISTING_NODE && | |
| 389 details_.existing_node->HasAncestor(node)) || | |
| 390 (parent_ && parent_->HasAncestor(node))) { | |
| 391 // The node, or its parent was removed. Close the dialog. | |
| 392 GetWidget()->Close(); | |
| 393 } else { | |
| 394 Reset(); | |
| 395 } | |
| 396 } | |
| 397 | |
| 398 void BookmarkEditorView::BookmarkAllUserNodesRemoved( | |
| 399 BookmarkModel* model, | |
| 400 const std::set<GURL>& removed_urls) { | |
| 401 Reset(); | |
| 402 } | |
| 403 | |
| 404 void BookmarkEditorView::BookmarkNodeChildrenReordered( | |
| 405 BookmarkModel* model, | |
| 406 const BookmarkNode* node) { | |
| 407 Reset(); | |
| 408 } | |
| 409 | |
| 410 void BookmarkEditorView::Reset() { | 414 void BookmarkEditorView::Reset() { |
| 411 if (!show_tree_) { | 415 if (!show_tree_) { |
| 412 if (parent()) | 416 if (parent()) |
| 413 UserInputChanged(); | 417 UserInputChanged(); |
| 414 return; | 418 return; |
| 415 } | 419 } |
| 416 | 420 |
| 417 new_folder_button_->SetEnabled(true); | 421 new_folder_button_->SetEnabled(true); |
| 418 | 422 |
| 419 // Do this first, otherwise when we invoke SetModel with the real one | 423 // Do this first, otherwise when we invoke SetModel with the real one |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 } | 645 } |
| 642 return context_menu_model_.get(); | 646 return context_menu_model_.get(); |
| 643 } | 647 } |
| 644 | 648 |
| 645 void BookmarkEditorView::EditorTreeModel::SetTitle( | 649 void BookmarkEditorView::EditorTreeModel::SetTitle( |
| 646 ui::TreeModelNode* node, | 650 ui::TreeModelNode* node, |
| 647 const base::string16& title) { | 651 const base::string16& title) { |
| 648 if (!title.empty()) | 652 if (!title.empty()) |
| 649 ui::TreeNodeModel<EditorNode>::SetTitle(node, title); | 653 ui::TreeNodeModel<EditorNode>::SetTitle(node, title); |
| 650 } | 654 } |
| OLD | NEW |