mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Changed order of loading configs
This commit is contained in:
@@ -22,35 +22,35 @@ public enum ConfigLocations
|
||||
/// </summary>
|
||||
Default = 0b_0000_0001,
|
||||
|
||||
/// <summary>
|
||||
/// Global settings in the current directory (e.g. <c>./.tui/config.json</c>).
|
||||
/// </summary>
|
||||
GlobalCurrent = 0b_0000_0010,
|
||||
|
||||
/// <summary>
|
||||
/// Global settings in the home directory (e.g. <c>~/.tui/config.json</c>).
|
||||
/// </summary>
|
||||
GlobalHome = 0b_0000_0100,
|
||||
|
||||
/// <summary>
|
||||
/// App resources (e.g. <c>MyApp.Resources.config.json</c>).
|
||||
/// </summary>
|
||||
AppResources = 0b_0000_1000,
|
||||
|
||||
/// <summary>
|
||||
/// App settings in the current directory (e.g. <c>./.tui/MyApp.config.json</c>).
|
||||
/// </summary>
|
||||
AppCurrent = 0b_0001_0000,
|
||||
|
||||
/// <summary>
|
||||
/// App settings in the home directory (e.g. <c>~/.tui/MyApp.config.json</c>).
|
||||
/// </summary>
|
||||
AppHome = 0b_0010_0000,
|
||||
AppResources = 0b_0000_0010,
|
||||
|
||||
/// <summary>
|
||||
/// Settings in the <see cref="ConfigurationManager.RuntimeConfig"/> static property.
|
||||
/// </summary>
|
||||
Runtime = 0b_0100_0000,
|
||||
Runtime = 0b_0000_0100,
|
||||
|
||||
/// <summary>
|
||||
/// Global settings in the current directory (e.g. <c>./.tui/config.json</c>).
|
||||
/// </summary>
|
||||
GlobalCurrent = 0b_0000_1000,
|
||||
|
||||
/// <summary>
|
||||
/// Global settings in the home directory (e.g. <c>~/.tui/config.json</c>).
|
||||
/// </summary>
|
||||
GlobalHome = 0b_0001_0000,
|
||||
|
||||
/// <summary>
|
||||
/// App settings in the current directory (e.g. <c>./.tui/MyApp.config.json</c>).
|
||||
/// </summary>
|
||||
AppCurrent = 0b_0010_0000,
|
||||
|
||||
/// <summary>
|
||||
/// App settings in the home directory (e.g. <c>~/.tui/MyApp.config.json</c>).
|
||||
/// </summary>
|
||||
AppHome = 0b_0100_0000,
|
||||
|
||||
/// <summary>This constant is a combination of all locations</summary>
|
||||
All = 0b_1111_1111
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user