Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load Preview Async #22

Merged
merged 4 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions rowsSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTest", "UnitTest\UnitTest.csproj", "{1D74A3BB-1E05-4B88-977D-C1467005C93B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTest", "UnitTest\UnitTest.csproj", "{A9C64AA4-5D42-4392-BC06-F859C27384B6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -22,10 +22,10 @@ Global
{F3FAEAFF-697C-4076-ACF7-A82E3AB42826}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F3FAEAFF-697C-4076-ACF7-A82E3AB42826}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F3FAEAFF-697C-4076-ACF7-A82E3AB42826}.Release|Any CPU.Build.0 = Release|Any CPU
{1D74A3BB-1E05-4B88-977D-C1467005C93B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1D74A3BB-1E05-4B88-977D-C1467005C93B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D74A3BB-1E05-4B88-977D-C1467005C93B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D74A3BB-1E05-4B88-977D-C1467005C93B}.Release|Any CPU.Build.0 = Release|Any CPU
{A9C64AA4-5D42-4392-BC06-F859C27384B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A9C64AA4-5D42-4392-BC06-F859C27384B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A9C64AA4-5D42-4392-BC06-F859C27384B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A9C64AA4-5D42-4392-BC06-F859C27384B6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
9 changes: 3 additions & 6 deletions rowsSharp/Domain/Clipboard.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
using System;
using System;
using System.Windows;
using System.Windows.Media.Imaging;

namespace RowsSharp.Domain;

public static class ClipboardHelper
{
public static void SetClipboardImage(string path)
public static void SetImage(BitmapImage bitmapImage)
{
Uri uri = new(path);
BitmapImage image = new(uri);

Clipboard.SetImage(image);
Clipboard.SetImage(bitmapImage);
}

public static string[,] SplitTo2DArray()
Expand Down
20 changes: 20 additions & 0 deletions rowsSharp/Domain/PreviewHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.IO;
using System.Windows.Media.Imaging;

namespace RowsSharp.Domain;

internal class PreviewHelper
{
internal static BitmapImage? FromPath(string path)
{
if (!File.Exists(path)) { return null; }

BitmapImage image = new();
image.BeginInit();
image.CacheOption = BitmapCacheOption.OnLoad;
image.UriSource = new(path);
image.EndInit();
image.Freeze();
return image;
}
}
2 changes: 1 addition & 1 deletion rowsSharp/View/Editor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@

<GridSplitter Grid.Column="1" Width="16" Background="Transparent" HorizontalAlignment="Left"/>

<Image Name="PreviewImage" Grid.Column="1" Source="{Binding Preview, Converter={StaticResource PathToImageConverter}, Mode=OneWay}"/>
<Image Name="PreviewImage" Grid.Column="1" Source="{Binding Preview, Mode=OneWay}"/>

<TextBlock Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center"
Text="No Preview Available">
Expand Down
32 changes: 23 additions & 9 deletions rowsSharp/ViewModel/EditorViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ObservableTable.Core;
using ObservableTable.Core;
using RowsSharp.Domain;
using RowsSharp.Model;
using RowsSharp.View;
Expand All @@ -7,11 +7,11 @@
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media.Imaging;

namespace RowsSharp.ViewModel;

Expand Down Expand Up @@ -73,10 +73,24 @@ public IEnumerable<DataGridColumn> DataGridColumns
}
}

public string Preview =>
selectedCells.Any()
? ColumnNotation.Expand(Preferences.Preview.Path, Table.Headers, (IEnumerable<string?>)selectedCells[0].Item)
: "";
private void UpdatePreview()
{
if (!selectedCells.Any())
{
Preview = null;
return;
}

string path = ColumnNotation.Expand(Preferences.Preview.Path, Table.Headers, (IEnumerable<string?>)selectedCells[0].Item);
Preview = PreviewHelper.FromPath(path);
}

private BitmapImage? preview;
public BitmapImage? Preview
{
get => preview;
internal set => SetField(ref preview, value);
}

private IList<DataGridCellInfo> selectedCells = new List<DataGridCellInfo>();

Expand Down Expand Up @@ -156,7 +170,7 @@ private void Autosave()
selectedCells = e;
OnPropertyChanged(nameof(SelectedRowsCount));
OnPropertyChanged(nameof(SelectedColumnsCount));
OnPropertyChanged(nameof(Preview));
UpdatePreview();
}
);

Expand All @@ -178,8 +192,8 @@ private void Autosave()
);

public DelegateCommand CopyPreview => new(
() => ClipboardHelper.SetClipboardImage(Preview),
() => File.Exists(Preview)
() => ClipboardHelper.SetImage(Preview!),
() => Preview is not null
);

public DelegateCommand SortColumn => new(
Expand Down
7 changes: 1 addition & 6 deletions rowsSharp/rowsSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,7 @@
<TreatAsUsed>true</TreatAsUsed>
</PackageReference>
<PackageReference Include="NLog" Version="5.1.4" />
</ItemGroup>

<ItemGroup>
<Reference Include="ObservableTable">
<HintPath>..\..\ObservableTable\Publish\ObservableTable.dll</HintPath>
</Reference>
<PackageReference Include="ObservableTable" Version="23.12.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading