Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(355)

Unified Diff: chrome/browser/bookmarks/bookmark_input_window_dialog_controller.cc

Issue 8438037: Change 'Add Page' to show a simple input dialog with --use-more-webui. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/bookmarks/bookmark_input_window_dialog_controller.cc
diff --git a/chrome/browser/bookmarks/bookmark_input_window_dialog_controller.cc b/chrome/browser/bookmarks/bookmark_input_window_dialog_controller.cc
new file mode 100644
index 0000000000000000000000000000000000000000..091ea16c6dfecf34fb962ed2e53cbea9e61634e7
--- /dev/null
+++ b/chrome/browser/bookmarks/bookmark_input_window_dialog_controller.cc
@@ -0,0 +1,142 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/bookmarks/bookmark_input_window_dialog_controller.h"
+
+#include "base/string16.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/bookmarks/bookmark_model.h"
+#include "chrome/browser/bookmarks/bookmark_utils.h"
+#include "chrome/browser/profiles/profile.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+
+namespace {
+string16 GetWindowTitle(BookmarkInputWindowDialogController::Type type) {
+ int title_id = 0;
+ switch (type) {
+ case BookmarkInputWindowDialogController::NEW_BOOKMARK_FOLDER:
+ title_id = IDS_BOOKMARK_FOLDER_EDITOR_WINDOW_TITLE_NEW;
+ break;
+ case BookmarkInputWindowDialogController::EXISTING_BOOKMARK_FOLDER:
+ title_id = IDS_BOOKMARK_FOLDER_EDITOR_WINDOW_TITLE;
+ break;
+ case BookmarkInputWindowDialogController::NEW_BOOKMARK_PAGE:
+ case BookmarkInputWindowDialogController::EXISTING_BOOKMARK_PAGE:
+ title_id = IDS_BOOKMARK_EDITOR_TITLE;
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+ return l10n_util::GetStringUTF16(title_id);
+}
+} // namespace
+
+BookmarkInputWindowDialogController::~BookmarkInputWindowDialogController() {
+ if (model_)
+ model_->RemoveObserver(this);
+}
+
+// static
+void BookmarkInputWindowDialogController::Show(Profile* profile,
+ gfx::NativeWindow wnd,
+ const BookmarkNode* node,
+ int index,
+ Type type) {
+ // BookmarkInputWindowDialogController deletes itself when done.
+ new BookmarkInputWindowDialogController(profile, wnd, node, index, type);
+}
+
+BookmarkInputWindowDialogController::BookmarkInputWindowDialogController(
+ Profile* profile,
+ gfx::NativeWindow wnd,
+ const BookmarkNode* node,
+ int index,
+ Type type)
+ : profile_(profile),
+ model_(profile->GetBookmarkModel()),
+ node_(node),
+ index_(index),
+ type_(type) {
+
+ model_->AddObserver(this);
+
+ InputWindowDialog::LabelContentsPairs label_contents_pairs;
+ string16 name_label =
+ l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_EDIT_FOLDER_LABEL);
+ if (type == NEW_BOOKMARK_PAGE || type == EXISTING_BOOKMARK_PAGE) {
+ string16 url_label =
+ l10n_util::GetStringUTF16(IDS_BOOKMARK_EDITOR_URL_LABEL);
+ string16 name;
+ GURL url;
+ if (type == NEW_BOOKMARK_PAGE) {
+ bookmark_utils::GetURLAndTitleToBookmarkFromCurrentTab(profile,
+ &url,
+ &name);
+ } else {
+ url = node_->url();
+ name = node->GetTitle();
+ }
+ label_contents_pairs.push_back(std::make_pair(name_label, name));
+ label_contents_pairs.push_back(std::make_pair(url_label,
+ UTF8ToUTF16(url.spec())));
+ } else {
+ string16 name = (type == NEW_BOOKMARK_FOLDER) ?
+ l10n_util::GetStringUTF16(IDS_BOOKMARK_EDITOR_NEW_FOLDER_NAME) :
+ node_->GetTitle();
+ label_contents_pairs.push_back(std::make_pair(name_label, name));
+ }
+
+ const InputWindowDialog::ButtonType button_type =
+ (type == NEW_BOOKMARK_FOLDER || type == NEW_BOOKMARK_PAGE) ?
+ InputWindowDialog::BUTTON_TYPE_ADD : InputWindowDialog::BUTTON_TYPE_SAVE;
+ dialog_ = InputWindowDialog::Create(wnd,
+ GetWindowTitle(type),
+ label_contents_pairs, this, button_type);
+ dialog_->Show();
+}
+
+bool BookmarkInputWindowDialogController::IsValid(
+ const InputWindowDialog::InputTexts& texts) {
+ if (texts.size() != 1 && texts.size() != 2) {
+ return false;
+ }
+ if (texts[0].empty() || (texts.size() == 2 && texts[1].empty())) {
+ return false;
+ }
+ return true;
+}
+
+void BookmarkInputWindowDialogController::InputAccepted(
+ const InputWindowDialog::InputTexts& texts) {
+ if (type_ == NEW_BOOKMARK_FOLDER) {
+ DCHECK_EQ(1U, texts.size());
+ model_->AddFolder(node_, index_, texts[0]);
+ } else if (type_ == EXISTING_BOOKMARK_FOLDER) {
+ DCHECK_EQ(1U, texts.size());
+ model_->SetTitle(node_, texts[0]);
+ } else if (type_ == NEW_BOOKMARK_PAGE) {
+ DCHECK_EQ(2U, texts.size());
+ model_->AddURL(node_, index_, texts[0], GURL(texts[1]));
+ } else if (type_ == EXISTING_BOOKMARK_PAGE) {
+ DCHECK_EQ(2U, texts.size());
+ model_->SetTitle(node_, texts[0]);
+ model_->SetURL(node_, GURL(texts[1]));
+ }
+}
+
+void BookmarkInputWindowDialogController::InputCanceled() {
+}
+
+void BookmarkInputWindowDialogController::BookmarkModelChanged() {
+ dialog_->Close();
+}
+
+void BookmarkInputWindowDialogController::BookmarkModelBeingDeleted(
+ BookmarkModel* model) {
+ model_->RemoveObserver(this);
+ model_ = NULL;
+ BookmarkModelChanged();
+}

Powered by Google App Engine
This is Rietveld 408576698