Коммит
bcd45a95b5
|
@ -1,8 +1,27 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<Application xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="XAMLator.SampleApp.App">
|
||||
<Application.Resources>
|
||||
|
||||
<ResourceDictionary>
|
||||
<ControlTemplate x:Key="TealTemplate">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="0.1*" />
|
||||
<RowDefinition Height="0.8*" />
|
||||
<RowDefinition Height="0.1*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="0.05*" />
|
||||
<ColumnDefinition Width="0.95*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<BoxView Grid.ColumnSpan="2" Color="Teal" />
|
||||
<Label Grid.Column="1" Text="{TemplateBinding Parent.HeaderText}" TextColor="White" VerticalOptions="Center" />
|
||||
<ContentPresenter Grid.Row="1" Grid.ColumnSpan="2" />
|
||||
<BoxView Grid.Row="2" Grid.ColumnSpan="2" Color="Teal" />
|
||||
<Label Grid.Row="2" Grid.Column="1" Text="{TemplateBinding Parent.FooterText}" TextColor="White" VerticalOptions="Center" />
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
</Application>
|
|
@ -2,7 +2,8 @@
|
|||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:local="clr-namespace:XAMLator.SampleApp"
|
||||
x:Class="XAMLator.SampleApp.PageWithCSS">
|
||||
x:Class="XAMLator.SampleApp.PageWithCSS"
|
||||
ControlTemplate="{StaticResource TealTemplate}">
|
||||
<ContentPage.Resources>
|
||||
<StyleSheet Source="/Global.css"/>
|
||||
</ContentPage.Resources>
|
||||
|
|
|
@ -1,36 +1,66 @@
|
|||
//
|
||||
// Copyright (C) 2018 Fluendo S.A.
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace XAMLator.Server
|
||||
{
|
||||
public class ErrorViewModel : INotifyPropertyChanged
|
||||
{
|
||||
private string _title;
|
||||
private string _error;
|
||||
private ICommand _closeCommand;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
string title;
|
||||
string error;
|
||||
|
||||
public ErrorViewModel (string title, Exception ex)
|
||||
public string Title
|
||||
{
|
||||
this.error = ex.ToString ();
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public ErrorViewModel (string title, EvalResult result)
|
||||
get => _title;
|
||||
set
|
||||
{
|
||||
error = result.Messages [0].Text;
|
||||
this.title = title;
|
||||
_title = value;
|
||||
EmitPropertyChanged(nameof(Title));
|
||||
}
|
||||
}
|
||||
|
||||
public string Title {
|
||||
get => title;
|
||||
public string Error
|
||||
{
|
||||
get => _error;
|
||||
set
|
||||
{
|
||||
_error = value;
|
||||
EmitPropertyChanged(nameof(Error));
|
||||
}
|
||||
}
|
||||
|
||||
public string Error {
|
||||
get => error;
|
||||
public ICommand CloseCommand
|
||||
{
|
||||
get => _closeCommand;
|
||||
set
|
||||
{
|
||||
_closeCommand = value;
|
||||
EmitPropertyChanged(nameof(CloseCommand));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetError(string title, Exception ex)
|
||||
{
|
||||
Error = ex.ToString();
|
||||
Title = title;
|
||||
}
|
||||
|
||||
public void SetError(string title, EvalResult result)
|
||||
{
|
||||
if (result.Messages.Length > 0)
|
||||
{
|
||||
Error = result.Messages[0].Text;
|
||||
}
|
||||
else
|
||||
{
|
||||
Error = "Unknown error";
|
||||
}
|
||||
Title = title;
|
||||
}
|
||||
|
||||
void EmitPropertyChanged(string v)
|
||||
|
|
|
@ -2,11 +2,14 @@
|
|||
// Copyright (C) 2018 Fluendo S.A.
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace XAMLator.Server
|
||||
{
|
||||
public interface IPreviewer
|
||||
{
|
||||
ICommand CloseCommand { get; }
|
||||
|
||||
Task Preview(EvalResult res);
|
||||
|
||||
Task NotifyError(ErrorViewModel errorViewModel);
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace XAMLator.Server
|
|||
IPreviewer previewer;
|
||||
bool isRunning;
|
||||
TcpCommunicatorClient client;
|
||||
ErrorViewModel errorViewModel;
|
||||
|
||||
internal static PreviewServer Instance => serverInstance;
|
||||
|
||||
|
@ -29,6 +30,7 @@ namespace XAMLator.Server
|
|||
{
|
||||
client = new TcpCommunicatorClient();
|
||||
client.DataReceived += HandleDataReceived;
|
||||
errorViewModel = new ErrorViewModel();
|
||||
}
|
||||
|
||||
public static Task<bool> Run(Dictionary<Type, object> viewModelsMapping = null, IPreviewer previewer = null)
|
||||
|
@ -54,6 +56,7 @@ namespace XAMLator.Server
|
|||
previewer = new Previewer(viewModelsMapping);
|
||||
}
|
||||
this.previewer = previewer;
|
||||
errorViewModel.CloseCommand = previewer.CloseCommand;
|
||||
vm = new VM();
|
||||
isRunning = true;
|
||||
return true;
|
||||
|
@ -115,7 +118,8 @@ namespace XAMLator.Server
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await previewer.NotifyError(new ErrorViewModel("Oh no! An exception!", ex));
|
||||
errorViewModel.SetError("Oh no! An exception!", ex);
|
||||
await previewer.NotifyError(errorViewModel);
|
||||
tcs.SetException(ex);
|
||||
}
|
||||
});
|
||||
|
@ -125,7 +129,8 @@ namespace XAMLator.Server
|
|||
{
|
||||
Xamarin.Forms.Device.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
await previewer.NotifyError(new ErrorViewModel("Oh no! An evaluation error!", result));
|
||||
errorViewModel.SetError("Oh no! An evaluation error!", result);
|
||||
await previewer.NotifyError(errorViewModel);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace XAMLator.Server
|
||||
|
@ -11,27 +12,31 @@ namespace XAMLator.Server
|
|||
/// </summary>
|
||||
public class Previewer : IPreviewer
|
||||
{
|
||||
bool presented;
|
||||
protected PreviewPage previewPage;
|
||||
protected ErrorPage errorPage;
|
||||
protected Dictionary<Type, object> viewModelsMapping;
|
||||
bool presented;
|
||||
ICommand closeCommand;
|
||||
|
||||
public Previewer(Dictionary<Type, object> viewModelsMapping)
|
||||
{
|
||||
this.viewModelsMapping = viewModelsMapping;
|
||||
var quitLive = new ToolbarItem
|
||||
{
|
||||
Text = "Quit live preview",
|
||||
Command = new Command(() =>
|
||||
errorPage = new ErrorPage();
|
||||
closeCommand = new Command(() =>
|
||||
{
|
||||
HidePreviewPage(previewPage);
|
||||
presented = false;
|
||||
}),
|
||||
});
|
||||
var quitLive = new ToolbarItem
|
||||
{
|
||||
Text = "Quit live preview",
|
||||
Command = closeCommand
|
||||
};
|
||||
previewPage = new PreviewPage(quitLive);
|
||||
errorPage = new ErrorPage();
|
||||
}
|
||||
|
||||
public ICommand CloseCommand => closeCommand;
|
||||
|
||||
/// <summary>
|
||||
/// Preview the specified evaluation result.
|
||||
/// </summary>
|
||||
|
|
Загрузка…
Ссылка в новой задаче