Skip to content
Permalink
Browse files

[skip ci] Add more selection options

  • Loading branch information...
nopara73 committed Nov 23, 2018
1 parent fa7e72a commit b78f3d76d3c238e3f7c1563f06c86a88d3eb0343
@@ -18,7 +18,7 @@
</Style>
<Style Selector="TextBox.Transaparent">
<Setter Property="Background" Value="Transparent" />
</Style>
</Style>
</UserControl.Styles>
<i:Interaction.Behaviors>
<behaviors:ClearPropertyOnLostFocusBehavior TargetProperty="{Binding SelectedCoin}" />
@@ -32,39 +32,41 @@
<TextBlock Text="Privacy" Grid.Column="4" Margin="20 0 0 0" />
<TextBlock Text="History" Grid.Column="5" />
</Grid>
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" >
<CheckBox Content = "Select All" IsThreeState="true" IsChecked = "{Binding SelectAllCheckBoxState}" Command="{Binding SelectAllCheckBoxCommand}" ToolTip.Tip="Select All"/>
<StackPanel Margin="10" Spacing="10" DockPanel.Dock="Bottom" Orientation="Horizontal">
<CheckBox Content = "Select All" IsThreeState="True" IsChecked = "{Binding SelectAllCheckBoxState}" Command="{Binding SelectAllCheckBoxCommand}" />
<CheckBox Content = "Select All Private" IsThreeState="True" IsChecked = "{Binding SelectPrivateCheckBoxState}" Command="{Binding SelectPrivateCheckBoxCommand}" ToolTip.Tip="Coins those anonymity sets are over 50." />
<CheckBox Content = "Select All Non-Private" IsThreeState="True" IsChecked = "{Binding SelectNonPrivateCheckBoxState}" Command="{Binding SelectNonPrivateCheckBoxCommand}" ToolTip.Tip="Coins those anonymity sets are under 50." />
</StackPanel>
<ListBox Items="{Binding Coins}" VirtualizationMode="None" SelectedItem="{Binding Path=SelectedCoin, Mode=TwoWay}">
<ListBox.ContextMenu>
<ContextMenu>
<!--Enqueuing needs password, TODO: jump to password box OR display pw box in context menu + send button-->
<MenuItem Command="{Binding EnqueueCoin}" IsVisible="false">
<MenuItem.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Text="Enqueue Coin, password:" VerticalAlignment="Center"/>
<TextBox Width="50" Grid.Column="1"/>
</Grid>
</MenuItem.Header>
</MenuItem>
<MenuItem Header="Dequeue from CoinJoin" Command="{Binding DequeueCoin}">
<MenuItem.Icon>
<Path HorizontalAlignment="Left"
Data="M3.24,7.51c-0.146,0.142-0.146,0.381,0,0.523l5.199,5.193c0.234,0.238,0.633,0.064,0.633-0.262v-2.634c0.105-0.007,0.212-0.011,0.321-0.011c2.373,0,4.302,1.91,4.302,4.258c0,0.957-0.33,1.809-1.008,2.602c-0.259,0.307,0.084,0.762,0.451,0.572c2.336-1.195,3.73-3.408,3.73-5.924c0-3.741-3.103-6.783-6.916-6.783c-0.307,0-0.615,0.028-0.881,0.063V2.575c0-0.327-0.398-0.5-0.633-0.261L3.24,7.51 M4.027,7.771l4.301-4.3v2.073c0,0.232,0.21,0.409,0.441,0.366c0.298-0.056,0.746-0.123,1.184-0.123c3.402,0,6.172,2.709,6.172,6.041c0,1.695-0.718,3.24-1.979,4.352c0.193-0.51,0.293-1.045,0.293-1.602c0-2.76-2.266-5-5.046-5c-0.256,0-0.528,0.018-0.747,0.05C8.465,9.653,8.328,9.81,8.328,9.995v2.074L4.027,7.771z" Fill="#22B14C"
Height="16" Width="16" Stretch="Fill" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Command="{Binding EnqueueCoin}" IsVisible="false">
<MenuItem.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Text="Enqueue Coin, password:" VerticalAlignment="Center" />
<TextBox Width="50" Grid.Column="1" />
</Grid>
</MenuItem.Header>
</MenuItem>
<MenuItem Header="Dequeue from CoinJoin" Command="{Binding DequeueCoin}">
<MenuItem.Icon>
<Path HorizontalAlignment="Left"
Data="M3.24,7.51c-0.146,0.142-0.146,0.381,0,0.523l5.199,5.193c0.234,0.238,0.633,0.064,0.633-0.262v-2.634c0.105-0.007,0.212-0.011,0.321-0.011c2.373,0,4.302,1.91,4.302,4.258c0,0.957-0.33,1.809-1.008,2.602c-0.259,0.307,0.084,0.762,0.451,0.572c2.336-1.195,3.73-3.408,3.73-5.924c0-3.741-3.103-6.783-6.916-6.783c-0.307,0-0.615,0.028-0.881,0.063V2.575c0-0.327-0.398-0.5-0.633-0.261L3.24,7.51 M4.027,7.771l4.301-4.3v2.073c0,0.232,0.21,0.409,0.441,0.366c0.298-0.056,0.746-0.123,1.184-0.123c3.402,0,6.172,2.709,6.172,6.041c0,1.695-0.718,3.24-1.979,4.352c0.193-0.51,0.293-1.045,0.293-1.602c0-2.76-2.266-5-5.046-5c-0.256,0-0.528,0.018-0.747,0.05C8.465,9.653,8.328,9.81,8.328,9.995v2.074L4.027,7.771z" Fill="#22B14C"
Height="16" Width="16" Stretch="Fill" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</ListBox.ContextMenu>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Expander Name="coinExpander" ExpandDirection="Down" Classes="coloredExpander" Background="{Binding ElementName=coinExpander, Path=IsExpanded, Converter={StaticResource CoinItemExpanderColorConverter}}">
<Expander Name="coinExpander" ExpandDirection="Down" Classes="coloredExpander" Background="{Binding ElementName=coinExpander, Path=IsExpanded, Converter={StaticResource CoinItemExpanderColorConverter}}">

<StackPanel>
<Grid HorizontalAlignment="Left" ColumnDefinitions="150, *" RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto" MaxWidth="800">
<TextBlock Text="Transaction Id:" Grid.Row="0" />
@@ -112,7 +114,5 @@
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

</DockPanel>

</UserControl>
@@ -1,6 +1,8 @@
using NBitcoin;
using ReactiveUI;
using ReactiveUI.Legacy;
using System;
using System.Linq;
using WalletWasabi.Gui.ViewModels;

namespace WalletWasabi.Gui.Controls.WalletExplorer
@@ -11,10 +13,15 @@ public class CoinListViewModel : ViewModelBase
private IReactiveDerivedList<CoinViewModel> _coins;
private CoinViewModel _selectedCoin;
private bool? _selectAllCheckBoxState;
private bool? _selectPrivateCheckBoxState;
private bool? _selectNonPrivateCheckBoxState;

public ReactiveCommand EnqueueCoin { get; }
public ReactiveCommand DequeueCoin { get; }
public ReactiveCommand SelectAllCheckBoxCommand { get; }
public ReactiveCommand SelectPrivateCheckBoxCommand { get; }
public ReactiveCommand SelectNonPrivateCheckBoxCommand { get; }

public CoinViewModel SelectedCoin
{
get => _selectedCoin;
@@ -42,22 +49,46 @@ public bool CanDeqeue
}
set
{
var changed = _selectAllCheckBoxState != value;
this.RaiseAndSetIfChanged(ref _selectAllCheckBoxState,value);
this.RaiseAndSetIfChanged(ref _selectAllCheckBoxState, value);
}
}

public bool? SelectPrivateCheckBoxState
{
get
{
return _selectPrivateCheckBoxState;
}
set
{
this.RaiseAndSetIfChanged(ref _selectPrivateCheckBoxState, value);
}
}

private bool? GetCheckBoxesSelectedState()
public bool? SelectNonPrivateCheckBoxState
{
get
{
return _selectNonPrivateCheckBoxState;
}
set
{
this.RaiseAndSetIfChanged(ref _selectNonPrivateCheckBoxState, value);
}
}

private bool? GetCheckBoxesSelectedState(Func<CoinViewModel, bool> coinFilterPredicate)
{
var coins = Coins.Where(coinFilterPredicate).ToArray();
bool IsAllSelected = true;
foreach (CoinViewModel coin in Coins)
foreach (CoinViewModel coin in coins)
if (!coin.IsSelected)
{
IsAllSelected = false;
break;
}
bool IsAllDeselected = true;
foreach (CoinViewModel coin in Coins)
foreach (CoinViewModel coin in coins)
if (coin.IsSelected)
{
IsAllDeselected = false;
@@ -67,9 +98,14 @@ public bool CanDeqeue
if (IsAllDeselected) return false;
return null;
}
private void SelectAllCoins(bool valueOfSelected)

private void SelectAllCoins(bool valueOfSelected, Func<CoinViewModel, bool> coinFilterPredicate)
{
foreach (var c in Coins) c.IsSelected = valueOfSelected;
var coins = Coins.Where(coinFilterPredicate).ToArray();
foreach (var c in coins)
{
c.IsSelected = valueOfSelected;
}
}

public CoinListViewModel(IReactiveDerivedList<CoinViewModel> coins, Money preSelectMinAmountIncludingCondition = null, int? preSelectMaxAnonSetExcludingCondition = null)
@@ -107,25 +143,70 @@ public CoinListViewModel(IReactiveDerivedList<CoinViewModel> coins, Money preSel
switch (SelectAllCheckBoxState)
{
case true:
SelectAllCoins(true);
SelectAllCoins(true, x => true);
break;

case false:
SelectAllCoins(false);
SelectAllCoins(false, x => true);
break;

case null:
SelectAllCoins(false);
SelectAllCoins(false, x => true);
SelectAllCheckBoxState = false;
break;
}
});
SelectAllCheckBoxState = GetCheckBoxesSelectedState();

SelectPrivateCheckBoxCommand = ReactiveCommand.Create(() =>
{
switch (SelectPrivateCheckBoxState)
{
case true:
SelectAllCoins(true, x => x.AnonymitySet >= 50);
break;

case false:
SelectAllCoins(false, x => x.AnonymitySet >= 50);
break;

case null:
SelectAllCoins(false, x => x.AnonymitySet >= 50);
SelectPrivateCheckBoxState = false;
break;
}
});

SelectNonPrivateCheckBoxCommand = ReactiveCommand.Create(() =>
{
switch (SelectNonPrivateCheckBoxState)
{
case true:
SelectAllCoins(true, x => x.AnonymitySet < 50);
break;

case false:
SelectAllCoins(false, x => x.AnonymitySet < 50);
break;

case null:
SelectAllCoins(false, x => x.AnonymitySet < 50);
SelectNonPrivateCheckBoxState = false;
break;
}
});

SelectAllCheckBoxState = GetCheckBoxesSelectedState(x => true);
SelectPrivateCheckBoxState = GetCheckBoxesSelectedState(x => x.AnonymitySet >= 50);
SelectNonPrivateCheckBoxState = GetCheckBoxesSelectedState(x => x.AnonymitySet < 50);
}

void Coin_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
private void Coin_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(CoinViewModel.IsSelected))
{
SelectAllCheckBoxState = GetCheckBoxesSelectedState();
SelectAllCheckBoxState = GetCheckBoxesSelectedState(x => true);
SelectPrivateCheckBoxState = GetCheckBoxesSelectedState(x => x.AnonymitySet >= 50);
SelectNonPrivateCheckBoxState = GetCheckBoxesSelectedState(x => x.AnonymitySet < 50);
}
}

0 comments on commit b78f3d7

Please sign in to comment.
You can’t perform that action at this time.