summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-06 18:08:34 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-06 18:08:34 +0000
commit561abe688fc5ebcec902ea6cc2ccb4122441595e (patch)
tree5d5b001676b82c824d22619f0cc3a92b22648ab2 /chrome/browser/views
parent5ce729688e2b16ebc97decb032175ba230855c1d (diff)
downloadchromium_src-561abe688fc5ebcec902ea6cc2ccb4122441595e.zip
chromium_src-561abe688fc5ebcec902ea6cc2ccb4122441595e.tar.gz
chromium_src-561abe688fc5ebcec902ea6cc2ccb4122441595e.tar.bz2
First pass of refactoring dialogs.
Review URL: http://codereview.chromium.org/60110 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13168 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r--chrome/browser/views/bookmark_manager_view.cc15
-rw-r--r--chrome/browser/views/bookmark_manager_view.h2
-rw-r--r--chrome/browser/views/options/content_page_view.cc9
-rw-r--r--chrome/browser/views/options/content_page_view.h2
-rw-r--r--chrome/browser/views/shell_dialogs_win.cc87
-rw-r--r--chrome/browser/views/user_data_dir_dialog.cc6
-rw-r--r--chrome/browser/views/user_data_dir_dialog.h2
7 files changed, 64 insertions, 59 deletions
diff --git a/chrome/browser/views/bookmark_manager_view.cc b/chrome/browser/views/bookmark_manager_view.cc
index bc0b344..b9fccb1a 100644
--- a/chrome/browser/views/bookmark_manager_view.cc
+++ b/chrome/browser/views/bookmark_manager_view.cc
@@ -517,7 +517,7 @@ void BookmarkManagerView::ExecuteCommand(int id) {
}
}
-void BookmarkManagerView::FileSelected(const std::wstring& path,
+void BookmarkManagerView::FileSelected(const FilePath& path,
int index,
void* params) {
int id = reinterpret_cast<int>(params);
@@ -526,7 +526,7 @@ void BookmarkManagerView::FileSelected(const std::wstring& path,
ImporterHost* host = new ImporterHost();
ProfileInfo profile_info;
profile_info.browser_type = BOOKMARKS_HTML;
- profile_info.source_path = path;
+ profile_info.source_path = path.ToWStringHack();
StartImportingWithUI(GetWidget()->GetNativeView(), FAVORITES, host,
profile_info, profile_,
new ImportObserverImpl(profile()), false);
@@ -534,7 +534,7 @@ void BookmarkManagerView::FileSelected(const std::wstring& path,
if (g_browser_process->io_thread()) {
bookmark_html_writer::WriteBookmarks(
g_browser_process->io_thread()->message_loop(), GetBookmarkModel(),
- path);
+ path.ToWStringHack());
}
} else {
NOTREACHED();
@@ -718,8 +718,10 @@ void BookmarkManagerView::ShowImportBookmarksFileChooser() {
win_util::GetFileFilterFromExtensions(L"*.html;*.htm", true);
select_file_dialog_ = SelectFileDialog::Create(this);
select_file_dialog_->SelectFile(
- SelectFileDialog::SELECT_OPEN_FILE, std::wstring(), L"bookmarks.html",
- filter_string, 0, std::wstring(), GetWidget()->GetNativeView(),
+ SelectFileDialog::SELECT_OPEN_FILE, std::wstring(),
+ FilePath(FILE_PATH_LITERAL("bookmarks.html")), filter_string, 0,
+ std::wstring(),
+ GetWidget()->GetNativeView(),
reinterpret_cast<void*>(IDS_BOOKMARK_MANAGER_IMPORT_MENU));
}
@@ -729,7 +731,8 @@ void BookmarkManagerView::ShowExportBookmarksFileChooser() {
select_file_dialog_ = SelectFileDialog::Create(this);
select_file_dialog_->SelectFile(
- SelectFileDialog::SELECT_SAVEAS_FILE, std::wstring(), L"bookmarks.html",
+ SelectFileDialog::SELECT_SAVEAS_FILE, std::wstring(),
+ FilePath(FILE_PATH_LITERAL("bookmarks.html")),
win_util::GetFileFilterFromPath(L"bookmarks.html"), 0, L"html",
GetWidget()->GetNativeView(),
reinterpret_cast<void*>(IDS_BOOKMARK_MANAGER_EXPORT_MENU));
diff --git a/chrome/browser/views/bookmark_manager_view.h b/chrome/browser/views/bookmark_manager_view.h
index e9233e8..bf0826a 100644
--- a/chrome/browser/views/bookmark_manager_view.h
+++ b/chrome/browser/views/bookmark_manager_view.h
@@ -153,7 +153,7 @@ class BookmarkManagerView : public views::View,
virtual void ExecuteCommand(int id);
// SelectFileDialog::Listener.
- virtual void FileSelected(const std::wstring& path,
+ virtual void FileSelected(const FilePath& path,
int index, void* params);
virtual void FileSelectionCanceled(void* params);
diff --git a/chrome/browser/views/options/content_page_view.cc b/chrome/browser/views/options/content_page_view.cc
index 4072111..e6966e0 100644
--- a/chrome/browser/views/options/content_page_view.cc
+++ b/chrome/browser/views/options/content_page_view.cc
@@ -194,11 +194,11 @@ ContentPageView::~ContentPageView() {
////////////////////////////////////////////////////////////////////////////////
// ContentPageView, SelectFileDialog::Listener implementation:
-void ContentPageView::FileSelected(const std::wstring& path,
+void ContentPageView::FileSelected(const FilePath& path,
int index, void* params) {
UserMetricsRecordAction(L"Options_SetDownloadDirectory",
profile()->GetPrefs());
- default_download_location_.SetValue(path);
+ default_download_location_.SetValue(path.ToWStringHack());
// We need to call this manually here since because we're setting the value
// through the pref member which avoids notifying the listener that set the
// value.
@@ -214,8 +214,9 @@ void ContentPageView::ButtonPressed(views::Button* sender) {
l10n_util::GetString(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE);
select_file_dialog_->SelectFile(SelectFileDialog::SELECT_FOLDER,
dialog_title,
- profile()->GetPrefs()->GetString(
- prefs::kDownloadDefaultDirectory),
+ FilePath::FromWStringHack(
+ profile()->GetPrefs()->GetString(
+ prefs::kDownloadDefaultDirectory)),
std::wstring(), 0, std::wstring(),
GetRootWindow(),
NULL);
diff --git a/chrome/browser/views/options/content_page_view.h b/chrome/browser/views/options/content_page_view.h
index f7b6b28..98d2030 100644
--- a/chrome/browser/views/options/content_page_view.h
+++ b/chrome/browser/views/options/content_page_view.h
@@ -34,7 +34,7 @@ class ContentPageView : public OptionsPageView,
virtual void ButtonPressed(views::Button* sender);
// SelectFileDialog::Listener implementation:
- virtual void FileSelected(const std::wstring& path, int index, void* params);
+ virtual void FileSelected(const FilePath& path, int index, void* params);
// OptionsPageView implementation:
virtual bool CanClose() const;
diff --git a/chrome/browser/views/shell_dialogs_win.cc b/chrome/browser/views/shell_dialogs_win.cc
index 746073b..b4df9ed 100644
--- a/chrome/browser/views/shell_dialogs_win.cc
+++ b/chrome/browser/views/shell_dialogs_win.cc
@@ -192,11 +192,11 @@ class SelectFileDialogImpl : public SelectFileDialog,
virtual ~SelectFileDialogImpl();
// SelectFileDialog implementation:
- virtual void SelectFile(Type type, const std::wstring& title,
- const std::wstring& default_path,
+ virtual void SelectFile(Type type, const string16& title,
+ const FilePath& default_path,
const std::wstring& filter,
int filter_index,
- const std::wstring& default_extension,
+ const FilePath::StringType& default_extension,
HWND owning_hwnd,
void* params);
virtual bool IsRunning(HWND owning_hwnd) const;
@@ -207,7 +207,7 @@ class SelectFileDialogImpl : public SelectFileDialog,
struct ExecuteSelectParams {
ExecuteSelectParams(Type type,
const std::wstring& title,
- const std::wstring& default_path,
+ const FilePath& default_path,
const std::wstring& filter,
int filter_index,
const std::wstring& default_extension,
@@ -220,7 +220,7 @@ class SelectFileDialogImpl : public SelectFileDialog,
}
SelectFileDialog::Type type;
std::wstring title;
- std::wstring default_path;
+ FilePath default_path;
std::wstring filter;
int filter_index;
std::wstring default_extension;
@@ -234,11 +234,11 @@ class SelectFileDialogImpl : public SelectFileDialog,
void ExecuteSelectFile(const ExecuteSelectParams& params);
// Notifies the listener that a folder was chosen. Run on the ui thread.
- void FileSelected(const std::wstring& path, int index,
+ void FileSelected(const FilePath& path, int index,
void* params, RunState run_state);
// Notifies listener that multiple files were chosen. Run on the ui thread.
- void MultiFilesSelected(const std::vector<std::wstring>& paths, void* params,
+ void MultiFilesSelected(const std::vector<FilePath>& paths, void* params,
RunState run_state);
// Notifies the listener that no file was chosen (the action was canceled).
@@ -252,21 +252,21 @@ class SelectFileDialogImpl : public SelectFileDialog,
// dialog thread.
bool RunSelectFolderDialog(const std::wstring& title,
HWND owner,
- std::wstring* path);
+ FilePath* path);
// Runs an Open file dialog box, with similar semantics for input paramaters
// as RunSelectFolderDialog.
bool RunOpenFileDialog(const std::wstring& title,
const std::wstring& filters,
HWND owner,
- std::wstring* path);
+ FilePath* path);
// Runs an Open file dialog box that supports multi-select, with similar
// semantics for input paramaters as RunOpenFileDialog.
bool RunOpenMultiFileDialog(const std::wstring& title,
const std::wstring& filter,
HWND owner,
- std::vector<std::wstring>* paths);
+ std::vector<FilePath>* paths);
// The callback function for when the select folder dialog is opened.
static int CALLBACK BrowseCallbackProc(HWND window, UINT message,
@@ -287,16 +287,17 @@ SelectFileDialogImpl::SelectFileDialogImpl(Listener* listener)
SelectFileDialogImpl::~SelectFileDialogImpl() {
}
-void SelectFileDialogImpl::SelectFile(Type type,
- const std::wstring& title,
- const std::wstring& default_path,
- const std::wstring& filter,
- int filter_index,
- const std::wstring& default_extension,
- HWND owner,
- void* params) {
- ExecuteSelectParams execute_params(type, title, default_path, filter,
- filter_index, default_extension,
+void SelectFileDialogImpl::SelectFile(
+ Type type,
+ const string16& title,
+ const FilePath& default_path,
+ const std::wstring& filter,
+ int filter_index,
+ const FilePath::StringType& default_extension,
+ HWND owner,
+ void* params) {
+ ExecuteSelectParams execute_params(type, UTF16ToWide(title), default_path,
+ filter, filter_index, default_extension,
BeginRun(owner), owner, params);
execute_params.run_state.dialog_thread->message_loop()->PostTask(FROM_HERE,
NewRunnableMethod(this, &SelectFileDialogImpl::ExecuteSelectFile,
@@ -315,7 +316,7 @@ void SelectFileDialogImpl::ListenerDestroyed() {
void SelectFileDialogImpl::ExecuteSelectFile(
const ExecuteSelectParams& params) {
- std::wstring path = params.default_path;
+ FilePath path = params.default_path;
bool success = false;
unsigned filter_index = params.filter_index;
if (params.type == SELECT_FOLDER) {
@@ -324,14 +325,14 @@ void SelectFileDialogImpl::ExecuteSelectFile(
&path);
} else if (params.type == SELECT_SAVEAS_FILE) {
success = win_util::SaveFileAsWithFilter(params.run_state.owner,
- params.default_path, params.filter, params.default_extension, false,
- &filter_index, &path);
+ params.default_path.ToWStringHack(), params.filter,
+ params.default_extension, false, &filter_index, &path.ToWStringHack());
DisableOwner(params.run_state.owner);
} else if (params.type == SELECT_OPEN_FILE) {
success = RunOpenFileDialog(params.title, params.filter,
params.run_state.owner, &path);
} else if (params.type == SELECT_OPEN_MULTI_FILE) {
- std::vector<std::wstring> paths;
+ std::vector<FilePath> paths;
if (RunOpenMultiFileDialog(params.title, params.filter,
params.run_state.owner, &paths)) {
ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
@@ -352,7 +353,7 @@ void SelectFileDialogImpl::ExecuteSelectFile(
}
}
-void SelectFileDialogImpl::FileSelected(const std::wstring& selected_folder,
+void SelectFileDialogImpl::FileSelected(const FilePath& selected_folder,
int index,
void* params,
RunState run_state) {
@@ -362,9 +363,9 @@ void SelectFileDialogImpl::FileSelected(const std::wstring& selected_folder,
}
void SelectFileDialogImpl::MultiFilesSelected(
- const std::vector<std::wstring>& selected_files,
- void* params,
- RunState run_state) {
+ const std::vector<FilePath>& selected_files,
+ void* params,
+ RunState run_state) {
if (listener_)
listener_->MultiFilesSelected(selected_files, params);
EndRun(run_state);
@@ -391,7 +392,7 @@ int CALLBACK SelectFileDialogImpl::BrowseCallbackProc(HWND window,
bool SelectFileDialogImpl::RunSelectFolderDialog(const std::wstring& title,
HWND owner,
- std::wstring* path) {
+ FilePath* path) {
DCHECK(path);
wchar_t dir_buffer[MAX_PATH + 1];
@@ -403,9 +404,9 @@ bool SelectFileDialogImpl::RunSelectFolderDialog(const std::wstring& title,
browse_info.pszDisplayName = dir_buffer;
browse_info.ulFlags = BIF_USENEWUI | BIF_RETURNONLYFSDIRS;
- if (path->length()) {
+ if (path->value().length()) {
// Highlight the current value.
- browse_info.lParam = (LPARAM)path->c_str();
+ browse_info.lParam = (LPARAM)path->value().c_str();
browse_info.lpfn = &BrowseCallbackProc;
}
@@ -420,7 +421,7 @@ bool SelectFileDialogImpl::RunSelectFolderDialog(const std::wstring& title,
HRESULT hr = shell_folder->GetDisplayNameOf(list, SHGDN_FORPARSING,
&out_dir_buffer);
if (SUCCEEDED(hr) && out_dir_buffer.uType == STRRET_WSTR) {
- *path = out_dir_buffer.pOleStr;
+ *path = FilePath::FromWStringHack(out_dir_buffer.pOleStr);
CoTaskMemFree(out_dir_buffer.pOleStr);
result = true;
}
@@ -428,7 +429,7 @@ bool SelectFileDialogImpl::RunSelectFolderDialog(const std::wstring& title,
// Use old way if we don't get what we want.
wchar_t old_out_dir_buffer[MAX_PATH + 1];
if (SHGetPathFromIDList(list, old_out_dir_buffer)) {
- *path = old_out_dir_buffer;
+ *path = FilePath::FromWStringHack(old_out_dir_buffer);
result = true;
}
}
@@ -446,7 +447,7 @@ bool SelectFileDialogImpl::RunOpenFileDialog(
const std::wstring& title,
const std::wstring& filter,
HWND owner,
- std::wstring* path) {
+ FilePath* path) {
OPENFILENAME ofn;
// We must do this otherwise the ofn's FlagsEx may be initialized to random
// junk in release builds which can cause the Places Bar not to show up!
@@ -455,7 +456,7 @@ bool SelectFileDialogImpl::RunOpenFileDialog(
ofn.hwndOwner = owner;
wchar_t filename[MAX_PATH];
- base::wcslcpy(filename, path->c_str(), arraysize(filename));
+ base::wcslcpy(filename, path->value().c_str(), arraysize(filename));
ofn.lpstrFile = filename;
ofn.nMaxFile = MAX_PATH;
@@ -469,7 +470,7 @@ bool SelectFileDialogImpl::RunOpenFileDialog(
bool success = !!GetOpenFileName(&ofn);
DisableOwner(owner);
if (success)
- *path = filename;
+ *path = FilePath(filename);
return success;
}
@@ -477,7 +478,7 @@ bool SelectFileDialogImpl::RunOpenMultiFileDialog(
const std::wstring& title,
const std::wstring& filter,
HWND owner,
- std::vector<std::wstring>* paths) {
+ std::vector<FilePath>* paths) {
OPENFILENAME ofn;
// We must do this otherwise the ofn's FlagsEx may be initialized to random
// junk in release builds which can cause the Places Bar not to show up!
@@ -500,12 +501,12 @@ bool SelectFileDialogImpl::RunOpenMultiFileDialog(
bool success = !!GetOpenFileName(&ofn);
DisableOwner(owner);
if (success) {
- std::vector<std::wstring> files;
+ std::vector<FilePath> files;
const wchar_t* selection = ofn.lpstrFile;
while (*selection) { // Empty string indicates end of list.
- files.push_back(selection);
+ files.push_back(FilePath(selection));
// Skip over filename and null-terminator.
- selection += files.back().length() + 1;
+ selection += files.back().value().length() + 1;
}
if (files.empty()) {
success = false;
@@ -515,10 +516,10 @@ bool SelectFileDialogImpl::RunOpenMultiFileDialog(
} else {
// Otherwise, the first string is the path, and the remainder are
// filenames.
- std::vector<std::wstring>::iterator path = files.begin();
- for (std::vector<std::wstring>::iterator file = path + 1;
+ std::vector<FilePath>::iterator path = files.begin();
+ for (std::vector<FilePath>::iterator file = path + 1;
file != files.end(); ++file) {
- paths->push_back(*path + L'\\' + *file);
+ paths->push_back(path->Append(*file));
}
}
}
diff --git a/chrome/browser/views/user_data_dir_dialog.cc b/chrome/browser/views/user_data_dir_dialog.cc
index 650ed05..958e4ce 100644
--- a/chrome/browser/views/user_data_dir_dialog.cc
+++ b/chrome/browser/views/user_data_dir_dialog.cc
@@ -73,7 +73,7 @@ bool UserDataDirDialog::Accept() {
HWND owning_hwnd =
GetAncestor(message_box_view_->GetWidget()->GetNativeView(), GA_ROOT);
select_file_dialog_->SelectFile(SelectFileDialog::SELECT_FOLDER,
- dialog_title, std::wstring(), std::wstring(),
+ dialog_title, FilePath(), std::wstring(),
0, std::wstring(), owning_hwnd, NULL);
return false;
}
@@ -93,9 +93,9 @@ bool UserDataDirDialog::Dispatch(const MSG& msg) {
return is_blocking_;
}
-void UserDataDirDialog::FileSelected(const std::wstring& path,
+void UserDataDirDialog::FileSelected(const FilePath& path,
int index, void* params) {
- user_data_dir_ = path;
+ user_data_dir_ = path.ToWStringHack();
is_blocking_ = false;
window()->Close();
}
diff --git a/chrome/browser/views/user_data_dir_dialog.h b/chrome/browser/views/user_data_dir_dialog.h
index ea989b8..78192ce 100644
--- a/chrome/browser/views/user_data_dir_dialog.h
+++ b/chrome/browser/views/user_data_dir_dialog.h
@@ -48,7 +48,7 @@ class UserDataDirDialog : public views::DialogDelegate,
virtual bool Dispatch(const MSG& msg);
// SelectFileDialog::Listener Methods:
- virtual void FileSelected(const std::wstring& path, int index, void* params);
+ virtual void FileSelected(const FilePath& path, int index, void* params);
virtual void FileSelectionCanceled(void* params);
private: