Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: ui/base/win/open_file_name_win.cc

Issue 618503002: Fix the open file dialog on Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixing unit tests and feedback Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/base/win/open_file_name_win_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/base/win/open_file_name_win.h" 5 #include "ui/base/win/open_file_name_win.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/win/windows_version.h" 9 #include "base/win/windows_version.h"
10 10
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 GetResult(&directory, &filenames); 144 GetResult(&directory, &filenames);
145 if (filenames.size() != 1) 145 if (filenames.size() != 1)
146 return base::FilePath(); 146 return base::FilePath();
147 return directory.Append(filenames[0]); 147 return directory.Append(filenames[0]);
148 } 148 }
149 149
150 void OpenFileName::GetResult(base::FilePath* directory, 150 void OpenFileName::GetResult(base::FilePath* directory,
151 std::vector<base::FilePath>* filenames) { 151 std::vector<base::FilePath>* filenames) {
152 DCHECK(filenames->empty()); 152 DCHECK(filenames->empty());
153 const wchar_t* selection = openfilename_.lpstrFile; 153 const wchar_t* selection = openfilename_.lpstrFile;
154 while (*selection) { // Empty string indicates end of list. 154 // The return value of |openfilename_.lpstrFile| is dependent on the
155 // value of the Multi-Select flag within |openfilename_|. If the flag is
156 // not set the return value will be a single null-terminated wide string.
157 // If it is set it will be more than one null-terminated wide string, itself
158 // terminated by an empty null-terminated wide string.
159 if (openfilename_.Flags & OFN_ALLOWMULTISELECT) {
160 while (*selection) { // Empty string indicates end of list.
161 filenames->push_back(base::FilePath(selection));
162 // Skip over filename and null-terminator.
163 selection += filenames->back().value().length() + 1;
164 }
165 } else {
155 filenames->push_back(base::FilePath(selection)); 166 filenames->push_back(base::FilePath(selection));
156 // Skip over filename and null-terminator.
157 selection += filenames->back().value().length() + 1;
158 } 167 }
159 if (filenames->size() == 1) { 168 if (filenames->size() == 1) {
160 // When there is one file, it contains the path and filename. 169 // When there is one file, it contains the path and filename.
161 *directory = (*filenames)[0].DirName(); 170 *directory = (*filenames)[0].DirName();
162 (*filenames)[0] = (*filenames)[0].BaseName(); 171 (*filenames)[0] = (*filenames)[0].BaseName();
163 } else if (filenames->size() > 1) { 172 } else if (filenames->size() > 1) {
164 // Otherwise, the first string is the path, and the remainder are 173 // Otherwise, the first string is the path, and the remainder are
165 // filenames. 174 // filenames.
166 *directory = (*filenames)[0]; 175 *directory = (*filenames)[0];
167 filenames->erase(filenames->begin()); 176 filenames->erase(filenames->begin());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 MakeTuple(base::string16(display_string, display_string_end), 225 MakeTuple(base::string16(display_string, display_string_end),
217 base::string16(pattern, pattern_end))); 226 base::string16(pattern, pattern_end)));
218 display_string = pattern_end + 1; 227 display_string = pattern_end + 1;
219 } 228 }
220 229
221 return filters; 230 return filters;
222 } 231 }
223 232
224 } // namespace win 233 } // namespace win
225 } // namespace ui 234 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | ui/base/win/open_file_name_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698