Skip to content

Commit bde471a

Browse files
Use binding for date time preview
1 parent 45e9a43 commit bde471a

File tree

3 files changed

+25
-39
lines changed

3 files changed

+25
-39
lines changed

Flow.Launcher/SettingWindow.xaml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
</Window.CommandBindings>
4040

4141
<Window.Resources>
42+
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
4243
<converters:BorderClipConverter x:Key="BorderClipConverter" />
4344
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
4445
<converters:TextConverter x:Key="TextConverter" />
@@ -1820,9 +1821,17 @@
18201821
Style="{DynamicResource QueryBoxStyle}"
18211822
Text="{DynamicResource hiThere}" />
18221823
</Border>
1823-
<StackPanel x:Name="ClockPanel" Style="{DynamicResource ClockPanel}">
1824-
<TextBlock x:Name="DateBox" Style="{DynamicResource DateBox}" />
1825-
<TextBlock x:Name="ClockBox" Style="{DynamicResource ClockBox}" />
1824+
<StackPanel
1825+
x:Name="ClockPanel"
1826+
Style="{DynamicResource ClockPanel}">
1827+
<TextBlock
1828+
Style="{DynamicResource DateBox}"
1829+
Text="{Binding DateText}"
1830+
Visibility="{Binding Settings.UseDate, Converter={StaticResource BooleanToVisibilityConverter}}" />
1831+
<TextBlock
1832+
Style="{DynamicResource ClockBox}"
1833+
Text="{Binding ClockText}"
1834+
Visibility="{Binding Settings.UseClock, Converter={StaticResource BooleanToVisibilityConverter}}" />
18261835
</StackPanel>
18271836
<Canvas Style="{DynamicResource SearchIconPosition}">
18281837
<Path
@@ -2172,14 +2181,12 @@
21722181
FontSize="14"
21732182
ItemsSource="{Binding TimeFormatDisplayList}"
21742183
SelectedIndex="{Binding TimeFormatIndex, Mode=OneWayToSource}"
2175-
DropDownOpened="RefreshDateTimeList"
2176-
SelectionChanged="PreviewClockAndDate" />
2184+
DropDownOpened="RefreshDateTimeList"/>
21772185
<ui:ToggleSwitch
21782186
IsOn="{Binding UseClock, Mode=TwoWay}"
21792187
OffContent="{DynamicResource disable}"
21802188
OnContent="{DynamicResource enable}"
2181-
Style="{DynamicResource SideToggleSwitch}"
2182-
Toggled="PreviewClockAndDate" />
2189+
Style="{DynamicResource SideToggleSwitch}"/>
21832190
</StackPanel>
21842191
<TextBlock Style="{StaticResource Glyph}">
21852192
&#xec92;
@@ -2211,14 +2218,12 @@
22112218
FontSize="14"
22122219
ItemsSource="{Binding DateFormatDisplayList}"
22132220
SelectedIndex="{Binding DateFormatIndex, Mode=OneWayToSource}"
2214-
DropDownOpened="RefreshDateTimeList"
2215-
SelectionChanged="PreviewClockAndDate" />
2221+
DropDownOpened="RefreshDateTimeList"/>
22162222
<ui:ToggleSwitch
22172223
IsOn="{Binding UseDate, Mode=TwoWay}"
22182224
OffContent="{DynamicResource disable}"
22192225
OnContent="{DynamicResource enable}"
2220-
Style="{DynamicResource SideToggleSwitch}"
2221-
Toggled="PreviewClockAndDate" />
2226+
Style="{DynamicResource SideToggleSwitch}"/>
22222227
</StackPanel>
22232228
<TextBlock Style="{StaticResource Glyph}">
22242229
&#xe787;

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -517,34 +517,6 @@ private void PluginStore_OnKeyDown(object sender, KeyEventArgs e)
517517
}
518518
}
519519

520-
private void PreviewClockAndDate(object sender, RoutedEventArgs e)
521-
{
522-
ClockDisplay();
523-
}
524-
525-
public void ClockDisplay()
526-
{
527-
if (settings.UseClock)
528-
{
529-
ClockBox.Visibility = Visibility.Visible;
530-
ClockBox.Text = DateTime.Now.ToString(settings.TimeFormat);
531-
}
532-
else
533-
{
534-
ClockBox.Visibility = Visibility.Collapsed;
535-
}
536-
537-
if (settings.UseDate)
538-
{
539-
DateBox.Visibility = Visibility.Visible;
540-
DateBox.Text = DateTime.Now.ToString(settings.DateFormat);
541-
}
542-
else
543-
{
544-
DateBox.Visibility = Visibility.Collapsed;
545-
}
546-
}
547-
548520
public void InitializePosition()
549521
{
550522
if (settings.SettingWindowTop >= 0 && settings.SettingWindowLeft >= 0)

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ public int TimeFormatIndex
486486
{
487487
timeFormatIndex = value;
488488
Settings.TimeFormat = TimeFormatList[value];
489+
ClockText = DateTime.Now.ToString(Settings.TimeFormat, CultureInfo.CurrentCulture);
489490
}
490491
}
491492
}
@@ -500,10 +501,15 @@ public int DateFormatIndex
500501
{
501502
dateFormatIndex = value;
502503
Settings.DateFormat = DateFormatList[value];
504+
DateText = DateTime.Now.ToString(Settings.DateFormat, CultureInfo.CurrentCulture);
503505
}
504506
}
505507
}
506508

509+
public string ClockText { get; private set; }
510+
511+
public string DateText { get; private set; }
512+
507513
public List<string> TimeFormatDisplayList { get; set; } = null;
508514

509515
public List<string> DateFormatDisplayList { get; set; } = null;
@@ -519,6 +525,9 @@ public void UpdateDateTimeDisplayList()
519525
{
520526
DateFormatDisplayList[i] = DateTime.Now.ToString(DateFormatList[i], CultureInfo.CurrentCulture);
521527
}
528+
529+
ClockText = DateTime.Now.ToString(Settings.TimeFormat, CultureInfo.CurrentCulture);
530+
DateText = DateTime.Now.ToString(Settings.DateFormat, CultureInfo.CurrentCulture);
522531
}
523532

524533
public double WindowWidthSize

0 commit comments

Comments
 (0)