From 41f339d4fe8fd2fef03de38a02d223dc07f421d6 Mon Sep 17 00:00:00 2001 From: Stuart Meeks Date: Sat, 30 May 2026 12:34:44 +0000 Subject: [PATCH] Shared parameter definitions: management UI (2/2) Adds the authoring surfaces for the shared-parameter resolution landed in part 1: - CLI-scoped params: a "Shared parameters" section in the CLI editor dialog (reuses the existing parameter-row editor); CliEditorViewModel gains an editable Parameters collection. - Global params: a new GlobalParametersViewModel content view, opened from a "Shared parameters" entry in the pane footer (Trash-style), with add/remove rows and a Save persisted by ShellViewModel.SaveGlobalParameters. Global params live in the main UI, not Settings, per the agreed design. Both reuse ParameterEditorRowViewModel and the existing param-row layout. Co-Authored-By: Claude Opus 4.8 --- CHANGELOG.md | 17 ++- src/Snipdeck.App/Views/CliEditorDialog.xaml | 101 +++++++++++++++--- .../Views/CliEditorDialog.xaml.cs | 13 +++ .../Views/ShellContentTemplateSelector.cs | 3 + src/Snipdeck.App/Views/ShellPage.xaml | 100 ++++++++++++++++- src/Snipdeck.App/Views/ShellPage.xaml.cs | 5 + .../ViewModels/CliEditorViewModel.cs | 21 +++- .../ViewModels/GlobalParametersViewModel.cs | 48 +++++++++ .../ViewModels/ShellViewModel.cs | 19 ++++ .../ViewModels/CliEditorViewModelTests.cs | 21 +++- .../GlobalParametersViewModelTests.cs | 42 ++++++++ .../ViewModels/ShellViewModelCommandsTests.cs | 19 ++++ 12 files changed, 376 insertions(+), 33 deletions(-) create mode 100644 src/Snipdeck.Core/ViewModels/GlobalParametersViewModel.cs create mode 100644 tests/Snipdeck.Core.Tests/ViewModels/GlobalParametersViewModelTests.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 10f04fa..a3d0e06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,15 +8,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Changed -- **Shared parameter definitions — resolution groundwork.** A Snip's - `{token}` now resolves its parameter definition by name with precedence: - the Snip's own parameter overrides a CLI-scoped one, which overrides a - global one. A Snip can omit a parameter to inherit the shared definition - (e.g. an `env` Choice defined once on a CLI). Store schema is now v2 - (additive: `Cli.Parameters` + `SnipStoreDocument.GlobalParameters`); an - older build refuses a v2 store rather than dropping shared definitions. - The UI to manage shared parameters lands next; existing snips are - unaffected. - **JSON stores moved to System.Text.Json source generation.** `JsonSnipStore` and `JsonSettingsStore` now serialise via a generated `JsonSerializerContext` instead of the reflection-based serializer, removing the IL2026 trim warnings. @@ -26,6 +17,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 IL2104 on the WinAppSDK/WinRT/Jdenticon assemblies, which aren't trim-safe. ### Added +- **Shared parameter definitions.** Define a parameter once and reuse it + across snips, at two scopes: **CLI-scoped** (in the CLI editor — inherited by + every snip under that CLI) and **global** (a new "Shared parameters" entry in + the left pane — available to every snip across all CLIs). A snip's `{token}` + resolves its definition by name with precedence **snip-local → CLI → global**; + omit a parameter to inherit the shared one, or define it locally to override. + Existing snips are unaffected. (Store schema is now v2; an older build refuses + a v2 store rather than dropping shared definitions.) - **Change the storage location.** A "Change…" button on Settings → Storage location lets you pick a new folder for your snips. If the folder already contains a Snipdeck store it's adopted (your current snips are left where diff --git a/src/Snipdeck.App/Views/CliEditorDialog.xaml b/src/Snipdeck.App/Views/CliEditorDialog.xaml index 184222e..051280b 100644 --- a/src/Snipdeck.App/Views/CliEditorDialog.xaml +++ b/src/Snipdeck.App/Views/CliEditorDialog.xaml @@ -3,6 +3,7 @@ x:Class="Snipdeck.App.Views.CliEditorDialog" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:vm="using:Snipdeck.Core.ViewModels" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" @@ -11,30 +12,96 @@ CloseButtonText="Cancel" DefaultButton="Primary"> - - + + + + + + + + + + + + + + + + + Text + Choice + + + + + + + + - + diff --git a/src/Snipdeck.App/Views/CliEditorDialog.xaml.cs b/src/Snipdeck.App/Views/CliEditorDialog.xaml.cs index e3da04d..278d57f 100644 --- a/src/Snipdeck.App/Views/CliEditorDialog.xaml.cs +++ b/src/Snipdeck.App/Views/CliEditorDialog.xaml.cs @@ -34,6 +34,19 @@ private void UpdatePrimaryButtonEnabled() IsPrimaryButtonEnabled = ViewModel.CanSave; } + private void OnAddParameterClicked(object sender, RoutedEventArgs e) + { + ViewModel.AddParameter(); + } + + private void OnRemoveParameterClicked(object sender, RoutedEventArgs e) + { + if (sender is FrameworkElement element && element.Tag is ParameterEditorRowViewModel row) + { + ViewModel.RemoveParameter(row); + } + } + private async void OnPickIconClicked(object sender, RoutedEventArgs e) { var picked = await _filePicker.PickImageAsync(); diff --git a/src/Snipdeck.App/Views/ShellContentTemplateSelector.cs b/src/Snipdeck.App/Views/ShellContentTemplateSelector.cs index 5c37434..ec2a33c 100644 --- a/src/Snipdeck.App/Views/ShellContentTemplateSelector.cs +++ b/src/Snipdeck.App/Views/ShellContentTemplateSelector.cs @@ -19,6 +19,8 @@ public sealed partial class ShellContentTemplateSelector : DataTemplateSelector public DataTemplate? TrashTemplate { get; set; } + public DataTemplate? GlobalParametersTemplate { get; set; } + protected override DataTemplate? SelectTemplateCore(object item) { return item switch @@ -27,6 +29,7 @@ public sealed partial class ShellContentTemplateSelector : DataTemplateSelector CliViewModel => CliTemplate, SettingsViewModel => SettingsTemplate, TrashViewModel => TrashTemplate, + GlobalParametersViewModel => GlobalParametersTemplate, _ => null, }; } diff --git a/src/Snipdeck.App/Views/ShellPage.xaml b/src/Snipdeck.App/Views/ShellPage.xaml index e4f81df..9400993 100644 --- a/src/Snipdeck.App/Views/ShellPage.xaml +++ b/src/Snipdeck.App/Views/ShellPage.xaml @@ -17,6 +17,7 @@ + @@ -316,11 +317,97 @@ + + + + + + + + + + + + + + + + + Text + Choice + + + + + + + + + + + + + TrashTemplate="{StaticResource TrashContentTemplate}" + GlobalParametersTemplate="{StaticResource GlobalParametersContentTemplate}" /> +