diff options
author | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-12 22:10:20 +0000 |
---|---|---|
committer | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-12 22:10:20 +0000 |
commit | 39a248b002d0f41ad816754bb2833eea0aff9c61 (patch) | |
tree | 2b3c12b82e8ba1779f3b5cf0b6e1783bb357c8bb /chrome/browser | |
parent | fe60fbbb329988a1b4eab5fcc78faaad719cda1b (diff) | |
download | chromium_src-39a248b002d0f41ad816754bb2833eea0aff9c61.zip chromium_src-39a248b002d0f41ad816754bb2833eea0aff9c61.tar.gz chromium_src-39a248b002d0f41ad816754bb2833eea0aff9c61.tar.bz2 |
Adds the ability for save dialogs to take a default extension.
BUG=4287
TEST=see bug
Review URL: http://codereview.chromium.org/10621
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5304 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser.cc | 5 | ||||
-rw-r--r-- | chrome/browser/download/download_manager.cc | 1 | ||||
-rw-r--r-- | chrome/browser/shell_dialogs.h | 14 | ||||
-rw-r--r-- | chrome/browser/views/bookmark_manager_view.cc | 20 | ||||
-rw-r--r-- | chrome/browser/views/options/content_page_view.cc | 4 | ||||
-rw-r--r-- | chrome/browser/views/shell_dialogs.cc | 12 | ||||
-rw-r--r-- | chrome/browser/views/user_data_dir_dialog.cc | 4 | ||||
-rw-r--r-- | chrome/browser/web_contents.cc | 5 |
8 files changed, 38 insertions, 27 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 86174b4..b8715a3 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -1068,7 +1068,9 @@ void Browser::OpenFile() { if (!select_file_dialog_.get()) select_file_dialog_ = SelectFileDialog::Create(this); select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, - L"", L"", GetTopLevelHWND(), NULL); + std::wstring(), std::wstring(), + std::wstring(), std::wstring(), + GetTopLevelHWND(), NULL); } void Browser::OpenTaskManager() { @@ -2477,4 +2479,3 @@ void Browser::RegisterAppPrefs(const std::wstring& app_name) { prefs->RegisterDictionaryPref(window_pref.c_str()); } - diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc index e10173d..ec6aa37 100644 --- a/chrome/browser/download/download_manager.cc +++ b/chrome/browser/download/download_manager.cc @@ -608,6 +608,7 @@ void DownloadManager::OnPathExistenceAvailable(DownloadCreateInfo* info) { contents ? GetAncestor(contents->GetContainerHWND(), GA_ROOT) : NULL; select_file_dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, std::wstring(), info->suggested_path, + std::wstring(), std::wstring(), owning_hwnd, info); } else { // No prompting for download, just continue with the suggested name. diff --git a/chrome/browser/shell_dialogs.h b/chrome/browser/shell_dialogs.h index 74cf66c..183081dc 100644 --- a/chrome/browser/shell_dialogs.h +++ b/chrome/browser/shell_dialogs.h @@ -77,26 +77,20 @@ class SelectFileDialog // and filters and terminated with two nulls. // |owning_hwnd| is the window the dialog is modal to, or NULL for a modeless // dialog. + // |default_extension| is the default extension to add to the file if the + // user doesn't type one. This should NOT include the '.'. If you specify + // this you must also specify a filter. // |params| is data from the calling context which will be passed through to // the listener. Can be NULL. // NOTE: only one instance of any shell dialog can be shown per owning_hwnd // at a time (for obvious reasons). - // TODO: convert all callers to this and rip out the old. virtual void SelectFile(Type type, const std::wstring& title, const std::wstring& default_path, const std::wstring& filter, + const std::wstring& default_extension, HWND owning_hwnd, void* params) = 0; - - void SelectFile(Type type, - const std::wstring& title, - const std::wstring& default_path, - HWND owning_hwnd, - void* params) { - SelectFile(type, title, default_path, std::wstring(), - owning_hwnd, params); - } }; // Shows a dialog box for selecting a font. diff --git a/chrome/browser/views/bookmark_manager_view.cc b/chrome/browser/views/bookmark_manager_view.cc index e5bd6ae..9172b28 100644 --- a/chrome/browser/views/bookmark_manager_view.cc +++ b/chrome/browser/views/bookmark_manager_view.cc @@ -26,6 +26,7 @@ #include "chrome/common/gfx/color_utils.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" +#include "chrome/common/win_util.h" #include "chrome/views/container_win.h" #include "chrome/views/grid_layout.h" #include "chrome/views/menu_button.h" @@ -683,18 +684,20 @@ void BookmarkManagerView::ShowToolsMenu(HWND host, int x, int y) { views::MenuItemView::TOPLEFT, true); } +// The filter used when opening a file. +// TODO(sky): need a textual description here once we can add new +// strings. +static const wchar_t KFilterString[] = L"*.html\0*.html\0"; + void BookmarkManagerView::ShowImportBookmarksFileChooser() { if (select_file_dialog_.get()) select_file_dialog_->ListenerDestroyed(); - // TODO(sky): need a textual description here once we can add new - // strings. - const wchar_t filter_c_str[] = L"*.html\0*.html\0\0\0"; - std::wstring filter_string(filter_c_str, arraysize(filter_c_str)); + std::wstring filter_string(KFilterString, arraysize(KFilterString)); select_file_dialog_ = SelectFileDialog::Create(this); select_file_dialog_->SelectFile( - SelectFileDialog::SELECT_OPEN_FILE, std::wstring(), std::wstring(), - filter_string, GetContainer()->GetHWND(), + SelectFileDialog::SELECT_OPEN_FILE, std::wstring(), L"bookmarks.html", + filter_string, std::wstring(), GetContainer()->GetHWND(), reinterpret_cast<void*>(IDS_BOOKMARK_MANAGER_IMPORT_MENU)); } @@ -704,7 +707,8 @@ void BookmarkManagerView::ShowExportBookmarksFileChooser() { select_file_dialog_ = SelectFileDialog::Create(this); select_file_dialog_->SelectFile( - SelectFileDialog::SELECT_SAVEAS_FILE, std::wstring(), std::wstring(), - std::wstring(), GetContainer()->GetHWND(), + SelectFileDialog::SELECT_SAVEAS_FILE, std::wstring(), L"bookmarks.html", + win_util::GetFileFilterFromPath(L"bookmarks.html"), L"html", + GetContainer()->GetHWND(), reinterpret_cast<void*>(IDS_BOOKMARK_MANAGER_EXPORT_MENU)); } diff --git a/chrome/browser/views/options/content_page_view.cc b/chrome/browser/views/options/content_page_view.cc index edd83b4..665b14b 100644 --- a/chrome/browser/views/options/content_page_view.cc +++ b/chrome/browser/views/options/content_page_view.cc @@ -196,7 +196,9 @@ void ContentPageView::ButtonPressed(views::NativeButton* sender) { const std::wstring dialog_title = l10n_util::GetString(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE); select_file_dialog_->SelectFile(SelectFileDialog::SELECT_FOLDER, - dialog_title, L"", GetRootWindow(), NULL); + dialog_title, std::wstring(), + std::wstring(), std::wstring(), + GetRootWindow(), NULL); } else if (sender == download_ask_for_save_location_checkbox_) { bool enabled = download_ask_for_save_location_checkbox_->IsSelected(); if (enabled) { diff --git a/chrome/browser/views/shell_dialogs.cc b/chrome/browser/views/shell_dialogs.cc index feadbed..31cbaa5b 100644 --- a/chrome/browser/views/shell_dialogs.cc +++ b/chrome/browser/views/shell_dialogs.cc @@ -194,6 +194,7 @@ class SelectFileDialogImpl : public SelectFileDialog, virtual void SelectFile(Type type, const std::wstring& title, const std::wstring& default_path, const std::wstring& filter, + const std::wstring& default_extension, HWND owning_hwnd, void* params); virtual bool IsRunning(HWND owning_hwnd) const; @@ -206,6 +207,7 @@ class SelectFileDialogImpl : public SelectFileDialog, const std::wstring& title, const std::wstring& default_path, const std::wstring& filter, + const std::wstring& default_extension, RunState run_state, void* params); @@ -250,12 +252,14 @@ void SelectFileDialogImpl::SelectFile(Type type, const std::wstring& title, const std::wstring& default_path, const std::wstring& filter, + 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, run_state, params)); + title, default_path, filter, default_extension, + run_state, params)); } bool SelectFileDialogImpl::IsRunning(HWND owning_hwnd) const { @@ -273,6 +277,7 @@ void SelectFileDialogImpl::ExecuteSelectFile( 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; @@ -280,7 +285,10 @@ void SelectFileDialogImpl::ExecuteSelectFile( if (type == SELECT_FOLDER) { success = RunSelectFolderDialog(title, run_state.owner, &path); } else if (type == SELECT_SAVEAS_FILE) { - success = win_util::SaveFileAs(run_state.owner, default_path, &path); + const wchar_t* filter_string = filter.empty() ? NULL : filter.c_str(); + unsigned index = 0; + success = win_util::SaveFileAsWithFilter(run_state.owner, default_path, + filter_string, default_extension, &index, &path); DisableOwner(run_state.owner); } else if (type == SELECT_OPEN_FILE) { success = RunOpenFileDialog(title, filter, run_state.owner, &path); diff --git a/chrome/browser/views/user_data_dir_dialog.cc b/chrome/browser/views/user_data_dir_dialog.cc index 8189331..85e512d 100644 --- a/chrome/browser/views/user_data_dir_dialog.cc +++ b/chrome/browser/views/user_data_dir_dialog.cc @@ -72,8 +72,8 @@ bool UserDataDirDialog::Accept() { HWND owning_hwnd = GetAncestor(message_box_view_->GetContainer()->GetHWND(), GA_ROOT); select_file_dialog_->SelectFile(SelectFileDialog::SELECT_FOLDER, - dialog_title, std::wstring(), owning_hwnd, - NULL); + dialog_title, std::wstring(), std::wstring(), + std::wstring(), owning_hwnd, NULL); return false; } diff --git a/chrome/browser/web_contents.cc b/chrome/browser/web_contents.cc index 0ed5904..2f2fd39 100644 --- a/chrome/browser/web_contents.cc +++ b/chrome/browser/web_contents.cc @@ -1067,8 +1067,9 @@ void WebContents::RunFileChooser(const std::wstring& default_file) { HWND toplevel_hwnd = GetAncestor(GetContainerHWND(), GA_ROOT); if (!select_file_dialog_.get()) select_file_dialog_ = SelectFileDialog::Create(this); - select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, L"", - default_file, toplevel_hwnd, NULL); + select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, + std::wstring(), default_file, std::wstring(), + std::wstring(), toplevel_hwnd, NULL); } void WebContents::RunJavaScriptMessage( |