From b845680b2e270c4028cc53eda71c17b277779390 Mon Sep 17 00:00:00 2001 From: danwalmsley Date: Fri, 19 Feb 2016 13:27:42 +0000 Subject: [PATCH] Font scaling on linux, and FolderBrowse implementation for linux. --- .../ViewModels/MainWindowViewModel.cs | 22 +++++++++++++ .../Views/MainWindow.paml | 6 ++-- .../Perspex.Cairo/Media/FormattedTextImpl.cs | 9 ++++-- src/Gtk/Perspex.Gtk/SystemDialogImpl.cs | 32 +++++++++++++++++-- src/Perspex.Controls/Utils/UndoRedoHelper.cs | 15 +++++++-- 5 files changed, 74 insertions(+), 10 deletions(-) diff --git a/samples/XamlTestApplicationPcl/ViewModels/MainWindowViewModel.cs b/samples/XamlTestApplicationPcl/ViewModels/MainWindowViewModel.cs index 9ac24a622e..3ae72e138c 100644 --- a/samples/XamlTestApplicationPcl/ViewModels/MainWindowViewModel.cs +++ b/samples/XamlTestApplicationPcl/ViewModels/MainWindowViewModel.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using ReactiveUI; +using Perspex.Controls; namespace XamlTestApplication.ViewModels { @@ -59,6 +60,23 @@ namespace XamlTestApplication.ViewModels CollapseNodesCommand.Subscribe(_ => ExpandNodes(false)); ExpandNodesCommand = ReactiveCommand.Create(); ExpandNodesCommand.Subscribe(_ => ExpandNodes(true)); + + OpenFileCommand = ReactiveCommand.Create(); + OpenFileCommand.Subscribe(_ => + { + var ofd = new OpenFileDialog(); + + ofd.ShowAsync(); + }); + + OpenFolderCommand = ReactiveCommand.Create(); + OpenFolderCommand.Subscribe(_ => + { + var ofd = new OpenFolderDialog(); + + ofd.ShowAsync(); + }); + } public List Items { get; } @@ -68,6 +86,10 @@ namespace XamlTestApplication.ViewModels public ReactiveCommand ExpandNodesCommand { get; } + public ReactiveCommand OpenFileCommand { get; } + + public ReactiveCommand OpenFolderCommand { get; } + public void ExpandNodes(bool expanded) { foreach (var node in Nodes) diff --git a/samples/XamlTestApplicationPcl/Views/MainWindow.paml b/samples/XamlTestApplicationPcl/Views/MainWindow.paml index cadb70edac..e5155b0b95 100644 --- a/samples/XamlTestApplicationPcl/Views/MainWindow.paml +++ b/samples/XamlTestApplicationPcl/Views/MainWindow.paml @@ -6,11 +6,13 @@ Title="Perspex Test Application" Width="800" Height="600"> - + + + - + diff --git a/src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs b/src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs index 956a522002..e8fc9bc924 100644 --- a/src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs +++ b/src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs @@ -15,6 +15,11 @@ namespace Perspex.Cairo.Media private Size _size; private readonly string _text; + static double CorrectScale(double input) + { + return input * 0.75; + } + public FormattedTextImpl( Pango.Context context, string text, @@ -25,14 +30,14 @@ namespace Perspex.Cairo.Media FontWeight fontWeight) { Contract.Requires(context != null); - Contract.Requires (text != null); + Contract.Requires(text != null); Layout = new Pango.Layout(context); _text = text; Layout.SetText(text); Layout.FontDescription = new Pango.FontDescription { Family = fontFamily, - Size = Pango.Units.FromDouble(fontSize), + Size = Pango.Units.FromDouble(CorrectScale(fontSize)), Style = (Pango.Style)fontStyle, Weight = fontWeight.ToCairo() }; diff --git a/src/Gtk/Perspex.Gtk/SystemDialogImpl.cs b/src/Gtk/Perspex.Gtk/SystemDialogImpl.cs index 304de86fc3..9789beb7c7 100644 --- a/src/Gtk/Perspex.Gtk/SystemDialogImpl.cs +++ b/src/Gtk/Perspex.Gtk/SystemDialogImpl.cs @@ -15,7 +15,7 @@ namespace Perspex.Gtk public Task ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent) { var tcs = new TaskCompletionSource(); - var dlg = new global::Gtk.FileChooserDialog(dialog.Title, ((WindowImpl) parent), + var dlg = new global::Gtk.FileChooserDialog(dialog.Title, ((WindowImpl)parent), dialog is OpenFileDialog ? FileChooserAction.Open : FileChooserAction.Save, @@ -44,7 +44,7 @@ namespace Perspex.Gtk dlg.Hide(); dlg.Dispose(); }; - + dlg.Close += delegate { tcs.TrySetResult(null); @@ -56,7 +56,33 @@ namespace Perspex.Gtk public Task ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent) { - throw new NotImplementedException(); + var tcs = new TaskCompletionSource(); + var dlg = new global::Gtk.FileChooserDialog(dialog.Title, ((WindowImpl)parent), + FileChooserAction.SelectFolder, + "Cancel", ResponseType.Cancel, + "Select Folder", ResponseType.Accept) + { + + }; + + dlg.Modal = true; + + dlg.Response += (_, args) => + { + if (args.ResponseId == ResponseType.Accept) + tcs.TrySetResult(dlg.Filename); + + dlg.Hide(); + dlg.Dispose(); + }; + + dlg.Close += delegate + { + tcs.TrySetResult(null); + dlg.Dispose(); + }; + dlg.Show(); + return tcs.Task; } } } diff --git a/src/Perspex.Controls/Utils/UndoRedoHelper.cs b/src/Perspex.Controls/Utils/UndoRedoHelper.cs index 9de2ca9b35..60b6839dad 100644 --- a/src/Perspex.Controls/Utils/UndoRedoHelper.cs +++ b/src/Perspex.Controls/Utils/UndoRedoHelper.cs @@ -37,7 +37,12 @@ namespace Perspex.Controls.Utils public void Undo() { - _host.UndoRedoState= (_currentNode = _currentNode?.Previous ?? _currentNode).Value; + if (_currentNode != null) + { + _currentNode = _currentNode.Previous; + } + + _host.UndoRedoState = _currentNode.Value; } public bool IsLastState => _currentNode.Next == null; @@ -62,8 +67,12 @@ namespace Perspex.Controls.Utils } public void Redo() - { - _host.UndoRedoState = (_currentNode = _currentNode?.Next ?? _currentNode).Value; + { + if (_currentNode != null) { + _currentNode = _currentNode.Next; + } + + _host.UndoRedoState = _currentNode.Value; } public void Snapshot()