diff --git a/src/DesktopMagic/DataContexts/ModEntryDataContext.cs b/src/DesktopMagic/DataContexts/ModEntryDataContext.cs index 5732e0d..14f57d2 100644 --- a/src/DesktopMagic/DataContexts/ModEntryDataContext.cs +++ b/src/DesktopMagic/DataContexts/ModEntryDataContext.cs @@ -1,9 +1,10 @@ using Modio.NET.Models; using System; +using System.Windows.Input; namespace DesktopMagic.DataContexts; -internal class ModEntryDataContext(Mod mod) +internal class ModEntryDataContext(Mod mod, ICommand installCommand) { public string Name => mod.Name!; @@ -13,4 +14,6 @@ internal class ModEntryDataContext(Mod mod) public DateTime FormattedDateAdded => DateTimeOffset.FromUnixTimeSeconds(mod.DateAdded).LocalDateTime; public DateTime FormattedDateUpdated => DateTimeOffset.FromUnixTimeSeconds(mod.DateUpdated).LocalDateTime; + + public ICommand InstallCommand => installCommand; } diff --git a/src/DesktopMagic/Helpers/CommandHandler.cs b/src/DesktopMagic/Helpers/CommandHandler.cs new file mode 100644 index 0000000..0373d07 --- /dev/null +++ b/src/DesktopMagic/Helpers/CommandHandler.cs @@ -0,0 +1,26 @@ +using System; +using System.Windows.Input; + +namespace DesktopMagic.Helpers; + +public class CommandHandler(Action action, Func? canExecute = null) : ICommand +{ + private readonly Action action = action; + private readonly Func canExecute = canExecute ?? new Func(() => true); + + public event EventHandler? CanExecuteChanged + { + add => CommandManager.RequerySuggested += value; + remove => CommandManager.RequerySuggested -= value; + } + + public bool CanExecute(object? parameter) + { + return canExecute.Invoke(); + } + + public void Execute(object? parameter) + { + action(); + } +} diff --git a/src/DesktopMagic/MainWindow.xaml b/src/DesktopMagic/MainWindow.xaml index d14d802..eb8c587 100644 --- a/src/DesktopMagic/MainWindow.xaml +++ b/src/DesktopMagic/MainWindow.xaml @@ -136,11 +136,11 @@