Procházet zdrojové kódy

Changed order of loading configs

Tig před 8 měsíci
rodič
revize
fa040870a9

+ 12 - 12
Terminal.Gui/Configuration/ConfigLocations.cs

@@ -23,34 +23,34 @@ public enum ConfigLocations
     Default = 0b_0000_0001,
 
     /// <summary>
-    ///     Global settings in the current directory (e.g. <c>./.tui/config.json</c>).
+    ///     App resources (e.g. <c>MyApp.Resources.config.json</c>).
     /// </summary>
-    GlobalCurrent = 0b_0000_0010,
+    AppResources = 0b_0000_0010,
 
     /// <summary>
-    ///    Global settings in the home directory (e.g. <c>~/.tui/config.json</c>).
+    ///     Settings in the <see cref="ConfigurationManager.RuntimeConfig"/> static property.
     /// </summary>
-    GlobalHome = 0b_0000_0100,
+    Runtime = 0b_0000_0100,
 
     /// <summary>
-    ///     App resources (e.g. <c>MyApp.Resources.config.json</c>).
+    ///     Global settings in the current directory (e.g. <c>./.tui/config.json</c>).
     /// </summary>
-    AppResources = 0b_0000_1000,
+    GlobalCurrent = 0b_0000_1000,
 
     /// <summary>
-    ///     App settings in the current directory (e.g. <c>./.tui/MyApp.config.json</c>).
+    ///    Global settings in the home directory (e.g. <c>~/.tui/config.json</c>).
     /// </summary>
-    AppCurrent = 0b_0001_0000,
+    GlobalHome = 0b_0001_0000,
 
     /// <summary>
-    ///     App settings in the home directory (e.g. <c>~/.tui/MyApp.config.json</c>).
+    ///     App settings in the current directory (e.g. <c>./.tui/MyApp.config.json</c>).
     /// </summary>
-    AppHome = 0b_0010_0000,
+    AppCurrent = 0b_0010_0000,
 
     /// <summary>
-    ///     Settings in the <see cref="ConfigurationManager.RuntimeConfig"/> static property.
+    ///     App settings in the home directory (e.g. <c>~/.tui/MyApp.config.json</c>).
     /// </summary>
-    Runtime = 0b_0100_0000,
+    AppHome = 0b_0100_0000,
 
     /// <summary>This constant is a combination of all locations</summary>
     All = 0b_1111_1111

+ 16 - 15
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";
     }
 

+ 7 - 7
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.