diff --git a/Terminal.Gui/Configuration/ConfigLocations.cs b/Terminal.Gui/Configuration/ConfigLocations.cs index c2499c6c3..b5469c1c9 100644 --- a/Terminal.Gui/Configuration/ConfigLocations.cs +++ b/Terminal.Gui/Configuration/ConfigLocations.cs @@ -22,35 +22,35 @@ public enum ConfigLocations /// Default = 0b_0000_0001, - /// - /// Global settings in the current directory (e.g. ./.tui/config.json). - /// - GlobalCurrent = 0b_0000_0010, - - /// - /// Global settings in the home directory (e.g. ~/.tui/config.json). - /// - GlobalHome = 0b_0000_0100, - /// /// App resources (e.g. MyApp.Resources.config.json). /// - AppResources = 0b_0000_1000, - - /// - /// App settings in the current directory (e.g. ./.tui/MyApp.config.json). - /// - AppCurrent = 0b_0001_0000, - - /// - /// App settings in the home directory (e.g. ~/.tui/MyApp.config.json). - /// - AppHome = 0b_0010_0000, + AppResources = 0b_0000_0010, /// /// Settings in the static property. /// - Runtime = 0b_0100_0000, + Runtime = 0b_0000_0100, + + /// + /// Global settings in the current directory (e.g. ./.tui/config.json). + /// + GlobalCurrent = 0b_0000_1000, + + /// + /// Global settings in the home directory (e.g. ~/.tui/config.json). + /// + GlobalHome = 0b_0001_0000, + + /// + /// App settings in the current directory (e.g. ./.tui/MyApp.config.json). + /// + AppCurrent = 0b_0010_0000, + + /// + /// App settings in the home directory (e.g. ~/.tui/MyApp.config.json). + /// + AppHome = 0b_0100_0000, /// This constant is a combination of all locations All = 0b_1111_1111 diff --git a/Terminal.Gui/Configuration/ConfigurationManager.cs b/Terminal.Gui/Configuration/ConfigurationManager.cs index 1f4e6a061..473f1bf65 100644 --- a/Terminal.Gui/Configuration/ConfigurationManager.cs +++ b/Terminal.Gui/Configuration/ConfigurationManager.cs @@ -250,16 +250,6 @@ public static class ConfigurationManager Reset (); } - if (Locations.HasFlag (ConfigLocations.GlobalCurrent)) - { - Settings?.Update ($"./.tui/{_configFilename}", ConfigLocations.GlobalCurrent); - } - - if (Locations.HasFlag (ConfigLocations.GlobalHome)) - { - Settings?.Update ($"~/.tui/{_configFilename}", ConfigLocations.GlobalHome); - } - if (Locations.HasFlag (ConfigLocations.AppResources)) { string? embeddedStylesResourceName = Assembly.GetEntryAssembly () @@ -275,6 +265,22 @@ public static class ConfigurationManager Settings?.UpdateFromResource (Assembly.GetEntryAssembly ()!, embeddedStylesResourceName!, ConfigLocations.AppResources); } + if (Locations.HasFlag (ConfigLocations.Runtime) && !string.IsNullOrEmpty (RuntimeConfig)) + { + Settings?.Update (RuntimeConfig, "ConfigurationManager.RuntimeConfig", ConfigLocations.Runtime); + } + + if (Locations.HasFlag (ConfigLocations.GlobalCurrent)) + { + Settings?.Update ($"./.tui/{_configFilename}", ConfigLocations.GlobalCurrent); + } + + if (Locations.HasFlag (ConfigLocations.GlobalHome)) + { + Settings?.Update ($"~/.tui/{_configFilename}", ConfigLocations.GlobalHome); + } + + if (Locations.HasFlag (ConfigLocations.AppCurrent)) { Settings?.Update ($"./.tui/{AppName}.{_configFilename}", ConfigLocations.AppCurrent); @@ -285,11 +291,6 @@ public static class ConfigurationManager Settings?.Update ($"~/.tui/{AppName}.{_configFilename}", ConfigLocations.AppHome); } - if (Locations.HasFlag (ConfigLocations.Runtime) && !string.IsNullOrEmpty (RuntimeConfig)) - { - Settings?.Update (RuntimeConfig, "ConfigurationManager.RuntimeConfig", ConfigLocations.Runtime); - } - ThemeManager.SelectedTheme = Settings!["Theme"].PropertyValue as string ?? "Default"; } diff --git a/docfx/docs/config.md b/docfx/docs/config.md index e593f921f..d806e7f3e 100644 --- a/docfx/docs/config.md +++ b/docfx/docs/config.md @@ -12,19 +12,19 @@ Settings that will apply to all applications (global settings) reside in files n Settings are applied using the following precedence (higher precedence settings overwrite lower precedence settings): -1. @Terminal.Gui.ConfigLocations.Runtime - Settings stored in the @Terminal.Gui.ConfigurationManager.RuntimeConfig static property --- Hightest precedence. +1. @Terminal.Gui.ConfigLocations.Default - Default settings in the Terminal.Gui assembly -- Lowest precedence. -2. @Terminal.Gui.ConfigLocations.AppHome - App-specific settings in the users's home directory (`~/.tui/appname.config.json`). +2. @Terminal.Gui.ConfigLocations.Runtime - Settings stored in the @Terminal.Gui.ConfigurationManager.RuntimeConfig static property. -3. @Terminal.Gui.ConfigLocations.AppCurrent - App-specific settings in the directory the app was launched from (`./.tui/appname.config.json`). +3. @Terminal.Gui.ConfigLocations.AppResources - App settings in app resources (`Resources/config.json`). -4. @Terminal.Gui.ConfigLocations.AppResources - App settings in app resources (`Resources/config.json`). +4. @Terminal.Gui.ConfigLocations.AppHome - App-specific settings in the users's home directory (`~/.tui/appname.config.json`). -5. @Terminal.Gui.ConfigLocations.GlobalHome - Global settings in the the user's home directory (`~/.tui/config.json`). +5. @Terminal.Gui.ConfigLocations.AppCurrent - App-specific settings in the directory the app was launched from (`./.tui/appname.config.json`). -6. @Terminal.Gui.ConfigLocations.GlobalCurrent - Global settings in the directory the app was launched from (`./.tui/config.json`). +6. @Terminal.Gui.ConfigLocations.GlobalHome - Global settings in the the user's home directory (`~/.tui/config.json`). -7. @Terminal.Gui.ConfigLocations.Default - Default settings in the Terminal.Gui assembly -- Lowest precedence. +7. @Terminal.Gui.ConfigLocations.GlobalCurrent - Global settings in the directory the app was launched from (`./.tui/config.json`) --- Hightest precedence. The `UI Catalog` application provides an example of how to use the [`ConfigurationManager`](~/api/Terminal.Gui.ConfigurationManager.yml) class to load and save configuration files. The `Configuration Editor` scenario provides an editor that allows users to edit the configuration files. UI Catalog also uses a file system watcher to detect changes to the configuration files to tell [`ConfigurationManager`](~/api/Terminal.Gui.ConfigurationManager.yml) to reload them; allowing users to change settings without having to restart the application.