Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
DialogService.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Windows;
5 using System.Windows.Threading;
6 using SiliconStudio.Presentation.Services;
10 
11 namespace SiliconStudio.Presentation.Dialogs
12 {
14  {
15  private readonly Dispatcher dispatcher;
16 
17  public DialogService(Dispatcher dispatcher, Window parentWindow)
18  {
19  if (dispatcher == null) throw new ArgumentNullException("dispatcher");
20  this.dispatcher = dispatcher;
21  ParentWindow = parentWindow;
22  }
23 
24  public Window ParentWindow { get; private set; }
25 
27  {
28  return new FileOpenModalDialog(dispatcher, ParentWindow);
29  }
30 
32  {
33  return new FolderOpenModalDialog(dispatcher, ParentWindow);
34  }
35 
37  {
38  return new FileSaveModalDialog(dispatcher, ParentWindow);
39  }
40 
41  public MessageBoxResult ShowMessageBox(string message, string caption, MessageBoxButton button, MessageBoxImage image)
42  {
43  return (MessageBoxResult)MessageBox.Show(message, caption, (System.Windows.MessageBoxButton)button, (System.Windows.MessageBoxImage)image);
44  }
45 
46  public void CloseCurrentWindow(bool? dialogResult = null)
47  {
48  // Window.DialogResult setter will throw an exception when the window was not displayed with ShowDialog, even if we're setting null.
49  if (ParentWindow.DialogResult != dialogResult)
50  {
51  ParentWindow.DialogResult = dialogResult;
52  }
53  ParentWindow.Close();
54  ParentWindow = null;
55  }
56  }
57 }
SiliconStudio.Presentation.Services.MessageBoxResult MessageBoxResult
Definition: DialogService.cs:9
IFileOpenModalDialog CreateFileOpenModalDialog()
Creates a modal file open dialog.
MessageBoxResult ShowMessageBox(string message, string caption, MessageBoxButton button, MessageBoxImage image)
Displays a modal message box.
SiliconStudio.Presentation.Services.MessageBoxImage MessageBoxImage
Definition: DialogService.cs:8
MessageBoxResult
An enum representing the button pressed by the user to close a message box.
MessageBoxImage
An enum representing the image to display in a message box.
void CloseCurrentWindow(bool?dialogResult=null)
Attempts to close the current window.
IFileSaveModalDialog CreateFileSaveModalDialog()
Creates a modal file save dialog.
MessageBoxButton
An enum representing the buttons to display in a message box.
An interface representing a modal file save dialog.
An interface to invoke dialogs from commands implemented in view models
An interface representing a modal file open dialog.
An interface representing a modal folder selection dialog.
IFolderOpenModalDialog CreateFolderOpenModalDialog()
Create a modal folder open dialog.
DialogService(Dispatcher dispatcher, Window parentWindow)
SiliconStudio.Presentation.Services.MessageBoxButton MessageBoxButton
Definition: DialogService.cs:7