Browse Source

Font scaling on linux, and FolderBrowse implementation for linux.

pull/440/head
danwalmsley 11 years ago
parent
commit
b845680b2e
  1. 22
      samples/XamlTestApplicationPcl/ViewModels/MainWindowViewModel.cs
  2. 6
      samples/XamlTestApplicationPcl/Views/MainWindow.paml
  3. 9
      src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs
  4. 32
      src/Gtk/Perspex.Gtk/SystemDialogImpl.cs
  5. 15
      src/Perspex.Controls/Utils/UndoRedoHelper.cs

22
samples/XamlTestApplicationPcl/ViewModels/MainWindowViewModel.cs

@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using ReactiveUI; using ReactiveUI;
using Perspex.Controls;
namespace XamlTestApplication.ViewModels namespace XamlTestApplication.ViewModels
{ {
@ -59,6 +60,23 @@ namespace XamlTestApplication.ViewModels
CollapseNodesCommand.Subscribe(_ => ExpandNodes(false)); CollapseNodesCommand.Subscribe(_ => ExpandNodes(false));
ExpandNodesCommand = ReactiveCommand.Create(); ExpandNodesCommand = ReactiveCommand.Create();
ExpandNodesCommand.Subscribe(_ => ExpandNodes(true)); 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<TestItem> Items { get; } public List<TestItem> Items { get; }
@ -68,6 +86,10 @@ namespace XamlTestApplication.ViewModels
public ReactiveCommand<object> ExpandNodesCommand { get; } public ReactiveCommand<object> ExpandNodesCommand { get; }
public ReactiveCommand<object> OpenFileCommand { get; }
public ReactiveCommand<object> OpenFolderCommand { get; }
public void ExpandNodes(bool expanded) public void ExpandNodes(bool expanded)
{ {
foreach (var node in Nodes) foreach (var node in Nodes)

6
samples/XamlTestApplicationPcl/Views/MainWindow.paml

@ -6,11 +6,13 @@
Title="Perspex Test Application" Width="800" Height="600"> Title="Perspex Test Application" Width="800" Height="600">
<Grid RowDefinitions="Auto,*,Auto" ColumnDefinitions="*,*"> <Grid RowDefinitions="Auto,*,Auto" ColumnDefinitions="*,*">
<Menu Grid.ColumnSpan="2"> <Menu Grid.ColumnSpan="2">
<MenuItem Header="_File" Background="Red"> <MenuItem Header="_File">
<MenuItem Header="_Open" Command="{Binding OpenFileCommand}" />
<MenuItem Header="_Open Folder" Command="{Binding OpenFolderCommand}" />
<MenuItem Header="_Hello"> <MenuItem Header="_Hello">
<MenuItem Header="_Goodbye"/> <MenuItem Header="_Goodbye"/>
<Separator/> <Separator/>
<MenuItem Header="_World" Background="Red"/> <MenuItem Header="_World" />
</MenuItem> </MenuItem>
<Separator Background="Red"/> <Separator Background="Red"/>
<MenuItem Header="_Test"/> <MenuItem Header="_Test"/>

9
src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs

@ -15,6 +15,11 @@ namespace Perspex.Cairo.Media
private Size _size; private Size _size;
private readonly string _text; private readonly string _text;
static double CorrectScale(double input)
{
return input * 0.75;
}
public FormattedTextImpl( public FormattedTextImpl(
Pango.Context context, Pango.Context context,
string text, string text,
@ -25,14 +30,14 @@ namespace Perspex.Cairo.Media
FontWeight fontWeight) FontWeight fontWeight)
{ {
Contract.Requires<ArgumentNullException>(context != null); Contract.Requires<ArgumentNullException>(context != null);
Contract.Requires<ArgumentNullException> (text != null); Contract.Requires<ArgumentNullException>(text != null);
Layout = new Pango.Layout(context); Layout = new Pango.Layout(context);
_text = text; _text = text;
Layout.SetText(text); Layout.SetText(text);
Layout.FontDescription = new Pango.FontDescription Layout.FontDescription = new Pango.FontDescription
{ {
Family = fontFamily, Family = fontFamily,
Size = Pango.Units.FromDouble(fontSize), Size = Pango.Units.FromDouble(CorrectScale(fontSize)),
Style = (Pango.Style)fontStyle, Style = (Pango.Style)fontStyle,
Weight = fontWeight.ToCairo() Weight = fontWeight.ToCairo()
}; };

32
src/Gtk/Perspex.Gtk/SystemDialogImpl.cs

@ -15,7 +15,7 @@ namespace Perspex.Gtk
public Task<string[]> ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent) public Task<string[]> ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent)
{ {
var tcs = new TaskCompletionSource<string[]>(); var tcs = new TaskCompletionSource<string[]>();
var dlg = new global::Gtk.FileChooserDialog(dialog.Title, ((WindowImpl) parent), var dlg = new global::Gtk.FileChooserDialog(dialog.Title, ((WindowImpl)parent),
dialog is OpenFileDialog dialog is OpenFileDialog
? FileChooserAction.Open ? FileChooserAction.Open
: FileChooserAction.Save, : FileChooserAction.Save,
@ -44,7 +44,7 @@ namespace Perspex.Gtk
dlg.Hide(); dlg.Hide();
dlg.Dispose(); dlg.Dispose();
}; };
dlg.Close += delegate dlg.Close += delegate
{ {
tcs.TrySetResult(null); tcs.TrySetResult(null);
@ -56,7 +56,33 @@ namespace Perspex.Gtk
public Task<string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent) public Task<string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent)
{ {
throw new NotImplementedException(); var tcs = new TaskCompletionSource<string>();
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;
} }
} }
} }

15
src/Perspex.Controls/Utils/UndoRedoHelper.cs

@ -37,7 +37,12 @@ namespace Perspex.Controls.Utils
public void Undo() 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; public bool IsLastState => _currentNode.Next == null;
@ -62,8 +67,12 @@ namespace Perspex.Controls.Utils
} }
public void Redo() public void Redo()
{ {
_host.UndoRedoState = (_currentNode = _currentNode?.Next ?? _currentNode).Value; if (_currentNode != null) {
_currentNode = _currentNode.Next;
}
_host.UndoRedoState = _currentNode.Value;
} }
public void Snapshot() public void Snapshot()

Loading…
Cancel
Save