From 7270c9f35d392e8f26bf2b3f53df810e48da9324 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Sat, 19 Nov 2022 00:47:04 +0800 Subject: [PATCH] Display current time in time/date format combobox --- Flow.Launcher/SettingWindow.xaml | 8 ++-- Flow.Launcher/SettingWindow.xaml.cs | 11 +++++ .../ViewModel/SettingWindowViewModel.cs | 44 ++++++++++++++++++- 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 5584983a9..6e2aa590c 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -2169,8 +2169,8 @@ Margin="0,0,18,0" VerticalAlignment="Center" FontSize="14" - ItemsSource="{Binding TimeFormatList}" - SelectedValue="{Binding Settings.TimeFormat}" + ItemsSource="{Binding TimeFormatDisplayList}" + SelectedIndex="{Binding TimeFormatIndex, Mode=OneTime}" SelectionChanged="PreviewClockAndDate" /> x.Equals(Settings.TimeFormat))) >= 0 ? tmp : 0; + DateFormatIndex = (tmp = DateFormatList.FindIndex(x => x.Equals(Settings.DateFormat))) >= 0 ? tmp : 0; + + TimeFormatDisplayList = TimeFormatList.Select(x => DateTime.Now.ToString(x, CultureInfo.CurrentCulture)).ToList(); + DateFormatDisplayList = DateFormatList.Select(x => DateTime.Now.ToString(x, CultureInfo.CurrentCulture)).ToList(); + UpdateSettingsDateTimeFormat(); // just in case something wrong } public Settings Settings { get; set; } @@ -422,8 +430,6 @@ namespace Flow.Launcher.ViewModel } } - - public class SearchWindowPosition { public string Display { get; set; } @@ -470,6 +476,40 @@ namespace Flow.Launcher.ViewModel "dd', 'MMMM" }; + public int TimeFormatIndex { get; set; } = 0; + + public int DateFormatIndex { get; set; } = 0; + + public List TimeFormatDisplayList { get; set; } = null; + + public List DateFormatDisplayList { get; set; } = null; + + public void UpdateSettingsDateTimeFormat() + { + Settings.DateFormat = DateFormatList[DateFormatIndex]; + Settings.TimeFormat = TimeFormatList[TimeFormatIndex]; + } + + public void UpdateDateTimeDisplayList(int dateIndex, int timeIndex) + { + if (dateIndex == -1 || timeIndex == -1) + return; + DateFormatIndex = dateIndex; + TimeFormatIndex = timeIndex; + + for (int i = 0; i < TimeFormatList.Count; ++i) + { + TimeFormatDisplayList[i] = DateTime.Now.ToString(TimeFormatList[i], CultureInfo.CurrentCulture); + } + + for (int i = 0; i < DateFormatList.Count; ++i) + { + DateFormatDisplayList[i] = DateTime.Now.ToString(DateFormatList[i], CultureInfo.CurrentCulture); + } + + UpdateSettingsDateTimeFormat(); + } + public double WindowWidthSize { get => Settings.WindowSize;