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

Side by Side Diff: chrome/browser/views/new_profile_dialog.cc

Issue 12895: Chromium-MultiProfile-Prototype... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/views/new_profile_dialog.h ('k') | chrome/browser/views/select_profile_dialog.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/views/new_profile_dialog.h"
6
7 #include <string>
8
9 #include "base/logging.h"
10 #include "base/file_util.h"
11 #include "chrome/app/locales/locale_settings.h"
12 #include "chrome/browser/user_data_manager.h"
13 #include "chrome/common/l10n_util.h"
14 #include "chrome/views/message_box_view.h"
15 #include "chrome/views/text_field.h"
16 #include "chrome/views/view.h"
17 #include "chrome/views/window.h"
18
19 #include "chromium_strings.h"
20 #include "generated_resources.h"
21
22 // static
23 void NewProfileDialog::RunDialog() {
24 NewProfileDialog* dlg = new NewProfileDialog();
25 views::Window::CreateChromeWindow(NULL, gfx::Rect(), dlg)->Show();
26 }
27
28 NewProfileDialog::NewProfileDialog() {
29 std::wstring message_text = l10n_util::GetString(
30 IDS_NEW_PROFILE_DIALOG_LABEL_TEXT);
31 const int kDialogWidth = views::Window::GetLocalizedContentsWidth(
32 IDS_NEW_PROFILE_DIALOG_WIDTH_CHARS);
33 const int kMessageBoxFlags = MessageBoxView::kFlagHasOKButton |
34 MessageBoxView::kFlagHasCancelButton |
35 MessageBoxView::kFlagHasPromptField;
36 message_box_view_ = new MessageBoxView(kMessageBoxFlags,
37 message_text.c_str(),
38 std::wstring(),
39 kDialogWidth);
40 message_box_view_->SetCheckBoxLabel(
41 l10n_util::GetString(IDS_NEW_PROFILE_DIALOG_CREATE_SHORTCUT_TEXT));
42 message_box_view_->SetCheckBoxSelected(true);
43 message_box_view_->text_box()->SetController(this);
44 }
45
46 NewProfileDialog::~NewProfileDialog() {
47 }
48
49 int NewProfileDialog::GetDialogButtons() const {
50 return DIALOGBUTTON_OK | DIALOGBUTTON_CANCEL;
51 }
52
53 views::View* NewProfileDialog::GetInitiallyFocusedView() const {
54 views::TextField* text_box = message_box_view_->text_box();
55 DCHECK(text_box);
56 return text_box;
57 }
58
59 bool NewProfileDialog::IsDialogButtonEnabled(
60 DialogButton button) const {
61 if (button == DIALOGBUTTON_OK) {
62 std::wstring profile_name = message_box_view_->GetInputText();
63 // TODO(munjal): Refactor the function ReplaceIllegalCharacters in
64 // file_util to something that just checks if there are illegal chars
65 // since that's what we really need. Also, replaceIllegalChars seems to
66 // be expensive since it builds a list of illegal characters for each call.
67 // So at the least fix that.
68 file_util::ReplaceIllegalCharacters(&profile_name, L'_');
69 return !profile_name.empty() &&
70 profile_name == message_box_view_->GetInputText();
71 }
72 return true;
73 }
74
75 std::wstring NewProfileDialog::GetWindowTitle() const {
76 return l10n_util::GetString(IDS_NEW_PROFILE_DIALOG_TITLE);
77 }
78
79 void NewProfileDialog::WindowClosing() {
80 delete this;
81 }
82
83 void NewProfileDialog::ContentsChanged(views::TextField* sender,
84 const std::wstring& new_contents) {
85 GetDialogClientView()->UpdateDialogButtons();
86 }
87
88 bool NewProfileDialog::Accept() {
89 std::wstring profile_name = message_box_view_->GetInputText();
90 if (profile_name.empty()) {
91 NOTREACHED();
92 return true;
93 }
94 // Create a desktop shortcut if the corresponding checkbox is checked.
95 if (message_box_view_->IsCheckBoxSelected())
96 UserDataManager::Get()->CreateDesktopShortcutForProfile(
97 profile_name);
98
99 UserDataManager::Get()->LaunchChromeForProfile(profile_name);
100 return true;
101 }
102
103 views::View* NewProfileDialog::GetContentsView() {
104 return message_box_view_;
105 }
OLDNEW
« no previous file with comments | « chrome/browser/views/new_profile_dialog.h ('k') | chrome/browser/views/select_profile_dialog.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698