Skip to content

Commit 7270c9f

Browse files
Display current time in time/date format combobox
1 parent 3426c94 commit 7270c9f

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

Flow.Launcher/SettingWindow.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,8 +2169,8 @@
21692169
Margin="0,0,18,0"
21702170
VerticalAlignment="Center"
21712171
FontSize="14"
2172-
ItemsSource="{Binding TimeFormatList}"
2173-
SelectedValue="{Binding Settings.TimeFormat}"
2172+
ItemsSource="{Binding TimeFormatDisplayList}"
2173+
SelectedIndex="{Binding TimeFormatIndex, Mode=OneTime}"
21742174
SelectionChanged="PreviewClockAndDate" />
21752175
<ui:ToggleSwitch
21762176
IsOn="{Binding UseClock, Mode=TwoWay}"
@@ -2207,8 +2207,8 @@
22072207
Margin="0,0,18,0"
22082208
VerticalAlignment="Center"
22092209
FontSize="14"
2210-
ItemsSource="{Binding DateFormatList}"
2211-
SelectedValue="{Binding Settings.DateFormat}"
2210+
ItemsSource="{Binding DateFormatDisplayList}"
2211+
SelectedIndex="{Binding DateFormatIndex, Mode=OneTime}"
22122212
SelectionChanged="PreviewClockAndDate" />
22132213
<ui:ToggleSwitch
22142214
IsOn="{Binding UseDate, Mode=TwoWay}"

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Flow.Launcher.Plugin;
88
using Flow.Launcher.Plugin.SharedCommands;
99
using Flow.Launcher.ViewModel;
10+
using Microsoft.VisualBasic;
1011
using ModernWpf;
1112
using ModernWpf.Controls;
1213
using System;
@@ -516,6 +517,15 @@ private void PluginStore_OnKeyDown(object sender, KeyEventArgs e)
516517

517518
private void PreviewClockAndDate(object sender, RoutedEventArgs e)
518519
{
520+
if (DateFormat != null && TimeFormat != null)
521+
{
522+
viewModel.UpdateDateTimeDisplayList(DateFormat.SelectedIndex, TimeFormat.SelectedIndex);
523+
DateFormat.Items.Refresh();
524+
TimeFormat.Items.Refresh(); // selected = -1
525+
// todo avoid recursion
526+
DateFormat.SelectedIndex = viewModel.DateFormatIndex;
527+
TimeFormat.SelectedIndex = viewModel.TimeFormatIndex;
528+
}
519529
ClockDisplay();
520530
}
521531

@@ -556,6 +566,7 @@ public void InitializePosition()
556566
}
557567
WindowState = settings.SettingWindowState;
558568
}
569+
559570
public double WindowLeft()
560571
{
561572
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using Flow.Launcher.Plugin.SharedModels;
2222
using System.Collections.ObjectModel;
2323
using CommunityToolkit.Mvvm.Input;
24+
using System.Globalization;
2425

2526
namespace Flow.Launcher.ViewModel
2627
{
@@ -48,6 +49,13 @@ public SettingWindowViewModel(Updater updater, IPortable portable)
4849
break;
4950
}
5051
};
52+
int tmp = 0;
53+
TimeFormatIndex = (tmp = TimeFormatList.FindIndex(x => x.Equals(Settings.TimeFormat))) >= 0 ? tmp : 0;
54+
DateFormatIndex = (tmp = DateFormatList.FindIndex(x => x.Equals(Settings.DateFormat))) >= 0 ? tmp : 0;
55+
56+
TimeFormatDisplayList = TimeFormatList.Select(x => DateTime.Now.ToString(x, CultureInfo.CurrentCulture)).ToList();
57+
DateFormatDisplayList = DateFormatList.Select(x => DateTime.Now.ToString(x, CultureInfo.CurrentCulture)).ToList();
58+
UpdateSettingsDateTimeFormat(); // just in case something wrong
5159
}
5260

5361
public Settings Settings { get; set; }
@@ -422,8 +430,6 @@ public List<ColorScheme> ColorSchemes
422430
}
423431
}
424432

425-
426-
427433
public class SearchWindowPosition
428434
{
429435
public string Display { get; set; }
@@ -470,6 +476,40 @@ public List<SearchWindowPosition> SearchWindowPositions
470476
"dd', 'MMMM"
471477
};
472478

479+
public int TimeFormatIndex { get; set; } = 0;
480+
481+
public int DateFormatIndex { get; set; } = 0;
482+
483+
public List<string> TimeFormatDisplayList { get; set; } = null;
484+
485+
public List<string> DateFormatDisplayList { get; set; } = null;
486+
487+
public void UpdateSettingsDateTimeFormat()
488+
{
489+
Settings.DateFormat = DateFormatList[DateFormatIndex];
490+
Settings.TimeFormat = TimeFormatList[TimeFormatIndex];
491+
}
492+
493+
public void UpdateDateTimeDisplayList(int dateIndex, int timeIndex)
494+
{
495+
if (dateIndex == -1 || timeIndex == -1)
496+
return;
497+
DateFormatIndex = dateIndex;
498+
TimeFormatIndex = timeIndex;
499+
500+
for (int i = 0; i < TimeFormatList.Count; ++i)
501+
{
502+
TimeFormatDisplayList[i] = DateTime.Now.ToString(TimeFormatList[i], CultureInfo.CurrentCulture);
503+
}
504+
505+
for (int i = 0; i < DateFormatList.Count; ++i)
506+
{
507+
DateFormatDisplayList[i] = DateTime.Now.ToString(DateFormatList[i], CultureInfo.CurrentCulture);
508+
}
509+
510+
UpdateSettingsDateTimeFormat();
511+
}
512+
473513
public double WindowWidthSize
474514
{
475515
get => Settings.WindowSize;

0 commit comments

Comments
 (0)