-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wire up the "add" button in the channel mapping list
- Loading branch information
Showing
3 changed files
with
46 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,58 @@ | ||
using JonSkeet.WpfUtil; | ||
using DigiMixer.Controls; | ||
using JonSkeet.WpfUtil; | ||
using System.Collections.ObjectModel; | ||
using System.Windows.Input; | ||
|
||
namespace DigiMixer.Wpf; | ||
|
||
public class ChannelListViewModel : ViewModelBase, IReorderableList | ||
{ | ||
private readonly | ||
string idPrefix; | ||
public ObservableCollection<ChannelMappingViewModel> Mappings { get; } = new(); | ||
|
||
public ICommand AddChannelCommand { get; } | ||
|
||
private ChannelMappingViewModel selectedMapping; | ||
public ChannelMappingViewModel SelectedMapping | ||
{ | ||
get => selectedMapping; | ||
set => SetProperty(ref selectedMapping, value); | ||
} | ||
|
||
public ChannelListViewModel(string idPrefix) | ||
{ | ||
AddChannelCommand = ActionCommand.FromAction(AddChannel); | ||
this.idPrefix = idPrefix; | ||
} | ||
|
||
public void DeleteSelectedItem() => SelectedMapping = Mappings.RemoveSelected(SelectedMapping); | ||
public void MoveSelectedItemUp() => Mappings.MoveSelectedItemUp(SelectedMapping, value => SelectedMapping = value); | ||
public void MoveSelectedItemDown() => Mappings.MoveSelectedItemDown(SelectedMapping, value => SelectedMapping = value); | ||
|
||
private void AddChannel() | ||
{ | ||
// Generate an ID that's unused and somewhat plausible. | ||
int index = Mappings.Count + 1; | ||
while (Mappings.Any(m => m.Model.Id == $"{idPrefix}{index}")) | ||
{ | ||
index++; | ||
} | ||
string id = $"{idPrefix}{index}"; | ||
// Find the first unused channel number | ||
int channel = 1; | ||
while (Mappings.Any(m => m.Number == channel)) | ||
{ | ||
channel++; | ||
} | ||
var mapping = new ChannelMappingViewModel(new ChannelMapping | ||
{ | ||
Id = $"{idPrefix}{index}", | ||
DisplayName = "Unnamed channel", | ||
Channel = channel, | ||
InitiallyVisible = true | ||
}); | ||
Mappings.Add(mapping); | ||
SelectedMapping = mapping; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters