| 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 "chrome/browser/ui/select_file_dialog.h" | 5 #include "chrome/browser/ui/select_file_dialog.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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 NOTREACHED(); | 70 NOTREACHED(); |
| 71 return false; | 71 return false; |
| 72 } | 72 } |
| 73 | 73 |
| 74 return metro_get_save_file_name(ofn) == TRUE; | 74 return metro_get_save_file_name(ofn) == TRUE; |
| 75 } else { | 75 } else { |
| 76 return GetSaveFileName(ofn) == TRUE; | 76 return GetSaveFileName(ofn) == TRUE; |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 // Distinguish directories from regular files. |
| 81 bool IsDirectory(const FilePath& path) { |
| 82 base::PlatformFileInfo file_info; |
| 83 return file_util::GetFileInfo(path, &file_info) ? |
| 84 file_info.is_directory : file_util::EndsWithSeparator(path); |
| 85 } |
| 86 |
| 80 } // namespace | 87 } // namespace |
| 81 | 88 |
| 82 // This function takes the output of a SaveAs dialog: a filename, a filter and | 89 // This function takes the output of a SaveAs dialog: a filename, a filter and |
| 83 // the extension originally suggested to the user (shown in the dialog box) and | 90 // the extension originally suggested to the user (shown in the dialog box) and |
| 84 // returns back the filename with the appropriate extension tacked on. If the | 91 // returns back the filename with the appropriate extension tacked on. If the |
| 85 // user requests an unknown extension and is not using the 'All files' filter, | 92 // user requests an unknown extension and is not using the 'All files' filter, |
| 86 // the suggested extension will be appended, otherwise we will leave the | 93 // the suggested extension will be appended, otherwise we will leave the |
| 87 // filename unmodified. |filename| should contain the filename selected in the | 94 // filename unmodified. |filename| should contain the filename selected in the |
| 88 // SaveAs dialog box and may include the path, |filter_selected| should be | 95 // SaveAs dialog box and may include the path, |filter_selected| should be |
| 89 // '*.something', for example '*.*' or it can be blank (which is treated as | 96 // '*.something', for example '*.*' or it can be blank (which is treated as |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 save_as.lpstrCustomFilter = NULL; | 332 save_as.lpstrCustomFilter = NULL; |
| 326 save_as.nMaxCustFilter = 0; | 333 save_as.nMaxCustFilter = 0; |
| 327 save_as.nFilterIndex = *index; | 334 save_as.nFilterIndex = *index; |
| 328 save_as.lpstrFile = file_name; | 335 save_as.lpstrFile = file_name; |
| 329 save_as.nMaxFile = arraysize(file_name); | 336 save_as.nMaxFile = arraysize(file_name); |
| 330 save_as.lpstrFileTitle = NULL; | 337 save_as.lpstrFileTitle = NULL; |
| 331 save_as.nMaxFileTitle = 0; | 338 save_as.nMaxFileTitle = 0; |
| 332 | 339 |
| 333 // Set up the initial directory for the dialog. | 340 // Set up the initial directory for the dialog. |
| 334 std::wstring directory; | 341 std::wstring directory; |
| 335 if (!suggested_name.empty()) | 342 if (!suggested_name.empty()) { |
| 336 directory = suggested_path.DirName().value(); | 343 if (IsDirectory(suggested_path)) { |
| 344 directory = suggested_path.value(); |
| 345 file_part.clear(); |
| 346 } else { |
| 347 directory = suggested_path.DirName().value(); |
| 348 } |
| 349 } |
| 337 | 350 |
| 338 save_as.lpstrInitialDir = directory.c_str(); | 351 save_as.lpstrInitialDir = directory.c_str(); |
| 339 save_as.lpstrTitle = NULL; | 352 save_as.lpstrTitle = NULL; |
| 340 save_as.Flags = OFN_OVERWRITEPROMPT | OFN_EXPLORER | OFN_ENABLESIZING | | 353 save_as.Flags = OFN_OVERWRITEPROMPT | OFN_EXPLORER | OFN_ENABLESIZING | |
| 341 OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST; | 354 OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST; |
| 342 save_as.lpstrDefExt = &def_ext[0]; | 355 save_as.lpstrDefExt = &def_ext[0]; |
| 343 save_as.lCustData = NULL; | 356 save_as.lCustData = NULL; |
| 344 | 357 |
| 345 if (base::win::GetVersion() < base::win::VERSION_VISTA) { | 358 if (base::win::GetVersion() < base::win::VERSION_VISTA) { |
| 346 // The save as on Windows XP remembers its last position, | 359 // The save as on Windows XP remembers its last position, |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 wchar_t filename[MAX_PATH]; | 768 wchar_t filename[MAX_PATH]; |
| 756 // According to http://support.microsoft.com/?scid=kb;en-us;222003&x=8&y=12, | 769 // According to http://support.microsoft.com/?scid=kb;en-us;222003&x=8&y=12, |
| 757 // The lpstrFile Buffer MUST be NULL Terminated. | 770 // The lpstrFile Buffer MUST be NULL Terminated. |
| 758 filename[0] = 0; | 771 filename[0] = 0; |
| 759 // Define the dir in here to keep the string buffer pointer pointed to | 772 // Define the dir in here to keep the string buffer pointer pointed to |
| 760 // ofn.lpstrInitialDir available during the period of running the | 773 // ofn.lpstrInitialDir available during the period of running the |
| 761 // GetOpenFileName. | 774 // GetOpenFileName. |
| 762 FilePath dir; | 775 FilePath dir; |
| 763 // Use lpstrInitialDir to specify the initial directory | 776 // Use lpstrInitialDir to specify the initial directory |
| 764 if (!path->empty()) { | 777 if (!path->empty()) { |
| 765 bool is_dir; | 778 if (IsDirectory(*path)) { |
| 766 base::PlatformFileInfo file_info; | |
| 767 if (file_util::GetFileInfo(*path, &file_info)) | |
| 768 is_dir = file_info.is_directory; | |
| 769 else | |
| 770 is_dir = file_util::EndsWithSeparator(*path); | |
| 771 if (is_dir) { | |
| 772 ofn.lpstrInitialDir = path->value().c_str(); | 779 ofn.lpstrInitialDir = path->value().c_str(); |
| 773 } else { | 780 } else { |
| 774 dir = path->DirName(); | 781 dir = path->DirName(); |
| 775 ofn.lpstrInitialDir = dir.value().c_str(); | 782 ofn.lpstrInitialDir = dir.value().c_str(); |
| 776 // Only pure filename can be put in lpstrFile field. | 783 // Only pure filename can be put in lpstrFile field. |
| 777 base::wcslcpy(filename, path->BaseName().value().c_str(), | 784 base::wcslcpy(filename, path->BaseName().value().c_str(), |
| 778 arraysize(filename)); | 785 arraysize(filename)); |
| 779 } | 786 } |
| 780 } | 787 } |
| 781 | 788 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 } | 853 } |
| 847 } | 854 } |
| 848 } | 855 } |
| 849 return success; | 856 return success; |
| 850 } | 857 } |
| 851 | 858 |
| 852 // static | 859 // static |
| 853 SelectFileDialog* SelectFileDialog::Create(Listener* listener) { | 860 SelectFileDialog* SelectFileDialog::Create(Listener* listener) { |
| 854 return new SelectFileDialogImpl(listener); | 861 return new SelectFileDialogImpl(listener); |
| 855 } | 862 } |
| OLD | NEW |