Merge pull request #10015 from electron/input-dialog-filter-titles
Add filter descriptions for common accept types
This commit is contained in:
commit
2bac358064
1 changed files with 23 additions and 1 deletions
|
@ -120,8 +120,13 @@ file_dialog::Filters GetFileTypesFromAcceptType(
|
||||||
|
|
||||||
std::vector<base::FilePath::StringType> extensions;
|
std::vector<base::FilePath::StringType> extensions;
|
||||||
|
|
||||||
|
int valid_type_count = 0;
|
||||||
|
std::string description;
|
||||||
|
|
||||||
for (const auto& accept_type : accept_types) {
|
for (const auto& accept_type : accept_types) {
|
||||||
std::string ascii_type = base::UTF16ToASCII(accept_type);
|
std::string ascii_type = base::UTF16ToASCII(accept_type);
|
||||||
|
auto old_extension_size = extensions.size();
|
||||||
|
|
||||||
if (ascii_type[0] == '.') {
|
if (ascii_type[0] == '.') {
|
||||||
// If the type starts with a period it is assumed to be a file extension,
|
// If the type starts with a period it is assumed to be a file extension,
|
||||||
// like `.txt`, // so we just have to add it to the list.
|
// like `.txt`, // so we just have to add it to the list.
|
||||||
|
@ -130,9 +135,19 @@ file_dialog::Filters GetFileTypesFromAcceptType(
|
||||||
// Skip the first character.
|
// Skip the first character.
|
||||||
extensions.push_back(extension.substr(1));
|
extensions.push_back(extension.substr(1));
|
||||||
} else {
|
} else {
|
||||||
// For MIME Type, `audio/*, vidio/*, image/*
|
if (ascii_type == "image/*")
|
||||||
|
description = "Image Files";
|
||||||
|
else if (ascii_type == "audio/*")
|
||||||
|
description = "Audio Files";
|
||||||
|
else if (ascii_type == "video/*")
|
||||||
|
description = "Video Files";
|
||||||
|
|
||||||
|
// For MIME Type, `audio/*, video/*, image/*
|
||||||
net::GetExtensionsForMimeType(ascii_type, &extensions);
|
net::GetExtensionsForMimeType(ascii_type, &extensions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (extensions.size() > old_extension_size)
|
||||||
|
valid_type_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no valid exntesion is added, return empty filters.
|
// If no valid exntesion is added, return empty filters.
|
||||||
|
@ -140,6 +155,13 @@ file_dialog::Filters GetFileTypesFromAcceptType(
|
||||||
return filters;
|
return filters;
|
||||||
|
|
||||||
filters.push_back(file_dialog::Filter());
|
filters.push_back(file_dialog::Filter());
|
||||||
|
|
||||||
|
if (valid_type_count > 1 ||
|
||||||
|
(valid_type_count == 1 && description.empty() && extensions.size() > 1))
|
||||||
|
description = "Custom Files";
|
||||||
|
|
||||||
|
filters[0].first = description;
|
||||||
|
|
||||||
for (const auto& extension : extensions) {
|
for (const auto& extension : extensions) {
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
filters[0].second.push_back(base::UTF16ToASCII(extension));
|
filters[0].second.push_back(base::UTF16ToASCII(extension));
|
||||||
|
|
Loading…
Reference in a new issue