- add possibility to specify executable path

master
Simon G 5 years ago
parent 04fc09312a
commit ddd68e7377
  1. 5
      Mystify/MainModel.cs
  2. 2
      Mystify/ViewModels/ChannelViewModel.cs
  3. 45
      Mystify/ViewModels/ControllableSelectionViewModel.cs
  4. 15
      Mystify/Views/ControllableSelectionWindow.axaml

@ -20,11 +20,12 @@ namespace Mystify
private IDevice? _device;
private IControllableCollector? _controllableCollector;
public MainModel(IDriverLoaderFactory driverLoaderFactory, IDeviceFactory deviceFactory, IControllableCollectorFactory controllableCollectorFactory)
public MainModel(IDriverLoaderFactory driverLoaderFactory, IDeviceFactory deviceFactory, IControllableCollectorFactory controllableCollectorFactory, IControllableFactory controllableFactory)
{
_driverLoader = driverLoaderFactory.Create();
_deviceFactory = deviceFactory;
_controllableCollectorFactory = controllableCollectorFactory;
ControllableFactory = controllableFactory;
}
public string? DeviceName => _device?.Name;
@ -32,6 +33,8 @@ namespace Mystify
public List<IControllable>? Controllables => _controllableCollector?.Controllables;
public bool UseMidiView { get; set; }
public IControllableFactory ControllableFactory { get; }
public void LoadDriverAndDevice(string driverPath)
{

@ -44,7 +44,7 @@ namespace Mystify.ViewModels
private async Task SelectControllable()
{
ControllableSelectionWindow controllableSelectionWindow = new();
ControllableSelectionViewModel controllableSelectionViewModel = new(_mainModel.Controllables, controllableSelectionWindow);
ControllableSelectionViewModel controllableSelectionViewModel = new(_mainModel.Controllables, controllableSelectionWindow, _mainModel.ControllableFactory);
controllableSelectionWindow.DataContext = controllableSelectionViewModel;
Controllable = await controllableSelectionWindow.ShowDialog<ControllableViewModel>(_mainWindow);

@ -6,8 +6,12 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using Avalonia.Controls;
using Lib.Audio.Factories;
using Lib.Audio.Interfaces;
using Lib.Logging;
using Lib.Tools;
using Mystify.Views;
using ReactiveUI;
@ -16,7 +20,10 @@ namespace Mystify.ViewModels
{
public class ControllableSelectionViewModel : ViewModelBase
{
private readonly IControllableFactory? _controllableFactory;
private readonly ControllableSelectionWindow? _window;
private string _customControllableExecutablePath = "";
public ControllableSelectionViewModel()
{
@ -26,9 +33,10 @@ namespace Mystify.ViewModels
Controllables = new ObservableCollection<ControllableViewModel>();
}
public ControllableSelectionViewModel(List<IControllable>? controllables, ControllableSelectionWindow window)
public ControllableSelectionViewModel(List<IControllable>? controllables, ControllableSelectionWindow window, IControllableFactory controllableFactory)
{
_window = window;
_controllableFactory = controllableFactory;
Controllables = controllables == null ? new ObservableCollection<ControllableViewModel>() :
controllables.Select(c => new ControllableViewModel(c)).ToObservableCollection();
@ -40,9 +48,44 @@ namespace Mystify.ViewModels
public ObservableCollection<ControllableViewModel> Controllables { get; }
private ControllableViewModel? SelectedControllable { get; set; }
private string CustomControllableExecutablePath
{
get => _customControllableExecutablePath;
set
{
_customControllableExecutablePath = value;
RaisePropertyChanged(() => CustomControllableExecutablePath);
}
}
public ICommand CloseCommand => ReactiveCommand.Create(CloseWindow);
public ICommand SelectCustomControllableCommand => ReactiveCommand.CreateFromTask(SelectCustomControllable);
private void CloseWindow() => _window?.Close(SelectedControllable);
private async Task SelectCustomControllable()
{
if (_controllableFactory == null)
return;
OpenFileDialog openFileDialog = new()
{
Filters = new List<FileDialogFilter> {new() {Extensions = new List<string> {"exe"}, Name = "Executable"}}
};
string[] selectedPaths = await openFileDialog.ShowAsync(_window);
if (selectedPaths.Length == 0)
{
await Log.Write<MainWindowViewModel>("No Executable selected.");
return;
}
CustomControllableExecutablePath = selectedPaths[0];
IControllable controllable = _controllableFactory.Create(CustomControllableExecutablePath);
SelectedControllable = new ControllableViewModel(controllable);
CloseWindow();
}
private void OnControllableSelected(object? sender, bool isSelected)
{
if (!isSelected)

@ -37,6 +37,19 @@
</ExperimentalAcrylicBorder.Material>
</ExperimentalAcrylicBorder>
<ItemsControl Items="{Binding Controllables}"/>
<TabControl TabStripPlacement="Left">
<TabControl.Items>
<TabItem Header="Running Controllable">
<ItemsControl Items="{Binding Controllables}"/>
</TabItem>
<TabItem Header="Select other Executable">
<StackPanel Orientation="Vertical" Margin="20" >
<TextBox Text="{Binding CustomControllableExecutablePath}" Margin="5" Width="250"/>
<Button Content="Select Executable" Command="{Binding SelectCustomControllableCommand}" Margin="5"/>
</StackPanel>
</TabItem>
</TabControl.Items>
</TabControl>
</Panel>
</Window>
Loading…
Cancel
Save