| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_editor.h" | 9 #include "chrome/browser/bookmarks/bookmark_editor.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_manager.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_model.h" | 11 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 11 #include "chrome/browser/bookmarks/bookmark_utils.h" | 12 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 12 #include "chrome/browser/browser.h" | 13 #include "chrome/browser/browser.h" |
| 13 #include "chrome/browser/browser_list.h" | 14 #include "chrome/browser/browser_list.h" |
| 14 #include "chrome/browser/input_window_dialog.h" | 15 #include "chrome/browser/input_window_dialog.h" |
| 15 #include "chrome/browser/metrics/user_metrics.h" | 16 #include "chrome/browser/metrics/user_metrics.h" |
| 16 #include "chrome/browser/profile.h" | 17 #include "chrome/browser/profile.h" |
| 17 #include "chrome/browser/tab_contents/page_navigator.h" | 18 #include "chrome/browser/tab_contents/page_navigator.h" |
| 18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 19 #include "chrome/common/pref_service.h" | 20 #include "chrome/common/pref_service.h" |
| 20 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
| 21 | 22 |
| 22 // TODO(port): Port these files. | 23 // TODO(port): Port these files. |
| 23 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
| 24 #include "chrome/browser/tab_contents/tab_contents.h" | 25 #include "chrome/browser/tab_contents/tab_contents.h" |
| 25 #include "chrome/browser/views/bookmark_manager_view.h" | |
| 26 #include "views/window/window.h" | 26 #include "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()) |
| 35 return true; | 35 return true; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 // InputWindowDialog::Delegate methods. | 99 // InputWindowDialog::Delegate methods. |
| 100 virtual bool IsValid(const std::wstring& text) { | 100 virtual bool IsValid(const std::wstring& text) { |
| 101 return !text.empty(); | 101 return !text.empty(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 virtual void InputAccepted(const std::wstring& text) { | 104 virtual void InputAccepted(const std::wstring& text) { |
| 105 if (is_new_) { | 105 if (is_new_) { |
| 106 ALLOW_UNUSED BookmarkNode* node = | 106 ALLOW_UNUSED BookmarkNode* node = |
| 107 model_->AddGroup(node_, node_->GetChildCount(), text); | 107 model_->AddGroup(node_, node_->GetChildCount(), text); |
| 108 if (show_in_manager_) { | 108 if (show_in_manager_) { |
| 109 #if defined(OS_WIN) | 109 #if defined(OS_WIN) || defined(OS_LINUX) |
| 110 BookmarkManagerView* manager = BookmarkManagerView::current(); | 110 BookmarkManager::SelectInTree(profile_, node); |
| 111 if (manager && manager->profile() == profile_) | |
| 112 manager->SelectInTree(node); | |
| 113 #else | 111 #else |
| 114 NOTIMPLEMENTED() << "BookmarkManagerView not yet implemented"; | 112 NOTIMPLEMENTED() << "BookmarkManager not yet implemented"; |
| 115 #endif | 113 #endif |
| 116 } | 114 } |
| 117 } else { | 115 } else { |
| 118 model_->SetTitle(node_, text); | 116 model_->SetTitle(node_, text); |
| 119 } | 117 } |
| 120 } | 118 } |
| 121 | 119 |
| 122 virtual void InputCanceled() { | 120 virtual void InputCanceled() { |
| 123 } | 121 } |
| 124 | 122 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 // SelectOnCreationHandler ---------------------------------------------------- | 186 // SelectOnCreationHandler ---------------------------------------------------- |
| 189 | 187 |
| 190 // Used when adding a new bookmark. If a new bookmark is created it is selected | 188 // Used when adding a new bookmark. If a new bookmark is created it is selected |
| 191 // in the bookmark manager. | 189 // in the bookmark manager. |
| 192 class SelectOnCreationHandler : public BookmarkEditor::Handler { | 190 class SelectOnCreationHandler : public BookmarkEditor::Handler { |
| 193 public: | 191 public: |
| 194 explicit SelectOnCreationHandler(Profile* profile) : profile_(profile) { | 192 explicit SelectOnCreationHandler(Profile* profile) : profile_(profile) { |
| 195 } | 193 } |
| 196 | 194 |
| 197 virtual void NodeCreated(BookmarkNode* new_node) { | 195 virtual void NodeCreated(BookmarkNode* new_node) { |
| 198 BookmarkManagerView* manager = BookmarkManagerView::current(); | 196 BookmarkManager::SelectInTree(profile_, new_node); |
| 199 if (!manager || manager->profile() != profile_) | |
| 200 return; // Manager no longer showing, or showing a different profile. | |
| 201 | |
| 202 manager->SelectInTree(new_node); | |
| 203 } | 197 } |
| 204 | 198 |
| 205 private: | 199 private: |
| 206 Profile* profile_; | 200 Profile* profile_; |
| 207 | 201 |
| 208 DISALLOW_COPY_AND_ASSIGN(SelectOnCreationHandler); | 202 DISALLOW_COPY_AND_ASSIGN(SelectOnCreationHandler); |
| 209 }; | 203 }; |
| 210 #endif // #if defined(OS_WIN) | 204 #endif // #if defined(OS_WIN) |
| 211 | 205 |
| 212 } // namespace | 206 } // namespace |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 case IDS_BOOKMARK_BAR_RENAME_FOLDER: | 323 case IDS_BOOKMARK_BAR_RENAME_FOLDER: |
| 330 case IDS_BOOKMARK_BAR_EDIT: | 324 case IDS_BOOKMARK_BAR_EDIT: |
| 331 UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_Edit", profile_); | 325 UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_Edit", profile_); |
| 332 | 326 |
| 333 if (selection_.size() != 1) { | 327 if (selection_.size() != 1) { |
| 334 NOTREACHED(); | 328 NOTREACHED(); |
| 335 return; | 329 return; |
| 336 } | 330 } |
| 337 | 331 |
| 338 if (selection_[0]->is_url()) { | 332 if (selection_[0]->is_url()) { |
| 339 #if defined(OS_WIN) | 333 #if defined(OS_WIN) || defined(OS_LINUX) |
| 340 BookmarkEditor::Configuration editor_config; | 334 BookmarkEditor::Configuration editor_config; |
| 341 if (configuration_ == BOOKMARK_BAR) | 335 if (configuration_ == BOOKMARK_BAR) |
| 342 editor_config = BookmarkEditor::SHOW_TREE; | 336 editor_config = BookmarkEditor::SHOW_TREE; |
| 343 else | 337 else |
| 344 editor_config = BookmarkEditor::NO_TREE; | 338 editor_config = BookmarkEditor::NO_TREE; |
| 345 BookmarkEditor::Show(wnd_, profile_, NULL, selection_[0], | 339 BookmarkEditor::Show(wnd_, profile_, NULL, selection_[0], |
| 346 editor_config, NULL); | 340 editor_config, NULL); |
| 347 #else | 341 #else |
| 348 NOTIMPLEMENTED(); | 342 NOTIMPLEMENTED(); |
| 349 #endif | 343 #endif |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 | 394 |
| 401 case IDS_BOOKMARK_MANAGER_SHOW_IN_FOLDER: | 395 case IDS_BOOKMARK_MANAGER_SHOW_IN_FOLDER: |
| 402 UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_ShowInFolder", | 396 UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_ShowInFolder", |
| 403 profile_); | 397 profile_); |
| 404 | 398 |
| 405 if (selection_.size() != 1) { | 399 if (selection_.size() != 1) { |
| 406 NOTREACHED(); | 400 NOTREACHED(); |
| 407 return; | 401 return; |
| 408 } | 402 } |
| 409 | 403 |
| 410 #if defined(OS_WIN) | 404 #if defined(OS_WIN) || defined(OS_LINUX) |
| 411 if (BookmarkManagerView::current()) | 405 BookmarkManager::SelectInTree(profile_, selection_[0]); |
| 412 BookmarkManagerView::current()->SelectInTree(selection_[0]); | |
| 413 #else | 406 #else |
| 414 NOTIMPLEMENTED() << "Bookmark Manager not implemented"; | 407 NOTIMPLEMENTED() << "Bookmark Manager not implemented"; |
| 415 #endif | 408 #endif |
| 416 break; | 409 break; |
| 417 | 410 |
| 418 case IDS_BOOKMARK_MANAGER: | 411 case IDS_BOOKMARK_MANAGER: |
| 419 UserMetrics::RecordAction(L"ShowBookmarkManager", profile_); | 412 UserMetrics::RecordAction(L"ShowBookmarkManager", profile_); |
| 420 #if defined(OS_WIN) | 413 #if defined(OS_WIN) || defined(OS_LINUX) |
| 421 BookmarkManagerView::Show(profile_); | 414 BookmarkManager::Show(profile_); |
| 422 #else | 415 #else |
| 423 NOTIMPLEMENTED() << "Bookmark Manager not implemented"; | 416 NOTIMPLEMENTED() << "Bookmark Manager not implemented"; |
| 424 #endif | 417 #endif |
| 425 break; | 418 break; |
| 426 | 419 |
| 427 case IDS_BOOKMARK_MANAGER_SORT: | 420 case IDS_BOOKMARK_MANAGER_SORT: |
| 428 UserMetrics::RecordAction(L"BookmarkManager_Sort", profile_); | 421 UserMetrics::RecordAction(L"BookmarkManager_Sort", profile_); |
| 429 model_->SortChildren(parent_); | 422 model_->SortChildren(parent_); |
| 430 break; | 423 break; |
| 431 | 424 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 if (NodeHasURLs(selection_[i])) | 548 if (NodeHasURLs(selection_[i])) |
| 556 return true; | 549 return true; |
| 557 } | 550 } |
| 558 return false; | 551 return false; |
| 559 } | 552 } |
| 560 | 553 |
| 561 BookmarkNode* BookmarkContextMenu::GetParentForNewNodes() const { | 554 BookmarkNode* BookmarkContextMenu::GetParentForNewNodes() const { |
| 562 return (selection_.size() == 1 && selection_[0]->is_folder()) ? | 555 return (selection_.size() == 1 && selection_[0]->is_folder()) ? |
| 563 selection_[0] : parent_; | 556 selection_[0] : parent_; |
| 564 } | 557 } |
| OLD | NEW |