Kill stringly-typed command tokens: Add Source menu passes SourceType enum via x:Static CommandParameter (typos break the build, not silently add an Image); webcam gets its own AddWebcamCommand; AddSource keeps Enum.TryParse fallback; docs updated (65 tests passing)
This commit is contained in:
@@ -525,6 +525,7 @@ public class MainViewModel : ViewModelBase
|
||||
public ICommand RemoveSceneCommand { get; }
|
||||
public ICommand ToggleSceneVisibilityCommand { get; }
|
||||
public ICommand AddSourceCommand { get; }
|
||||
public ICommand AddWebcamCommand { get; }
|
||||
public ICommand AddImageCommand { get; }
|
||||
public ICommand RemoveSourceCommand { get; }
|
||||
public ICommand ChangeWebcamCommand { get; }
|
||||
@@ -577,7 +578,8 @@ public class MainViewModel : ViewModelBase
|
||||
EditSceneCommand = new RelayCommand(scene => BeginEditScene(scene as Scene));
|
||||
RemoveSceneCommand = new RelayCommand(scene => RemoveScene(scene as Scene));
|
||||
ToggleSceneVisibilityCommand = new RelayCommand(scene => ToggleSceneVisibility(scene as Scene));
|
||||
AddSourceCommand = new RelayCommand(type => AddSource(type as string));
|
||||
AddSourceCommand = new RelayCommand(parameter => AddSource(parameter));
|
||||
AddWebcamCommand = new RelayCommand(_ => _ = AddWebcamToActiveSceneAsync());
|
||||
AddImageCommand = new RelayCommand(_ => AddImage());
|
||||
RemoveSourceCommand = new RelayCommand(element => RemoveElement(element as SceneElement));
|
||||
ChangeWebcamCommand = new RelayCommand(_ => _ = ChangeWebcamAsync(), _ => CanChangeWebcam);
|
||||
@@ -1060,25 +1062,14 @@ public class MainViewModel : ViewModelBase
|
||||
ActiveScene = Scenes.FirstOrDefault();
|
||||
}
|
||||
|
||||
private void AddSource(string? type)
|
||||
private void AddSource(object? parameter)
|
||||
{
|
||||
var scene = ActiveScene;
|
||||
if (scene == null) return;
|
||||
|
||||
if (string.Equals(type, "webcam", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_ = AddWebcamToActiveSceneAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
var sourceType = type?.ToLowerInvariant() switch
|
||||
{
|
||||
"screen" => SourceType.DisplayCapture,
|
||||
"window" => SourceType.WindowCapture,
|
||||
"background" => SourceType.Background,
|
||||
"text" => SourceType.TextOverlay,
|
||||
_ => SourceType.Image,
|
||||
};
|
||||
var sourceType = parameter is SourceType typed
|
||||
? typed
|
||||
: Enum.TryParse<SourceType>(parameter?.ToString(), true, out var parsed) ? parsed : SourceType.Image;
|
||||
var baseName = sourceType switch
|
||||
{
|
||||
SourceType.DisplayCapture => "Screen",
|
||||
|
||||
Reference in New Issue
Block a user