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

Side by Side Diff: chrome/browser/views/shell_dialogs.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/browser/shell_dialogs.h" 5 #include "chrome/browser/shell_dialogs.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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 class SelectFileDialogImpl : public SelectFileDialog, 187 class SelectFileDialogImpl : public SelectFileDialog,
188 public BaseShellDialogImpl { 188 public BaseShellDialogImpl {
189 public: 189 public:
190 explicit SelectFileDialogImpl(Listener* listener); 190 explicit SelectFileDialogImpl(Listener* listener);
191 virtual ~SelectFileDialogImpl(); 191 virtual ~SelectFileDialogImpl();
192 192
193 // SelectFileDialog implementation: 193 // SelectFileDialog implementation:
194 virtual void SelectFile(Type type, const std::wstring& title, 194 virtual void SelectFile(Type type, const std::wstring& title,
195 const std::wstring& default_path, 195 const std::wstring& default_path,
196 const std::wstring& filter, 196 const std::wstring& filter,
197 const std::wstring& default_extension,
197 HWND owning_hwnd, 198 HWND owning_hwnd,
198 void* params); 199 void* params);
199 virtual bool IsRunning(HWND owning_hwnd) const; 200 virtual bool IsRunning(HWND owning_hwnd) const;
200 virtual void ListenerDestroyed(); 201 virtual void ListenerDestroyed();
201 202
202 private: 203 private:
203 // Shows the file selection dialog modal to |owner| and calls the result 204 // Shows the file selection dialog modal to |owner| and calls the result
204 // back on the ui thread. Run on the dialog thread. 205 // back on the ui thread. Run on the dialog thread.
205 void ExecuteSelectFile(Type type, 206 void ExecuteSelectFile(Type type,
206 const std::wstring& title, 207 const std::wstring& title,
207 const std::wstring& default_path, 208 const std::wstring& default_path,
208 const std::wstring& filter, 209 const std::wstring& filter,
210 const std::wstring& default_extension,
209 RunState run_state, 211 RunState run_state,
210 void* params); 212 void* params);
211 213
212 // Notifies the listener that a folder was chosen. Run on the ui thread. 214 // Notifies the listener that a folder was chosen. Run on the ui thread.
213 void FileSelected(const std::wstring& path, void* params, RunState run_state); 215 void FileSelected(const std::wstring& path, void* params, RunState run_state);
214 216
215 // Notifies the listener that no file was chosen (the action was canceled). 217 // Notifies the listener that no file was chosen (the action was canceled).
216 // Run on the ui thread. 218 // Run on the ui thread.
217 void FileNotSelected(void* params, RunState run_state); 219 void FileNotSelected(void* params, RunState run_state);
218 220
(...skipping 24 matching lines...) Expand all
243 BaseShellDialogImpl() { 245 BaseShellDialogImpl() {
244 } 246 }
245 247
246 SelectFileDialogImpl::~SelectFileDialogImpl() { 248 SelectFileDialogImpl::~SelectFileDialogImpl() {
247 } 249 }
248 250
249 void SelectFileDialogImpl::SelectFile(Type type, 251 void SelectFileDialogImpl::SelectFile(Type type,
250 const std::wstring& title, 252 const std::wstring& title,
251 const std::wstring& default_path, 253 const std::wstring& default_path,
252 const std::wstring& filter, 254 const std::wstring& filter,
255 const std::wstring& default_extension,
253 HWND owner, 256 HWND owner,
254 void* params) { 257 void* params) {
255 RunState run_state = BeginRun(owner); 258 RunState run_state = BeginRun(owner);
256 run_state.dialog_thread->message_loop()->PostTask(FROM_HERE, 259 run_state.dialog_thread->message_loop()->PostTask(FROM_HERE,
257 NewRunnableMethod(this, &SelectFileDialogImpl::ExecuteSelectFile, type, 260 NewRunnableMethod(this, &SelectFileDialogImpl::ExecuteSelectFile, type,
258 title, default_path, filter, run_state, params)); 261 title, default_path, filter, default_extension,
262 run_state, params));
259 } 263 }
260 264
261 bool SelectFileDialogImpl::IsRunning(HWND owning_hwnd) const { 265 bool SelectFileDialogImpl::IsRunning(HWND owning_hwnd) const {
262 return listener_ && IsRunningDialogForOwner(owning_hwnd); 266 return listener_ && IsRunningDialogForOwner(owning_hwnd);
263 } 267 }
264 268
265 void SelectFileDialogImpl::ListenerDestroyed() { 269 void SelectFileDialogImpl::ListenerDestroyed() {
266 // Our associated listener has gone away, so we shouldn't call back to it if 270 // Our associated listener has gone away, so we shouldn't call back to it if
267 // our worker thread returns after the listener is dead. 271 // our worker thread returns after the listener is dead.
268 listener_ = NULL; 272 listener_ = NULL;
269 } 273 }
270 274
271 void SelectFileDialogImpl::ExecuteSelectFile( 275 void SelectFileDialogImpl::ExecuteSelectFile(
272 Type type, 276 Type type,
273 const std::wstring& title, 277 const std::wstring& title,
274 const std::wstring& default_path, 278 const std::wstring& default_path,
275 const std::wstring& filter, 279 const std::wstring& filter,
280 const std::wstring& default_extension,
276 RunState run_state, 281 RunState run_state,
277 void* params) { 282 void* params) {
278 std::wstring path = default_path; 283 std::wstring path = default_path;
279 bool success = false; 284 bool success = false;
280 if (type == SELECT_FOLDER) { 285 if (type == SELECT_FOLDER) {
281 success = RunSelectFolderDialog(title, run_state.owner, &path); 286 success = RunSelectFolderDialog(title, run_state.owner, &path);
282 } else if (type == SELECT_SAVEAS_FILE) { 287 } else if (type == SELECT_SAVEAS_FILE) {
283 success = win_util::SaveFileAs(run_state.owner, default_path, &path); 288 const wchar_t* filter_string = filter.empty() ? NULL : filter.c_str();
289 unsigned index = 0;
290 success = win_util::SaveFileAsWithFilter(run_state.owner, default_path,
291 filter_string, default_extension, &index, &path);
284 DisableOwner(run_state.owner); 292 DisableOwner(run_state.owner);
285 } else if (type == SELECT_OPEN_FILE) { 293 } else if (type == SELECT_OPEN_FILE) {
286 success = RunOpenFileDialog(title, filter, run_state.owner, &path); 294 success = RunOpenFileDialog(title, filter, run_state.owner, &path);
287 } 295 }
288 296
289 if (success) { 297 if (success) {
290 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, 298 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
291 &SelectFileDialogImpl::FileSelected, path, params, run_state)); 299 &SelectFileDialogImpl::FileSelected, path, params, run_state));
292 } else { 300 } else {
293 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, 301 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 void SelectFontDialogImpl::FontNotSelected(void* params, RunState run_state) { 538 void SelectFontDialogImpl::FontNotSelected(void* params, RunState run_state) {
531 if (listener_) 539 if (listener_)
532 listener_->FontSelectionCanceled(params); 540 listener_->FontSelectionCanceled(params);
533 EndRun(run_state); 541 EndRun(run_state);
534 } 542 }
535 543
536 // static 544 // static
537 SelectFontDialog* SelectFontDialog::Create(Listener* listener) { 545 SelectFontDialog* SelectFontDialog::Create(Listener* listener) {
538 return new SelectFontDialogImpl(listener); 546 return new SelectFontDialogImpl(listener);
539 } 547 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698