From ad1a0843deb777b2e72c70cc356d1126534f1985 Mon Sep 17 00:00:00 2001 From: erri120 Date: Mon, 9 Nov 2020 12:26:07 +0100 Subject: [PATCH] Removed the internal Manifest Viewer --- .../View Models/Installers/InstallerVM.cs | 2 +- Wabbajack/View Models/ManifestVM.cs | 102 ------------- Wabbajack/Views/ManifestView.xaml | 131 ---------------- Wabbajack/Views/ManifestView.xaml.cs | 143 ------------------ Wabbajack/Views/ManifestWindow.xaml | 22 --- Wabbajack/Views/ManifestWindow.xaml.cs | 22 --- 6 files changed, 1 insertion(+), 421 deletions(-) delete mode 100644 Wabbajack/View Models/ManifestVM.cs delete mode 100644 Wabbajack/Views/ManifestView.xaml delete mode 100644 Wabbajack/Views/ManifestView.xaml.cs delete mode 100644 Wabbajack/Views/ManifestWindow.xaml delete mode 100644 Wabbajack/Views/ManifestWindow.xaml.cs diff --git a/Wabbajack/View Models/Installers/InstallerVM.cs b/Wabbajack/View Models/Installers/InstallerVM.cs index 50271e1e..a56e3a66 100644 --- a/Wabbajack/View Models/Installers/InstallerVM.cs +++ b/Wabbajack/View Models/Installers/InstallerVM.cs @@ -313,7 +313,7 @@ namespace Wabbajack ShowManifestCommand = ReactiveCommand.Create(() => { - new ManifestWindow(ModList.SourceModList).Show(); + Utils.OpenWebsite(new Uri("https://www.wabbajack.org/#/modlists/manifest")); }, this.WhenAny(x => x.ModList) .Select(x => x?.SourceModList != null) .ObserveOnGuiThread()); diff --git a/Wabbajack/View Models/ManifestVM.cs b/Wabbajack/View Models/ManifestVM.cs deleted file mode 100644 index dd52745a..00000000 --- a/Wabbajack/View Models/ManifestVM.cs +++ /dev/null @@ -1,102 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reactive; -using System.Reactive.Linq; -using ReactiveUI; -using ReactiveUI.Fody.Helpers; -using Wabbajack.Common; -using Wabbajack.Lib; - -namespace Wabbajack -{ - public enum SortBy { Name, Size } - - public class ManifestVM : ViewModel - { - public Manifest Manifest { get; set; } - - public string Name => !string.IsNullOrWhiteSpace(Manifest.Name) ? Manifest.Name : "Wabbajack Modlist"; - public string Author => !string.IsNullOrWhiteSpace(Manifest.Author) ? $"Created by {Manifest.Author}" : "Created by Jyggalag"; - public string Description => !string.IsNullOrWhiteSpace(Manifest.Description) ? Manifest.Description : ""; - public string InstallSize => $"Install Size: {Manifest.InstallSize.ToFileSizeString()}"; - public string DownloadSize => $"Download Size: {Manifest.DownloadSize.ToFileSizeString()}"; - - public IEnumerable Archives => Manifest.Archives; - - [Reactive] - public string SearchTerm { get; set; } - - private readonly ObservableAsPropertyHelper> _searchResults; - public IEnumerable SearchResults => _searchResults.Value; - - [Reactive] - public bool SortAscending { get; set; } = true; - - [Reactive] - public SortBy SortEnum { get; set; } = SortBy.Name; - - public ReactiveCommand SortByNameCommand; - public ReactiveCommand SortBySizeCommand; - - private IEnumerable Order(IEnumerable list) - { - if (SortAscending) - { - return SortEnum switch - { - SortBy.Name => list.OrderBy(x => x.Name), - SortBy.Size => list.OrderBy(x => x.Size), - _ => throw new ArgumentOutOfRangeException() - }; - } - - return SortEnum switch - { - SortBy.Name => list.OrderByDescending(x => x.Name), - SortBy.Size => list.OrderByDescending(x => x.Size), - _ => throw new ArgumentOutOfRangeException() - }; - } - - private void Swap(SortBy to) - { - if (SortEnum != to) - SortEnum = to; - else - SortAscending = !SortAscending; - } - - public ManifestVM(Manifest manifest) - { - Manifest = manifest; - - SortByNameCommand = ReactiveCommand.Create(() => Swap(SortBy.Name)); - - SortBySizeCommand = ReactiveCommand.Create(() => Swap(SortBy.Size)); - - _searchResults = - this.WhenAnyValue(x => x.SearchTerm) - .CombineLatest( - this.WhenAnyValue(x => x.SortAscending), - this.WhenAnyValue(x => x.SortEnum), - (term, ascending, sort) => term) - .Throttle(TimeSpan.FromMilliseconds(800)) - .Select(term => term?.Trim()) - //.DistinctUntilChanged() - .Select(term => - { - if (string.IsNullOrWhiteSpace(term)) - return Order(Archives); - - return Order(Archives.Where(x => - { - if (term.StartsWith("hash:")) - return x.Hash.ToString().StartsWith(term.Replace("hash:", "")); - return x.Name.StartsWith(term); - })); - }) - .ToGuiProperty(this, nameof(SearchResults), Order(Archives)); - } - } -} diff --git a/Wabbajack/Views/ManifestView.xaml b/Wabbajack/Views/ManifestView.xaml deleted file mode 100644 index 00aa995f..00000000 --- a/Wabbajack/Views/ManifestView.xaml +++ /dev/null @@ -1,131 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - Order by: - - - - - - - - - - - - - - - - - - - - - - - - - - Link - - - - - - - - - - - - diff --git a/Wabbajack/Views/ManifestView.xaml.cs b/Wabbajack/Views/ManifestView.xaml.cs deleted file mode 100644 index e6162108..00000000 --- a/Wabbajack/Views/ManifestView.xaml.cs +++ /dev/null @@ -1,143 +0,0 @@ -using System; -using System.Diagnostics; -using System.Reactive.Disposables; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Navigation; -using ReactiveUI; -using Wabbajack.Lib; - -namespace Wabbajack -{ - public partial class ManifestView - { - public ModList Modlist { get; set; } - - public ManifestView(ModList modlist) - { - Modlist = modlist; - - var manifest = new Manifest(modlist); - ViewModel ??= new ManifestVM(manifest); - - InitializeComponent(); - - this.WhenActivated(disposable => - { - this.OneWayBind(ViewModel, x => x.Name, x => x.Name.Text) - .DisposeWith(disposable); - this.OneWayBind(ViewModel, x => x.Manifest.Version, x => x.Version.Text) - .DisposeWith(disposable); - this.OneWayBind(ViewModel, x => x.Author, x => x.Author.Text) - .DisposeWith(disposable); - this.OneWayBind(ViewModel, x => x.Description, x => x.Description.Text) - .DisposeWith(disposable); - this.OneWayBind(ViewModel, x => x.SearchResults, x => x.ModsList.ItemsSource) - .DisposeWith(disposable); - this.OneWayBind(ViewModel, x => x.InstallSize, x => x.InstallSize.Text) - .DisposeWith(disposable); - this.OneWayBind(ViewModel, x => x.DownloadSize, x => x.DownloadSize.Text) - .DisposeWith(disposable); - this.Bind(ViewModel, x => x.SearchTerm, x => x.SearchBar.Text) - .DisposeWith(disposable); - this.BindCommand(ViewModel, x => x.SortByNameCommand, x => x.OrderByNameButton) - .DisposeWith(disposable); - this.BindCommand(ViewModel, x => x.SortBySizeCommand, x => x.OrderBySizeButton) - .DisposeWith(disposable); - }); - } - - private void Hyperlink_OnRequestNavigate(object sender, RequestNavigateEventArgs e) - { - if (!(sender is Hyperlink hyperlink)) return; - if (!(hyperlink.DataContext is Archive archive)) return; - - var url = archive.State.GetManifestURL(archive); - if (string.IsNullOrWhiteSpace(url)) return; - - if (url.StartsWith("https://github.com/")) - url = url.Substring(0, url.IndexOf("release", StringComparison.Ordinal)); - - //url = url.Replace("&", "^&"); - url = url.Replace(" ", "%20"); - Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") {CreateNoWindow = true}); - - e.Handled = true; - } - - //solution from https://stackoverflow.com/questions/5426232/how-can-i-make-wpf-scrollviewer-middle-click-scroll/5446307#5446307 - - private bool _isMoving; //False - ignore mouse movements and don't scroll - private bool _isDeferredMovingStarted; //True - Mouse down -> Mouse up without moving -> Move; False - Mouse down -> Move - private Point? _startPosition; - private const double Slowdown = 10; //smaller = faster - - private void ScrollViewer_MouseDown(object sender, MouseButtonEventArgs e) - { - if (_isMoving) - CancelScrolling(); - else if (e.ChangedButton == MouseButton.Middle && e.ButtonState == MouseButtonState.Pressed) - { - if (_isMoving) return; - - _isMoving = true; - _startPosition = e.GetPosition(sender as IInputElement); - _isDeferredMovingStarted = true; - - AddScrollSign(e.GetPosition(TopLayer).X, e.GetPosition(TopLayer).Y); - } - } - - private void ScrollViewer_MouseUp(object sender, MouseButtonEventArgs e) - { - if(e.ChangedButton == MouseButton.Middle && e.ButtonState == MouseButtonState.Released && _isDeferredMovingStarted != true) - CancelScrolling(); - } - - private void ScrollViewer_MouseMove(object sender, MouseEventArgs e) - { - if (!_isMoving || !(sender is ScrollViewer sv)) - return; - - _isDeferredMovingStarted = false; - - var currentPosition = e.GetPosition(sv); - if (_startPosition == null) - return; - - var offset = currentPosition - _startPosition.Value; - offset.Y /= Slowdown; - offset.X /= Slowdown; - - sv.ScrollToVerticalOffset(sv.VerticalOffset + offset.Y); - sv.ScrollToHorizontalOffset(sv.HorizontalOffset + offset.X); - } - - private void CancelScrolling() - { - _isMoving = false; - _startPosition = null; - _isDeferredMovingStarted = false; - RemoveScrollSign(); - } - - private void AddScrollSign(double x, double y) - { - const double size = 50.0; - var img = ResourceLinks.MiddleMouseButton.Value; - var icon = new Image {Source = img, Width = size, Height = size}; - //var icon = new Ellipse { Stroke = Brushes.Red, StrokeThickness = 2.0, Width = 20, Height = 20 }; - - TopLayer.Children.Add(icon); - Canvas.SetLeft(icon, x - size / 2); - Canvas.SetTop(icon, y - size / 2); - } - - private void RemoveScrollSign() - { - TopLayer.Children.Clear(); - } - } -} diff --git a/Wabbajack/Views/ManifestWindow.xaml b/Wabbajack/Views/ManifestWindow.xaml deleted file mode 100644 index 2f686a82..00000000 --- a/Wabbajack/Views/ManifestWindow.xaml +++ /dev/null @@ -1,22 +0,0 @@ - - - diff --git a/Wabbajack/Views/ManifestWindow.xaml.cs b/Wabbajack/Views/ManifestWindow.xaml.cs deleted file mode 100644 index 532754c6..00000000 --- a/Wabbajack/Views/ManifestWindow.xaml.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Wabbajack.Lib; - -namespace Wabbajack -{ - public partial class ManifestWindow - { - public ModList Modlist { get; set; } - - public ManifestWindow(ModList modlist) - { - Modlist = modlist; - - InitializeComponent(); - - var manifestView = new ManifestView(Modlist); - - Grid.Children.Add(manifestView); - - Title = $"{Modlist.Name} by {Modlist.Author}"; - } - } -}