diff --git a/src/client/spark/Modules/Trading/PNL/Settings/PNLSettings.cs b/src/client/spark/Modules/Trading/PNL/Settings/PNLSettings.cs index f0cf93eca..2951a8289 100644 --- a/src/client/spark/Modules/Trading/PNL/Settings/PNLSettings.cs +++ b/src/client/spark/Modules/Trading/PNL/Settings/PNLSettings.cs @@ -9,9 +9,13 @@ using mbts.user.settings; using ProtoBuf; +using Spark.Core; + using System; using System.Collections.Generic; +using System.IO; using System.Linq; +using System.Reflection; using System.Windows; using System.Windows.Media; @@ -110,7 +114,22 @@ namespace bts.shell.pnl { GridSettings _grid_backing; PNLCellAppearanceProto _grid_cell_appearance_backing; - public static PNLSettings Default => + static LazyOnce defaultProfile; + + static PNLSettings() { + defaultProfile = new(() => { + var binDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + var store = ShellWindowSettingsDirectoryStore.Create( + Path.Combine(binDir, "ShellWindowSettings", "Pnl"), "*." + mbts.spark.UserSettings.FileExtensions.PNL); + return store.Profiles.GetValueOrDefault("Default") + ?? store.Profiles.Values.FirstOrDefault() + ?? historicDefault; + }); + } + + public static PNLSettings Default => defaultProfile.Value; + + static PNLSettings historicDefault => new PNLSettings { _sorting_criteria = new[] { new SortingCriteria(nameof(Columns.Account), true), diff --git a/src/client/spark/ShellWindowSettings/Pnl/Default.pnl b/src/client/spark/ShellWindowSettings/Pnl/Default.pnl new file mode 100644 index 000000000..59cc8286d Binary files /dev/null and b/src/client/spark/ShellWindowSettings/Pnl/Default.pnl differ diff --git a/src/client/spark/ShellWindowSettingsDirectoryStore.cs b/src/client/spark/ShellWindowSettingsDirectoryStore.cs new file mode 100644 index 000000000..6439c9aec --- /dev/null +++ b/src/client/spark/ShellWindowSettingsDirectoryStore.cs @@ -0,0 +1,59 @@ +#nullable enable +using bts.collections; + +using Spark.Core; +using Spark.Core.Protobuf; + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace bts.shell; + +static class ShellWindowSettingsDirectoryStore { + public static ShellWindowSettingsDirectoryStore Create(string path, string searchPattern) => + new(path, searchPattern); +} + +class ShellWindowSettingsDirectoryStore { + readonly LazyOnce> profiles; + + public ShellWindowSettingsDirectoryStore(string path, string searchPattern) => + profiles = new(() => { + try { + return Directory.EnumerateFiles(path, searchPattern).Select(SingleFileStore.FromPath).ToDictionary(sfs => sfs.Name); + } catch (Exception ex) { + Log.Ui.error($"Failed to enumerate {typeof(T)} settings files in '{path}'. {ex}"); + } + return new(0); + }); + + public IReadOnlyDictionary Profiles => + MappedDictionary.create(profiles.Value, sfs => sfs.Value); + + class SingleFileStore { + LazyOnce value; + + public SingleFileStore(string path) { + Name = Path.GetFileNameWithoutExtension(path); + value = new(LoadValue); + + T? LoadValue() { + try { + using var f = File.OpenRead(path); + return ProtobufSerializationHelper.deserialize(f); + } catch (Exception ex) { + Log.Ui.error($"Failed to load {typeof(T)} file '{path}'. {ex}"); + } + return default; + } + } + + public static SingleFileStore FromPath(string path) => + new(path); + + public string Name { get; } + public T? Value => value.Value; + } +} diff --git a/src/client/spark/Spark.csproj b/src/client/spark/Spark.csproj index a1203d145..479ed7763 100644 --- a/src/client/spark/Spark.csproj +++ b/src/client/spark/Spark.csproj @@ -77,6 +77,10 @@ + + + + diff --git a/src/client/spark/core/FontsAndColors/BTSColors.cs b/src/client/spark/core/FontsAndColors/BTSColors.cs index 07fa8e843..aa87b6800 100644 --- a/src/client/spark/core/FontsAndColors/BTSColors.cs +++ b/src/client/spark/core/FontsAndColors/BTSColors.cs @@ -254,9 +254,9 @@ namespace mbts.ui { public static class PNL { public static BTSColor foreground => UI.default_foreground; public static BTSColor anchor => Colors.Gold; - public static BTSColor profit => Colors.Green; + public static BTSColor profit => BTSCoreColors.spring_green; public static BTSColor net_zero => BTSCoreColors.gray; - public static BTSColor loss => BTSCoreColors.venetian_red; + public static BTSColor loss => BTSCoreColors.fire_brick; public static BTSColor header_row_background => 0xffaaaaaa; // group background colors public static BTSColor group_row_background1 => 0x19141420; @@ -276,8 +276,8 @@ namespace mbts.ui { } public static Color anchor_color => Colors.Gold; - public static Color profit_color => Colors.Green; - public static Color loss_color => BTSCoreColors.venetian_red; + public static Color profit_color => profit; + public static Color loss_color => loss; public static Color header_row_background_color => 0xffaaaaaa.argb_color(); // group background colors public static Color group_row_background_color1 => group_row_background1; diff --git a/src/client/spark/core/FontsAndColors/BTSCoreColors.cs b/src/client/spark/core/FontsAndColors/BTSCoreColors.cs index 6ee1c203f..5d303a376 100644 --- a/src/client/spark/core/FontsAndColors/BTSCoreColors.cs +++ b/src/client/spark/core/FontsAndColors/BTSCoreColors.cs @@ -83,6 +83,7 @@ public static BTSColor green => 0xff00c000; public static BTSColor green_p_light => 0xff99ee90; public static BTSColor green_dark_light => 0xff255d25; + public static BTSColor spring_green => 0xff00fb76; public static BTSColor light_sea_green => 0xff17b794; public static BTSColor very_light_malachite_green => 0xff52e887; public static BTSColor may_green => 0xff43a23c; @@ -100,6 +101,7 @@ public static BTSColor red_light_dark => 0xffd69a9a; public static BTSColor red_light_dark_saturated => 0xffd67e7e; public static BTSColor permanent_geranium_lake => 0xffde3429; + public static BTSColor fire_brick => 0xffb1373a; public static BTSColor fire_opal => 0xfff05454; public static BTSColor paradise_pink => 0xffe94560; public static BTSColor tulip => 0xffff878d;