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

Side by Side Diff: chrome/browser/views/shell_dialogs_win.cc

Issue 45048: Remove Windows "Save As" dialogs from Save Page code.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 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 | 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 #include <atlbase.h> 10 #include <atlbase.h>
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 class SelectFileDialogImpl : public SelectFileDialog, 188 class SelectFileDialogImpl : public SelectFileDialog,
189 public BaseShellDialogImpl { 189 public BaseShellDialogImpl {
190 public: 190 public:
191 explicit SelectFileDialogImpl(Listener* listener); 191 explicit SelectFileDialogImpl(Listener* listener);
192 virtual ~SelectFileDialogImpl(); 192 virtual ~SelectFileDialogImpl();
193 193
194 // SelectFileDialog implementation: 194 // SelectFileDialog implementation:
195 virtual void SelectFile(Type type, const std::wstring& title, 195 virtual void SelectFile(Type type, const std::wstring& title,
196 const std::wstring& default_path, 196 const std::wstring& default_path,
197 const std::wstring& filter, 197 const std::wstring& filter,
198 int filter_index,
198 const std::wstring& default_extension, 199 const std::wstring& default_extension,
199 HWND owning_hwnd, 200 HWND owning_hwnd,
200 void* params); 201 void* params);
201 virtual bool IsRunning(HWND owning_hwnd) const; 202 virtual bool IsRunning(HWND owning_hwnd) const;
202 virtual void ListenerDestroyed(); 203 virtual void ListenerDestroyed();
203 204
204 private: 205 private:
206 // A struct for holding all the state necessary for displaying a Save dialog.
207 struct ExecuteSelectParams {
208 ExecuteSelectParams(Type type,
209 const std::wstring& title,
210 const std::wstring& default_path,
211 const std::wstring& filter,
212 int filter_index,
213 const std::wstring& default_extension,
214 RunState run_state,
215 HWND owner,
216 void* params)
217 : type(type), title(title), default_path(default_path), filter(filter),
218 filter_index(filter_index), default_extension(default_extension),
219 run_state(run_state), owner(owner), params(params) {
220 }
221 SelectFileDialog::Type type;
222 std::wstring title;
223 std::wstring default_path;
224 std::wstring filter;
225 int filter_index;
226 std::wstring default_extension;
227 RunState run_state;
228 HWND owner;
229 void* params;
230 };
231
205 // Shows the file selection dialog modal to |owner| and calls the result 232 // Shows the file selection dialog modal to |owner| and calls the result
206 // back on the ui thread. Run on the dialog thread. 233 // back on the ui thread. Run on the dialog thread.
207 void ExecuteSelectFile(Type type, 234 void ExecuteSelectFile(const ExecuteSelectParams& params);
208 const std::wstring& title,
209 const std::wstring& default_path,
210 const std::wstring& filter,
211 const std::wstring& default_extension,
212 RunState run_state,
213 void* params);
214 235
215 // Notifies the listener that a folder was chosen. Run on the ui thread. 236 // Notifies the listener that a folder was chosen. Run on the ui thread.
216 void FileSelected(const std::wstring& path, void* params, RunState run_state); 237 void FileSelected(const std::wstring& path, int index,
238 void* params, RunState run_state);
217 239
218 // Notifies listener that multiple files were chosen. Run on the ui thread. 240 // Notifies listener that multiple files were chosen. Run on the ui thread.
219 void MultiFilesSelected(const std::vector<std::wstring>& paths, void* params, 241 void MultiFilesSelected(const std::vector<std::wstring>& paths, void* params,
220 RunState run_state); 242 RunState run_state);
221 243
222 // Notifies the listener that no file was chosen (the action was canceled). 244 // Notifies the listener that no file was chosen (the action was canceled).
223 // Run on the ui thread. 245 // Run on the ui thread.
224 void FileNotSelected(void* params, RunState run_state); 246 void FileNotSelected(void* params, RunState run_state);
225 247
226 // Runs a Folder selection dialog box, passes back the selected folder in 248 // Runs a Folder selection dialog box, passes back the selected folder in
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 BaseShellDialogImpl() { 284 BaseShellDialogImpl() {
263 } 285 }
264 286
265 SelectFileDialogImpl::~SelectFileDialogImpl() { 287 SelectFileDialogImpl::~SelectFileDialogImpl() {
266 } 288 }
267 289
268 void SelectFileDialogImpl::SelectFile(Type type, 290 void SelectFileDialogImpl::SelectFile(Type type,
269 const std::wstring& title, 291 const std::wstring& title,
270 const std::wstring& default_path, 292 const std::wstring& default_path,
271 const std::wstring& filter, 293 const std::wstring& filter,
294 int filter_index,
272 const std::wstring& default_extension, 295 const std::wstring& default_extension,
273 HWND owner, 296 HWND owner,
274 void* params) { 297 void* params) {
275 RunState run_state = BeginRun(owner); 298 ExecuteSelectParams execute_params(type, title, default_path, filter,
276 run_state.dialog_thread->message_loop()->PostTask(FROM_HERE, 299 filter_index, default_extension,
277 NewRunnableMethod(this, &SelectFileDialogImpl::ExecuteSelectFile, type, 300 BeginRun(owner), owner, params);
278 title, default_path, filter, default_extension, 301 execute_params.run_state.dialog_thread->message_loop()->PostTask(FROM_HERE,
279 run_state, params)); 302 NewRunnableMethod(this, &SelectFileDialogImpl::ExecuteSelectFile,
303 execute_params));
280 } 304 }
281 305
282 bool SelectFileDialogImpl::IsRunning(HWND owning_hwnd) const { 306 bool SelectFileDialogImpl::IsRunning(HWND owning_hwnd) const {
283 return listener_ && IsRunningDialogForOwner(owning_hwnd); 307 return listener_ && IsRunningDialogForOwner(owning_hwnd);
284 } 308 }
285 309
286 void SelectFileDialogImpl::ListenerDestroyed() { 310 void SelectFileDialogImpl::ListenerDestroyed() {
287 // Our associated listener has gone away, so we shouldn't call back to it if 311 // Our associated listener has gone away, so we shouldn't call back to it if
288 // our worker thread returns after the listener is dead. 312 // our worker thread returns after the listener is dead.
289 listener_ = NULL; 313 listener_ = NULL;
290 } 314 }
291 315
292 void SelectFileDialogImpl::ExecuteSelectFile( 316 void SelectFileDialogImpl::ExecuteSelectFile(
293 Type type, 317 const ExecuteSelectParams& params) {
294 const std::wstring& title, 318 std::wstring path = params.default_path;
295 const std::wstring& default_path,
296 const std::wstring& filter,
297 const std::wstring& default_extension,
298 RunState run_state,
299 void* params) {
300 std::wstring path = default_path;
301 bool success = false; 319 bool success = false;
302 if (type == SELECT_FOLDER) { 320 unsigned filter_index = params.filter_index;
303 success = RunSelectFolderDialog(title, run_state.owner, &path); 321 if (params.type == SELECT_FOLDER) {
304 } else if (type == SELECT_SAVEAS_FILE) { 322 success = RunSelectFolderDialog(params.title,
305 unsigned index = 0; 323 params.run_state.owner,
306 success = win_util::SaveFileAsWithFilter(run_state.owner, default_path, 324 &path);
307 filter, default_extension, false, &index, &path); 325 } else if (params.type == SELECT_SAVEAS_FILE) {
308 DisableOwner(run_state.owner); 326 success = win_util::SaveFileAsWithFilter(params.run_state.owner,
309 } else if (type == SELECT_OPEN_FILE) { 327 params.default_path, params.filter, params.default_extension, false,
310 success = RunOpenFileDialog(title, filter, run_state.owner, &path); 328 &filter_index, &path);
311 } else if (type == SELECT_OPEN_MULTI_FILE) { 329 DisableOwner(params.run_state.owner);
330 } else if (params.type == SELECT_OPEN_FILE) {
331 success = RunOpenFileDialog(params.title, params.filter,
332 params.run_state.owner, &path);
333 } else if (params.type == SELECT_OPEN_MULTI_FILE) {
312 std::vector<std::wstring> paths; 334 std::vector<std::wstring> paths;
313 if (RunOpenMultiFileDialog(title, filter, run_state.owner, &paths)) { 335 if (RunOpenMultiFileDialog(params.title, params.filter,
336 params.run_state.owner, &paths)) {
314 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, 337 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
315 &SelectFileDialogImpl::MultiFilesSelected, paths, params, run_state)); 338 &SelectFileDialogImpl::MultiFilesSelected,
339 paths, params.params, params.run_state));
316 return; 340 return;
317 } 341 }
318 } 342 }
319 343
320 if (success) { 344 if (success) {
321 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, 345 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
322 &SelectFileDialogImpl::FileSelected, path, params, run_state)); 346 &SelectFileDialogImpl::FileSelected, path, filter_index,
347 params.params, params.run_state));
323 } else { 348 } else {
324 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, 349 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
325 &SelectFileDialogImpl::FileNotSelected, params, run_state)); 350 &SelectFileDialogImpl::FileNotSelected, params.params,
351 params.run_state));
326 } 352 }
327 } 353 }
328 354
329 void SelectFileDialogImpl::FileSelected(const std::wstring& selected_folder, 355 void SelectFileDialogImpl::FileSelected(const std::wstring& selected_folder,
356 int index,
330 void* params, 357 void* params,
331 RunState run_state) { 358 RunState run_state) {
332 if (listener_) 359 if (listener_)
333 listener_->FileSelected(selected_folder, params); 360 listener_->FileSelected(selected_folder, index, params);
334 EndRun(run_state); 361 EndRun(run_state);
335 } 362 }
336 363
337 void SelectFileDialogImpl::MultiFilesSelected( 364 void SelectFileDialogImpl::MultiFilesSelected(
338 const std::vector<std::wstring>& selected_files, 365 const std::vector<std::wstring>& selected_files,
339 void* params, 366 void* params,
340 RunState run_state) { 367 RunState run_state) {
341 if (listener_) 368 if (listener_)
342 listener_->MultiFilesSelected(selected_files, params); 369 listener_->MultiFilesSelected(selected_files, params);
343 EndRun(run_state); 370 EndRun(run_state);
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 void SelectFontDialogImpl::FontNotSelected(void* params, RunState run_state) { 686 void SelectFontDialogImpl::FontNotSelected(void* params, RunState run_state) {
660 if (listener_) 687 if (listener_)
661 listener_->FontSelectionCanceled(params); 688 listener_->FontSelectionCanceled(params);
662 EndRun(run_state); 689 EndRun(run_state);
663 } 690 }
664 691
665 // static 692 // static
666 SelectFontDialog* SelectFontDialog::Create(Listener* listener) { 693 SelectFontDialog* SelectFontDialog::Create(Listener* listener) {
667 return new SelectFontDialogImpl(listener); 694 return new SelectFontDialogImpl(listener);
668 } 695 }
OLDNEW
« no previous file with comments | « chrome/browser/views/options/content_page_view.cc ('k') | chrome/browser/views/user_data_dir_dialog.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698