diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/views/bookmark_manager_view.cc | 8 | ||||
-rw-r--r-- | chrome/common/win_util.cc | 38 | ||||
-rw-r--r-- | chrome/common/win_util.h | 7 |
3 files changed, 37 insertions, 16 deletions
diff --git a/chrome/browser/views/bookmark_manager_view.cc b/chrome/browser/views/bookmark_manager_view.cc index 141f57b..1f39d0f 100644 --- a/chrome/browser/views/bookmark_manager_view.cc +++ b/chrome/browser/views/bookmark_manager_view.cc @@ -700,16 +700,12 @@ 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;*.htm\0"; - void BookmarkManagerView::ShowImportBookmarksFileChooser() { if (select_file_dialog_.get()) select_file_dialog_->ListenerDestroyed(); - std::wstring filter_string(KFilterString, arraysize(KFilterString)); + std::wstring filter_string = + 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", diff --git a/chrome/common/win_util.cc b/chrome/common/win_util.cc index 48f29df..b14e0c9 100644 --- a/chrome/common/win_util.cc +++ b/chrome/common/win_util.cc @@ -281,11 +281,11 @@ static bool GetRegistryDescriptionFromExtension(const std::wstring& file_ext, return false; } -// Set up a filter for a "Save As" dialog, which will consist of 'file_ext' file -// extension, 'ext_desc' as the text description of the 'file_ext' type, and -// (optionally) the default 'All Files' view. The purpose of the filter is to -// show only files of a particular type in a Windows "Save As" dialog box. The -// resulting filter is stored in 'buffer', which is a vector since multiple +// Set up a filter for a Save/Open dialog, which will consist of 'file_ext' +// file extension, 'ext_desc' as the text description of the 'file_ext' type, +// and (optionally) the default 'All Files' view. The purpose of the filter is +// to show only files of a particular type in a Windows Save/Open dialog box. +// The resulting filter is stored in 'buffer', which is a vector since multiple // NULLs are embedded. The filters created here are: // 1. only files that have 'file_ext' as their extension // 2. all files (only added if 'include_all_files' is true) @@ -294,10 +294,10 @@ static bool GetRegistryDescriptionFromExtension(const std::wstring& file_ext, // ext_desc: "Text Document" // returned (in buffer): "Text Document\0*.txt\0All Files\0*.*\0\0" // This is painful to build, as you will soon see. -static void FormatSaveAsFilterForExtension(const std::wstring& file_ext, - const std::wstring& ext_desc, - bool include_all_files, - std::vector<wchar_t>* buffer) { +static void FormatFilterForExtension(const std::wstring& file_ext, + const std::wstring& ext_desc, + bool include_all_files, + std::vector<wchar_t>* buffer) { DCHECK(buffer); // Force something reasonable to appear in the dialog box if there is no @@ -356,7 +356,25 @@ std::wstring GetFileFilterFromPath(const std::wstring& file_name) { } std::vector<wchar_t> filter; - FormatSaveAsFilterForExtension(file_ext, reg_description, true, &filter); + FormatFilterForExtension(file_ext, reg_description, true, &filter); + return std::wstring(&filter[0], filter.size()); +} + +std::wstring GetFileFilterFromExtensions(const std::wstring& extensions, + bool include_all_files) { + DCHECK(extensions.find(L'.') != std::wstring::npos); + std::wstring first_extension = extensions.substr(extensions.find(L'.')); + size_t first_separator_index = first_extension.find(L';'); + if (first_separator_index != std::wstring::npos) + first_extension = first_extension.substr(0, first_separator_index); + + std::wstring description; + GetRegistryDescriptionFromExtension(first_extension, &description); + if (description.empty()) + description = L"*." + first_extension; + + std::vector<wchar_t> filter; + FormatFilterForExtension(extensions, description, true, &filter); return std::wstring(&filter[0], filter.size()); } diff --git a/chrome/common/win_util.h b/chrome/common/win_util.h index 2aac0a1..112f1bd 100644 --- a/chrome/common/win_util.h +++ b/chrome/common/win_util.h @@ -127,6 +127,13 @@ bool OpenItemWithExternalApp(const std::wstring& full_path); std::wstring GetFileFilterFromPath(const std::wstring& file_name); +// Returns a file filter whose description comes from the OS for the first file +// extension in |extensions|. |extensions| is a semicolon separated list of +// extensions. Each extension is specified as '*.foo' where foo is the +// extension. +std::wstring GetFileFilterFromExtensions(const std::wstring& extensions, + bool include_all_files); + // 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: |