Skip to content

Commit

Permalink
single item viewer moved to dedicated control
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Rehkemper committed Jan 27, 2022
1 parent a002a78 commit 82971fd
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,18 @@ public LibraryPageVm(
IItemList itemList,
IFilteredListHeader listHeader,
IItemListFilter filter,
IItemModelViewer modelViewer,
IItemActions actions,
IItemDataViewer dataViewer,
IItemViewerHeader viewerHeader,
IItemFileList fileList,
IGallery gallery,
IGalleryService galleryService)
IGalleryService galleryService,
ISingleItemViewer singleItemViewer,
IItemActions itemActions)
{
_galleryService = galleryService;
ItemList = itemList.DisposeWith(_disposables);
ListHeader = listHeader;
Filter = filter;
ModelViewer = modelViewer;
Actions = actions;
Actions.GenerateThumbnailsByViewportCommand = ModelViewer.GenerateThumbnailCommand;
Actions.SelectedItems = ItemList.SelectedItems;
DataViewer = dataViewer;
ViewerHeader = viewerHeader;
Gallery = gallery;
FileList = fileList.DisposeWith(_disposables);
SingleItemViewer = singleItemViewer;
ItemActions = itemActions;

ItemActions.GenerateThumbnailsByViewportCommand = singleItemViewer.GenerateThumbnailCommand;

var selection = ItemList.SelectedItems
.Connect()
Expand All @@ -69,19 +61,8 @@ public LibraryPageVm(
.RefCount();
this.WhenActivated(() => new[]
{
itemChanges
.BindTo(this, vm => vm.ModelViewer.Item),
itemChanges
.BindTo(this, vm => vm.DataViewer.Item),
itemChanges
.BindTo(this, vm => vm.ViewerHeader.Item),
itemChanges
.BindTo(this, vm => vm.FileList.Item),
itemChanges
.BindTo(this, vm => vm.Gallery.Item),
itemChanges
.BindTo(this, vm => vm.Actions.Item),
filter.FilterChanges.BindTo(this, vm=>vm.ItemList.Filter),
itemChanges.BindTo(this, vm=>vm.SingleItemViewer.Item),
this._selectionErrorText = selection
.Select(items=>
items.Count switch
Expand All @@ -98,12 +79,8 @@ public LibraryPageVm(
public IItemList ItemList { get; }
public IFilteredListHeader ListHeader { get; }
public IItemListFilter Filter { get; }
public IItemModelViewer ModelViewer { get; }
public IItemActions Actions { get; }
public IItemDataViewer DataViewer { get; }
public IItemViewerHeader ViewerHeader { get; }
public IGallery Gallery { get; }
public IItemFileList FileList { get; }
public ISingleItemViewer SingleItemViewer { get; }
public IItemActions ItemActions { get; }
public ViewModelActivator Activator { get; } = new();
public PackIconKind? Icon => PackIconKind.Bookshelf;
public Name Title => Name.From("Item Library");
Expand All @@ -113,16 +90,5 @@ public LibraryPageVm(
public Message SelectionErrorText => _selectionErrorText.Value;
public void Dispose()
=> _disposables.Dispose();

public void HandleFileDrop(FilePath[] filePaths)
{
var images =
filePaths
.Where(file => file.IsImage())
.Select(img => img.ToImagePath())
.ToArray();
var item = ItemList.SelectedItems.Items.FirstOrDefault();
_galleryService.AddImagesToItem(item,images);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,45 +51,28 @@
Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="2" />

<rxui:ViewModelViewHost Name="ViewerHeader"
Grid.Row="0"
Grid.Column="1"/>

<rxui:ViewModelViewHost x:Name="ItemList"
Margin="4 4 12 4"
Grid.Column="0"
Grid.Row="1" />
<TabControl Style="{StaticResource MaterialDesignNavigatilRailTabControl}"
TabStripPlacement="Top"
AllowDrop="True"
Drop="UIElement_OnDrop"
Grid.Column="1"
Grid.Row="1">
<TabItem Header="3d Model">
<rxui:ViewModelViewHost x:Name="ModelViewer" />
</TabItem>
<TabItem Header="Data">
<rxui:ViewModelViewHost x:Name="DataViewer" />
</TabItem>
<TabItem Header="Gallery">
<rxui:ViewModelViewHost x:Name="Gallery" />
</TabItem>
<TabItem Header="Files">
<rxui:ViewModelViewHost x:Name="FileList" />
</TabItem>
</TabControl>
<uc:LoadingScreen x:Name="SelectionErrorDisplay"
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="1"/>

<GridSplitter Width="{DynamicResource GridSplitterWidth}"
Margin="{DynamicResource GridSplitterMargin}"
Grid.Column="0"
Grid.Row="0"
Grid.RowSpan="2" />


<rxui:ViewModelViewHost x:Name="SingleItemViewer"
Margin="4 4 12 4"
Grid.Column="1"
Grid.Row="0"
Grid.RowSpan="2"/>
<uc:LoadingScreen x:Name="SelectionErrorDisplay"
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="1"/>

</Grid>

</md:DrawerHost.Content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,23 @@ public LibraryPageV()
this.Bind(ViewModel,
vm => vm.ItemList,
v => v.ItemList.ViewModel),
this.Bind(ViewModel,
vm => vm.SingleItemViewer,
v => v.SingleItemViewer.ViewModel),
this.Bind(ViewModel,
vm => vm.ItemActions,
v => v.Actions.ViewModel),
this.Bind(ViewModel,
vm => vm.ListHeader,
v => v.ListHeader.ViewModel),
this.Bind(ViewModel,
vm => vm.Filter,
v => v.Filter.ViewModel),
this.Bind(ViewModel,
vm => vm.ModelViewer,
v => v.ModelViewer.ViewModel),
this.Bind(ViewModel,
vm => vm.DataViewer,
v => v.DataViewer.ViewModel),
this.Bind(ViewModel,
vm => vm.Actions,
v => v.Actions.ViewModel),
this.Bind(ViewModel,
vm => vm.ViewerHeader,
v => v.ViewerHeader.ViewModel),
this.Bind(ViewModel,
vm => vm.FileList,
v => v.FileList.ViewModel),
this.Bind(ViewModel,
vm => vm.Gallery,
v => v.Gallery.ViewModel),
this.OneWayBind(ViewModel,
vm=>vm.SelectionErrorText,
v=>v.SelectionErrorDisplay.Text),
});
}

private void UIElement_OnDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent("FileDrop"))
{
var paths =
(e.Data.GetData("FileDrop") as string[])
.Select(FilePath.From).ToArray()
.ToArray();
ViewModel.HandleFileDrop(paths);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ItemActionsVm : ReactiveObject, IItemActions, IActivatableViewModel
[Reactive]
public ReactiveCommand<Unit, Unit> GenerateThumbnailsByViewportCommand { get; set; }
[Reactive]
public ICommand GenerateThumbnailsCommand { get; private set; }
public ReactiveCommand<Unit,Unit> GenerateThumbnailsCommand { get; private set; }
public ICommand PickThumbnailsCommand { get; }
public Interaction<Unit, YesNoDialogResult> DeletionConfirmation { get; } = new();
public Interaction<Unit, IEnumerable<ImageFilePath>> SelectImages { get; } = new();
Expand Down Expand Up @@ -108,16 +108,16 @@ public ItemActionsVm(
}
);
});
this.WhenActivated(() => new[]
this.WhenActivated(() => new []
{
ReactiveCommandHelper.Create(() =>
GenerateThumbnailsCommand = ReactiveCommand.Create(() =>
{
if (SelectedItems!.Items.Count() == 1)
GenerateThumbnailsByViewportCommand!.Execute();
else
thumbnailGenerationService.GenerateManyAsync(SelectedItems.Items, null, true);

},GenerateThumbnailsByViewportCommand!.CanExecute,cmd=>GenerateThumbnailsCommand = cmd)
},GenerateThumbnailsByViewportCommand!.CanExecute.Select(_=>false))
});

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Text;
using System.Threading.Tasks;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using TableTopCrucible.Core.DependencyInjection.Attributes;
using TableTopCrucible.Core.ValueTypes;
using TableTopCrucible.Infrastructure.Models.Entities;
using TableTopCrucible.Shared.Services;
using TableTopCrucible.Shared.Wpf.UserControls.ViewModels;
using TableTopCrucible.Shared.Wpf.UserControls.ViewModels.ItemControls;

namespace TableTopCrucible.Domain.Library.Wpf.UserControls.ViewModels
{
[Transient]
public interface ISingleItemViewer:IDisposable
{
public Item Item { get; set; }
ReactiveCommand<Unit, Unit> GenerateThumbnailCommand { get; }
}
public class SingleItemViewerVm:ReactiveObject, IActivatableViewModel, ISingleItemViewer
{
private readonly IGalleryService _galleryService;
private readonly CompositeDisposable _disposables = new();
public IItemActions Actions { get; }
public IItemFileList FileList { get; }
public IGallery Gallery { get; }
public IItemDataViewer DataViewer { get; }
public IItemModelViewer ModelViewer { get; }
public IItemViewerHeader ViewerHeader { get; }
public ViewModelActivator Activator { get; } = new();

public SingleItemViewerVm(
IItemActions actions,
IItemFileList fileList,
IGallery gallery,
IItemDataViewer dataViewer,
IItemModelViewer modelViewer,
IItemViewerHeader viewerHeader,
IGalleryService galleryService)
{
_galleryService = galleryService;
Actions = actions;
FileList = fileList.DisposeWith(_disposables);
Gallery = gallery;
DataViewer = dataViewer;
ModelViewer = modelViewer;
ViewerHeader = viewerHeader;
Actions.GenerateThumbnailsByViewportCommand = ModelViewer.GenerateThumbnailCommand;

var itemChanges = this.WhenAnyValue(vm => vm.Item)
.Publish()
.RefCount();
this.WhenActivated(()=>new []
{
itemChanges
.BindTo(this, vm => vm.ModelViewer.Item),
itemChanges
.BindTo(this, vm => vm.DataViewer.Item),
itemChanges
.BindTo(this, vm => vm.ViewerHeader.Item),
itemChanges
.BindTo(this, vm => vm.FileList.Item),
itemChanges
.BindTo(this, vm => vm.Gallery.Item),
itemChanges
.BindTo(this, vm => vm.Actions.Item)
});
}
[Reactive]
public Item Item { get; set; }

public ReactiveCommand<Unit, Unit> GenerateThumbnailCommand => ModelViewer.GenerateThumbnailCommand;

public void Dispose()
=> _disposables.Dispose();
public void HandleFileDrop(FilePath[] filePaths)
{
var images =
filePaths
.Where(file => file.IsImage())
.Select(img => img.ToImagePath())
.ToArray();
_galleryService.AddImagesToItem(Item, images);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<rxui:ReactiveUserControl x:TypeArguments="viewModels:SingleItemViewerVm"
x:Class="TableTopCrucible.Domain.Library.Wpf.UserControls.Views.SingleItemViewerV"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:TableTopCrucible.Domain.Library.Wpf.UserControls.Views"
xmlns:rxui="http://reactiveui.net"
xmlns:viewModels="clr-namespace:TableTopCrucible.Domain.Library.Wpf.UserControls.ViewModels"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<rxui:ViewModelViewHost Name="ViewerHeader"
Grid.Row="0"/>
<TabControl Style="{StaticResource MaterialDesignNavigatilRailTabControl}"
TabStripPlacement="Top"
AllowDrop="True"
Drop="UIElement_OnDrop"
Grid.Row="1">
<TabItem Header="3d Model">
<rxui:ViewModelViewHost x:Name="ModelViewer" />
</TabItem>
<TabItem Header="Data">
<rxui:ViewModelViewHost x:Name="DataViewer" />
</TabItem>
<TabItem Header="Gallery">
<rxui:ViewModelViewHost x:Name="Gallery" />
</TabItem>
<TabItem Header="Files">
<rxui:ViewModelViewHost x:Name="FileList" />
</TabItem>
</TabControl>

</Grid>
</rxui:ReactiveUserControl>
Loading

0 comments on commit 82971fd

Please sign in to comment.