Skip to content

Commit fa04087

Browse files
committed
Changed order of loading configs
1 parent 4ad5b05 commit fa04087

File tree

3 files changed

+35
-34
lines changed

3 files changed

+35
-34
lines changed

Terminal.Gui/Configuration/ConfigLocations.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,34 @@ public enum ConfigLocations
2323
Default = 0b_0000_0001,
2424

2525
/// <summary>
26-
/// Global settings in the current directory (e.g. <c>./.tui/config.json</c>).
26+
/// App resources (e.g. <c>MyApp.Resources.config.json</c>).
2727
/// </summary>
28-
GlobalCurrent = 0b_0000_0010,
28+
AppResources = 0b_0000_0010,
2929

3030
/// <summary>
31-
/// Global settings in the home directory (e.g. <c>~/.tui/config.json</c>).
31+
/// Settings in the <see cref="ConfigurationManager.RuntimeConfig"/> static property.
3232
/// </summary>
33-
GlobalHome = 0b_0000_0100,
33+
Runtime = 0b_0000_0100,
3434

3535
/// <summary>
36-
/// App resources (e.g. <c>MyApp.Resources.config.json</c>).
36+
/// Global settings in the current directory (e.g. <c>./.tui/config.json</c>).
3737
/// </summary>
38-
AppResources = 0b_0000_1000,
38+
GlobalCurrent = 0b_0000_1000,
3939

4040
/// <summary>
41-
/// App settings in the current directory (e.g. <c>./.tui/MyApp.config.json</c>).
41+
/// Global settings in the home directory (e.g. <c>~/.tui/config.json</c>).
4242
/// </summary>
43-
AppCurrent = 0b_0001_0000,
43+
GlobalHome = 0b_0001_0000,
4444

4545
/// <summary>
46-
/// App settings in the home directory (e.g. <c>~/.tui/MyApp.config.json</c>).
46+
/// App settings in the current directory (e.g. <c>./.tui/MyApp.config.json</c>).
4747
/// </summary>
48-
AppHome = 0b_0010_0000,
48+
AppCurrent = 0b_0010_0000,
4949

5050
/// <summary>
51-
/// Settings in the <see cref="ConfigurationManager.RuntimeConfig"/> static property.
51+
/// App settings in the home directory (e.g. <c>~/.tui/MyApp.config.json</c>).
5252
/// </summary>
53-
Runtime = 0b_0100_0000,
53+
AppHome = 0b_0100_0000,
5454

5555
/// <summary>This constant is a combination of all locations</summary>
5656
All = 0b_1111_1111

Terminal.Gui/Configuration/ConfigurationManager.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -250,16 +250,6 @@ public static void Load (bool reset = false)
250250
Reset ();
251251
}
252252

253-
if (Locations.HasFlag (ConfigLocations.GlobalCurrent))
254-
{
255-
Settings?.Update ($"./.tui/{_configFilename}", ConfigLocations.GlobalCurrent);
256-
}
257-
258-
if (Locations.HasFlag (ConfigLocations.GlobalHome))
259-
{
260-
Settings?.Update ($"~/.tui/{_configFilename}", ConfigLocations.GlobalHome);
261-
}
262-
263253
if (Locations.HasFlag (ConfigLocations.AppResources))
264254
{
265255
string? embeddedStylesResourceName = Assembly.GetEntryAssembly ()
@@ -275,6 +265,22 @@ public static void Load (bool reset = false)
275265
Settings?.UpdateFromResource (Assembly.GetEntryAssembly ()!, embeddedStylesResourceName!, ConfigLocations.AppResources);
276266
}
277267

268+
if (Locations.HasFlag (ConfigLocations.Runtime) && !string.IsNullOrEmpty (RuntimeConfig))
269+
{
270+
Settings?.Update (RuntimeConfig, "ConfigurationManager.RuntimeConfig", ConfigLocations.Runtime);
271+
}
272+
273+
if (Locations.HasFlag (ConfigLocations.GlobalCurrent))
274+
{
275+
Settings?.Update ($"./.tui/{_configFilename}", ConfigLocations.GlobalCurrent);
276+
}
277+
278+
if (Locations.HasFlag (ConfigLocations.GlobalHome))
279+
{
280+
Settings?.Update ($"~/.tui/{_configFilename}", ConfigLocations.GlobalHome);
281+
}
282+
283+
278284
if (Locations.HasFlag (ConfigLocations.AppCurrent))
279285
{
280286
Settings?.Update ($"./.tui/{AppName}.{_configFilename}", ConfigLocations.AppCurrent);
@@ -285,11 +291,6 @@ public static void Load (bool reset = false)
285291
Settings?.Update ($"~/.tui/{AppName}.{_configFilename}", ConfigLocations.AppHome);
286292
}
287293

288-
if (Locations.HasFlag (ConfigLocations.Runtime) && !string.IsNullOrEmpty (RuntimeConfig))
289-
{
290-
Settings?.Update (RuntimeConfig, "ConfigurationManager.RuntimeConfig", ConfigLocations.Runtime);
291-
}
292-
293294
ThemeManager.SelectedTheme = Settings!["Theme"].PropertyValue as string ?? "Default";
294295
}
295296

docfx/docs/config.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ Settings that will apply to all applications (global settings) reside in files n
1212

1313
Settings are applied using the following precedence (higher precedence settings overwrite lower precedence settings):
1414

15-
1. @Terminal.Gui.ConfigLocations.Runtime - Settings stored in the @Terminal.Gui.ConfigurationManager.RuntimeConfig static property --- Hightest precedence.
15+
1. @Terminal.Gui.ConfigLocations.Default - Default settings in the Terminal.Gui assembly -- Lowest precedence.
1616

17-
2. @Terminal.Gui.ConfigLocations.AppHome - App-specific settings in the users's home directory (`~/.tui/appname.config.json`).
17+
2. @Terminal.Gui.ConfigLocations.Runtime - Settings stored in the @Terminal.Gui.ConfigurationManager.RuntimeConfig static property.
1818

19-
3. @Terminal.Gui.ConfigLocations.AppCurrent - App-specific settings in the directory the app was launched from (`./.tui/appname.config.json`).
19+
3. @Terminal.Gui.ConfigLocations.AppResources - App settings in app resources (`Resources/config.json`).
2020

21-
4. @Terminal.Gui.ConfigLocations.AppResources - App settings in app resources (`Resources/config.json`).
21+
4. @Terminal.Gui.ConfigLocations.AppHome - App-specific settings in the users's home directory (`~/.tui/appname.config.json`).
2222

23-
5. @Terminal.Gui.ConfigLocations.GlobalHome - Global settings in the the user's home directory (`~/.tui/config.json`).
23+
5. @Terminal.Gui.ConfigLocations.AppCurrent - App-specific settings in the directory the app was launched from (`./.tui/appname.config.json`).
2424

25-
6. @Terminal.Gui.ConfigLocations.GlobalCurrent - Global settings in the directory the app was launched from (`./.tui/config.json`).
25+
6. @Terminal.Gui.ConfigLocations.GlobalHome - Global settings in the the user's home directory (`~/.tui/config.json`).
2626

27-
7. @Terminal.Gui.ConfigLocations.Default - Default settings in the Terminal.Gui assembly -- Lowest precedence.
27+
7. @Terminal.Gui.ConfigLocations.GlobalCurrent - Global settings in the directory the app was launched from (`./.tui/config.json`) --- Hightest precedence.
2828

2929
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.
3030

0 commit comments

Comments
 (0)