mirror of
https://github.com/Stone-Red-Code/DesktopMagic.git
synced 2026-09-04 00:46:12 +02:00
Plugin manager layout improvments
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
using DesktopMagic.Plugins;
|
||||
using DesktopMagic.Helpers;
|
||||
using DesktopMagic.Plugins;
|
||||
|
||||
using MaterialDesignThemes.Wpf;
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace DesktopMagic.DataContexts;
|
||||
|
||||
internal class PluginEntryDataContext(PluginMetadata pluginMetadata, ICommand command, bool installed = false) : INotifyPropertyChanged
|
||||
internal class PluginEntryDataContext(PluginMetadata pluginMetadata, ICommand command, string? buttonText = "") : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
@@ -18,18 +22,26 @@ internal class PluginEntryDataContext(PluginMetadata pluginMetadata, ICommand co
|
||||
|
||||
public string? Description => pluginMetadata.Description;
|
||||
|
||||
public string Author => pluginMetadata.Author ?? "Unknown";
|
||||
|
||||
public string? Version => pluginMetadata.Version ?? "Unknown";
|
||||
|
||||
public string? Logo => pluginMetadata.IconUri?.ToString();
|
||||
|
||||
public DateTime? FormattedDateAdded => pluginMetadata.Added;
|
||||
public DateTime? FormattedDateUpdated => pluginMetadata.Updated;
|
||||
public DateTime? DateAdded => pluginMetadata.Added;
|
||||
public DateTime? DateUpdated => pluginMetadata.Updated;
|
||||
|
||||
public uint Id => pluginMetadata.Id;
|
||||
|
||||
public string? ButtonText => buttonText;
|
||||
|
||||
public ICommand Command => command;
|
||||
|
||||
public Visibility InstallButtonVisibility => installed ? Visibility.Collapsed : Visibility.Visible;
|
||||
public ButtonData InstallUninstallButtonData => new(ButtonText ?? "Install", true, Command);
|
||||
public ButtonData OpenModioButtonData => new("modio", true, new CommandHandler(OpenModioPage));
|
||||
|
||||
public Visibility RemoveButtonVisibility => installed ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
public Visibility ButtonVisibility => string.IsNullOrWhiteSpace(buttonText) ? Visibility.Collapsed : Visibility.Visible;
|
||||
|
||||
public bool IsVisible
|
||||
{
|
||||
@@ -41,11 +53,25 @@ internal class PluginEntryDataContext(PluginMetadata pluginMetadata, ICommand co
|
||||
OnPropertyChanged(nameof(Visibility));
|
||||
}
|
||||
}
|
||||
public MaterialDesignThemes.Wpf.PackIconKind IconKind => MaterialDesignThemes.Wpf.PackIconKind.Information;
|
||||
|
||||
public Visibility Visibility => IsVisible ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
private void OpenModioPage()
|
||||
{
|
||||
ProcessStartInfo psi = new ProcessStartInfo
|
||||
{
|
||||
UseShellExecute = true,
|
||||
FileName = pluginMetadata.ProfileUri?.ToString()
|
||||
};
|
||||
|
||||
_ = Process.Start(psi);
|
||||
}
|
||||
|
||||
private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
public record ButtonData(PackIconKind IconKind, string Text, bool IsEnabled, ICommand Command);
|
||||
}
|
||||
@@ -14,8 +14,9 @@
|
||||
Visibility="{Binding Visibility}">
|
||||
<Grid Background="White" Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="2*" />
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="3*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
@@ -23,20 +24,39 @@
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Border HorizontalAlignment="Left" Width="100" Height="100" BorderThickness="1" BorderBrush="LightGray">
|
||||
<Border HorizontalAlignment="Center" Margin="10" Width="100" Height="100" BorderThickness="1" BorderBrush="LightGray">
|
||||
<Image Source="{Binding Logo, FallbackValue={StaticResource ModioCogBlue}, TargetNullValue={StaticResource ModioCogBlue}}" Width="100" Height="100" />
|
||||
</Border>
|
||||
|
||||
<StackPanel Grid.Column="1" HorizontalAlignment="Stretch">
|
||||
<Label Content="{Binding FormattedDateAdded}" HorizontalAlignment="Center" ContentStringFormat="Added: {0}" />
|
||||
<Label Content="{Binding FormattedDateUpdated}" HorizontalAlignment="Center" ContentStringFormat="Updated: {0}" />
|
||||
|
||||
<Button Command="{Binding Command}" Visibility="{Binding InstallButtonVisibility}" HorizontalAlignment="Stretch" Margin="10" Content="Install" />
|
||||
<Button Command="{Binding Command}" Visibility="{Binding RemoveButtonVisibility}" HorizontalAlignment="Stretch" Margin="10" Content="Remove" />
|
||||
<StackPanel Grid.Column="1" VerticalAlignment="Center">
|
||||
<Label Content="{Binding Author}" HorizontalAlignment="Center" ContentStringFormat="Author: {0}" />
|
||||
<Label Content="{Binding DateAdded}" HorizontalAlignment="Center" ContentStringFormat="Added: {0}" />
|
||||
<Label Content="{Binding DateUpdated}" HorizontalAlignment="Center" ContentStringFormat="Updated: {0}" />
|
||||
<Label Content="{Binding Version}" HorizontalAlignment="Center" ContentStringFormat="Version: {0}" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="1" Grid.ColumnSpan="2">
|
||||
<Label Content="{Binding Name}" FontSize="20" />
|
||||
<Grid Grid.Row="1" Grid.ColumnSpan="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Button Grid.Column="0" Command="{Binding Command}" Visibility="{Binding ButtonVisibility}" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Margin="10 5 5 0">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<materialDesign:PackIcon Kind="{Binding IconKind}" Margin="0 0 10 0"/>
|
||||
<TextBlock Text="{Binding ButtonText}" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Grid.Column="1" Command="{Binding OpenModioCommand}" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Margin="5 5 10 0">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<materialDesign:PackIcon Kind="ExternalLink" Margin="0 0 10 0"/>
|
||||
<TextBlock Text="mod.io" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</Grid>
|
||||
|
||||
<StackPanel Grid.Row="2" Grid.ColumnSpan="2" Margin="10">
|
||||
<Label Content="{Binding Name}" FontSize="20" Padding="0" />
|
||||
<TextBlock Text="{Binding Description}" TextWrapping="Wrap" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
@@ -97,7 +97,7 @@ public partial class PluginManager : Window
|
||||
|
||||
if (pluginMetadata is not null)
|
||||
{
|
||||
pluginManagerDataContext.InstalledPlugins.Add(new PluginEntryDataContext(pluginMetadata, new CommandHandler(() => Remove(pluginPath, pluginMetadata.Id)), true));
|
||||
pluginManagerDataContext.InstalledPlugins.Add(new PluginEntryDataContext(pluginMetadata, new CommandHandler(() => Remove(pluginPath, pluginMetadata.Id)), "Uninstall"));
|
||||
_ = pluginIds.Add(pluginMetadata.Id);
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,7 @@ public partial class PluginManager : Window
|
||||
continue;
|
||||
}
|
||||
|
||||
pluginManagerDataContext.AllPlugins.Add(new PluginEntryDataContext(new(mod), new CommandHandler(async () => await Install(mod))));
|
||||
pluginManagerDataContext.AllPlugins.Add(new PluginEntryDataContext(new(mod), new CommandHandler(async () => await Install(mod)), "Install"));
|
||||
}
|
||||
|
||||
pluginManagerDataContext.IsLoading = false;
|
||||
@@ -168,7 +168,7 @@ public partial class PluginManager : Window
|
||||
_ = pluginManagerDataContext.AllPlugins.Remove(pluginEntryDataContext);
|
||||
}
|
||||
|
||||
pluginManagerDataContext.InstalledPlugins.Add(new PluginEntryDataContext(new PluginMetadata(mod), new CommandHandler(() => Remove(pluginPath, mod.Id)), true));
|
||||
pluginManagerDataContext.InstalledPlugins.Add(new PluginEntryDataContext(new PluginMetadata(mod), new CommandHandler(() => Remove(pluginPath, mod.Id)), "Uninstall"));
|
||||
|
||||
pluginManagerDataContext.IsLoading = false;
|
||||
}
|
||||
@@ -228,7 +228,7 @@ public partial class PluginManager : Window
|
||||
continue;
|
||||
}
|
||||
|
||||
pluginManagerDataContext.AllPlugins.Add(new PluginEntryDataContext(new(mod), new CommandHandler(async () => await Install(mod))));
|
||||
pluginManagerDataContext.AllPlugins.Add(new PluginEntryDataContext(new(mod), new CommandHandler(async () => await Install(mod)), "Install"));
|
||||
}
|
||||
|
||||
pluginManagerDataContext.IsSearching = false;
|
||||
|
||||
@@ -15,12 +15,16 @@ public class PluginMetadata
|
||||
|
||||
public Uri? IconUri { get; set; }
|
||||
|
||||
public Uri? ProfileUri { get; set; }
|
||||
|
||||
public DateTime? Added { get; set; }
|
||||
|
||||
public DateTime? Updated { get; set; }
|
||||
|
||||
public string? Description { get; set; }
|
||||
|
||||
public string? Summary { get; set; }
|
||||
|
||||
public string? Version { get; set; }
|
||||
|
||||
public PluginMetadata(Mod mod)
|
||||
@@ -29,9 +33,11 @@ public class PluginMetadata
|
||||
Id = mod.Id;
|
||||
Author = mod.SubmittedBy?.Username;
|
||||
IconUri = mod.Logo?.Thumb320x180;
|
||||
ProfileUri = mod.ProfileUrl;
|
||||
Added = DateTimeOffset.FromUnixTimeSeconds(mod.DateAdded).DateTime;
|
||||
Updated = DateTimeOffset.FromUnixTimeSeconds(mod.DateUpdated).DateTime;
|
||||
Description = mod.DescriptionPlaintext;
|
||||
Summary = mod.Summary;
|
||||
Version = mod.Modfile?.Version;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user