1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Scripts - Properly register script with its owner

Scripts UI - Save on close
Scripts UI - Dispose script on removal
This commit is contained in:
Robert 2021-06-21 22:43:31 +02:00
parent 5367027471
commit a5c13bb543
5 changed files with 28 additions and 1 deletions

View File

@ -11,6 +11,10 @@ namespace Artemis.Core.ScriptingProviders
protected LayerScript(Layer layer, ScriptConfiguration configuration) : base(configuration)
{
Layer = layer;
lock (Layer.Scripts)
{
Layer.Scripts.Add(this);
}
}
/// <summary>

View File

@ -11,6 +11,10 @@ namespace Artemis.Core.ScriptingProviders
protected ProfileScript(Profile profile, ScriptConfiguration configuration) : base(configuration)
{
Profile = profile;
lock (Profile.Scripts)
{
Profile.Scripts.Add(this);
}
}
/// <summary>

View File

@ -10,6 +10,10 @@
protected PropertyScript(ILayerProperty layerProperty, ScriptConfiguration configuration) : base(configuration)
{
LayerProperty = layerProperty;
lock (LayerProperty.Scripts)
{
LayerProperty.Scripts.Add(this);
}
}
/// <summary>

View File

@ -68,6 +68,7 @@ namespace Artemis.UI.Screens.Scripting
}
ScriptConfiguration.DiscardPendingChanges();
ScriptConfiguration.Script?.Dispose();
RequestClose();
}
}

View File

@ -15,15 +15,17 @@ namespace Artemis.UI.Screens.Scripting
{
private readonly IScriptingService _scriptingService;
private readonly IDialogService _dialogService;
private readonly IProfileEditorService _profileEditorService;
private readonly IScriptVmFactory _scriptVmFactory;
public Profile Profile { get; }
public Layer Layer { get; }
public ILayerProperty LayerProperty { get; }
public ScriptsDialogViewModel(Profile profile, IScriptingService scriptingService, IDialogService dialogService, IScriptVmFactory scriptVmFactory)
public ScriptsDialogViewModel(Profile profile, IScriptingService scriptingService, IDialogService dialogService, IProfileEditorService profileEditorService, IScriptVmFactory scriptVmFactory)
{
_scriptingService = scriptingService;
_dialogService = dialogService;
_profileEditorService = profileEditorService;
_scriptVmFactory = scriptVmFactory;
DisplayName = "Artemis | Profile Scripts";
@ -74,5 +76,17 @@ namespace Artemis.UI.Screens.Scripting
Items.Add(_scriptVmFactory.ScriptConfigurationViewModel(scriptConfiguration));
}
#region Overrides of OneActive
/// <inheritdoc />
protected override void OnClose()
{
_profileEditorService.SaveSelectedProfileConfiguration();
base.OnClose();
}
#endregion
}
}