diff --git a/src/Gtk/Perspex.Gtk/CommonDialogImpl.cs b/src/Gtk/Perspex.Gtk/CommonDialogImpl.cs new file mode 100644 index 0000000000..ed194420c5 --- /dev/null +++ b/src/Gtk/Perspex.Gtk/CommonDialogImpl.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Perspex.Controls; +using Perspex.Controls.Platform; +using Perspex.Platform; + +namespace Perspex.Gtk +{ + using global::Gtk; + class CommonDialogImpl : ICommonDialogImpl + { + public Task ShowAsync(CommonDialog dialog, IWindowImpl parent) + { + var tcs = new TaskCompletionSource(); + var dlg = new global::Gtk.FileChooserDialog(dialog.Title, ((WindowImpl) parent), + dialog.Action == CommonDialogAction.OpenFile + ? FileChooserAction.Open + : FileChooserAction.Save, + "Cancel", ResponseType.Cancel, + "Open", ResponseType.Accept) + { + SelectMultiple = dialog.AllowMultiple, + }; + foreach (var filter in dialog.Filters) + { + var ffilter = new FileFilter() + { + Name = filter.Name + " (" + string.Join(";", filter.Extensions.Select(e => "*." + e)) + ")" + }; + foreach (var ext in filter.Extensions) + ffilter.AddPattern("*." + ext); + dlg.AddFilter(ffilter); + } + dlg.SetFilename(dialog.InitialFileName); + dlg.Modal = true; + + dlg.Response += (_, args) => + { + if (args.ResponseId == ResponseType.Accept) + tcs.TrySetResult(dlg.Filenames); + dlg.Hide(); + dlg.Dispose(); + }; + + dlg.Close += delegate + { + tcs.TrySetResult(null); + dlg.Dispose(); + }; + dlg.Show(); + return tcs.Task; + } + } +} diff --git a/src/Gtk/Perspex.Gtk/GtkPlatform.cs b/src/Gtk/Perspex.Gtk/GtkPlatform.cs index f6aa72ba5b..dc37708981 100644 --- a/src/Gtk/Perspex.Gtk/GtkPlatform.cs +++ b/src/Gtk/Perspex.Gtk/GtkPlatform.cs @@ -3,6 +3,7 @@ using System; using System.Reactive.Disposables; +using Perspex.Controls.Platform; using Perspex.Input.Platform; using Perspex.Input; using Perspex.Platform; @@ -36,6 +37,7 @@ namespace Perspex.Gtk locator.Register(() => GtkKeyboardDevice.Instance, typeof(IKeyboardDevice)); locator.Register(() => s_instance, typeof(IPlatformSettings)); locator.Register(() => s_instance, typeof(IPlatformThreadingInterface)); + locator.Register(() => new CommonDialogImpl(), typeof (ICommonDialogImpl)); SharedPlatform.Register(); } diff --git a/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj b/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj index 828c09d532..fa548b7882 100644 --- a/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj +++ b/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj @@ -50,6 +50,7 @@ +