summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authorsky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-12 16:54:44 +0000
committersky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-12 16:54:44 +0000
commit579776669a98ccd550bbee50c3eea37fbea1dc3f (patch)
tree429026e6c804c1b013eeb352eac4ca3e4a0bce6b /chrome/common
parentf87a4bf419625a4b240557168397ac507d987038 (diff)
downloadchromium_src-579776669a98ccd550bbee50c3eea37fbea1dc3f.zip
chromium_src-579776669a98ccd550bbee50c3eea37fbea1dc3f.tar.gz
chromium_src-579776669a98ccd550bbee50c3eea37fbea1dc3f.tar.bz2
Changes bookmark manager's import to show a description in the files
of type instead of *.html. BUG=4479 TEST=Bring up the bookmark manager, click tools->import. Make sure the import dialog 'files of type' has something like 'Chrome Document' (although this depends upon your registry), and that selecting it shows all html and htm files. Additionally make sure you have 'all files' in the 'files of type' combobox too. Review URL: http://codereview.chromium.org/14025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6890 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/win_util.cc38
-rw-r--r--chrome/common/win_util.h7
2 files changed, 35 insertions, 10 deletions
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: