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

Side by Side Diff: chrome/common/win_util.cc

Issue 10621: Adds the ability for save dialogs to take a default extension.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/common/win_util.h" 5 #include "chrome/common/win_util.h"
6 6
7 #include <atlbase.h> 7 #include <atlbase.h>
8 #include <atlapp.h> 8 #include <atlapp.h>
9 #include <commdlg.h> 9 #include <commdlg.h>
10 #include <dwmapi.h> 10 #include <dwmapi.h>
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 334
335 // Copy in the default file extension ("*.*") + NULL. 335 // Copy in the default file extension ("*.*") + NULL.
336 size = all_ext.length() + 1; 336 size = all_ext.length() + 1;
337 memcpy(&(*buffer)[offset], all_ext.c_str(), size * sizeof(wchar_t)); 337 memcpy(&(*buffer)[offset], all_ext.c_str(), size * sizeof(wchar_t));
338 offset += size; 338 offset += size;
339 } 339 }
340 340
341 (*buffer)[offset] = L'\0'; // Double NULL required. 341 (*buffer)[offset] = L'\0'; // Double NULL required.
342 } 342 }
343 343
344 bool SaveFileAs(HWND owner, 344 std::wstring GetFileFilterFromPath(const std::wstring& file_name) {
345 const std::wstring& suggested_name,
346 std::wstring* final_name) {
347 std::wstring reg_description; 345 std::wstring reg_description;
348 std::wstring file_ext = file_util::GetFileExtensionFromPath(suggested_name); 346 std::wstring file_ext = file_util::GetFileExtensionFromPath(file_name);
349 if (!file_ext.empty()) { 347 if (!file_ext.empty()) {
350 file_ext = L"." + file_ext; 348 file_ext = L"." + file_ext;
351 GetRegistryDescriptionFromExtension(file_ext, &reg_description); 349 GetRegistryDescriptionFromExtension(file_ext, &reg_description);
352 } 350 }
353 351
354 std::vector<wchar_t> filter; 352 std::vector<wchar_t> filter;
355 FormatSaveAsFilterForExtension(file_ext, reg_description, true, &filter); 353 FormatSaveAsFilterForExtension(file_ext, reg_description, true, &filter);
354 return std::wstring(&filter[0], filter.size());
355 }
356 356
357 bool SaveFileAs(HWND owner,
358 const std::wstring& suggested_name,
359 std::wstring* final_name) {
360 std::wstring filter = GetFileFilterFromPath(suggested_name);
357 unsigned index = 1; 361 unsigned index = 1;
358 return SaveFileAsWithFilter(owner, 362 return SaveFileAsWithFilter(owner,
359 suggested_name, 363 suggested_name,
360 &filter[0], 364 filter.c_str(),
361 L"", 365 L"",
362 &index, 366 &index,
363 final_name); 367 final_name);
364 } 368 }
365 369
366 bool SaveFileAsWithFilter(HWND owner, 370 bool SaveFileAsWithFilter(HWND owner,
367 const std::wstring& suggested_name, 371 const std::wstring& suggested_name,
368 const wchar_t* filter, 372 const wchar_t* filter,
369 const std::wstring& def_ext, 373 const std::wstring& def_ext,
370 unsigned* index, 374 unsigned* index,
(...skipping 12 matching lines...) Expand all
383 base::wcslcpy(file_name, file_part.c_str(), arraysize(file_name)); 387 base::wcslcpy(file_name, file_part.c_str(), arraysize(file_name));
384 388
385 OPENFILENAME save_as; 389 OPENFILENAME save_as;
386 // We must do this otherwise the ofn's FlagsEx may be initialized to random 390 // We must do this otherwise the ofn's FlagsEx may be initialized to random
387 // junk in release builds which can cause the Places Bar not to show up! 391 // junk in release builds which can cause the Places Bar not to show up!
388 ZeroMemory(&save_as, sizeof(save_as)); 392 ZeroMemory(&save_as, sizeof(save_as));
389 save_as.lStructSize = sizeof(OPENFILENAME); 393 save_as.lStructSize = sizeof(OPENFILENAME);
390 save_as.hwndOwner = owner; 394 save_as.hwndOwner = owner;
391 save_as.hInstance = NULL; 395 save_as.hInstance = NULL;
392 396
393 save_as.lpstrFilter = &filter[0]; 397 save_as.lpstrFilter = filter;
394 398
395 save_as.lpstrCustomFilter = NULL; 399 save_as.lpstrCustomFilter = NULL;
396 save_as.nMaxCustFilter = 0; 400 save_as.nMaxCustFilter = 0;
397 save_as.nFilterIndex = *index; 401 save_as.nFilterIndex = *index;
398 save_as.lpstrFile = file_name; 402 save_as.lpstrFile = file_name;
399 save_as.nMaxFile = arraysize(file_name); 403 save_as.nMaxFile = arraysize(file_name);
400 save_as.lpstrFileTitle = NULL; 404 save_as.lpstrFileTitle = NULL;
401 save_as.nMaxFileTitle = 0; 405 save_as.nMaxFileTitle = 0;
402 406
403 // Set up the initial directory for the dialog. 407 // Set up the initial directory for the dialog.
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 811
808 ChromeFont GetWindowTitleFont() { 812 ChromeFont GetWindowTitleFont() {
809 NONCLIENTMETRICS ncm; 813 NONCLIENTMETRICS ncm;
810 win_util::GetNonClientMetrics(&ncm); 814 win_util::GetNonClientMetrics(&ncm);
811 ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont))); 815 ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont)));
812 return ChromeFont::CreateFont(caption_font); 816 return ChromeFont::CreateFont(caption_font);
813 } 817 }
814 818
815 } // namespace win_util 819 } // namespace win_util
816 820
OLDNEW
« chrome/browser/views/bookmark_manager_view.cc ('K') | « chrome/common/win_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698