Skip to content

Commit 4d2e773

Browse files
author
tznind
committed
More NS fixes
1 parent a73bdaa commit 4d2e773

4 files changed

Lines changed: 43 additions & 43 deletions

File tree

src/ColorSchemeManager.cs

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,66 @@
11
using System.Collections.ObjectModel;
22
using System.Reflection;
3-
using Terminal.Gui;
43
using Terminal.Gui.Drawing;
5-
using TerminalGuiDesigner;
6-
using TerminalGuiDesigner.Operations;
74

85
namespace 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
}

src/UI/Windows/ColorPicker.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/UI/Windows/ColorSchemeEditor.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
// </auto-generated>
99
// -----------------------------------------------------------------------------
1010

11+
using Terminal.Gui.App;
1112
using Terminal.Gui.Drawing;
1213
using Terminal.Gui.ViewBase;
14+
using Terminal.Gui.Views;
1315

1416
namespace TerminalGuiDesigner.UI.Windows;
1517
using System;
@@ -47,51 +49,51 @@ public SchemeEditor(Scheme scheme) {
4749

4850
btnEditNormal.Accepting += (s, e)=>
4951
{
50-
e.Cancel = true;
52+
e.Handled = true;
5153
_result.Normal = PickNewColorsFor(Result.Normal);
5254
SetColorPatches();
5355
};
5456

5557

5658
btnEditHotNormal.Accepting += (s, e)=>
5759
{
58-
e.Cancel = true;
60+
e.Handled = true;
5961
_result.HotNormal = PickNewColorsFor(Result.HotNormal);
6062
SetColorPatches();
6163
};
6264

6365

6466
btnEditFocus.Accepting += (s, e)=>{
65-
e.Cancel = true;
67+
e.Handled = true;
6668
_result.Focus = PickNewColorsFor(Result.Focus);
6769
SetColorPatches();
6870
};
6971

7072

7173
btnEditHotFocus.Accepting += (s, e)=>
7274
{
73-
e.Cancel = true;
75+
e.Handled = true;
7476
_result.HotFocus = PickNewColorsFor(Result.HotFocus);
7577
SetColorPatches();
7678
};
7779

7880

7981
btnEditDisabled.Accepting += (s, e)=>{
80-
e.Cancel = true;
82+
e.Handled = true;
8183
_result.Disabled = PickNewColorsFor(Result.Disabled);
8284
SetColorPatches();
8385
};
8486

8587
btnCancel.Accepting += (s, e)=>
8688
{
87-
e.Cancel = true;
89+
e.Handled = true;
8890
Cancelled = true;
8991
Application.RequestStop();
9092
};
9193

9294
btnOk.Accepting += (s, e)=>
9395
{
94-
e.Cancel = true;
96+
e.Handled = true;
9597
Cancelled = false;
9698
Application.RequestStop();
9799
};
@@ -138,6 +140,6 @@ private void SetColorPatches()
138140

139141
private void SetColor(Label label, Color color)
140142
{
141-
label.Scheme = new Scheme{Normal = new Terminal.Gui.Drawing.Attribute(color,color)};
143+
label.SetScheme(new Scheme{Normal = new Terminal.Gui.Drawing.Attribute(color,color)});
142144
}
143145
}

src/UI/Windows/Modals.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Diagnostics.CodeAnalysis;
22
using System.Text;
33
using Terminal.Gui;
4+
using Terminal.Gui.App;
45
using Terminal.Gui.Drivers;
56
using Terminal.Gui.Input;
67
using YamlDotNet.Core.Tokens;

0 commit comments

Comments
 (0)