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; 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) public AppState(Dispatcher d, TaskMode mode)
{ {
_wabbajackLogo = UIUtils.BitmapImageFromResource("Wabbajack.UI.banner.png"); _wabbajackLogo = UIUtils.BitmapImageFromResource("Wabbajack.UI.banner.png");
@ -47,6 +57,7 @@ namespace Wabbajack
_nextIcon = UIUtils.BitmapImageFromResource("Wabbajack.UI.Icons.next.png"); _nextIcon = UIUtils.BitmapImageFromResource("Wabbajack.UI.Icons.next.png");
_slideShow = new SlideShow(this, true); _slideShow = new SlideShow(this, true);
this.SlideShowNextItemCommand = ReactiveCommand.Create(_slideShow.UpdateSlideShowItem);
if (Assembly.GetEntryAssembly().Location.ToLower().Contains("\\downloads\\")) if (Assembly.GetEntryAssembly().Location.ToLower().Contains("\\downloads\\"))
{ {
@ -113,72 +124,6 @@ namespace Wabbajack
private List<CPUStatus> InternalStatus { get; } = new List<CPUStatus>(); private List<CPUStatus> InternalStatus { get; } = new List<CPUStatus>();
public string LogFile { get; } 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() private void ExecuteChangePath()
{ {
if (Mode == TaskMode.INSTALLING) if (Mode == TaskMode.INSTALLING)
@ -244,13 +189,6 @@ namespace Wabbajack
} }
public bool HasReadme { get; set; } public bool HasReadme { get; set; }
public ICommand OpenReadme
{
get
{
return new LambdaCommand(()=> true,OpenReadmeWindow);
}
}
private void 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" <Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x:Class="Wabbajack.MainWindow"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 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:Wabbajack" xmlns:local="clr-namespace:Wabbajack"
mc:Ignorable="d" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="Wabbajack" Title="Wabbajack"
MinWidth="1280" MinHeight="960" Width="1280"
Width="1280" Height="960" Height="960"
Style="{StaticResource {x:Type Window}}" Icon="Icons/wabbajack.ico" WindowStyle="ToolWindow" MinWidth="1280"
ResizeMode="CanResize" MinHeight="960"
Closing="Window_Closing"> Closing="Window_Closing"
Icon="Icons/wabbajack.ico"
ResizeMode="CanResize"
Style="{StaticResource {x:Type Window}}"
WindowStyle="ToolWindow"
mc:Ignorable="d">
<Viewbox Stretch="Uniform"> <Viewbox Stretch="Uniform">
<!--<Grid Width="1280" Height="960">--> <!--<Grid Width="1280" Height="960">-->
<Grid Margin="4,0,4,0"> <Grid Margin="4,0,4,0">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="435"/> <RowDefinition Height="435" />
<RowDefinition Height="10" /> <RowDefinition Height="10" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="320"/> <RowDefinition Height="320" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="640"/> <ColumnDefinition Width="640" />
<ColumnDefinition Width="640"/> <ColumnDefinition Width="640" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" Margin="0, 8, 0, 8"> <StackPanel
<TextBlock Text="{Binding Mode}" FontSize="16" FontWeight="Bold" /> Grid.Row="0"
<TextBlock Text=" : " FontSize="16" /> Margin="0,8,0,8"
<TextBlock Text="{Binding ModListName}" FontSize="16" /> Orientation="Horizontal">
<TextBlock
FontSize="16"
FontWeight="Bold"
Text="{Binding Mode}" />
<TextBlock FontSize="16" Text=" : " />
<TextBlock FontSize="16" Text="{Binding ModListName}" />
</StackPanel> </StackPanel>
<!-- Properties --> <!-- Properties -->
<Grid Grid.Row="1" Grid.Column="0" Margin="0,0,2,4" Name="PropertyCompilerGrid"> <Grid
Name="PropertyCompilerGrid"
Grid.Row="1"
Grid.Column="0"
Margin="0,0,2,4">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*"/> <RowDefinition Height="*" />
<RowDefinition Height="30"/> <RowDefinition Height="30" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Image Grid.Row="0" Margin="0,0,0,4" Source="{Binding SplashScreenImage}" Stretch="Fill"/> <Image
<Button Grid.Row="1" Height="30" Command="{Binding OpenModListPropertiesCommand}" IsEnabled="{Binding UIReady}"> Grid.Row="0"
<TextBlock Text="Modlist Properties" FontSize="15" FontWeight="Bold"/> 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> </Button>
</Grid> </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> <Grid.RowDefinitions>
<RowDefinition Height="*"/> <RowDefinition Height="*" />
<RowDefinition Height="30"/> <RowDefinition Height="30" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Image Grid.Row="0" Source="{Binding SplashScreenImage}" Stretch="Fill"/> <Image
<Button Grid.Row="1" Height="30" Command="{Binding OpenReadme}" IsEnabled="{Binding HasReadme}"> Grid.Row="0"
<TextBlock Text="Open README" FontSize="15" FontWeight="Bold"/> 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> </Button>
</Grid> </Grid>
<!-- End Properties --> <!-- End Properties -->
<!-- Slideshow --> <!-- Slideshow -->
<Grid Grid.Row="1" Grid.Column="1" Margin="2,0,0,4"> <Grid
Grid.Row="1"
Grid.Column="1"
Margin="2,0,0,4">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto" />
<RowDefinition Height="*"/> <RowDefinition Height="*" />
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Text="{Binding SplashScreenModName}" Grid.Row="0" FontSize="30" FontWeight="Bold"/> <TextBlock
<TextBlock Text="{Binding SplashScreenAuthorName}" Grid.Row="1" FontSize="15" FontWeight="Bold"/> Grid.Row="0"
<TextBlock Text="{Binding SplashScreenSummary}" TextWrapping="Wrap" Grid.Row="2" FontSize="15" FontWeight="Bold"/> 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 Grid.Row="3" VerticalAlignment="Bottom">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*" />
<ColumnDefinition Width="48"/> <ColumnDefinition Width="48" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<CheckBox Margin="0,10,0,0" Grid.Column="0" IsChecked="{Binding EnableSlideShow}" Name="EnableSlideShow">Enable the Slideshow</CheckBox> <CheckBox
<CheckBox Margin="4,10,0,0" Grid.Column="1" IsChecked="{Binding SplashShowNSFW}" Name="ShowNSFWContent">Show NSFW Mods in the Slideshow</CheckBox> Name="EnableSlideShow"
<Button HorizontalAlignment="Right" Height="30" Grid.Column="2" Command="{Binding SlideShowNextItem}" ToolTip="Spamming this button will result in problems"> 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> <DockPanel>
<Image Source="{Binding NextIcon}" Stretch="Fill"/> <Image Source="{Binding NextIcon}" Stretch="Fill" />
</DockPanel> </DockPanel>
</Button> </Button>
</Grid> </Grid>
<Button Height="30" Grid.Row="4" Command="{Binding VisitNexusSiteCommand}"> <Button
<TextBlock Text="View Nexus Site" FontSize="15" FontWeight="Bold"/> Grid.Row="4"
Height="30"
Command="{Binding VisitNexusSiteCommand}">
<TextBlock
FontSize="15"
FontWeight="Bold"
Text="View Nexus Site" />
</Button> </Button>
</Grid> </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 --> <!-- Log -->
<TextBlock Text="Log:" Grid.Row="3" FontSize="14" Margin="0, 16, 0, 8" /> <TextBlock
<ListBox local:AutoScrollBehavior.ScrollOnNewItem="True" Margin="0,0,2,0" Grid.Row="4" ItemsSource="{Binding Log}" /> Grid.Row="3"
<!-- End Log --> 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 --> <!-- Location -->
<Grid HorizontalAlignment="Stretch" Margin="-4,10,2,10" Grid.Row="5" Grid.Column="0" Grid.RowSpan="2"> <Grid
Grid.Row="5"
Grid.RowSpan="2"
Grid.Column="0"
Margin="-4,10,2,10"
HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
@ -109,20 +209,57 @@
<RowDefinition MinHeight="10" /> <RowDefinition MinHeight="10" />
<RowDefinition /> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Label Grid.Row="0" Content="{Binding LocationLabel}" Grid.Column="0" /> <Label
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Location, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" IsEnabled="{Binding UIReady}"/> Grid.Row="0"
<Button Grid.Row="0" Content="Select" MinWidth="80" Grid.Column="2" Command="{Binding ChangePath}" IsEnabled="{Binding UIReady}"/> Grid.Column="0"
<Label Grid.Row="2" Content="Download Location:" Grid.Column="0" /> Content="{Binding LocationLabel}" />
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding DownloadLocation}" IsEnabled="{Binding UIReady}"/> <TextBox
<Button Grid.Row="2" Content="Select" MinWidth="80" Grid.Column="2" Command="{Binding ChangeDownloadPath}" IsEnabled="{Binding UIReady}"/> 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> </Grid>
<!-- End Location --> <!-- End Location -->
<!-- Work Queue Start --> <!-- Work Queue Start -->
<TextBlock Text="Work Queue:" Grid.Row="3" Grid.Column="1" FontSize="14" Margin="2, 16, 0, 8" /> <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> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<Grid HorizontalAlignment="Stretch"> <Grid HorizontalAlignment="Stretch">
@ -133,8 +270,12 @@
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<ProgressBar Minimum="0" Maximum="100" Value="{Binding Progress, Mode=OneTime}" Width="100" <ProgressBar
Grid.Column="0"> Grid.Column="0"
Width="100"
Maximum="100"
Minimum="0"
Value="{Binding Progress, Mode=OneTime}">
<ProgressBar.Style> <ProgressBar.Style>
<Style TargetType="ProgressBar"> <Style TargetType="ProgressBar">
<Setter Property="Visibility" Value="Visible" /> <Setter Property="Visibility" Value="Visible" />
@ -146,25 +287,37 @@
</Style> </Style>
</ProgressBar.Style> </ProgressBar.Style>
</ProgressBar> </ProgressBar>
<TextBlock Text=" CPU " Grid.Column="1" /> <TextBlock Grid.Column="1" Text=" CPU " />
<TextBlock Text="{Binding ID}" Grid.Column="2" /> <TextBlock Grid.Column="2" Text="{Binding ID}" />
<TextBlock Text=" - " Grid.Column="3" /> <TextBlock Grid.Column="3" Text=" - " />
<TextBlock Text="{Binding Msg}" Grid.Column="4" /> <TextBlock Grid.Column="4" Text="{Binding Msg}" />
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
</ListBox> </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> <Grid.RowDefinitions>
<RowDefinition Height="30"/> <RowDefinition Height="30" />
<RowDefinition Height="30"/> <RowDefinition Height="30" />
</Grid.RowDefinitions> </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> <TextBlock FontSize="13" FontWeight="Bold">View ModList Contents</TextBlock>
</Button> </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> <TextBlock FontSize="13" FontWeight="Bold">Begin</TextBlock>
</Button> </Button>
</Grid> </Grid>

View File

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