Skip to content

Commit

Permalink
Merge pull request #2385 from BDisp/v2_layout-improvements
Browse files Browse the repository at this point in the history
Fixes #2358 - BREAKING CHANGE: Pos.Combine is incorrect for scenarios involving PosAbsolute.
  • Loading branch information
tig authored Mar 7, 2023
2 parents 02791bc + 5ec653a commit b7d206b
Show file tree
Hide file tree
Showing 39 changed files with 1,771 additions and 1,520 deletions.
26 changes: 13 additions & 13 deletions Terminal.Gui/Configuration/ConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace Terminal.Gui.Configuration {
/// 3. Application configuration found in the applications's resources (<c>Resources/config.json</c>).
/// </para>
/// <para>
/// 4. Global configuration found in the the user's home directory (<c>~/.tui/config.json</c>).
/// 4. Global configuration found in the user's home directory (<c>~/.tui/config.json</c>).
/// </para>
/// <para>
/// 5. Global configuration found in the directory the app was launched from (<c>./.tui/config.json</c>).
Expand All @@ -63,7 +63,7 @@ public static partial class ConfigurationManager {
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
WriteIndented = true,
Converters = {
// No need to set converterss - the ConfigRootConverter uses property attributes apply the correct
// No need to set converters - the ConfigRootConverter uses property attributes apply the correct
// Converter.
},
};
Expand Down Expand Up @@ -196,7 +196,7 @@ public bool Apply ()
/// </summary>
/// <remarks>
/// Is <see langword="null"/> until <see cref="Reset"/> is called. Gets set to a new instance by
/// deserializtion (see <see cref="Load"/>).
/// deserialization (see <see cref="Load"/>).
/// </remarks>
private static SettingsScope? _settings;

Expand All @@ -223,14 +223,14 @@ public static SettingsScope? Settings {
public static ThemeManager? Themes => ThemeManager.Instance;

/// <summary>
/// Aplication-specific configuration settings scope.
/// Application-specific configuration settings scope.
/// </summary>
[SerializableConfigurationProperty (Scope = typeof (SettingsScope), OmitClassName = true), JsonPropertyName ("AppSettings")]
public static AppScope? AppSettings { get; set; }

/// <summary>
/// Initializes the internal state of ConfiguraitonManager. Nominally called once as part of application
/// startup to initilaize global state. Also called from some Unit Tests to ensure correctness (e.g. Reset()).
/// Initializes the internal state of ConfigurationManager. Nominally called once as part of application
/// startup to initialize global state. Also called from some Unit Tests to ensure correctness (e.g. Reset()).
/// </summary>
internal static void Initialize ()
{
Expand Down Expand Up @@ -260,7 +260,7 @@ from p in enumerable
select p) {
if (p.GetCustomAttribute (typeof (SerializableConfigurationProperty)) is SerializableConfigurationProperty scp) {
if (p.GetGetMethod (true)!.IsStatic) {
// If the class name is ommited, JsonPropertyName is allowed.
// If the class name is omitted, JsonPropertyName is allowed.
_allConfigProperties!.Add (scp.OmitClassName ? ConfigProperty.GetJsonPropertyName (p) : $"{p.DeclaringType?.Name}.{p.Name}", new ConfigProperty {
PropertyInfo = p,
PropertyValue = null
Expand Down Expand Up @@ -357,7 +357,7 @@ public static void OnUpdated ()
}

/// <summary>
/// Event fired when the configuration has been upddated from a configuration source.
/// Event fired when the configuration has been updated from a configuration source.
/// application.
/// </summary>
public static event Action<ConfigurationManagerEventArgs>? Updated;
Expand All @@ -378,7 +378,7 @@ public static void Reset ()
}

ClearJsonErrors ();

Settings = new SettingsScope ();
ThemeManager.Reset ();
AppSettings = new AppScope ();
Expand All @@ -402,7 +402,7 @@ public static void Reset ()
/// to generate the JSON doc that is embedded into Terminal.Gui (during development).
/// </para>
/// <para>
/// WARNING: The <c>Terminal.Gui.Resources.config.json</c> resource has setting defintions (Themes)
/// WARNING: The <c>Terminal.Gui.Resources.config.json</c> resource has setting definitions (Themes)
/// that are NOT generated by this function. If you use this function to regenerate <c>Terminal.Gui.Resources.config.json</c>,
/// make sure you copy the Theme definitions from the existing <c>Terminal.Gui.Resources.config.json</c> file.
/// </para>
Expand Down Expand Up @@ -455,7 +455,7 @@ public static void OnApplied ()
public static string AppName { get; set; } = Assembly.GetEntryAssembly ()?.FullName?.Split (',') [0]?.Trim ()!;

/// <summary>
/// Describes the location of the configuration files. The constancts can be
/// Describes the location of the configuration files. The constants can be
/// combined (bitwise) to specify multiple locations.
/// </summary>
[Flags]
Expand Down Expand Up @@ -488,7 +488,7 @@ public enum ConfigLocations {
public static ConfigLocations Locations { get; set; } = ConfigLocations.All;

/// <summary>
/// Loads all settings found in the various configuraiton storage locations to
/// Loads all settings found in the various configuration storage locations to
/// the <see cref="ConfigurationManager"/>. Optionally,
/// resets all settings attributed with <see cref="SerializableConfigurationProperty"/> to the defaults.
/// </summary>
Expand All @@ -507,7 +507,7 @@ public static void Load (bool reset = false)
if (Locations == ConfigLocations.All) {
var embeddedStylesResourceName = Assembly.GetEntryAssembly ()?
.GetManifestResourceNames ().FirstOrDefault (x => x.EndsWith (_configFilename));
if (string.IsNullOrEmpty(embeddedStylesResourceName)) {
if (string.IsNullOrEmpty (embeddedStylesResourceName)) {
embeddedStylesResourceName = _configFilename;
}

Expand Down
12 changes: 10 additions & 2 deletions Terminal.Gui/Configuration/Scope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,17 @@ public override scopeT Read (ref Utf8JsonReader reader, Type typeToConvert, Json
}
}
var readHelper = Activator.CreateInstance ((Type?)typeof (ReadHelper<>).MakeGenericType (typeof (scopeT), propertyType!)!, converter) as ReadHelper;
scope! [propertyName].PropertyValue = readHelper?.Read (ref reader, propertyType!, options);
try {
scope! [propertyName].PropertyValue = readHelper?.Read (ref reader, propertyType!, options);
} catch (NotSupportedException e) {
throw new JsonException ($"Error reading property \"{propertyName}\" of type \"{propertyType?.Name}\".", e);
}
} else {
scope! [propertyName].PropertyValue = JsonSerializer.Deserialize (ref reader, propertyType!, options);
try {
scope! [propertyName].PropertyValue = JsonSerializer.Deserialize (ref reader, propertyType!, options);
} catch (Exception ex) {
System.Diagnostics.Debug.WriteLine ($"scopeT Read: {ex}");
}
}
} else {
// It is not a config property. Maybe it's just a property on the Scope with [JsonInclude]
Expand Down
14 changes: 7 additions & 7 deletions Terminal.Gui/Configuration/ThemeScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,21 @@ private ThemeManager () { } // Prevent instantiation outside
/// </summary>
public static ThemeManager Instance { get { return _instance; } }

private static string theme = string.Empty;
private static string _theme = string.Empty;

/// <summary>
/// The currently selected theme. This is the internal version; see <see cref="Theme"/>.
/// </summary>
[JsonInclude, SerializableConfigurationProperty (Scope = typeof (SettingsScope), OmitClassName = true), JsonPropertyName ("Theme")]
internal static string SelectedTheme {
get => theme;
get => _theme;
set {
var oldTheme = theme;
theme = value;
if (oldTheme != theme &&
var oldTheme = _theme;
_theme = value;
if (oldTheme != _theme &&
ConfigurationManager.Settings! ["Themes"]?.PropertyValue is Dictionary<string, ThemeScope> themes &&
themes.ContainsKey (theme)) {
ConfigurationManager.Settings! ["Theme"].PropertyValue = theme;
themes.ContainsKey (_theme)) {
ConfigurationManager.Settings! ["Theme"].PropertyValue = _theme;
Instance.OnThemeChanged (oldTheme);
}
}
Expand Down
5 changes: 0 additions & 5 deletions Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ internal class CursesDriver : ConsoleDriver {
public override int Left => 0;
public override int Top => 0;
public override bool EnableConsoleScrolling { get; set; }
[Obsolete ("This API is deprecated; use EnableConsoleScrolling instead.", false)]
public override bool HeightAsBuffer {
get => EnableConsoleScrolling;
set => EnableConsoleScrolling = value;
}
public override IClipboard Clipboard { get => clipboard; }

CursorVisibility? initialCursorVisibility = null;
Expand Down
5 changes: 0 additions & 5 deletions Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ public Behaviors (bool useFakeClipboard = false, bool fakeClipboardAlwaysThrowsN
public override int Left => 0;
public override int Top => 0;
public override bool EnableConsoleScrolling { get; set; }
[Obsolete ("This API is deprecated; use EnableConsoleScrolling instead.", false)]
public override bool HeightAsBuffer {
get => EnableConsoleScrolling;
set => EnableConsoleScrolling = value;
}
private IClipboard clipboard = null;
public override IClipboard Clipboard => clipboard;

Expand Down
6 changes: 0 additions & 6 deletions Terminal.Gui/ConsoleDrivers/NetDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -621,12 +621,6 @@ internal class NetDriver : ConsoleDriver {
public override int Left => left;
public override int Top => top;
public override bool EnableConsoleScrolling { get; set; }
[Obsolete ("This API is deprecated; use EnableConsoleScrolling instead.", false)]
public override bool HeightAsBuffer {
get => EnableConsoleScrolling;
set => EnableConsoleScrolling = value;
}

public NetWinVTConsole NetWinConsole { get; }
public bool IsWinPlatform { get; }
public override IClipboard Clipboard { get; }
Expand Down
5 changes: 0 additions & 5 deletions Terminal.Gui/ConsoleDrivers/WindowsDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -716,11 +716,6 @@ internal class WindowsDriver : ConsoleDriver {
public override int Left => left;
public override int Top => top;
public override bool EnableConsoleScrolling { get; set; }
[Obsolete ("This API is deprecated; use EnableConsoleScrolling instead.", false)]
public override bool HeightAsBuffer {
get => EnableConsoleScrolling;
set => EnableConsoleScrolling = value;
}
public override IClipboard Clipboard => clipboard;
public override int [,,] Contents => contents;

Expand Down
17 changes: 4 additions & 13 deletions Terminal.Gui/Core/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static Toplevel MdiTop {
/// </para>
/// This API was previously named 'HeightAsBuffer` but was renamed to make its purpose more clear.
/// </remarks>
[SerializableConfigurationProperty (Scope = typeof(SettingsScope))]
[SerializableConfigurationProperty (Scope = typeof (SettingsScope))]
public static bool EnableConsoleScrolling {
get {
if (Driver == null) {
Expand All @@ -150,21 +150,12 @@ public static bool EnableConsoleScrolling {
}
}

/// <summary>
/// This API is deprecated; use <see cref="EnableConsoleScrolling"/> instead.
/// </summary>
[Obsolete ("This API is deprecated; use EnableConsoleScrolling instead.", false)]
public static bool HeightAsBuffer {
get => EnableConsoleScrolling;
set => EnableConsoleScrolling = value;
}

static Key alternateForwardKey = Key.PageDown | Key.CtrlMask;

/// <summary>
/// Alternative key to navigate forwards through views. Ctrl+Tab is the primary key.
/// </summary>
[SerializableConfigurationProperty (Scope = typeof(SettingsScope)), JsonConverter(typeof(KeyJsonConverter))]
[SerializableConfigurationProperty (Scope = typeof (SettingsScope)), JsonConverter (typeof (KeyJsonConverter))]
public static Key AlternateForwardKey {
get => alternateForwardKey;
set {
Expand All @@ -188,7 +179,7 @@ static void OnAlternateForwardKeyChanged (Key oldKey)
/// <summary>
/// Alternative key to navigate backwards through views. Shift+Ctrl+Tab is the primary key.
/// </summary>
[SerializableConfigurationProperty (Scope = typeof(SettingsScope)), JsonConverter (typeof (KeyJsonConverter))]
[SerializableConfigurationProperty (Scope = typeof (SettingsScope)), JsonConverter (typeof (KeyJsonConverter))]
public static Key AlternateBackwardKey {
get => alternateBackwardKey;
set {
Expand All @@ -212,7 +203,7 @@ static void OnAlternateBackwardKeyChanged (Key oldKey)
/// <summary>
/// Gets or sets the key to quit the application.
/// </summary>
[SerializableConfigurationProperty (Scope = typeof(SettingsScope)), JsonConverter (typeof (KeyJsonConverter))]
[SerializableConfigurationProperty (Scope = typeof (SettingsScope)), JsonConverter (typeof (KeyJsonConverter))]
public static Key QuitKey {
get => quitKey;
set {
Expand Down
3 changes: 2 additions & 1 deletion Terminal.Gui/Core/Autocomplete/Autocomplete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private void ManipulatePopup ()
}

if (!Visible && popup != null) {
top.Remove (popup);
top?.Remove (popup);
popup.Dispose ();
popup = null;
}
Expand Down Expand Up @@ -323,6 +323,7 @@ public virtual bool ProcessKey (KeyEvent kb)
{
if (IsWordChar ((char)kb.Key)) {
Visible = true;
ManipulatePopup ();
closed = false;
return false;
}
Expand Down
Loading

0 comments on commit b7d206b

Please sign in to comment.