Skip to content

Commit

Permalink
chore: remove FileChooser AddExtensionForFilename (#15510)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckerr authored and codebytere committed Nov 20, 2018
1 parent f02f9ba commit 40619ef
Showing 1 changed file with 6 additions and 34 deletions.
40 changes: 6 additions & 34 deletions atom/browser/ui/file_dialog_gtk.cc
Expand Up @@ -130,20 +130,18 @@ class FileChooserDialog {

base::FilePath GetFileName() const {
gchar* filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog_));
base::FilePath path = AddExtensionForFilename(filename);
const base::FilePath path(filename);
g_free(filename);
return path;
}

std::vector<base::FilePath> GetFileNames() const {
std::vector<base::FilePath> paths;
GSList* filenames =
gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog_));
for (GSList* iter = filenames; iter != NULL; iter = g_slist_next(iter)) {
base::FilePath path =
AddExtensionForFilename(static_cast<char*>(iter->data));
g_free(iter->data);
paths.push_back(path);
auto* filenames = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog_));
for (auto* iter = filenames; iter != NULL; iter = iter->next) {
auto* filename = static_cast<char*>(iter->data);
paths.emplace_back(filename);
g_free(filename);
}
g_slist_free(filenames);
return paths;
Expand All @@ -155,7 +153,6 @@ class FileChooserDialog {

private:
void AddFilters(const Filters& filters);
base::FilePath AddExtensionForFilename(const gchar* filename) const;

atom::NativeWindowViews* parent_;
atom::UnresponsiveSuppressor unresponsive_suppressor_;
Expand Down Expand Up @@ -206,31 +203,6 @@ void FileChooserDialog::AddFilters(const Filters& filters) {
}
}

base::FilePath FileChooserDialog::AddExtensionForFilename(
const gchar* filename) const {
base::FilePath path(filename);
GtkFileFilter* selected_filter =
gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog_));
if (!selected_filter)
return path;

GSList* filters = gtk_file_chooser_list_filters(GTK_FILE_CHOOSER(dialog_));
size_t i = g_slist_index(filters, selected_filter);
g_slist_free(filters);
if (i >= filters_.size())
return path;

const auto& extensions = filters_[i].second;
for (const auto& extension : extensions) {
if (extension == "*" ||
base::EndsWith(path.value(), "." + extension,
base::CompareCase::INSENSITIVE_ASCII))
return path;
}

return path.ReplaceExtension(extensions[0]);
}

} // namespace

bool ShowOpenDialog(const DialogSettings& settings,
Expand Down

0 comments on commit 40619ef

Please sign in to comment.