| 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/bookmarks/bookmark_context_menu.h" | 5 #include "chrome/browser/bookmarks/bookmark_context_menu.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_editor.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_model.h" | 9 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_utils.h" | 10 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 10 #include "chrome/browser/browser.h" | 11 #include "chrome/browser/browser.h" |
| 11 #include "chrome/browser/browser_list.h" | 12 #include "chrome/browser/browser_list.h" |
| 12 #include "chrome/browser/input_window_dialog.h" | 13 #include "chrome/browser/input_window_dialog.h" |
| 13 #include "chrome/browser/metrics/user_metrics.h" | 14 #include "chrome/browser/metrics/user_metrics.h" |
| 14 #include "chrome/browser/profile.h" | 15 #include "chrome/browser/profile.h" |
| 15 #include "chrome/browser/tab_contents/page_navigator.h" | 16 #include "chrome/browser/tab_contents/page_navigator.h" |
| 16 #include "chrome/common/l10n_util.h" | 17 #include "chrome/common/l10n_util.h" |
| 17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/common/pref_service.h" | 19 #include "chrome/common/pref_service.h" |
| 19 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
| 20 | 21 |
| 21 // TODO(port): Port these files. | 22 // TODO(port): Port these files. |
| 22 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 23 #include "chrome/browser/tab_contents/tab_contents.h" | 24 #include "chrome/browser/tab_contents/tab_contents.h" |
| 24 #include "chrome/browser/views/bookmark_editor_view.h" | |
| 25 #include "chrome/browser/views/bookmark_manager_view.h" | 25 #include "chrome/browser/views/bookmark_manager_view.h" |
| 26 #include "chrome/views/window/window.h" | 26 #include "chrome/views/window/window.h" |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 // Returns true if the specified node is of type URL, or has a descendant | 31 // Returns true if the specified node is of type URL, or has a descendant |
| 32 // of type URL. | 32 // of type URL. |
| 33 bool NodeHasURLs(BookmarkNode* node) { | 33 bool NodeHasURLs(BookmarkNode* node) { |
| 34 if (node->is_url()) | 34 if (node->is_url()) |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 InputWindowDialog* dialog_; | 182 InputWindowDialog* dialog_; |
| 183 | 183 |
| 184 DISALLOW_COPY_AND_ASSIGN(EditFolderController); | 184 DISALLOW_COPY_AND_ASSIGN(EditFolderController); |
| 185 }; | 185 }; |
| 186 | 186 |
| 187 #if defined(OS_WIN) | 187 #if defined(OS_WIN) |
| 188 // SelectOnCreationHandler ---------------------------------------------------- | 188 // SelectOnCreationHandler ---------------------------------------------------- |
| 189 | 189 |
| 190 // Used when adding a new bookmark. If a new bookmark is created it is selected | 190 // Used when adding a new bookmark. If a new bookmark is created it is selected |
| 191 // in the bookmark manager. | 191 // in the bookmark manager. |
| 192 class SelectOnCreationHandler : public BookmarkEditorView::Handler { | 192 class SelectOnCreationHandler : public BookmarkEditor::Handler { |
| 193 public: | 193 public: |
| 194 explicit SelectOnCreationHandler(Profile* profile) : profile_(profile) { | 194 explicit SelectOnCreationHandler(Profile* profile) : profile_(profile) { |
| 195 } | 195 } |
| 196 | 196 |
| 197 virtual void NodeCreated(BookmarkNode* new_node) { | 197 virtual void NodeCreated(BookmarkNode* new_node) { |
| 198 BookmarkManagerView* manager = BookmarkManagerView::current(); | 198 BookmarkManagerView* manager = BookmarkManagerView::current(); |
| 199 if (!manager || manager->profile() != profile_) | 199 if (!manager || manager->profile() != profile_) |
| 200 return; // Manager no longer showing, or showing a different profile. | 200 return; // Manager no longer showing, or showing a different profile. |
| 201 | 201 |
| 202 manager->SelectInTree(new_node); | 202 manager->SelectInTree(new_node); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 case IDS_BOOKMARK_BAR_RENAME_FOLDER: | 329 case IDS_BOOKMARK_BAR_RENAME_FOLDER: |
| 330 case IDS_BOOKMARK_BAR_EDIT: | 330 case IDS_BOOKMARK_BAR_EDIT: |
| 331 UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_Edit", profile_); | 331 UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_Edit", profile_); |
| 332 | 332 |
| 333 if (selection_.size() != 1) { | 333 if (selection_.size() != 1) { |
| 334 NOTREACHED(); | 334 NOTREACHED(); |
| 335 return; | 335 return; |
| 336 } | 336 } |
| 337 | 337 |
| 338 if (selection_[0]->is_url()) { | 338 if (selection_[0]->is_url()) { |
| 339 #if defined(OS_WIN) | 339 BookmarkEditor::Configuration editor_config; |
| 340 BookmarkEditorView::Configuration editor_config; | |
| 341 if (configuration_ == BOOKMARK_BAR) | 340 if (configuration_ == BOOKMARK_BAR) |
| 342 editor_config = BookmarkEditorView::SHOW_TREE; | 341 editor_config = BookmarkEditor::SHOW_TREE; |
| 343 else | 342 else |
| 344 editor_config = BookmarkEditorView::NO_TREE; | 343 editor_config = BookmarkEditor::NO_TREE; |
| 345 BookmarkEditorView::Show(wnd_, profile_, NULL, selection_[0], | 344 BookmarkEditor::Show(wnd_, profile_, NULL, selection_[0], |
| 346 editor_config, NULL); | 345 editor_config, NULL); |
| 347 #else | |
| 348 NOTIMPLEMENTED() << "BookmarkEditorView unimplemented"; | |
| 349 #endif | |
| 350 } else { | 346 } else { |
| 351 EditFolderController::Show(profile_, wnd_, selection_[0], false, | 347 EditFolderController::Show(profile_, wnd_, selection_[0], false, |
| 352 false); | 348 false); |
| 353 } | 349 } |
| 354 break; | 350 break; |
| 355 | 351 |
| 356 case IDS_BOOKMARK_BAR_REMOVE: { | 352 case IDS_BOOKMARK_BAR_REMOVE: { |
| 357 UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_Remove", profile_); | 353 UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_Remove", profile_); |
| 358 BookmarkModel* model = RemoveModelObserver(); | 354 BookmarkModel* model = RemoveModelObserver(); |
| 359 | 355 |
| 360 for (size_t i = 0; i < selection_.size(); ++i) { | 356 for (size_t i = 0; i < selection_.size(); ++i) { |
| 361 model->Remove(selection_[i]->GetParent(), | 357 model->Remove(selection_[i]->GetParent(), |
| 362 selection_[i]->GetParent()->IndexOfChild(selection_[i])); | 358 selection_[i]->GetParent()->IndexOfChild(selection_[i])); |
| 363 } | 359 } |
| 364 selection_.clear(); | 360 selection_.clear(); |
| 365 break; | 361 break; |
| 366 } | 362 } |
| 367 | 363 |
| 368 case IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK: { | 364 case IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK: { |
| 369 UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_Add", profile_); | 365 UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_Add", profile_); |
| 370 | 366 |
| 367 BookmarkEditor::Configuration editor_config; |
| 368 BookmarkEditor::Handler* handler = NULL; |
| 369 if (configuration_ == BOOKMARK_BAR) { |
| 370 editor_config = BookmarkEditor::SHOW_TREE; |
| 371 } else { |
| 372 editor_config = BookmarkEditor::NO_TREE; |
| 371 #if defined(OS_WIN) | 373 #if defined(OS_WIN) |
| 372 BookmarkEditorView::Configuration editor_config; | |
| 373 BookmarkEditorView::Handler* handler = NULL; | |
| 374 if (configuration_ == BOOKMARK_BAR) { | |
| 375 editor_config = BookmarkEditorView::SHOW_TREE; | |
| 376 } else { | |
| 377 editor_config = BookmarkEditorView::NO_TREE; | |
| 378 // This is owned by the BookmarkEditorView. | 374 // This is owned by the BookmarkEditorView. |
| 379 handler = new SelectOnCreationHandler(profile_); | 375 handler = new SelectOnCreationHandler(profile_); |
| 376 #else |
| 377 NOTIMPLEMENTED() << "Custom SelectOnCreationHandler not implemented"; |
| 378 #endif |
| 380 } | 379 } |
| 381 BookmarkEditorView::Show(wnd_, profile_, GetParentForNewNodes(), NULL, | 380 BookmarkEditor::Show(wnd_, profile_, GetParentForNewNodes(), NULL, |
| 382 editor_config, handler); | 381 editor_config, handler); |
| 383 #else | |
| 384 NOTIMPLEMENTED() << "Adding new bookmark not implemented"; | |
| 385 #endif | |
| 386 break; | 382 break; |
| 387 } | 383 } |
| 388 | 384 |
| 389 case IDS_BOOMARK_BAR_NEW_FOLDER: { | 385 case IDS_BOOMARK_BAR_NEW_FOLDER: { |
| 390 UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_NewFolder", | 386 UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_NewFolder", |
| 391 profile_); | 387 profile_); |
| 392 EditFolderController::Show(profile_, wnd_, GetParentForNewNodes(), | 388 EditFolderController::Show(profile_, wnd_, GetParentForNewNodes(), |
| 393 true, (configuration_ != BOOKMARK_BAR)); | 389 true, (configuration_ != BOOKMARK_BAR)); |
| 394 break; | 390 break; |
| 395 } | 391 } |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 if (NodeHasURLs(selection_[i])) | 551 if (NodeHasURLs(selection_[i])) |
| 556 return true; | 552 return true; |
| 557 } | 553 } |
| 558 return false; | 554 return false; |
| 559 } | 555 } |
| 560 | 556 |
| 561 BookmarkNode* BookmarkContextMenu::GetParentForNewNodes() const { | 557 BookmarkNode* BookmarkContextMenu::GetParentForNewNodes() const { |
| 562 return (selection_.size() == 1 && selection_[0]->is_folder()) ? | 558 return (selection_.size() == 1 && selection_[0]->is_folder()) ? |
| 563 selection_[0] : parent_; | 559 selection_[0] : parent_; |
| 564 } | 560 } |
| OLD | NEW |