| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/bookmarks/bookmark_folder_editor_controller.h" | |
| 6 | |
| 7 #include "base/string16.h" | |
| 8 #include "base/utf_string_conversions.h" | |
| 9 #include "chrome/browser/bookmarks/bookmark_model.h" | |
| 10 #include "chrome/browser/profiles/profile.h" | |
| 11 #include "grit/generated_resources.h" | |
| 12 #include "ui/base/l10n/l10n_util.h" | |
| 13 | |
| 14 BookmarkFolderEditorController::~BookmarkFolderEditorController() { | |
| 15 if (model_) | |
| 16 model_->RemoveObserver(this); | |
| 17 } | |
| 18 | |
| 19 // static | |
| 20 void BookmarkFolderEditorController::Show(Profile* profile, | |
| 21 gfx::NativeWindow wnd, | |
| 22 const BookmarkNode* node, | |
| 23 int index, | |
| 24 Type type) { | |
| 25 // BookmarkFolderEditorController deletes itself when done. | |
| 26 new BookmarkFolderEditorController(profile, wnd, node, index, type); | |
| 27 } | |
| 28 | |
| 29 BookmarkFolderEditorController::BookmarkFolderEditorController( | |
| 30 Profile* profile, | |
| 31 gfx::NativeWindow wnd, | |
| 32 const BookmarkNode* node, | |
| 33 int index, | |
| 34 Type type) | |
| 35 : profile_(profile), | |
| 36 model_(profile->GetBookmarkModel()), | |
| 37 node_(node), | |
| 38 index_(index), | |
| 39 is_new_(type == NEW_BOOKMARK) { | |
| 40 DCHECK(is_new_ || node); | |
| 41 | |
| 42 model_->AddObserver(this); | |
| 43 | |
| 44 string16 title = is_new_ ? | |
| 45 l10n_util::GetStringUTF16(IDS_BOOKMARK_FOLDER_EDITOR_WINDOW_TITLE_NEW) : | |
| 46 l10n_util::GetStringUTF16(IDS_BOOKMARK_FOLDER_EDITOR_WINDOW_TITLE); | |
| 47 string16 label = | |
| 48 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_EDIT_FOLDER_LABEL); | |
| 49 string16 contents = is_new_ ? | |
| 50 l10n_util::GetStringUTF16(IDS_BOOKMARK_EDITOR_NEW_FOLDER_NAME) : | |
| 51 node_->GetTitle(); | |
| 52 | |
| 53 dialog_ = InputWindowDialog::Create(wnd, title, label, contents, this, | |
| 54 is_new_ ? InputWindowDialog::BUTTON_TYPE_ADD | |
| 55 : InputWindowDialog::BUTTON_TYPE_SAVE); | |
| 56 dialog_->Show(); | |
| 57 } | |
| 58 | |
| 59 bool BookmarkFolderEditorController::IsValid(const string16& text) { | |
| 60 return !text.empty(); | |
| 61 } | |
| 62 | |
| 63 void BookmarkFolderEditorController::InputAccepted(const string16& text) { | |
| 64 if (is_new_) | |
| 65 model_->AddFolder(node_, index_, text); | |
| 66 else | |
| 67 model_->SetTitle(node_, text); | |
| 68 } | |
| 69 | |
| 70 void BookmarkFolderEditorController::InputCanceled() { | |
| 71 } | |
| 72 | |
| 73 void BookmarkFolderEditorController::BookmarkModelChanged() { | |
| 74 dialog_->Close(); | |
| 75 } | |
| 76 | |
| 77 void BookmarkFolderEditorController::BookmarkModelBeingDeleted( | |
| 78 BookmarkModel* model) { | |
| 79 model_->RemoveObserver(this); | |
| 80 model_ = NULL; | |
| 81 BookmarkModelChanged(); | |
| 82 } | |
| OLD | NEW |