-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
single item viewer moved to dedicated control
- Loading branch information
Marcel Rehkemper
committed
Jan 27, 2022
1 parent
a002a78
commit 82971fd
Showing
8 changed files
with
239 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
Domain/TableTopCrucible.Domain.Library.Wpf/UserControls/ViewModels/SingleItemViewerVm.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
Domain/TableTopCrucible.Domain.Library.Wpf/UserControls/Views/SingleItemViewerV.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.