OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/dialogs/select_file_dialog_win.h" | 5 #include "ui/base/dialogs/select_file_dialog_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <commdlg.h> | 8 #include <commdlg.h> |
9 #include <shlobj.h> | 9 #include <shlobj.h> |
10 | 10 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 NOTREACHED(); | 68 NOTREACHED(); |
69 return false; | 69 return false; |
70 } | 70 } |
71 | 71 |
72 return metro_get_save_file_name(ofn) == TRUE; | 72 return metro_get_save_file_name(ofn) == TRUE; |
73 } else { | 73 } else { |
74 return GetSaveFileName(ofn) == TRUE; | 74 return GetSaveFileName(ofn) == TRUE; |
75 } | 75 } |
76 } | 76 } |
77 | 77 |
78 // Distinguish directories from regular files. | |
79 bool IsDirectory(const FilePath& path) { | |
80 base::PlatformFileInfo file_info; | |
81 return file_util::GetFileInfo(path, &file_info) ? | |
82 file_info.is_directory : file_util::EndsWithSeparator(path); | |
Ben Goodger (Google)
2012/08/14 23:06:54
4-space indent
Tom Sepez
2012/08/14 23:10:43
Done.
| |
83 } | |
84 | |
78 // Get the file type description from the registry. This will be "Text Document" | 85 // Get the file type description from the registry. This will be "Text Document" |
79 // for .txt files, "JPEG Image" for .jpg files, etc. If the registry doesn't | 86 // for .txt files, "JPEG Image" for .jpg files, etc. If the registry doesn't |
80 // have an entry for the file type, we return false, true if the description was | 87 // have an entry for the file type, we return false, true if the description was |
81 // found. 'file_ext' must be in form ".txt". | 88 // found. 'file_ext' must be in form ".txt". |
82 static bool GetRegistryDescriptionFromExtension(const std::wstring& file_ext, | 89 static bool GetRegistryDescriptionFromExtension(const std::wstring& file_ext, |
83 std::wstring* reg_description) { | 90 std::wstring* reg_description) { |
84 DCHECK(reg_description); | 91 DCHECK(reg_description); |
85 base::win::RegKey reg_ext(HKEY_CLASSES_ROOT, file_ext.c_str(), KEY_READ); | 92 base::win::RegKey reg_ext(HKEY_CLASSES_ROOT, file_ext.c_str(), KEY_READ); |
86 std::wstring reg_app; | 93 std::wstring reg_app; |
87 if (reg_ext.ReadValue(NULL, ®_app) == ERROR_SUCCESS && !reg_app.empty()) { | 94 if (reg_ext.ReadValue(NULL, ®_app) == ERROR_SUCCESS && !reg_app.empty()) { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 save_as.lpstrCustomFilter = NULL; | 286 save_as.lpstrCustomFilter = NULL; |
280 save_as.nMaxCustFilter = 0; | 287 save_as.nMaxCustFilter = 0; |
281 save_as.nFilterIndex = *index; | 288 save_as.nFilterIndex = *index; |
282 save_as.lpstrFile = file_name; | 289 save_as.lpstrFile = file_name; |
283 save_as.nMaxFile = arraysize(file_name); | 290 save_as.nMaxFile = arraysize(file_name); |
284 save_as.lpstrFileTitle = NULL; | 291 save_as.lpstrFileTitle = NULL; |
285 save_as.nMaxFileTitle = 0; | 292 save_as.nMaxFileTitle = 0; |
286 | 293 |
287 // Set up the initial directory for the dialog. | 294 // Set up the initial directory for the dialog. |
288 std::wstring directory; | 295 std::wstring directory; |
289 if (!suggested_name.empty()) | 296 if (!suggested_name.empty()) { |
290 directory = suggested_path.DirName().value(); | 297 if (IsDirectory(suggested_path)) { |
298 directory = suggested_path.value(); | |
299 file_part.clear(); | |
300 } else { | |
301 directory = suggested_path.DirName().value(); | |
302 } | |
303 } | |
291 | 304 |
292 save_as.lpstrInitialDir = directory.c_str(); | 305 save_as.lpstrInitialDir = directory.c_str(); |
293 save_as.lpstrTitle = NULL; | 306 save_as.lpstrTitle = NULL; |
294 save_as.Flags = OFN_OVERWRITEPROMPT | OFN_EXPLORER | OFN_ENABLESIZING | | 307 save_as.Flags = OFN_OVERWRITEPROMPT | OFN_EXPLORER | OFN_ENABLESIZING | |
295 OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST; | 308 OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST; |
296 save_as.lpstrDefExt = &def_ext[0]; | 309 save_as.lpstrDefExt = &def_ext[0]; |
297 save_as.lCustData = NULL; | 310 save_as.lCustData = NULL; |
298 | 311 |
299 if (base::win::GetVersion() < base::win::VERSION_VISTA) { | 312 if (base::win::GetVersion() < base::win::VERSION_VISTA) { |
300 // The save as on Windows XP remembers its last position, | 313 // The save as on Windows XP remembers its last position, |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
708 wchar_t filename[MAX_PATH]; | 721 wchar_t filename[MAX_PATH]; |
709 // According to http://support.microsoft.com/?scid=kb;en-us;222003&x=8&y=12, | 722 // According to http://support.microsoft.com/?scid=kb;en-us;222003&x=8&y=12, |
710 // The lpstrFile Buffer MUST be NULL Terminated. | 723 // The lpstrFile Buffer MUST be NULL Terminated. |
711 filename[0] = 0; | 724 filename[0] = 0; |
712 // Define the dir in here to keep the string buffer pointer pointed to | 725 // Define the dir in here to keep the string buffer pointer pointed to |
713 // ofn.lpstrInitialDir available during the period of running the | 726 // ofn.lpstrInitialDir available during the period of running the |
714 // GetOpenFileName. | 727 // GetOpenFileName. |
715 FilePath dir; | 728 FilePath dir; |
716 // Use lpstrInitialDir to specify the initial directory | 729 // Use lpstrInitialDir to specify the initial directory |
717 if (!path->empty()) { | 730 if (!path->empty()) { |
718 bool is_dir; | 731 if (IsDirectory(*path)) { |
719 base::PlatformFileInfo file_info; | |
720 if (file_util::GetFileInfo(*path, &file_info)) | |
721 is_dir = file_info.is_directory; | |
722 else | |
723 is_dir = file_util::EndsWithSeparator(*path); | |
724 if (is_dir) { | |
725 ofn.lpstrInitialDir = path->value().c_str(); | 732 ofn.lpstrInitialDir = path->value().c_str(); |
726 } else { | 733 } else { |
727 dir = path->DirName(); | 734 dir = path->DirName(); |
728 ofn.lpstrInitialDir = dir.value().c_str(); | 735 ofn.lpstrInitialDir = dir.value().c_str(); |
729 // Only pure filename can be put in lpstrFile field. | 736 // Only pure filename can be put in lpstrFile field. |
730 base::wcslcpy(filename, path->BaseName().value().c_str(), | 737 base::wcslcpy(filename, path->BaseName().value().c_str(), |
731 arraysize(filename)); | 738 arraysize(filename)); |
732 } | 739 } |
733 } | 740 } |
734 | 741 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
847 return return_value; | 854 return return_value; |
848 } | 855 } |
849 | 856 |
850 SelectFileDialog* CreateWinSelectFileDialog( | 857 SelectFileDialog* CreateWinSelectFileDialog( |
851 SelectFileDialog::Listener* listener, | 858 SelectFileDialog::Listener* listener, |
852 SelectFilePolicy* policy) { | 859 SelectFilePolicy* policy) { |
853 return new SelectFileDialogImpl(listener, policy); | 860 return new SelectFileDialogImpl(listener, policy); |
854 } | 861 } |
855 | 862 |
856 } // namespace ui | 863 } // namespace ui |
OLD | NEW |