| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/views/bookmark_editor_view.h" | 5 #include "chrome/browser/views/bookmark_editor_view.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 return (command_id != IDS_EDIT || !running_menu_for_root_); | 196 return (command_id != IDS_EDIT || !running_menu_for_root_); |
| 197 } | 197 } |
| 198 | 198 |
| 199 bool BookmarkEditorView::GetAcceleratorForCommandId( | 199 bool BookmarkEditorView::GetAcceleratorForCommandId( |
| 200 int command_id, | 200 int command_id, |
| 201 views::Accelerator* accelerator) { | 201 views::Accelerator* accelerator) { |
| 202 return GetWidget()->GetAccelerator(command_id, accelerator); | 202 return GetWidget()->GetAccelerator(command_id, accelerator); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void BookmarkEditorView::ExecuteCommand(int command_id) { | 205 void BookmarkEditorView::ExecuteCommand(int command_id) { |
| 206 DCHECK(tree_view_->GetSelectedNode()); | 206 TreeModelNode* selected_node = tree_view_->GetSelectedNode(); |
| 207 DCHECK(selected_node); |
| 207 if (command_id == IDS_EDIT) { | 208 if (command_id == IDS_EDIT) { |
| 208 tree_view_->StartEditing(tree_view_->GetSelectedNode()); | 209 tree_view_->StartEditing(selected_node); |
| 210 } else if (command_id == IDS_DELETE) { |
| 211 // We can only delete newly created folders. Remove the node from the |
| 212 // TreeModel. |
| 213 ApplyDelete(selected_node); |
| 209 } else { | 214 } else { |
| 210 DCHECK(command_id == IDS_BOOMARK_EDITOR_NEW_FOLDER_MENU_ITEM); | 215 DCHECK(command_id == IDS_BOOMARK_EDITOR_NEW_FOLDER_MENU_ITEM); |
| 211 NewGroup(); | 216 NewGroup(); |
| 212 } | 217 } |
| 213 } | 218 } |
| 214 | 219 |
| 215 void BookmarkEditorView::Show(HWND parent_hwnd) { | 220 void BookmarkEditorView::Show(HWND parent_hwnd) { |
| 216 views::Window::CreateChromeWindow(parent_hwnd, gfx::Rect(), this); | 221 views::Window::CreateChromeWindow(parent_hwnd, gfx::Rect(), this); |
| 217 UserInputChanged(); | 222 UserInputChanged(); |
| 218 if (show_tree_ && bb_model_->IsLoaded()) | 223 if (show_tree_ && bb_model_->IsLoaded()) |
| 219 ExpandAndSelect(); | 224 ExpandAndSelect(); |
| 220 window()->Show(); | 225 window()->Show(); |
| 221 // Select all the text in the name Textfield. | 226 // Select all the text in the name Textfield. |
| 222 title_tf_.SelectAll(); | 227 title_tf_.SelectAll(); |
| 223 // Give focus to the name Textfield. | 228 // Give focus to the name Textfield. |
| 224 title_tf_.RequestFocus(); | 229 title_tf_.RequestFocus(); |
| 225 } | 230 } |
| 226 | 231 |
| 227 void BookmarkEditorView::Close() { | 232 void BookmarkEditorView::Close() { |
| 228 DCHECK(window()); | 233 DCHECK(window()); |
| 229 window()->Close(); | 234 window()->Close(); |
| 230 } | 235 } |
| 231 | 236 |
| 232 void BookmarkEditorView::ShowContextMenu(View* source, | 237 void BookmarkEditorView::ShowContextMenu(View* source, |
| 233 int x, | 238 int x, |
| 234 int y, | 239 int y, |
| 235 bool is_mouse_gesture) { | 240 bool is_mouse_gesture) { |
| 236 DCHECK(source == tree_view_); | 241 DCHECK(source == tree_view_); |
| 237 if (!tree_view_->GetSelectedNode()) | 242 TreeModelNode* selected_node = tree_view_->GetSelectedNode(); |
| 243 if (!selected_node) |
| 238 return; | 244 return; |
| 239 running_menu_for_root_ = | 245 running_menu_for_root_ = |
| 240 (tree_model_->GetParent(tree_view_->GetSelectedNode()) == | 246 (tree_model_->GetParent(selected_node) == tree_model_->GetRoot()); |
| 241 tree_model_->GetRoot()); | 247 |
| 242 if (!context_menu_contents_.get()) { | 248 EditorNode* node = tree_model_->AsNode(selected_node); |
| 249 |
| 250 bool reload_menu_contents = false; |
| 251 if (context_menu_contents_.get()) { |
| 252 bool has_delete_in_menu = |
| 253 context_menu_contents_->GetCommandIdAt(1) == IDS_DELETE; |
| 254 |
| 255 // Only show delete option for new groups. |
| 256 reload_menu_contents = (node->value == 0) ^ has_delete_in_menu; |
| 257 } |
| 258 |
| 259 if (!context_menu_contents_.get() || reload_menu_contents) { |
| 243 context_menu_contents_.reset(new views::SimpleMenuModel(this)); | 260 context_menu_contents_.reset(new views::SimpleMenuModel(this)); |
| 244 context_menu_contents_->AddItemWithStringId(IDS_EDIT, IDS_EDIT); | 261 context_menu_contents_->AddItemWithStringId(IDS_EDIT, IDS_EDIT); |
| 262 // If this is a newly created folder that has not been added to the |
| 263 // BookmarkModel, a user may delete the folder. |
| 264 if (node->value == 0) |
| 265 context_menu_contents_->AddItemWithStringId(IDS_DELETE, IDS_DELETE); |
| 245 context_menu_contents_->AddItemWithStringId( | 266 context_menu_contents_->AddItemWithStringId( |
| 246 IDS_BOOMARK_EDITOR_NEW_FOLDER_MENU_ITEM, | 267 IDS_BOOMARK_EDITOR_NEW_FOLDER_MENU_ITEM, |
| 247 IDS_BOOMARK_EDITOR_NEW_FOLDER_MENU_ITEM); | 268 IDS_BOOMARK_EDITOR_NEW_FOLDER_MENU_ITEM); |
| 248 context_menu_.reset(new views::Menu2(context_menu_contents_.get())); | 269 context_menu_.reset(new views::Menu2(context_menu_contents_.get())); |
| 249 } | 270 } |
| 250 context_menu_->RunContextMenuAt(gfx::Point(x, y)); | 271 context_menu_->RunContextMenuAt(gfx::Point(x, y)); |
| 251 } | 272 } |
| 252 | 273 |
| 253 void BookmarkEditorView::Init() { | 274 void BookmarkEditorView::Init() { |
| 254 bb_model_ = profile_->GetBookmarkModel(); | 275 bb_model_ = profile_->GetBookmarkModel(); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 if (node->value == id) | 504 if (node->value == id) |
| 484 return node; | 505 return node; |
| 485 for (int i = 0; i < node->GetChildCount(); ++i) { | 506 for (int i = 0; i < node->GetChildCount(); ++i) { |
| 486 EditorNode* result = FindNodeWithID(node->GetChild(i), id); | 507 EditorNode* result = FindNodeWithID(node->GetChild(i), id); |
| 487 if (result) | 508 if (result) |
| 488 return result; | 509 return result; |
| 489 } | 510 } |
| 490 return NULL; | 511 return NULL; |
| 491 } | 512 } |
| 492 | 513 |
| 514 void BookmarkEditorView::ApplyDelete(TreeModelNode* node) { |
| 515 EditorNode* deleted_node = show_tree_ ? |
| 516 tree_model_->AsNode(node) : NULL; |
| 517 |
| 518 if (show_tree_ && !deleted_node) { |
| 519 NOTREACHED(); |
| 520 return; |
| 521 } |
| 522 |
| 523 EditorNode* parent = deleted_node ? deleted_node->GetParent() : NULL; |
| 524 const int index = parent ? parent->IndexOfChild(deleted_node) : -1; |
| 525 |
| 526 if (index == -1) { |
| 527 NOTREACHED(); |
| 528 return; |
| 529 } |
| 530 |
| 531 tree_model_->Remove(parent, index); |
| 532 } |
| 533 |
| 493 void BookmarkEditorView::ApplyEdits() { | 534 void BookmarkEditorView::ApplyEdits() { |
| 494 DCHECK(bb_model_->IsLoaded()); | 535 DCHECK(bb_model_->IsLoaded()); |
| 495 | 536 |
| 496 EditorNode* parent = show_tree_ ? | 537 EditorNode* parent = show_tree_ ? |
| 497 tree_model_->AsNode(tree_view_->GetSelectedNode()) : NULL; | 538 tree_model_->AsNode(tree_view_->GetSelectedNode()) : NULL; |
| 498 if (show_tree_ && !parent) { | 539 if (show_tree_ && !parent) { |
| 499 NOTREACHED(); | 540 NOTREACHED(); |
| 500 return; | 541 return; |
| 501 } | 542 } |
| 502 ApplyEdits(parent); | 543 ApplyEdits(parent); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 break; | 593 break; |
| 553 } | 594 } |
| 554 } | 595 } |
| 555 DCHECK(child_bb_node); | 596 DCHECK(child_bb_node); |
| 556 bb_model_->SetTitle(child_bb_node, child_b_node->GetTitle()); | 597 bb_model_->SetTitle(child_bb_node, child_b_node->GetTitle()); |
| 557 } | 598 } |
| 558 ApplyNameChangesAndCreateNewGroups(child_bb_node, child_b_node, | 599 ApplyNameChangesAndCreateNewGroups(child_bb_node, child_b_node, |
| 559 parent_b_node, parent_bb_node); | 600 parent_b_node, parent_bb_node); |
| 560 } | 601 } |
| 561 } | 602 } |
| OLD | NEW |