Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
FileOpenModalDialog.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.Collections.Generic;
4 using System.Windows;
5 using System.Windows.Threading;
6 using Microsoft.WindowsAPICodePack.Dialogs;
7 using SiliconStudio.Presentation.Services;
8 
9 namespace SiliconStudio.Presentation.Dialogs
10 {
12  {
13  internal FileOpenModalDialog(Dispatcher dispatcher, Window parentWindow)
14  : base(dispatcher, parentWindow)
15  {
16  Dialog = new CommonOpenFileDialog { EnsureFileExists = true };
17  Filters = new List<FileDialogFilter>();
18  FilePaths = new List<string>();
19  }
20 
21  /// <inheritdoc/>
22  public bool AllowMultiSelection { get { return OpenDlg.Multiselect; } set { OpenDlg.Multiselect = value; } }
23 
24  /// <inheritdoc/>
25  public IList<FileDialogFilter> Filters { get; set; }
26 
27  /// <inheritdoc/>
28  public IReadOnlyCollection<string> FilePaths { get; private set; }
29 
30  /// <inheritdoc/>
31  public string InitialDirectory { get { return OpenDlg.InitialDirectory; } set { OpenDlg.InitialDirectory = value != null ? value.Replace('/', '\\') : null; } }
32 
33  /// <inheritdoc/>
34  public string DefaultFileName { get { return OpenDlg.DefaultFileName; } set { OpenDlg.DefaultFileName = value; } }
35 
36  private CommonOpenFileDialog OpenDlg { get { return (CommonOpenFileDialog)Dialog; } }
37 
38  /// <inheritdoc/>
39  public override DialogResult Show()
40  {
41  OpenDlg.Filters.Clear();
42  foreach (var filter in Filters)
43  {
44  OpenDlg.Filters.Add(new CommonFileDialogFilter(filter.Description, filter.ExtensionList));
45  }
46  var result = InvokeDialog();
47  FilePaths = result != DialogResult.Cancel ? new List<string>(OpenDlg.FileNames) : new List<string>();
48  return result;
49  }
50  }
51 }
override DialogResult Show()
Display the modal dialog. This method will block until the user close the dialog. A DialogResult valu...
DialogResult
An enum representing the result of a dialog invocation.
Definition: DialogResult.cs:9
An interface representing a modal file open dialog.