-
Notifications
You must be signed in to change notification settings - Fork 773
Fixes #4885. View.GetScheme() falls back gracefully instead of throwing when SchemeName is not found #4886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tig
merged 7 commits into
gui-cs:develop
from
YourRobotOverlord:feat/theme-fallback-chain
Apr 8, 2026
Merged
Fixes #4885. View.GetScheme() falls back gracefully instead of throwing when SchemeName is not found #4886
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c1a871c
Fixes #4457. Implement graceful scheme fallback chain in View.GetSche…
YourRobotOverlord 8605df5
Add ThemeFallback UICatalog scenario demonstrating SchemeName fallbac…
YourRobotOverlord c84308e
Merge branch 'v2_develop' into feat/theme-fallback-chain
tig c9d7639
Merge branch 'v2_develop' into feat/theme-fallback-chain
tig c1d39fc
Merge branch 'develop' into feat/theme-fallback-chain
tig 217f3d6
Merge branch 'develop' into feat/theme-fallback-chain
tig 7b65b7f
Code Review/code cleanup and fix stupid UICatalog bug I introduced an…
tig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| #nullable enable | ||
|
|
||
| namespace UICatalog.Scenarios; | ||
|
|
||
| /// <summary> | ||
| /// Demonstrates the SchemeName fallback chain introduced in v2. | ||
| /// When a view's <see cref="View.SchemeName"/> is not found in the active theme, the view no longer | ||
| /// throws a <see cref="KeyNotFoundException"/>. Instead, it walks the fallback chain: | ||
| /// <list type="number"> | ||
| /// <item> | ||
| /// <description>Named scheme (if found in current theme)</description> | ||
| /// </item> | ||
| /// <item> | ||
| /// <description>SuperView's scheme (recursive)</description> | ||
| /// </item> | ||
| /// <item> | ||
| /// <description>"Base" scheme from the current theme</description> | ||
| /// </item> | ||
| /// <item> | ||
| /// <description>Hard-coded "Base" scheme (always present)</description> | ||
| /// </item> | ||
| /// </list> | ||
| /// </summary> | ||
| [ScenarioMetadata ("Theme Fallback", "Demonstrates graceful SchemeName fallback when a named scheme is missing from the active theme.")] | ||
| [ScenarioCategory ("Colors")] | ||
| [ScenarioCategory ("Configuration")] | ||
| public sealed class ThemeFallback : Scenario | ||
| { | ||
| private const string CUSTOM_SCHEME_NAME = "CustomHighlight"; | ||
| private const string MISSING_SCHEME_NAME = "NonExistentScheme"; | ||
|
|
||
| public override void Main () | ||
| { | ||
| ConfigurationManager.Enable (ConfigLocations.All); | ||
|
|
||
| using IApplication app = Application.Create (); | ||
| app.Init (); | ||
|
|
||
| // Extend the Default theme with a custom scheme that has TextStyle.Blink | ||
| // so it stands out visually. Other built-in themes do NOT contain this scheme, | ||
| // so switching themes lets you watch the fallback chain activate in real time. | ||
| SchemeManager.AddScheme (CUSTOM_SCHEME_NAME, new () { Normal = new Attribute (Color.BrightYellow, Color.Blue, TextStyle.Blink) }); | ||
|
|
||
| using Window appWindow = new (); | ||
| appWindow.Title = GetQuitKeyAndName (); | ||
|
|
||
| // --- Theme selector --- | ||
| string [] themeLabels = ThemeManager.GetThemeNames ().Select (n => "_" + n).ToArray (); | ||
|
|
||
| OptionSelector themeSelector = new () | ||
| { | ||
| Title = "_Theme", | ||
| BorderStyle = LineStyle.Rounded, | ||
| X = 1, | ||
| Y = 1, | ||
| Width = Dim.Auto (), | ||
| Height = Dim.Auto (), | ||
| Labels = themeLabels, | ||
| Value = ThemeManager.GetThemeNames ().IndexOf (ThemeManager.Theme) | ||
| }; | ||
|
|
||
| themeSelector.ValueChanged += (sender, args) => | ||
| { | ||
| if (sender is not OptionSelector sel) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| string rawLabel = sel.Labels! [(int)args.NewValue!]; | ||
|
|
||
| // Strip the leading underscore added for keyboard shortcut. | ||
| ThemeManager.Theme = rawLabel [1..]; | ||
| ConfigurationManager.Apply (); | ||
|
|
||
| // Re-add the custom scheme to the newly-active theme so the | ||
| // "Default" theme always demonstrates the found case. | ||
| if (ThemeManager.Theme == ThemeManager.DEFAULT_THEME_NAME) | ||
| { | ||
| SchemeManager.AddScheme (CUSTOM_SCHEME_NAME, | ||
| new () { Normal = new Attribute (Color.BrightYellow, Color.Blue, TextStyle.Blink) }); | ||
| } | ||
| }; | ||
|
|
||
| // --- Explanation --- | ||
| Label intro = new () | ||
| { | ||
| X = Pos.Right (themeSelector) + 1, | ||
| Y = 1, | ||
| Width = Dim.Fill (1), | ||
| Text = $"Switch to a non-Default theme to see the fallback activate.\n" | ||
| + $" • \"{CUSTOM_SCHEME_NAME}\" is only in the Default theme.\n" | ||
| + $" • \"{MISSING_SCHEME_NAME}\" is never in any theme.\n" | ||
| + $"In both missing cases the view falls back gracefully instead of throwing." | ||
| }; | ||
|
|
||
| // --- View 1: scheme FOUND in the active theme --- | ||
| FrameView foundFrame = new () | ||
| { | ||
| Title = $"SchemeName = \"{CUSTOM_SCHEME_NAME}\"", | ||
| X = Pos.Right (themeSelector) + 1, | ||
| Y = Pos.Bottom (intro) + 1, | ||
| Width = Dim.Fill (1), | ||
| Height = 5, | ||
| SchemeName = CUSTOM_SCHEME_NAME | ||
| }; | ||
|
|
||
| Label foundLabel = new () | ||
| { | ||
| X = 1, | ||
| Y = 1, | ||
| Width = Dim.Fill (2), | ||
| Text = $"On the Default theme this scheme exists (BrightYellow/Blue + Blink).\n" | ||
| + $"On any other theme the scheme is missing → fallback chain activates." | ||
| }; | ||
| foundFrame.Add (foundLabel); | ||
|
|
||
| // --- View 2: scheme NEVER found — fallback always activates --- | ||
| FrameView missingFrame = new () | ||
| { | ||
| Title = $"SchemeName = \"{MISSING_SCHEME_NAME}\"", | ||
| X = Pos.Right (themeSelector) + 1, | ||
| Y = Pos.Bottom (foundFrame) + 1, | ||
| Width = Dim.Fill (1), | ||
| Height = 5, | ||
| SchemeName = MISSING_SCHEME_NAME | ||
| }; | ||
|
|
||
| Label missingLabel = new () | ||
| { | ||
| X = 1, | ||
| Y = 1, | ||
| Width = Dim.Fill (2), | ||
| Text = $"This scheme does not exist in any theme.\n" | ||
| + $"The view silently falls back to its SuperView's scheme (no exception).\n" | ||
| + $"A warning is written to the debug log." | ||
| }; | ||
| missingFrame.Add (missingLabel); | ||
|
|
||
| appWindow.Add (themeSelector, intro, foundFrame, missingFrame); | ||
|
|
||
| app.Run (appWindow); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.