diff --git a/Windows/MassiveKnob/Core/MassiveKnobOrchestrator.cs b/Windows/MassiveKnob/Core/MassiveKnobOrchestrator.cs index 75e1d35..d1c28e9 100644 --- a/Windows/MassiveKnob/Core/MassiveKnobOrchestrator.cs +++ b/Windows/MassiveKnob/Core/MassiveKnobOrchestrator.cs @@ -132,7 +132,7 @@ namespace MassiveKnob.Core return null; if (list[index]?.ActionInfo.Info == action) - return list[index].ActionInfo; + return list[index]?.ActionInfo; list[index]?.ActionInfo.Instance?.Dispose(); @@ -175,7 +175,7 @@ namespace MassiveKnob.Core if (analogOutputIndex >= settingsList.Count) return new MassiveKnobSettings.DigitalToAnalogSettings(); - return settingsList[analogOutputIndex].DigitalToAnalog?.Clone() ?? new MassiveKnobSettings.DigitalToAnalogSettings(); + return settingsList[analogOutputIndex]?.DigitalToAnalog?.Clone() ?? new MassiveKnobSettings.DigitalToAnalogSettings(); } } @@ -320,18 +320,18 @@ namespace MassiveKnob.Core } - protected T GetActionSettings(IMassiveKnobActionContext context, IMassiveKnobAction action, int index) where T : class, new() + protected T GetActionSettings(IMassiveKnobActionContext context, MassiveKnobActionType actionType, IMassiveKnobAction action, int index) where T : class, new() { lock (settingsLock) { - var list = GetActionMappingList(action.ActionType); + var list = GetActionMappingList(actionType); if (index >= list.Count) return new T(); if (list[index]?.Context != context) throw new InvalidOperationException("Caller must be the active action to retrieve the settings"); - var settingsList = GetActionSettingsList(action.ActionType); + var settingsList = GetActionSettingsList(actionType); if (index >= settingsList.Count) return new T(); @@ -340,18 +340,18 @@ namespace MassiveKnob.Core } - protected void SetActionSettings(IMassiveKnobActionContext context, IMassiveKnobAction action, int index, T actionSettings) where T : class, new() + protected void SetActionSettings(IMassiveKnobActionContext context, MassiveKnobActionType actionType, IMassiveKnobAction action, int index, T actionSettings) where T : class, new() { lock (settingsLock) { - var list = GetActionMappingList(action.ActionType); + var list = GetActionMappingList(actionType); if (index >= list.Count) return; if (list[index]?.Context != context) throw new InvalidOperationException("Caller must be the active action to retrieve the settings"); - var settingsList = GetActionSettingsList(action.ActionType); + var settingsList = GetActionSettingsList(actionType); while (index >= settingsList.Count) settingsList.Add(null); @@ -752,13 +752,13 @@ namespace MassiveKnob.Core public T GetSettings() where T : class, new() { - return owner.GetActionSettings(this, action, index); + return owner.GetActionSettings(this, assignedActionType, action, index); } public void SetSettings(T settings) where T : class, new() { - owner.SetActionSettings(this, action, index, settings); + owner.SetActionSettings(this, assignedActionType, action, index, settings); } diff --git a/Windows/MassiveKnob/ViewModel/InputOutputViewModel.cs b/Windows/MassiveKnob/ViewModel/InputOutputViewModel.cs index ee18670..77c3d11 100644 --- a/Windows/MassiveKnob/ViewModel/InputOutputViewModel.cs +++ b/Windows/MassiveKnob/ViewModel/InputOutputViewModel.cs @@ -26,7 +26,7 @@ namespace MassiveKnob.ViewModel public string DisplayName => string.Format( actionType == MassiveKnobActionType.OutputAnalog || actionType == MassiveKnobActionType.OutputDigital ? Strings.OutputHeader - : Strings.InputHeader, + : Strings.InputHeader, index + 1); public IList Actions { get; } @@ -40,7 +40,7 @@ namespace MassiveKnob.ViewModel if (value == selectedAction) return; - selectedAction = value == null || value.RepresentsNull ? null : value; + selectedAction = value == null || value.RepresentsNull ? Actions.Single(a => a.RepresentsNull) : value; var actionInfo = orchestrator.SetAction(actionType, index, selectedAction?.Action); OnPropertyChanged(); @@ -60,7 +60,7 @@ namespace MassiveKnob.ViewModel if (actionSettingsControl is IDisposable disposable) disposable.Dispose(); - + actionSettingsControl = value; OnPropertyChanged(); } @@ -91,6 +91,7 @@ namespace MassiveKnob.ViewModel private readonly IDisposable digitalToAnalogChangedSubscription; private byte digitalToAnalogOn; + public byte DigitalToAnalogOn { get => digitalToAnalogOn; @@ -107,6 +108,7 @@ namespace MassiveKnob.ViewModel private byte digitalToAnalogOff; + public byte DigitalToAnalogOff { get => digitalToAnalogOff; @@ -123,13 +125,14 @@ namespace MassiveKnob.ViewModel // ReSharper restore UnusedMember.Global - public InputOutputViewModel(SettingsViewModel settingsViewModel, IMassiveKnobOrchestrator orchestrator, MassiveKnobActionType actionType, int index) + public InputOutputViewModel(SettingsViewModel settingsViewModel, IMassiveKnobOrchestrator orchestrator, + MassiveKnobActionType actionType, int index) { this.orchestrator = orchestrator; this.actionType = actionType; this.index = index; - - + + // For design-time support if (orchestrator == null) { @@ -142,7 +145,7 @@ namespace MassiveKnob.ViewModel { if (actionViewModel.RepresentsNull) return true; - + if (actionViewModel.Action.ActionType == actionType) return true; @@ -150,12 +153,12 @@ namespace MassiveKnob.ViewModel return actionType == MassiveKnobActionType.OutputAnalog && actionViewModel.Action.ActionType == MassiveKnobActionType.OutputDigital; } - - + + Actions = settingsViewModel.Actions.Where(AllowAction).ToList(); var actionInfo = orchestrator.GetAction(actionType, index); - + selectedAction = actionInfo != null ? Actions.SingleOrDefault(a => !a.RepresentsNull && a.Action.ActionId == actionInfo.Info.ActionId) : Actions.Single(a => a.RepresentsNull); @@ -163,9 +166,9 @@ namespace MassiveKnob.ViewModel actionSettingsControl = actionInfo?.Instance.CreateSettingsControl(); - if (actionType != MassiveKnobActionType.OutputAnalog) + if (actionType != MassiveKnobActionType.OutputAnalog) return; - + var digitalToAnalogSettings = orchestrator.GetDigitalToAnalogSettings(index); digitalToAnalogOn = digitalToAnalogSettings.OnValue; digitalToAnalogOff = digitalToAnalogSettings.OffValue; @@ -213,4 +216,4 @@ namespace MassiveKnob.ViewModel { } } -} +} \ No newline at end of file