1
0
mirror of synced 2024-11-05 01:49:15 +00:00

Fixed #1: Settings for Analog Outputs are not remembered

And a few other null-related fixes
This commit is contained in:
Mark van Renswoude 2021-03-08 20:46:18 +01:00
parent df57d665bf
commit 217013d4cc
2 changed files with 26 additions and 23 deletions

View File

@ -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<T>(IMassiveKnobActionContext context, IMassiveKnobAction action, int index) where T : class, new()
protected T GetActionSettings<T>(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<T>(IMassiveKnobActionContext context, IMassiveKnobAction action, int index, T actionSettings) where T : class, new()
protected void SetActionSettings<T>(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<T>() where T : class, new()
{
return owner.GetActionSettings<T>(this, action, index);
return owner.GetActionSettings<T>(this, assignedActionType, action, index);
}
public void SetSettings<T>(T settings) where T : class, new()
{
owner.SetActionSettings(this, action, index, settings);
owner.SetActionSettings(this, assignedActionType, action, index, settings);
}

View File

@ -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<ActionViewModel> 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
{
}
}
}
}