Skip to content

Commit 45e9a43

Browse files
reorganize logic for date/time dropdown
1 parent 8159b6e commit 45e9a43

File tree

3 files changed

+36
-31
lines changed

3 files changed

+36
-31
lines changed

Flow.Launcher/SettingWindow.xaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,6 +1815,7 @@
18151815
</Grid.RowDefinitions>
18161816
<Border Grid.Row="0">
18171817
<TextBox
1818+
x:Name="QueryTextBox"
18181819
IsReadOnly="True"
18191820
Style="{DynamicResource QueryBoxStyle}"
18201821
Text="{DynamicResource hiThere}" />
@@ -2170,7 +2171,8 @@
21702171
VerticalAlignment="Center"
21712172
FontSize="14"
21722173
ItemsSource="{Binding TimeFormatDisplayList}"
2173-
SelectedIndex="{Binding TimeFormatIndex, Mode=OneTime}"
2174+
SelectedIndex="{Binding TimeFormatIndex, Mode=OneWayToSource}"
2175+
DropDownOpened="RefreshDateTimeList"
21742176
SelectionChanged="PreviewClockAndDate" />
21752177
<ui:ToggleSwitch
21762178
IsOn="{Binding UseClock, Mode=TwoWay}"
@@ -2208,7 +2210,8 @@
22082210
VerticalAlignment="Center"
22092211
FontSize="14"
22102212
ItemsSource="{Binding DateFormatDisplayList}"
2211-
SelectedIndex="{Binding DateFormatIndex, Mode=OneTime}"
2213+
SelectedIndex="{Binding DateFormatIndex, Mode=OneWayToSource}"
2214+
DropDownOpened="RefreshDateTimeList"
22122215
SelectionChanged="PreviewClockAndDate" />
22132216
<ui:ToggleSwitch
22142217
IsOn="{Binding UseDate, Mode=TwoWay}"

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel)
4545
API = api;
4646
InitializePosition();
4747
InitializeComponent();
48+
49+
RefreshDateTimeListLogic(viewModel.DateFormatIndex, viewModel.TimeFormatIndex);
4850
}
4951

5052
#region General
@@ -517,19 +519,6 @@ private void PluginStore_OnKeyDown(object sender, KeyEventArgs e)
517519

518520
private void PreviewClockAndDate(object sender, RoutedEventArgs e)
519521
{
520-
if (DateFormat != null && TimeFormat != null)
521-
{
522-
if (DateFormat.SelectedIndex == -1 || TimeFormat.SelectedIndex == -1)
523-
{
524-
return;
525-
}
526-
viewModel.UpdateDateTimeDisplayList(DateFormat.SelectedIndex, TimeFormat.SelectedIndex);
527-
DateFormat.Items.Refresh();
528-
TimeFormat.Items.Refresh(); // selected = -1
529-
// todo avoid recursion
530-
DateFormat.SelectedIndex = viewModel.DateFormatIndex;
531-
TimeFormat.SelectedIndex = viewModel.TimeFormatIndex;
532-
}
533522
ClockDisplay();
534523
}
535524

@@ -605,5 +594,23 @@ private void StoreListItem_Click(object sender, RoutedEventArgs e)
605594
};
606595

607596
}
597+
598+
private void RefreshDateTimeList(object sender, EventArgs e)
599+
{
600+
RefreshDateTimeListLogic(DateFormat.SelectedIndex, TimeFormat.SelectedIndex);
601+
}
602+
603+
private void RefreshDateTimeListLogic(int dateIndex, int timeIndex)
604+
{
605+
viewModel.UpdateDateTimeDisplayList();
606+
RefreshComboBox(DateFormat, dateIndex);
607+
RefreshComboBox(TimeFormat, timeIndex);
608+
}
609+
610+
private static void RefreshComboBox(System.Windows.Controls.ComboBox box, int index)
611+
{
612+
box.Items.Refresh();
613+
box.SelectedIndex = index;
614+
}
608615
}
609616
}

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,11 @@ public int TimeFormatIndex
482482
get => timeFormatIndex;
483483
set
484484
{
485-
timeFormatIndex = value;
486-
Settings.TimeFormat = TimeFormatList[TimeFormatIndex];
485+
if (value != -1)
486+
{
487+
timeFormatIndex = value;
488+
Settings.TimeFormat = TimeFormatList[value];
489+
}
487490
}
488491
}
489492

@@ -493,26 +496,20 @@ public int DateFormatIndex
493496
get => dateFormatIndex;
494497
set
495498
{
496-
dateFormatIndex = value;
497-
Settings.DateFormat = DateFormatList[DateFormatIndex];
499+
if (value != -1)
500+
{
501+
dateFormatIndex = value;
502+
Settings.DateFormat = DateFormatList[value];
503+
}
498504
}
499505
}
500506

501507
public List<string> TimeFormatDisplayList { get; set; } = null;
502508

503509
public List<string> DateFormatDisplayList { get; set; } = null;
504510

505-
public void UpdateSettingsDateTimeFormat()
511+
public void UpdateDateTimeDisplayList()
506512
{
507-
Settings.DateFormat = DateFormatList[DateFormatIndex];
508-
Settings.TimeFormat = TimeFormatList[TimeFormatIndex];
509-
}
510-
511-
public void UpdateDateTimeDisplayList(int dateIndex, int timeIndex)
512-
{
513-
DateFormatIndex = dateIndex;
514-
TimeFormatIndex = timeIndex;
515-
516513
for (int i = 0; i < TimeFormatList.Count; ++i)
517514
{
518515
TimeFormatDisplayList[i] = DateTime.Now.ToString(TimeFormatList[i], CultureInfo.CurrentCulture);
@@ -522,8 +519,6 @@ public void UpdateDateTimeDisplayList(int dateIndex, int timeIndex)
522519
{
523520
DateFormatDisplayList[i] = DateTime.Now.ToString(DateFormatList[i], CultureInfo.CurrentCulture);
524521
}
525-
526-
//UpdateSettingsDateTimeFormat();
527522
}
528523

529524
public double WindowWidthSize

0 commit comments

Comments
 (0)