Skip to content
Permalink
Browse files

[skip ci] Added select all functionality to coinlist

  • Loading branch information...
molnard committed Nov 23, 2018
1 parent 98e59e8 commit 0d6820f0a9185ecd6598ce95a641c676a5a075f4
@@ -32,7 +32,10 @@
<TextBlock Text="Privacy" Grid.Column="4" Margin="20 0 0 0" />
<TextBlock Text="History" Grid.Column="5" />
</Grid>
<ListBox Items="{Binding Coins}" VirtualizationMode="None" SelectedItem="{Binding Path=SelectedCoin, Mode=TwoWay}">
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" >
<CheckBox Content = "Select All" IsThreeState="true" IsChecked = "{Binding SelectAllCheckBoxState}" Command="{Binding SelectAllCheckBoxCommand}" ToolTip.Tip="Select All"/>
</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-->
@@ -109,5 +112,7 @@
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

</DockPanel>

</UserControl>
@@ -10,9 +10,11 @@ public class CoinListViewModel : ViewModelBase
#pragma warning disable CS0618 // Type or member is obsolete
private IReactiveDerivedList<CoinViewModel> _coins;
private CoinViewModel _selectedCoin;
private bool? _selectAllCheckBoxState;

public ReactiveCommand EnqueueCoin { get; }
public ReactiveCommand DequeueCoin { get; }
public ReactiveCommand SelectAllCheckBoxCommand { get; }
public CoinViewModel SelectedCoin
{
get => _selectedCoin;
@@ -25,13 +27,51 @@ public CoinViewModel SelectedCoin

public bool CanDeqeue
{
get
{
get
{
if (SelectedCoin == null) return false;
return SelectedCoin.CoinJoinInProgress;
}
}

public bool? SelectAllCheckBoxState
{
get
{
return _selectAllCheckBoxState;
}
set
{
var changed = _selectAllCheckBoxState != value;
this.RaiseAndSetIfChanged(ref _selectAllCheckBoxState,value);
}
}

private bool? GetCheckBoxesSelectedState()
{
bool IsAllSelected = true;
foreach (CoinViewModel coin in Coins)
if (!coin.IsSelected)
{
IsAllSelected = false;
break;
}
bool IsAllDeselected = true;
foreach (CoinViewModel coin in Coins)
if (coin.IsSelected)
{
IsAllDeselected = false;
break;
}
if (IsAllSelected) return true;
if (IsAllDeselected) return false;
return null;
}
private void SelectAllCoins(bool valueOfSelected)
{
foreach (var c in Coins) c.IsSelected = valueOfSelected;
}

public CoinListViewModel(IReactiveDerivedList<CoinViewModel> coins, Money preSelectMinAmountIncludingCondition = null, int? preSelectMaxAnonSetExcludingCondition = null)
{
Coins = coins;
@@ -46,16 +86,47 @@ public CoinListViewModel(IReactiveDerivedList<CoinViewModel> coins, Money preSel
}
}
}

foreach (CoinViewModel coin in Coins)
coin.PropertyChanged += Coin_PropertyChanged;

EnqueueCoin = ReactiveCommand.Create(() =>
{
if (SelectedCoin == null) return;
//await Global.ChaumianClient.QueueCoinsToMixAsync()
});

DequeueCoin = ReactiveCommand.Create(async () =>
{
if (SelectedCoin == null) return;
await Global.ChaumianClient.DequeueCoinsFromMixAsync(SelectedCoin.Model);
}, this.WhenAnyValue(x => x.CanDeqeue));

SelectAllCheckBoxCommand = ReactiveCommand.Create(() =>
{
switch (SelectAllCheckBoxState)
{
case true:
SelectAllCoins(true);
break;
case false:
SelectAllCoins(false);
break;
case null:
SelectAllCoins(false);
SelectAllCheckBoxState = false;
break;
}
});
SelectAllCheckBoxState = GetCheckBoxesSelectedState();
}

void Coin_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(CoinViewModel.IsSelected))
{
SelectAllCheckBoxState = GetCheckBoxesSelectedState();
}
}

public IReactiveDerivedList<CoinViewModel> Coins

0 comments on commit 0d6820f

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