Skip to content

Commit

Permalink
Add a copy/paste buttons to search space option
Browse files Browse the repository at this point in the history
  • Loading branch information
Coding-Enthusiast committed May 14, 2024
1 parent 0ffbb1b commit f9a2cb2
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 9 deletions.
9 changes: 7 additions & 2 deletions Src/FinderOuter/ViewModels/MissingBase58ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ public MissingBase58ViewModel(Settings settings)
searchSpace = new();

IObservable<bool> isFindEnabled = this.WhenAnyValue(
x => x.Input, x => x.SelectedMissingChar,
x => x.Result.CurrentState, (b58, c, state) =>
x => x.Input,
x => x.SelectedMissingChar,
x => x.Result.CurrentState,
(b58, c, state) =>
!string.IsNullOrEmpty(b58) &&
InputService.IsMissingCharValid(c) &&
state != State.Working);
Expand All @@ -56,6 +58,8 @@ public MissingBase58ViewModel(Settings settings)
AddNumberCommand = ReactiveCommand.Create(AddNumber, canAdd);
AddExactCommand = ReactiveCommand.Create(AddExact, canAdd);
AddSimilarCommand = ReactiveCommand.Create(AddSimilar, canAdd);

CopyCommand = ReactiveCommand.Create(Copy, isFindEnabled);
}


Expand Down Expand Up @@ -93,6 +97,7 @@ public Base58Type SelectedInputType

private void Start()
{
CopiedList = Array.Empty<string>();
isChanged = false;
Index = 0;
Max = 0;
Expand Down
42 changes: 42 additions & 0 deletions Src/FinderOuter/ViewModels/OptionVmBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;

namespace FinderOuter.ViewModels
{
Expand Down Expand Up @@ -41,6 +42,9 @@ public OptionVmBase(IReport report, IWindowManager winMan) : base(winMan)
PreviousCommand = ReactiveCommand.Create(Previous, isPrevEnabled);
RemoveSelectedCommand = ReactiveCommand.Create(RemoveSelected, canRemove);
ClearAllCommand = ReactiveCommand.Create(ClearAll, canAdd);

IObservable<bool> canPaste = this.WhenAnyValue(x => x.CopiedList, (item) => item != null && item.Length > 0);
PasteCommand = ReactiveCommand.Create<bool>(Paste, canPaste);
}


Expand Down Expand Up @@ -97,6 +101,44 @@ public DescriptiveItem<CompareInputType> SelectedCompareInputType
public FontFamily CjkFont => FontFamily.Parse("Microsoft YaHei,Simsun,苹方-简,宋体-简");


public IReactiveCommand CopyCommand { get; protected set; }
public IReactiveCommand PasteCommand { get; protected set; }

private string[] _copied = Array.Empty<string>();
public string[] CopiedList
{
get => _copied;
set => this.RaiseAndSetIfChanged(ref _copied, value);
}

public void Copy()
{
if (CurrentItems is not null)
{
CopiedList = CurrentItems.ToArray();
}
}

public void Paste(bool replace)
{
if (CurrentItems is not null)
{
if (replace)
{
CurrentItems.Clear();
}

foreach (var item in CopiedList)
{
if (!CurrentItems.Contains(item))
{
CurrentItems.Add(item);
}
}
}
}


protected ObservableCollection<string>[] allItems = [];

private ObservableCollection<string> _items;
Expand Down
31 changes: 24 additions & 7 deletions Src/FinderOuter/Views/MissingBase58View.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
x:CompileBindings="True"
x:DataType="vm:MissingBase58ViewModel"
x:Class="FinderOuter.Views.MissingBase58View">

<Design.DataContext>
<vm:MissingBase58ViewModel/>
</Design.DataContext>
Expand Down Expand Up @@ -84,14 +84,31 @@
<Button Content="Similar letters" Command="{Binding AddSimilarCommand}"
Margin="2" Width="100"
Grid.Column="0" Grid.Row="1"/>

</Grid>

<ListBox ItemsSource="{Binding CurrentItems}"
SelectedItem="{Binding SelectedItem}"
Height="130"
Margin="3"
Grid.Column="1" Grid.Row="1"/>
<Grid Grid.Column="1" Grid.Row="1" RowDefinitions="*,auto">
<ListBox ItemsSource="{Binding CurrentItems}"
SelectedItem="{Binding SelectedItem}"
Height="130"
Margin="3"
Grid.Row="0"/>
<Grid ColumnDefinitions="auto,*,*" Grid.Row="1">
<Button Content="Copy"
Command="{Binding CopyCommand}"
Width="65"
Grid.Column="0"/>
<Button Content="Paste (add)"
Command="{Binding PasteCommand}"
CommandParameter="{x:False}"
Width="100"
Grid.Column="1"/>
<Button Content="Paste (replace)"
Command="{Binding PasteCommand}"
CommandParameter="{x:True}"
Width="100"
Grid.Column="2"/>
</Grid>
</Grid>

<Grid ColumnDefinitions="auto,auto" RowDefinitions="auto,auto,auto,auto" Grid.Column="2" Grid.Row="1">
<Button Content="Add all letters" Command="{Binding AddAllCommand}"
Expand Down

0 comments on commit f9a2cb2

Please sign in to comment.