summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views
diff options
context:
space:
mode:
authorpaulg@google.com <paulg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-30 20:02:36 +0000
committerpaulg@google.com <paulg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-30 20:02:36 +0000
commit23b357b59e5eb192d6c747c9ff19c3d91e1556e1 (patch)
tree7c4673aee2b8fe7748e409cd7a2aa71dae67a951 /chrome/browser/views
parent808f640d6ef38a1d879ecfeff30a1c0aae6f9427 (diff)
downloadchromium_src-23b357b59e5eb192d6c747c9ff19c3d91e1556e1.zip
chromium_src-23b357b59e5eb192d6c747c9ff19c3d91e1556e1.tar.gz
chromium_src-23b357b59e5eb192d6c747c9ff19c3d91e1556e1.tar.bz2
Remove Windows "Save As" dialogs from Save Page code.In this change:- convert SavePackage to use async SelectFileDialog- return the chosen filter index in the FileSelected callback- some clean up of save_package.ccBUG=8691 (http://crbug.com/8691)
Review URL: http://codereview.chromium.org/45048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12799 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r--chrome/browser/views/bookmark_manager_view.cc5
-rw-r--r--chrome/browser/views/bookmark_manager_view.h3
-rw-r--r--chrome/browser/views/options/content_page_view.cc5
-rw-r--r--chrome/browser/views/options/content_page_view.h2
-rw-r--r--chrome/browser/views/shell_dialogs_win.cc99
-rw-r--r--chrome/browser/views/user_data_dir_dialog.cc5
-rw-r--r--chrome/browser/views/user_data_dir_dialog.h2
7 files changed, 76 insertions, 45 deletions
diff --git a/chrome/browser/views/bookmark_manager_view.cc b/chrome/browser/views/bookmark_manager_view.cc
index d59de81..bc0b344 100644
--- a/chrome/browser/views/bookmark_manager_view.cc
+++ b/chrome/browser/views/bookmark_manager_view.cc
@@ -518,6 +518,7 @@ void BookmarkManagerView::ExecuteCommand(int id) {
}
void BookmarkManagerView::FileSelected(const std::wstring& path,
+ int index,
void* params) {
int id = reinterpret_cast<int>(params);
if (id == IDS_BOOKMARK_MANAGER_IMPORT_MENU) {
@@ -718,7 +719,7 @@ void BookmarkManagerView::ShowImportBookmarksFileChooser() {
select_file_dialog_ = SelectFileDialog::Create(this);
select_file_dialog_->SelectFile(
SelectFileDialog::SELECT_OPEN_FILE, std::wstring(), L"bookmarks.html",
- filter_string, std::wstring(), GetWidget()->GetNativeView(),
+ filter_string, 0, std::wstring(), GetWidget()->GetNativeView(),
reinterpret_cast<void*>(IDS_BOOKMARK_MANAGER_IMPORT_MENU));
}
@@ -729,7 +730,7 @@ void BookmarkManagerView::ShowExportBookmarksFileChooser() {
select_file_dialog_ = SelectFileDialog::Create(this);
select_file_dialog_->SelectFile(
SelectFileDialog::SELECT_SAVEAS_FILE, std::wstring(), L"bookmarks.html",
- win_util::GetFileFilterFromPath(L"bookmarks.html"), L"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 1b044bd..e9233e8 100644
--- a/chrome/browser/views/bookmark_manager_view.h
+++ b/chrome/browser/views/bookmark_manager_view.h
@@ -153,7 +153,8 @@ class BookmarkManagerView : public views::View,
virtual void ExecuteCommand(int id);
// SelectFileDialog::Listener.
- virtual void FileSelected(const std::wstring& path, void* params);
+ virtual void FileSelected(const std::wstring& path,
+ int index, void* params);
virtual void FileSelectionCanceled(void* params);
// Creates the table model to use when searching. This returns NULL if there
diff --git a/chrome/browser/views/options/content_page_view.cc b/chrome/browser/views/options/content_page_view.cc
index e6d6e40..4072111 100644
--- a/chrome/browser/views/options/content_page_view.cc
+++ b/chrome/browser/views/options/content_page_view.cc
@@ -194,7 +194,8 @@ ContentPageView::~ContentPageView() {
////////////////////////////////////////////////////////////////////////////////
// ContentPageView, SelectFileDialog::Listener implementation:
-void ContentPageView::FileSelected(const std::wstring& path, void* params) {
+void ContentPageView::FileSelected(const std::wstring& path,
+ int index, void* params) {
UserMetricsRecordAction(L"Options_SetDownloadDirectory",
profile()->GetPrefs());
default_download_location_.SetValue(path);
@@ -215,7 +216,7 @@ void ContentPageView::ButtonPressed(views::Button* sender) {
dialog_title,
profile()->GetPrefs()->GetString(
prefs::kDownloadDefaultDirectory),
- std::wstring(), std::wstring(),
+ std::wstring(), 0, std::wstring(),
GetRootWindow(),
NULL);
} else if (sender == download_ask_for_save_location_checkbox_) {
diff --git a/chrome/browser/views/options/content_page_view.h b/chrome/browser/views/options/content_page_view.h
index 508b568..f7b6b28 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, void* params);
+ virtual void FileSelected(const std::wstring& 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 a883ad5..746073b 100644
--- a/chrome/browser/views/shell_dialogs_win.cc
+++ b/chrome/browser/views/shell_dialogs_win.cc
@@ -195,6 +195,7 @@ class SelectFileDialogImpl : public SelectFileDialog,
virtual void 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 owning_hwnd,
void* params);
@@ -202,18 +203,39 @@ class SelectFileDialogImpl : public SelectFileDialog,
virtual void ListenerDestroyed();
private:
+ // A struct for holding all the state necessary for displaying a Save dialog.
+ struct ExecuteSelectParams {
+ ExecuteSelectParams(Type type,
+ const std::wstring& title,
+ const std::wstring& default_path,
+ const std::wstring& filter,
+ int filter_index,
+ const std::wstring& default_extension,
+ RunState run_state,
+ HWND owner,
+ void* params)
+ : type(type), title(title), default_path(default_path), filter(filter),
+ filter_index(filter_index), default_extension(default_extension),
+ run_state(run_state), owner(owner), params(params) {
+ }
+ SelectFileDialog::Type type;
+ std::wstring title;
+ std::wstring default_path;
+ std::wstring filter;
+ int filter_index;
+ std::wstring default_extension;
+ RunState run_state;
+ HWND owner;
+ void* params;
+ };
+
// Shows the file selection dialog modal to |owner| and calls the result
// back on the ui thread. Run on the dialog thread.
- void ExecuteSelectFile(Type type,
- const std::wstring& title,
- const std::wstring& default_path,
- const std::wstring& filter,
- const std::wstring& default_extension,
- RunState run_state,
- void* params);
+ void ExecuteSelectFile(const ExecuteSelectParams& params);
// Notifies the listener that a folder was chosen. Run on the ui thread.
- void FileSelected(const std::wstring& path, void* params, RunState run_state);
+ void FileSelected(const std::wstring& 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,
@@ -269,14 +291,16 @@ 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) {
- RunState run_state = BeginRun(owner);
- run_state.dialog_thread->message_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(this, &SelectFileDialogImpl::ExecuteSelectFile, type,
- title, default_path, filter, default_extension,
- run_state, params));
+ ExecuteSelectParams execute_params(type, 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,
+ execute_params));
}
bool SelectFileDialogImpl::IsRunning(HWND owning_hwnd) const {
@@ -290,47 +314,50 @@ void SelectFileDialogImpl::ListenerDestroyed() {
}
void SelectFileDialogImpl::ExecuteSelectFile(
- Type type,
- const std::wstring& title,
- const std::wstring& default_path,
- const std::wstring& filter,
- const std::wstring& default_extension,
- RunState run_state,
- void* params) {
- std::wstring path = default_path;
+ const ExecuteSelectParams& params) {
+ std::wstring path = params.default_path;
bool success = false;
- if (type == SELECT_FOLDER) {
- success = RunSelectFolderDialog(title, run_state.owner, &path);
- } else if (type == SELECT_SAVEAS_FILE) {
- unsigned index = 0;
- success = win_util::SaveFileAsWithFilter(run_state.owner, default_path,
- filter, default_extension, false, &index, &path);
- DisableOwner(run_state.owner);
- } else if (type == SELECT_OPEN_FILE) {
- success = RunOpenFileDialog(title, filter, run_state.owner, &path);
- } else if (type == SELECT_OPEN_MULTI_FILE) {
+ unsigned filter_index = params.filter_index;
+ if (params.type == SELECT_FOLDER) {
+ success = RunSelectFolderDialog(params.title,
+ params.run_state.owner,
+ &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);
+ 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;
- if (RunOpenMultiFileDialog(title, filter, run_state.owner, &paths)) {
+ if (RunOpenMultiFileDialog(params.title, params.filter,
+ params.run_state.owner, &paths)) {
ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
- &SelectFileDialogImpl::MultiFilesSelected, paths, params, run_state));
+ &SelectFileDialogImpl::MultiFilesSelected,
+ paths, params.params, params.run_state));
return;
}
}
if (success) {
ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
- &SelectFileDialogImpl::FileSelected, path, params, run_state));
+ &SelectFileDialogImpl::FileSelected, path, filter_index,
+ params.params, params.run_state));
} else {
ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
- &SelectFileDialogImpl::FileNotSelected, params, run_state));
+ &SelectFileDialogImpl::FileNotSelected, params.params,
+ params.run_state));
}
}
void SelectFileDialogImpl::FileSelected(const std::wstring& selected_folder,
+ int index,
void* params,
RunState run_state) {
if (listener_)
- listener_->FileSelected(selected_folder, params);
+ listener_->FileSelected(selected_folder, index, params);
EndRun(run_state);
}
diff --git a/chrome/browser/views/user_data_dir_dialog.cc b/chrome/browser/views/user_data_dir_dialog.cc
index 041ae8a..650ed05 100644
--- a/chrome/browser/views/user_data_dir_dialog.cc
+++ b/chrome/browser/views/user_data_dir_dialog.cc
@@ -74,7 +74,7 @@ bool UserDataDirDialog::Accept() {
GetAncestor(message_box_view_->GetWidget()->GetNativeView(), GA_ROOT);
select_file_dialog_->SelectFile(SelectFileDialog::SELECT_FOLDER,
dialog_title, std::wstring(), std::wstring(),
- std::wstring(), owning_hwnd, NULL);
+ 0, std::wstring(), owning_hwnd, NULL);
return false;
}
@@ -93,7 +93,8 @@ bool UserDataDirDialog::Dispatch(const MSG& msg) {
return is_blocking_;
}
-void UserDataDirDialog::FileSelected(const std::wstring& path, void* params) {
+void UserDataDirDialog::FileSelected(const std::wstring& path,
+ int index, void* params) {
user_data_dir_ = path;
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 87f0275..ea989b8 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, void* params);
+ virtual void FileSelected(const std::wstring& path, int index, void* params);
virtual void FileSelectionCanceled(void* params);
private: