Skip to content

Commit

Permalink
Implemented thisismy-github's clock customisation
Browse files Browse the repository at this point in the history
  • Loading branch information
SeventySev3n committed Oct 5, 2024
1 parent 58c9d99 commit 953d978
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 9 deletions.
47 changes: 38 additions & 9 deletions RetroBar/Controls/Clock.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,27 @@ private void StopClock()

private void Settings_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Settings.ShowClock))
switch (e.PropertyName)
{
if (Settings.Instance.ShowClock)
{
StartClock();
}
else
{
StopClock();
}
case "ShowClock":
if (Settings.Instance.ShowClock)
{
StartClock();
}
else
{
StopClock();
}
break;

case "Theme":
case "OverrideClockFormat":
case "ClockFormat":
case "OverrideAMPMDesignators":
case "AMDesignator":
case "PMDesignator":
SetCurrentCulture();
break;
}
}

Expand Down Expand Up @@ -156,6 +167,24 @@ private void SetCurrentCulture()
iCi.DateTimeFormat.AMDesignator = (string)iKey.GetValue("s1159");
iCi.DateTimeFormat.PMDesignator = (string)iKey.GetValue("s2359");

// Override culture info if desired, inserting newlines where appropriate
if (Settings.Instance.OverrideClockFormat && Settings.Instance.ClockFormat != "")
{
iCi.DateTimeFormat.ShortTimePattern = Settings.Instance.ClockFormat.Replace("\\n", "\n");
}

if (Settings.Instance.OverrideAMPMDesignators)
{
if (Settings.Instance.AMDesignator != "")
{
iCi.DateTimeFormat.AMDesignator = Settings.Instance.AMDesignator;
}
if (Settings.Instance.PMDesignator != "")
{
iCi.DateTimeFormat.PMDesignator = Settings.Instance.PMDesignator;
}
}

CultureInfo.CurrentCulture = iCi;
SetConverterCultureRecursively(this);
SetConverterCultureRecursively(ClockTip);
Expand Down
8 changes: 8 additions & 0 deletions RetroBar/Languages/English.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

<s:String x:Key="retrobar_properties">RetroBar Properties</s:String>
<s:String x:Key="taskbar_tab">Taskbar</s:String>
<s:String x:Key="clock_tab">Clock</s:String>
<s:String x:Key="advanced_tab">Advanced</s:String>
<s:String x:Key="taskbar_appearance">Taskbar appearance</s:String>
<s:String x:Key="notification_area">Notification area</s:String>
Expand Down Expand Up @@ -63,6 +64,13 @@
<s:String x:Key="debug_logging">Enable debug logging</s:String>
<s:String x:Key="check_for_updates">Check for updates</s:String>
<s:String x:Key="ok_dialog">OK</s:String>
<s:String x:Key="clock_appearance">Clock appearance</s:String>
<s:String x:Key="clock_format_info" xml:space="preserve">What the notations mean:&#10;&#10;h = hour; m = minute, s = second, tt = AM/PM&#10;d = day; M = month; yy, yyyy = year&#10;ddd, dddd = weekday; MMM, MMMM = month name&#10;&#10;h/H = 12/24 hour&#10;hh, mm, ss, dd, MM = display leading zero&#10;h, m, s, d, M = do not display leading zero&#10;&#10;\n = split clock into multiple lines&#10;(not recommended on all themes)&#10;&#10;Use "\" in front of other notations to use their actual characters</s:String>
<s:String x:Key="clock_format_warning" xml:space="preserve">Note: Custom clock formatting may not be applied&#10;if your selected theme specifies its own format.</s:String>
<s:String x:Key="override_clock_format">Custom clock _format:</s:String>
<s:String x:Key="override_ampm_designators">Custom _designators:</s:String>
<s:String x:Key="am_designator">AM:</s:String>
<s:String x:Key="pm_designator">PM:</s:String>

<s:String x:Key="customize_notifications">Customize Notifications</s:String>
<s:String x:Key="customize_notifications_info">RetroBar displays icons for active and urgent notifications, and hides inactive ones. You can change this behavior for items in the list below.</s:String>
Expand Down
110 changes: 110 additions & 0 deletions RetroBar/PropertiesWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,50 @@
<Setter Property="Width"
Value="335" />
</Style>
<ControlTemplate x:Key="NotificationAreaPreview">
<Border Style="{StaticResource PreviewBorder}">
<ContentControl Height="{DynamicResource TaskbarHeight}"
IsHitTestVisible="False"
Focusable="False"
ClipToBounds="True"
Style="{DynamicResource Taskbar}">
<TextOptions.TextRenderingMode>
<Binding Source="{x:Static Settings:Settings.Instance}"
Path="AllowFontSmoothing"
Converter="{StaticResource textRenderingModeConverter}" />
</TextOptions.TextRenderingMode>
<DockPanel>
<controls:ShowDesktopButton DockPanel.Dock="Right" HorizontalAlignment="Center" Visibility="{Binding Source={x:Static Settings:Settings.Instance}, Path=ShowDesktopButton, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource boolToVisibilityConverter}}" />
<GroupBox Style="{DynamicResource Tray}"
DockPanel.Dock="Right">
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Horizontal">
<ToggleButton x:Name="NotifyIconToggleButton"
Focusable="False"
Visibility="{Binding CollapseNotifyIcons, Converter={StaticResource boolToVisibilityConverter}, Source={x:Static Settings:Settings.Instance}, UpdateSourceTrigger=PropertyChanged}"
Style="{DynamicResource TrayToggleButton}"/>
<ItemsControl Focusable="False"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<Border>
<Image Source="Resources\retrobar.ico"
Style="{DynamicResource NotifyIcon}" />
</Border>
</ItemsControl>
</StackPanel>
<controls:Clock VerticalAlignment="Center" />
</StackPanel>
</GroupBox>
<StackPanel/>
</DockPanel>
</ContentControl>
</Border>
</ControlTemplate>
</ResourceDictionary>
</Window.Resources>
<Grid Margin="7">
Expand Down Expand Up @@ -302,6 +346,72 @@
</GroupBox>
</StackPanel>
</TabItem>
<TabItem Header="{DynamicResource clock_tab}" >
<StackPanel Orientation="Vertical"
Margin="10">
<DockPanel>
<GroupBox Header="{DynamicResource clock_appearance}"
Margin="0,0,0,10">
<StackPanel Orientation="Vertical">
<ContentControl Template="{StaticResource NotificationAreaPreview}"
Focusable="False" />
<CheckBox IsChecked="{Binding Source={x:Static Settings:Settings.Instance}, Path=ShowClock, UpdateSourceTrigger=PropertyChanged}">
<Label Content="{DynamicResource show_clock}" />
</CheckBox>
<DockPanel DockPanel.Dock="Top">
<CheckBox x:Name="cbOverrideClockFormat"
VerticalAlignment="Center"
IsChecked="{Binding Source={x:Static Settings:Settings.Instance}, Path=OverrideClockFormat, UpdateSourceTrigger=PropertyChanged}">
<Label Content="{DynamicResource override_clock_format}" />
</CheckBox>
<TextBox Text="{Binding Source={x:Static Settings:Settings.Instance}, Path=ClockFormat, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap"
VerticalAlignment="Center"
Margin="5,0,0,0"
IsEnabled="{Binding Source={x:Static Settings:Settings.Instance}, Path=OverrideClockFormat, UpdateSourceTrigger=PropertyChanged}" />
</DockPanel>
<DockPanel VerticalAlignment="Top" >
<CheckBox x:Name="cbOverrideAMPMDesignators"
VerticalAlignment="Center"
IsChecked="{Binding Source={x:Static Settings:Settings.Instance}, Path=OverrideAMPMDesignators, UpdateSourceTrigger=PropertyChanged}">
<Label Content="{DynamicResource override_ampm_designators}" />
</CheckBox>
<UniformGrid Columns="2">
<DockPanel>
<Label Content="{DynamicResource am_designator}"
VerticalAlignment="Center"
Margin="10,0,0,2"
IsEnabled="{Binding Source={x:Static Settings:Settings.Instance}, Path=OverrideAMPMDesignators, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Text="{Binding Source={x:Static Settings:Settings.Instance}, Path=AMDesignator, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap"
VerticalAlignment="Center"
Margin="5,0,0,0"
IsEnabled="{Binding Source={x:Static Settings:Settings.Instance}, Path=OverrideAMPMDesignators, UpdateSourceTrigger=PropertyChanged}" />
</DockPanel>
<DockPanel>
<Label Content="{DynamicResource pm_designator}"
Margin="10,0,0,2"
VerticalAlignment="Center"
IsEnabled="{Binding Source={x:Static Settings:Settings.Instance}, Path=OverrideAMPMDesignators, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Text="{Binding Source={x:Static Settings:Settings.Instance}, Path=PMDesignator, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap"
VerticalAlignment="Center"
Margin="5,0,0,0"
IsEnabled="{Binding Source={x:Static Settings:Settings.Instance}, Path=OverrideAMPMDesignators, UpdateSourceTrigger=PropertyChanged}" />
</DockPanel>
</UniformGrid>
</DockPanel>
<TextBlock Text="{DynamicResource clock_format_warning}"
TextWrapping="Wrap"
TextAlignment="Center"
Margin="0,3,0,3" />
</StackPanel>
</GroupBox>
</DockPanel>
<TextBlock Text="{DynamicResource clock_format_info}"
TextWrapping="Wrap" />
</StackPanel>
</TabItem>
<TabItem Header="{DynamicResource advanced_tab}">
<StackPanel Orientation="Vertical"
Margin="10">
Expand Down
85 changes: 85 additions & 0 deletions RetroBar/Utilities/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,91 @@ public bool ShowClock
set => Set(ref _showClock, value);
}

private bool _overrideClockFormat = false;
public bool OverrideClockFormat
{
get
{
return _overrideClockFormat;
}
set
{
if (_overrideClockFormat != value)
{
_overrideClockFormat = value;
OnPropertyChanged();
}
}
}

private string _clockFormat = "h:mm:ss tt | ddd, MMM d, yyyy";
public string ClockFormat
{
get
{
return _clockFormat;
}
set
{
if (_clockFormat != value)
{
_clockFormat = value;
OnPropertyChanged();
}
}
}

private bool _overrideAMPMDesignators = false;
public bool OverrideAMPMDesignators
{
get
{
return _overrideAMPMDesignators;
}
set
{
if (_overrideAMPMDesignators != value)
{
_overrideAMPMDesignators = value;
OnPropertyChanged();
}
}
}

private string _amDesignator = "a.m.";
public string AMDesignator
{
get
{
return _amDesignator;
}
set
{
if (_amDesignator != value)
{
_amDesignator = value;
OnPropertyChanged();
}
}
}

private string _pmDesignator = "p.m.";
public string PMDesignator
{
get
{
return _pmDesignator;
}
set
{
if (_pmDesignator != value)
{
_pmDesignator = value;
OnPropertyChanged();
}
}
}

private bool _showDesktopButton = false;
public bool ShowDesktopButton
{
Expand Down

0 comments on commit 953d978

Please sign in to comment.