Skip to content

Commit

Permalink
Merge pull request #407 from workgroupengineering/features/Previewer/…
Browse files Browse the repository at this point in the history
…Show-last-view-on-error

feat(Previewer):  Show last view on error.
  • Loading branch information
maxkatz6 authored Nov 10, 2023
2 parents c240d3d + 6db853f commit e9e6870
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 41 deletions.
1 change: 0 additions & 1 deletion AvaloniaVS.Shared/Views/AvaloniaDesigner.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,6 @@ private void ShowError(string heading, string message)
previewer.error.Visibility = Visibility.Visible;
previewer.errorHeading.Text = heading;
previewer.errorMessage.Text = message;
previewer.previewScroller.Visibility = Visibility.Hidden;
}

private void ShowPreview()
Expand Down
75 changes: 41 additions & 34 deletions AvaloniaVS.Shared/Views/AvaloniaPreviewer.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,46 +34,53 @@
</Grid>
</ScrollViewer>

<StackPanel
Name="error"
HorizontalAlignment="Center"
VerticalAlignment="Center"
<Border Name="error"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="Gray"
Opacity=".75"
Visibility="Collapsed">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<Grid Margin="0,0,7,0">
<Ellipse
Width="22"
Height="22"
Fill="#f55762" />
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="16"
FontWeight="ExtraBold"
Foreground="White"
Text="!" />
</Grid>

<TextBlock
Name="errorHeading"
HorizontalAlignment="Center"
FontSize="18" />
</StackPanel>

<StackPanel Background="Black"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<Grid Margin="0,0,7,0">
<Ellipse
Width="22"
Height="22"
Fill="#f55762" />
<TextBlock
Name="errorMessage"
Margin="20,10,20,0"
HorizontalAlignment="Center"
TextWrapping="Wrap" />
<Button
Name="buildButton"
Margin="0,15,0,0"
Padding="7,5,7,5"
Visibility="Hidden"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="Build" />
FontSize="16"
FontWeight="ExtraBold"
Foreground="White"
Text="!" />
</Grid>

<TextBlock
Name="errorHeading"
HorizontalAlignment="Center"
FontSize="18" />
</StackPanel>

<TextBlock
Name="errorMessage"
Margin="20,10,20,0"
HorizontalAlignment="Center"
TextWrapping="Wrap" />
<Button
Name="buildButton"
Margin="0,15,0,0"
Padding="7,5,7,5"
Visibility="Hidden"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="Build" />
</StackPanel>
</Border>


</Grid>
</UserControl>
18 changes: 12 additions & 6 deletions AvaloniaVS.Shared/Views/AvaloniaPreviewer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Avalonia.Remote.Protocol.Input;
using AvaloniaVS.Models;
using AvaloniaVS.Services;
using EnvDTE;
using Microsoft.VisualStudio.Shell;
Expand All @@ -21,6 +20,7 @@ public partial class AvaloniaPreviewer : UserControl, IDisposable
private PreviewerProcess _process;
private bool _centerPreviewer;
private Size _lastBitmapSize;
private WeakReference<BitmapSource> _lastBitmap = new(default);

public Project SelectedProject { get; set; }
public AvaloniaPreviewer()
Expand Down Expand Up @@ -138,9 +138,18 @@ private async void Update(object sender, EventArgs e)

private void Update(BitmapSource bitmap)
{
if (Process is null)
{
return;
}
if (bitmap is null)
{
_lastBitmap.TryGetTarget(out bitmap);
}

preview.Source = bitmap;

if (bitmap != null)
if (bitmap is not null)
{
var scaling = VisualTreeHelper.GetDpi(this).DpiScaleX;

Expand Down Expand Up @@ -173,10 +182,7 @@ private void Update(BitmapSource bitmap)
_centerPreviewer = true;
_lastBitmapSize = new Size(preview.Width, preview.Height);
}
}
else
{
previewScroller.Visibility = Visibility.Collapsed;
_lastBitmap.SetTarget(bitmap);
}
}

Expand Down

0 comments on commit e9e6870

Please sign in to comment.