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/common | |
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/common')
-rw-r--r-- | chrome/common/win_util.cc | 16 | ||||
-rw-r--r-- | chrome/common/win_util.h | 11 |
2 files changed, 18 insertions, 9 deletions
diff --git a/chrome/common/win_util.cc b/chrome/common/win_util.cc index fc0e055..243d629 100644 --- a/chrome/common/win_util.cc +++ b/chrome/common/win_util.cc @@ -341,11 +341,9 @@ static void FormatSaveAsFilterForExtension(const std::wstring& file_ext, (*buffer)[offset] = L'\0'; // Double NULL required. } -bool SaveFileAs(HWND owner, - const std::wstring& suggested_name, - std::wstring* final_name) { +std::wstring GetFileFilterFromPath(const std::wstring& file_name) { std::wstring reg_description; - std::wstring file_ext = file_util::GetFileExtensionFromPath(suggested_name); + std::wstring file_ext = file_util::GetFileExtensionFromPath(file_name); if (!file_ext.empty()) { file_ext = L"." + file_ext; GetRegistryDescriptionFromExtension(file_ext, ®_description); @@ -353,11 +351,17 @@ bool SaveFileAs(HWND owner, std::vector<wchar_t> filter; FormatSaveAsFilterForExtension(file_ext, reg_description, true, &filter); + return std::wstring(&filter[0], filter.size()); +} +bool SaveFileAs(HWND owner, + const std::wstring& suggested_name, + std::wstring* final_name) { + std::wstring filter = GetFileFilterFromPath(suggested_name); unsigned index = 1; return SaveFileAsWithFilter(owner, suggested_name, - &filter[0], + filter.c_str(), L"", &index, final_name); @@ -390,7 +394,7 @@ bool SaveFileAsWithFilter(HWND owner, save_as.hwndOwner = owner; save_as.hInstance = NULL; - save_as.lpstrFilter = &filter[0]; + save_as.lpstrFilter = filter; save_as.lpstrCustomFilter = NULL; save_as.nMaxCustFilter = 0; diff --git a/chrome/common/win_util.h b/chrome/common/win_util.h index 6688892..5b0fc58 100644 --- a/chrome/common/win_util.h +++ b/chrome/common/win_util.h @@ -125,6 +125,8 @@ bool OpenItemViaShellNoZoneCheck(const std::wstring& full_path, // Returns 'true' on successful open, 'false' otherwise. bool OpenItemWithExternalApp(const std::wstring& full_path); +std::wstring GetFileFilterFromPath(const std::wstring& file_name); + // Prompt the user for location to save a file. 'suggested_name' is a full path // that gives the dialog box a hint as to how to initialize itself. // For example, a 'suggested_name' of: @@ -149,9 +151,12 @@ bool SaveFileAs(HWND owner, // The parameter |index| indicates the initial index of filter description // and filter pattern for the dialog box. If |index| is zero or greater than // the number of total filter types, the system uses the first filter in the -// |filter| buffer. The parameter |final_name| returns the file name which -// contains the drive designator, path, file name, and extension of the user -// selected file name. +// |filter| buffer. |index| is used to specify the initial selected extension, +// and when done contains the extension the user chose. The parameter +// |final_name| returns the file name which contains the drive designator, +// path, file name, and extension of the user selected file name. |def_ext| is +// the default extension to give to the file if the user did not enter an +// extension. bool SaveFileAsWithFilter(HWND owner, const std::wstring& suggested_name, const wchar_t* filter, |