Skip to content

Commit e606356

Browse files
Separate date/time format list refresh
1 parent bde471a commit e606356

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

Flow.Launcher/SettingWindow.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,7 +2181,7 @@
21812181
FontSize="14"
21822182
ItemsSource="{Binding TimeFormatDisplayList}"
21832183
SelectedIndex="{Binding TimeFormatIndex, Mode=OneWayToSource}"
2184-
DropDownOpened="RefreshDateTimeList"/>
2184+
DropDownOpened="RefreshTimeList"/>
21852185
<ui:ToggleSwitch
21862186
IsOn="{Binding UseClock, Mode=TwoWay}"
21872187
OffContent="{DynamicResource disable}"
@@ -2218,7 +2218,7 @@
22182218
FontSize="14"
22192219
ItemsSource="{Binding DateFormatDisplayList}"
22202220
SelectedIndex="{Binding DateFormatIndex, Mode=OneWayToSource}"
2221-
DropDownOpened="RefreshDateTimeList"/>
2221+
DropDownOpened="RefreshDateList"/>
22222222
<ui:ToggleSwitch
22232223
IsOn="{Binding UseDate, Mode=TwoWay}"
22242224
OffContent="{DynamicResource disable}"

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel)
4646
InitializePosition();
4747
InitializeComponent();
4848

49-
RefreshDateTimeListLogic(viewModel.DateFormatIndex, viewModel.TimeFormatIndex);
49+
RefreshDateListInternal(viewModel.DateFormatIndex);
50+
RefreshTimeListInternal(viewModel.TimeFormatIndex);
5051
}
5152

5253
#region General
@@ -67,7 +68,6 @@ private void OnLoaded(object sender, RoutedEventArgs e)
6768
pluginStoreView.Filter = PluginStoreFilter;
6869

6970
InitializePosition();
70-
ClockDisplay();
7171
}
7272

7373
private void OnSelectPythonDirectoryClick(object sender, RoutedEventArgs e)
@@ -567,16 +567,26 @@ private void StoreListItem_Click(object sender, RoutedEventArgs e)
567567

568568
}
569569

570-
private void RefreshDateTimeList(object sender, EventArgs e)
570+
private void RefreshDateList(object sender, EventArgs e)
571571
{
572-
RefreshDateTimeListLogic(DateFormat.SelectedIndex, TimeFormat.SelectedIndex);
572+
RefreshDateListInternal(DateFormat.SelectedIndex);
573573
}
574574

575-
private void RefreshDateTimeListLogic(int dateIndex, int timeIndex)
575+
private void RefreshDateListInternal(int index)
576576
{
577-
viewModel.UpdateDateTimeDisplayList();
578-
RefreshComboBox(DateFormat, dateIndex);
579-
RefreshComboBox(TimeFormat, timeIndex);
577+
viewModel.UpdateDateDisplayList();
578+
RefreshComboBox(DateFormat, index);
579+
}
580+
581+
private void RefreshTimeList(object sender, EventArgs e)
582+
{
583+
RefreshTimeListInternal(TimeFormat.SelectedIndex);
584+
}
585+
586+
private void RefreshTimeListInternal(int index)
587+
{
588+
viewModel.UpdateTimeDisplayList();
589+
RefreshComboBox(TimeFormat, index);
580590
}
581591

582592
private static void RefreshComboBox(System.Windows.Controls.ComboBox box, int index)

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ public SettingWindowViewModel(Updater updater, IPortable portable)
5252
int tmp = 0;
5353
TimeFormatIndex = (tmp = TimeFormatList.FindIndex(x => x.Equals(Settings.TimeFormat))) >= 0 ? tmp : 0;
5454
DateFormatIndex = (tmp = DateFormatList.FindIndex(x => x.Equals(Settings.DateFormat))) >= 0 ? tmp : 0;
55-
// TODO: CurrentCulture may equal to settings.language when this is constructed
55+
// TODO: CurrentCulture may not equal to settings.language when this is constructed
5656
TimeFormatDisplayList = TimeFormatList.Select(x => DateTime.Now.ToString(x, CultureInfo.CurrentCulture)).ToList();
5757
DateFormatDisplayList = DateFormatList.Select(x => DateTime.Now.ToString(x, CultureInfo.CurrentCulture)).ToList();
58-
//UpdateSettingsDateTimeFormat(); // just in case something wrong
5958
}
6059

6160
public Settings Settings { get; set; }
@@ -514,20 +513,26 @@ public int DateFormatIndex
514513

515514
public List<string> DateFormatDisplayList { get; set; } = null;
516515

517-
public void UpdateDateTimeDisplayList()
516+
public void UpdateDateDisplayList()
518517
{
519-
for (int i = 0; i < TimeFormatList.Count; ++i)
520-
{
521-
TimeFormatDisplayList[i] = DateTime.Now.ToString(TimeFormatList[i], CultureInfo.CurrentCulture);
522-
}
523-
524518
for (int i = 0; i < DateFormatList.Count; ++i)
525519
{
526520
DateFormatDisplayList[i] = DateTime.Now.ToString(DateFormatList[i], CultureInfo.CurrentCulture);
527521
}
522+
// TODO: CurrentCulture may not equal to settings.language
523+
// Cross thread issue?
524+
DateText = DateTime.Now.ToString(Settings.DateFormat, CultureInfo.CurrentCulture);
525+
}
528526

527+
public void UpdateTimeDisplayList()
528+
{
529+
for (int i = 0; i < TimeFormatList.Count; ++i)
530+
{
531+
TimeFormatDisplayList[i] = DateTime.Now.ToString(TimeFormatList[i], CultureInfo.CurrentCulture);
532+
}
533+
// TODO: CurrentCulture may not equal to settings.language
534+
// Cross thread issue?
529535
ClockText = DateTime.Now.ToString(Settings.TimeFormat, CultureInfo.CurrentCulture);
530-
DateText = DateTime.Now.ToString(Settings.DateFormat, CultureInfo.CurrentCulture);
531536
}
532537

533538
public double WindowWidthSize

0 commit comments

Comments
 (0)