11using System . Collections . ObjectModel ;
22using System . Reflection ;
3- using Terminal . Gui ;
43using Terminal . Gui . Drawing ;
5- using TerminalGuiDesigner ;
6- using TerminalGuiDesigner . Operations ;
74
85namespace TerminalGuiDesigner ;
96
107/// <summary>
11- /// Tracks usage of <see cref="Scheme "/> in designed views.
12- /// Each <see cref="Scheme "/> that the user has created or are
8+ /// Tracks usage of <see cref="ColorScheme "/> in designed views.
9+ /// Each <see cref="ColorScheme "/> that the user has created or are
1310/// supplied by the designer out of the box is modeled by <see cref="NamedScheme"/>.
1411/// This class hosts the collection of all <see cref="NamedScheme"/>.
1512/// </summary>
16- public class SchemeManager
13+ public class ColorSchemeManager
1714{
18- private readonly List < NamedScheme > Schemes = new ( ) ;
15+ private readonly List < NamedScheme > colorSchemes = new ( ) ;
1916
20- private SchemeManager ( )
17+ private ColorSchemeManager ( )
2118 {
2219 }
2320
2421 /// <summary>
25- /// Gets the Singleton instance of <see cref="SchemeManager "/>.
22+ /// Gets the Singleton instance of <see cref="ColorSchemeManager "/>.
2623 /// </summary>
27- public static SchemeManager Instance { get ; } = new ( ) ;
24+ public static ColorSchemeManager Instance { get ; } = new ( ) ;
2825
2926 /// <summary>
3027 /// Gets all known named color schemes defined in editor.
3128 /// </summary>
32- public ReadOnlyCollection < NamedScheme > Schemes => this . Schemes . ToList ( ) . AsReadOnly ( ) ;
29+ public ReadOnlyCollection < NamedScheme > Schemes => this . colorSchemes . ToList ( ) . AsReadOnly ( ) ;
3330
3431 /// <summary>
3532 /// Clears all <see cref="NamedScheme"/> tracked by manager.
3633 /// </summary>
3734 public void Clear ( )
3835 {
39- this . Schemes . Clear ( ) ;
36+ this . colorSchemes . Clear ( ) ;
4037 }
4138
4239 /// <summary>
43- /// Makes <see cref="SchemeManager "/> forget about <paramref name="toDelete"/>.
40+ /// Makes <see cref="ColorSchemeManager "/> forget about <paramref name="toDelete"/>.
4441 /// Note that this does not remove it from any users (to do that use
45- /// <see cref="DeleteSchemeOperation "/> instead).
42+ /// <see cref="DeleteColorSchemeOperation "/> instead).
4643 /// </summary>
4744 /// <param name="toDelete"><see cref="NamedScheme"/> to forget about.</param>
4845 public void Remove ( NamedScheme toDelete )
4946 {
5047 // match on name as instances may change e.g. due to Undo/Redo etc
51- var match = this . Schemes . FirstOrDefault ( s => s . Name . Equals ( toDelete . Name ) ) ;
48+ var match = this . colorSchemes . FirstOrDefault ( s => s . Name . Equals ( toDelete . Name ) ) ;
5249
5350 if ( match != null )
5451 {
55- this . Schemes . Remove ( match ) ;
52+ this . colorSchemes . Remove ( match ) ;
5653 }
5754 }
5855
5956 /// <summary>
60- /// Populates <see cref="Schemes"/> based on the private Scheme instances declared in the
57+ /// Populates <see cref="Schemes"/> based on the private ColorScheme instances declared in the
6158 /// Designer.cs file of the <paramref name="viewBeingEdited"/>. Does not clear any existing known
6259 /// schemes.
6360 /// </summary>
6461 /// <param name="viewBeingEdited">View to find color schemes in, must be the root design (i.e. <see cref="Design.IsRoot"/>).</param>
6562 /// <exception cref="ArgumentException">Thrown if passed a non-root <see cref="Design"/>.</exception>
66- public void FindDeclaredSchemes ( Design viewBeingEdited )
63+ public void FindDeclaredColorSchemes ( Design viewBeingEdited )
6764 {
6865 if ( ! viewBeingEdited . IsRoot )
6966 {
@@ -80,9 +77,9 @@ public void FindDeclaredSchemes(Design viewBeingEdited)
8077 {
8178 var val = f . GetValue ( view ) as Scheme ;
8279
83- if ( val != null && ! this . Schemes . Any ( s => s . Name . Equals ( f . Name ) ) )
80+ if ( val != null && ! this . colorSchemes . Any ( s => s . Name . Equals ( f . Name ) ) )
8481 {
85- this . Schemes . Add ( new NamedScheme ( f . Name , val ) ) ;
82+ this . colorSchemes . Add ( new NamedScheme ( f . Name , val ) ) ;
8683 }
8784 }
8885 }
@@ -91,11 +88,11 @@ public void FindDeclaredSchemes(Design viewBeingEdited)
9188 /// Returns the <see cref="NamedScheme.Name"/> for <paramref name="s"/>
9289 /// if it is in the collection of known <see cref="Schemes"/>.
9390 /// </summary>
94- /// <param name="s">A <see cref="Scheme "/> to look up.</param>
91+ /// <param name="s">A <see cref="ColorScheme "/> to look up.</param>
9592 /// <returns>The name of the scheme or null if it is not known.</returns>
96- public string ? GetNameForScheme ( Scheme s )
93+ public string ? GetNameForColorScheme ( Scheme s )
9794 {
98- var match = this . Schemes . Where ( kvp => s . Equals ( kvp . Scheme ) ) . ToArray ( ) ;
95+ var match = this . colorSchemes . Where ( kvp => s . Equals ( kvp . Scheme ) ) . ToArray ( ) ;
9996
10097 if ( match . Length > 0 )
10198 {
@@ -111,20 +108,20 @@ public void FindDeclaredSchemes(Design viewBeingEdited)
111108 /// will also update all Views in <paramref name="rootDesign"/> which currently use the
112109 /// named scheme.
113110 /// </summary>
114- /// <param name="name">The user generated name for the <see cref="Scheme "/>.
111+ /// <param name="name">The user generated name for the <see cref="ColorScheme "/>.
115112 /// Will become <see cref="NamedScheme.Name"/>.</param>
116- /// <param name="scheme">The new <see cref="Scheme "/> color values to use.</param>
113+ /// <param name="scheme">The new <see cref="ColorScheme "/> color values to use.</param>
117114 /// <param name="rootDesign">The topmost <see cref="Design"/> the user is editing (see <see cref="Design.GetRootDesign"/>).</param>
118- /// <returns>A reference to the <see cref="Scheme "/> that was added or updated.</returns>
115+ /// <returns>A reference to the <see cref="ColorScheme "/> that was added or updated.</returns>
119116 public Scheme AddOrUpdateScheme ( string name , Scheme scheme , Design rootDesign )
120117 {
121118 // if we don't currently know about this scheme
122- if ( this . Schemes . FirstOrDefault ( c => c . Name . Equals ( name ) ) is not { } oldScheme )
119+ if ( this . colorSchemes . FirstOrDefault ( c => c . Name . Equals ( name ) ) is not { } oldScheme )
123120 {
124121 // simply record that we now know about it and exit
125- NamedScheme newScheme = new ( name , scheme ) ;
126- this . Schemes . Add ( newScheme ) ;
127- return newScheme . Scheme ;
122+ NamedScheme newColorScheme = new ( name , scheme ) ;
123+ this . colorSchemes . Add ( newColorScheme ) ;
124+ return newColorScheme . Scheme ;
128125 }
129126
130127 // we know about this color already and people may be using it!
@@ -150,7 +147,7 @@ public Scheme AddOrUpdateScheme(string name, Scheme scheme, Design rootDesign)
150147 /// <param name="newName">The value to change it to.</param>
151148 public void RenameScheme ( string oldName , string newName )
152149 {
153- var match = this . Schemes . FirstOrDefault ( c => c . Name . Equals ( oldName ) ) ;
150+ var match = this . colorSchemes . FirstOrDefault ( c => c . Name . Equals ( oldName ) ) ;
154151
155152 if ( match != null )
156153 {
@@ -165,9 +162,9 @@ public void RenameScheme(string oldName, string newName)
165162 /// <param name="name">The name to look up.</param>
166163 /// <returns>The scheme if found or null.</returns>
167164 /// <exception cref="KeyNotFoundException">Thrown if the <paramref name="name"/> is not present in <see cref="Schemes"/>.</exception>
168- public NamedScheme GetNamedScheme ( string name )
165+ public NamedScheme GetNamedColorScheme ( string name )
169166 {
170- return this . Schemes . FirstOrDefault ( c => c . Name . Equals ( name ) )
171- ?? throw new KeyNotFoundException ( $ "Could not find a named Scheme called { name } ") ;
167+ return this . colorSchemes . FirstOrDefault ( c => c . Name . Equals ( name ) )
168+ ?? throw new KeyNotFoundException ( $ "Could not find a named ColorScheme called { name } ") ;
172169 }
173170}
0 commit comments