Removed LambdaCommand in favor of ReactiveCommand

Also standardized their naming
This commit is contained in:
Justin Swanson 2019-10-11 17:30:12 -05:00
parent 89b686cd0a
commit 5ebf9af0aa
4 changed files with 248 additions and 187 deletions

View File

@ -39,6 +39,16 @@ namespace Wabbajack
public readonly Dispatcher dispatcher;
// Command properties
public IReactiveCommand ChangePathCommand => ReactiveCommand.Create(ExecuteChangePath);
public IReactiveCommand ChangeDownloadPathCommand => ReactiveCommand.Create(ExecuteChangeDownloadPath);
public IReactiveCommand BeginCommand => ReactiveCommand.Create(ExecuteBegin);
public IReactiveCommand ShowReportCommand => ReactiveCommand.Create(ShowReport);
public IReactiveCommand VisitNexusSiteCommand => ReactiveCommand.Create(VisitNexusSite);
public IReactiveCommand OpenReadmeCommand => ReactiveCommand.Create(OpenReadmeWindow);
public IReactiveCommand OpenModListPropertiesCommand => ReactiveCommand.Create(OpenModListProperties);
public IReactiveCommand SlideShowNextItemCommand { get; }
public AppState(Dispatcher d, TaskMode mode)
{
_wabbajackLogo = UIUtils.BitmapImageFromResource("Wabbajack.UI.banner.png");
@ -47,6 +57,7 @@ namespace Wabbajack
_nextIcon = UIUtils.BitmapImageFromResource("Wabbajack.UI.Icons.next.png");
_slideShow = new SlideShow(this, true);
this.SlideShowNextItemCommand = ReactiveCommand.Create(_slideShow.UpdateSlideShowItem);
if (Assembly.GetEntryAssembly().Location.ToLower().Contains("\\downloads\\"))
{
@ -113,72 +124,6 @@ namespace Wabbajack
private List<CPUStatus> InternalStatus { get; } = new List<CPUStatus>();
public string LogFile { get; }
private ICommand _changePath;
public ICommand ChangePath
{
get
{
if (_changePath == null) _changePath = new LambdaCommand(() => true, ExecuteChangePath);
return _changePath;
}
}
private ICommand _changeDownloadPath;
public ICommand ChangeDownloadPath
{
get
{
if (_changeDownloadPath == null)
_changeDownloadPath = new LambdaCommand(() => true, ExecuteChangeDownloadPath);
return _changeDownloadPath;
}
}
private ICommand _begin;
public ICommand Begin
{
get
{
if (_begin == null) _begin = new LambdaCommand(() => true, ExecuteBegin);
return _begin;
}
}
private ICommand _showReportCommand;
public ICommand ShowReportCommand
{
get
{
return _showReportCommand ?? (_showReportCommand = new LambdaCommand(() => true, ShowReport));
}
}
private ICommand _visitNexusSiteCommand;
public ICommand VisitNexusSiteCommand
{
get
{
return _visitNexusSiteCommand ??
(_visitNexusSiteCommand = new LambdaCommand(() => true, VisitNexusSite));
}
}
public ICommand OpenModListPropertiesCommand
{
get
{
return new LambdaCommand(() => true, OpenModListProperties);
}
}
public ICommand SlideShowNextItem
{
get
{
return new LambdaCommand(() => true, _slideShow.UpdateSlideShowItem);
}
}
private void ExecuteChangePath()
{
if (Mode == TaskMode.INSTALLING)
@ -244,13 +189,6 @@ namespace Wabbajack
}
public bool HasReadme { get; set; }
public ICommand OpenReadme
{
get
{
return new LambdaCommand(()=> true,OpenReadmeWindow);
}
}
private void OpenReadmeWindow()
{

View File

@ -1,29 +0,0 @@
using System;
using System.Windows.Input;
namespace Wabbajack
{
internal class LambdaCommand : ICommand
{
private readonly Func<bool> _canExecute;
private readonly Action _execute;
public LambdaCommand(Func<bool> canExecute, Action execute)
{
_execute = execute;
_canExecute = canExecute;
}
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter)
{
return _canExecute();
}
public void Execute(object parameter)
{
_execute();
}
}
}

View File

@ -1,104 +1,204 @@
<Window x:Class="Wabbajack.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Wabbajack"
mc:Ignorable="d"
Title="Wabbajack"
MinWidth="1280" MinHeight="960"
Width="1280" Height="960"
Style="{StaticResource {x:Type Window}}" Icon="Icons/wabbajack.ico" WindowStyle="ToolWindow"
ResizeMode="CanResize"
Closing="Window_Closing">
<Window
x:Class="Wabbajack.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wabbajack"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="Wabbajack"
Width="1280"
Height="960"
MinWidth="1280"
MinHeight="960"
Closing="Window_Closing"
Icon="Icons/wabbajack.ico"
ResizeMode="CanResize"
Style="{StaticResource {x:Type Window}}"
WindowStyle="ToolWindow"
mc:Ignorable="d">
<Viewbox Stretch="Uniform">
<!--<Grid Width="1280" Height="960">-->
<Grid Margin="4,0,4,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="435"/>
<RowDefinition Height="435" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
<RowDefinition Height="320"/>
<RowDefinition Height="320" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="640"/>
<ColumnDefinition Width="640"/>
<ColumnDefinition Width="640" />
<ColumnDefinition Width="640" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" Margin="0, 8, 0, 8">
<TextBlock Text="{Binding Mode}" FontSize="16" FontWeight="Bold" />
<TextBlock Text=" : " FontSize="16" />
<TextBlock Text="{Binding ModListName}" FontSize="16" />
<StackPanel
Grid.Row="0"
Margin="0,8,0,8"
Orientation="Horizontal">
<TextBlock
FontSize="16"
FontWeight="Bold"
Text="{Binding Mode}" />
<TextBlock FontSize="16" Text=" : " />
<TextBlock FontSize="16" Text="{Binding ModListName}" />
</StackPanel>
<!-- Properties -->
<Grid Grid.Row="1" Grid.Column="0" Margin="0,0,2,4" Name="PropertyCompilerGrid">
<!-- Properties -->
<Grid
Name="PropertyCompilerGrid"
Grid.Row="1"
Grid.Column="0"
Margin="0,0,2,4">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="30"/>
<RowDefinition Height="*" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Image Grid.Row="0" Margin="0,0,0,4" Source="{Binding SplashScreenImage}" Stretch="Fill"/>
<Button Grid.Row="1" Height="30" Command="{Binding OpenModListPropertiesCommand}" IsEnabled="{Binding UIReady}">
<TextBlock Text="Modlist Properties" FontSize="15" FontWeight="Bold"/>
<Image
Grid.Row="0"
Margin="0,0,0,4"
Source="{Binding SplashScreenImage}"
Stretch="Fill" />
<Button
Grid.Row="1"
Height="30"
Command="{Binding OpenModListPropertiesCommand}"
IsEnabled="{Binding UIReady}">
<TextBlock
FontSize="15"
FontWeight="Bold"
Text="Modlist Properties" />
</Button>
</Grid>
<Grid Grid.Row="1" Grid.Column="0" Margin="0,0,2,4" Name="PropertyInstallerGrid">
<Grid
Name="PropertyInstallerGrid"
Grid.Row="1"
Grid.Column="0"
Margin="0,0,2,4">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="30"/>
<RowDefinition Height="*" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Image Grid.Row="0" Source="{Binding SplashScreenImage}" Stretch="Fill"/>
<Button Grid.Row="1" Height="30" Command="{Binding OpenReadme}" IsEnabled="{Binding HasReadme}">
<TextBlock Text="Open README" FontSize="15" FontWeight="Bold"/>
<Image
Grid.Row="0"
Source="{Binding SplashScreenImage}"
Stretch="Fill" />
<Button
Grid.Row="1"
Height="30"
Command="{Binding OpenReadmeCommand}"
IsEnabled="{Binding HasReadme}">
<TextBlock
FontSize="15"
FontWeight="Bold"
Text="Open README" />
</Button>
</Grid>
<!-- End Properties -->
<!-- End Properties -->
<!-- Slideshow -->
<Grid Grid.Row="1" Grid.Column="1" Margin="2,0,0,4">
<!-- Slideshow -->
<Grid
Grid.Row="1"
Grid.Column="1"
Margin="2,0,0,4">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="{Binding SplashScreenModName}" Grid.Row="0" FontSize="30" FontWeight="Bold"/>
<TextBlock Text="{Binding SplashScreenAuthorName}" Grid.Row="1" FontSize="15" FontWeight="Bold"/>
<TextBlock Text="{Binding SplashScreenSummary}" TextWrapping="Wrap" Grid.Row="2" FontSize="15" FontWeight="Bold"/>
<TextBlock
Grid.Row="0"
FontSize="30"
FontWeight="Bold"
Text="{Binding SplashScreenModName}" />
<TextBlock
Grid.Row="1"
FontSize="15"
FontWeight="Bold"
Text="{Binding SplashScreenAuthorName}" />
<TextBlock
Grid.Row="2"
FontSize="15"
FontWeight="Bold"
Text="{Binding SplashScreenSummary}"
TextWrapping="Wrap" />
<Grid Grid.Row="3" VerticalAlignment="Bottom">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="48"/>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="48" />
</Grid.ColumnDefinitions>
<CheckBox Margin="0,10,0,0" Grid.Column="0" IsChecked="{Binding EnableSlideShow}" Name="EnableSlideShow">Enable the Slideshow</CheckBox>
<CheckBox Margin="4,10,0,0" Grid.Column="1" IsChecked="{Binding SplashShowNSFW}" Name="ShowNSFWContent">Show NSFW Mods in the Slideshow</CheckBox>
<Button HorizontalAlignment="Right" Height="30" Grid.Column="2" Command="{Binding SlideShowNextItem}" ToolTip="Spamming this button will result in problems">
<CheckBox
Name="EnableSlideShow"
Grid.Column="0"
Margin="0,10,0,0"
IsChecked="{Binding EnableSlideShow}">
Enable the Slideshow
</CheckBox>
<CheckBox
Name="ShowNSFWContent"
Grid.Column="1"
Margin="4,10,0,0"
IsChecked="{Binding SplashShowNSFW}">
Show NSFW Mods in the Slideshow
</CheckBox>
<Button
Grid.Column="2"
Height="30"
HorizontalAlignment="Right"
Command="{Binding SlideShowNextItemCommand}"
ToolTip="Spamming this button will result in problems">
<DockPanel>
<Image Source="{Binding NextIcon}" Stretch="Fill"/>
<Image Source="{Binding NextIcon}" Stretch="Fill" />
</DockPanel>
</Button>
</Grid>
<Button Height="30" Grid.Row="4" Command="{Binding VisitNexusSiteCommand}">
<TextBlock Text="View Nexus Site" FontSize="15" FontWeight="Bold"/>
<Button
Grid.Row="4"
Height="30"
Command="{Binding VisitNexusSiteCommand}">
<TextBlock
FontSize="15"
FontWeight="Bold"
Text="View Nexus Site" />
</Button>
</Grid>
<!-- End Slideshow-->
<!-- End Slideshow -->
<ProgressBar Grid.Row="2" Margin="1,0,1,0" Grid.Column="0" Grid.ColumnSpan="2" Value="{Binding QueueProgress}" Minimum="0" Maximum="100" Background="#444444" />
<ProgressBar
Grid.Row="2"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="1,0,1,0"
Background="#444444"
Maximum="100"
Minimum="0"
Value="{Binding QueueProgress}" />
<!-- Log -->
<TextBlock Text="Log:" Grid.Row="3" FontSize="14" Margin="0, 16, 0, 8" />
<ListBox local:AutoScrollBehavior.ScrollOnNewItem="True" Margin="0,0,2,0" Grid.Row="4" ItemsSource="{Binding Log}" />
<!-- End Log -->
<!-- Log -->
<TextBlock
Grid.Row="3"
Margin="0,16,0,8"
FontSize="14"
Text="Log:" />
<ListBox
Grid.Row="4"
Margin="0,0,2,0"
local:AutoScrollBehavior.ScrollOnNewItem="True"
ItemsSource="{Binding Log}" />
<!-- End Log -->
<!-- Location -->
<Grid HorizontalAlignment="Stretch" Margin="-4,10,2,10" Grid.Row="5" Grid.Column="0" Grid.RowSpan="2">
<!-- Location -->
<Grid
Grid.Row="5"
Grid.RowSpan="2"
Grid.Column="0"
Margin="-4,10,2,10"
HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
@ -109,20 +209,57 @@
<RowDefinition MinHeight="10" />
<RowDefinition />
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="{Binding LocationLabel}" Grid.Column="0" />
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Location, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" IsEnabled="{Binding UIReady}"/>
<Button Grid.Row="0" Content="Select" MinWidth="80" Grid.Column="2" Command="{Binding ChangePath}" IsEnabled="{Binding UIReady}"/>
<Label Grid.Row="2" Content="Download Location:" Grid.Column="0" />
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding DownloadLocation}" IsEnabled="{Binding UIReady}"/>
<Button Grid.Row="2" Content="Select" MinWidth="80" Grid.Column="2" Command="{Binding ChangeDownloadPath}" IsEnabled="{Binding UIReady}"/>
<Label
Grid.Row="0"
Grid.Column="0"
Content="{Binding LocationLabel}" />
<TextBox
Grid.Row="0"
Grid.Column="1"
IsEnabled="{Binding UIReady}"
Text="{Binding Location, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" />
<Button
Grid.Row="0"
Grid.Column="2"
MinWidth="80"
Command="{Binding ChangePathCommand}"
Content="Select"
IsEnabled="{Binding UIReady}" />
<Label
Grid.Row="2"
Grid.Column="0"
Content="Download Location:" />
<TextBox
Grid.Row="2"
Grid.Column="1"
IsEnabled="{Binding UIReady}"
Text="{Binding DownloadLocation}" />
<Button
Grid.Row="2"
Grid.Column="2"
MinWidth="80"
Command="{Binding ChangeDownloadPathCommand}"
Content="Select"
IsEnabled="{Binding UIReady}" />
</Grid>
<!-- End Location -->
<!-- End Location -->
<!-- Work Queue Start -->
<TextBlock Text="Work Queue:" Grid.Row="3" Grid.Column="1" FontSize="14" Margin="2, 16, 0, 8" />
<!-- Work Queue Start -->
<TextBlock
Grid.Row="3"
Grid.Column="1"
Margin="2,16,0,8"
FontSize="14"
Text="Work Queue:" />
<ListBox Margin="2,0,0,0" Grid.Row="4" Grid.Column="1" ItemsSource="{Binding Status}" Width="Auto" HorizontalAlignment="Stretch">
<ListBox
Grid.Row="4"
Grid.Column="1"
Width="Auto"
Margin="2,0,0,0"
HorizontalAlignment="Stretch"
ItemsSource="{Binding Status}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch">
@ -133,8 +270,12 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ProgressBar Minimum="0" Maximum="100" Value="{Binding Progress, Mode=OneTime}" Width="100"
Grid.Column="0">
<ProgressBar
Grid.Column="0"
Width="100"
Maximum="100"
Minimum="0"
Value="{Binding Progress, Mode=OneTime}">
<ProgressBar.Style>
<Style TargetType="ProgressBar">
<Setter Property="Visibility" Value="Visible" />
@ -146,25 +287,37 @@
</Style>
</ProgressBar.Style>
</ProgressBar>
<TextBlock Text=" CPU " Grid.Column="1" />
<TextBlock Text="{Binding ID}" Grid.Column="2" />
<TextBlock Text=" - " Grid.Column="3" />
<TextBlock Text="{Binding Msg}" Grid.Column="4" />
<TextBlock Grid.Column="1" Text=" CPU " />
<TextBlock Grid.Column="2" Text="{Binding ID}" />
<TextBlock Grid.Column="3" Text=" - " />
<TextBlock Grid.Column="4" Text="{Binding Msg}" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<!-- Work Queue End-->
<!-- Work Queue End -->
<Grid Margin="2,10,0,10" Grid.Row="5" Grid.RowSpan="2" Grid.Column="1">
<Grid
Grid.Row="5"
Grid.RowSpan="2"
Grid.Column="1"
Margin="2,10,0,10">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Button Margin="0,0,0,4" Grid.Row="0" Visibility="{Binding ShowReportButton}" Command="{Binding ShowReportCommand}">
<Button
Grid.Row="0"
Margin="0,0,0,4"
Command="{Binding ShowReportCommand}"
Visibility="{Binding ShowReportButton}">
<TextBlock FontSize="13" FontWeight="Bold">View ModList Contents</TextBlock>
</Button>
<Button Margin="0,4,0,0" Grid.Row="1" Command="{Binding Begin}" IsEnabled="{Binding UIReady}">
<Button
Grid.Row="1"
Margin="0,4,0,0"
Command="{Binding BeginCommand}"
IsEnabled="{Binding UIReady}">
<TextBlock FontSize="13" FontWeight="Bold">Begin</TextBlock>
</Button>
</Grid>

View File

@ -222,7 +222,6 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Data.cs" />
<Compile Include="LambdaCommand.cs" />
<Compile Include="UI\ModlistPropertiesWindow.xaml.cs">
<DependentUpon>ModlistPropertiesWindow.xaml</DependentUpon>
</Compile>