Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ public override void Initialize()

var pref = ViewModels.Preferences.Instance;
SetLocale(pref.Locale);
Models.DateTimeFormat.UseCulture(pref.Locale);
SetTheme(pref.Theme, pref.ThemeOverrides);
SetFonts(pref.DefaultFontFamily, pref.MonospaceFontFamily);
}
Expand Down
56 changes: 49 additions & 7 deletions src/Models/DateTimeFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,56 @@ public static bool Use24Hours
set;
} = true;

public static int DayOfWeekStyle
{
get;
set;
} = 0;

public static bool UseLocalizedCulture
{
get;
set;
} = true;

public string DateFormat
{
get;
}

public string Example
{
get => DateTime.Now.ToString(DateFormat, _culture);
get => DateTime.Now.ToString(DateFormat, ActiveCulture);
}

private static readonly CultureInfo _culture = CreateCulture();
private static CultureInfo ActiveCulture => UseLocalizedCulture ? _localizedCulture : _invariantCulture;

private static CultureInfo _localizedCulture = CreateCulture(CultureInfo.CurrentCulture);
private static readonly CultureInfo _invariantCulture = CreateCulture(CultureInfo.InvariantCulture);

// Ties the localized day/month names to the application's selected language
// (e.g. locale key "el_GR"), instead of the operating-system culture.
public static void UseCulture(string localeKey)
{
var baseCulture = CultureInfo.CurrentCulture;
if (!string.IsNullOrEmpty(localeKey))
{
try
{
baseCulture = CultureInfo.GetCultureInfo(localeKey.Replace('_', '-'));
}
catch (CultureNotFoundException)
{
// fall back to the operating-system culture
}
}

_localizedCulture = CreateCulture(baseCulture);
}

private static CultureInfo CreateCulture()
private static CultureInfo CreateCulture(CultureInfo baseCulture)
{
var culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
var culture = (CultureInfo)baseCulture.Clone();
culture.DateTimeFormat.DateSeparator = "/";
culture.DateTimeFormat.TimeSeparator = ":";
return culture;
Expand All @@ -67,11 +102,18 @@ public static string Format(ulong timestamp, bool dateOnly = false)
public static string Format(DateTime localTime, bool dateOnly = false)
{
var actived = Supported[ActiveIndex];
var dateFormat = DayOfWeekStyle switch
{
1 => $"ddd {actived.DateFormat}",
2 => $"dddd {actived.DateFormat}",
_ => actived.DateFormat,
};

if (dateOnly)
return localTime.ToString(actived.DateFormat, _culture);
return localTime.ToString(dateFormat, ActiveCulture);

var format = Use24Hours ? $"{actived.DateFormat} HH:mm:ss" : $"{actived.DateFormat} hh:mm:ss tt";
return localTime.ToString(format, _culture);
var format = Use24Hours ? $"{dateFormat} HH:mm:ss" : $"{dateFormat} hh:mm:ss tt";
return localTime.ToString(format, ActiveCulture);
}
}
}
4 changes: 4 additions & 0 deletions src/Resources/Locales/el_GR.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,12 @@
<x:String x:Key="Text.Preferences.General" xml:space="preserve">ΓΕΝΙΚΑ</x:String>
<x:String x:Key="Text.Preferences.General.Check4UpdatesOnStartup" xml:space="preserve">Έλεγχος για ενημερώσεις κατά την εκκίνηση</x:String>
<x:String x:Key="Text.Preferences.General.DateFormat" xml:space="preserve">Μορφή ημερομηνίας</x:String>
<x:String x:Key="Text.Preferences.General.DayOfWeek.None" xml:space="preserve">Χωρίς ημέρα</x:String>
<x:String x:Key="Text.Preferences.General.DayOfWeek.Short" xml:space="preserve">Σύντομη ημέρα</x:String>
<x:String x:Key="Text.Preferences.General.DayOfWeek.Full" xml:space="preserve">Πλήρης ημέρα</x:String>
<x:String x:Key="Text.Preferences.General.EnableCompactFolders" xml:space="preserve">Ενεργοποίηση συμπαγών φακέλων στο δέντρο αλλαγών</x:String>
<x:String x:Key="Text.Preferences.General.Locale" xml:space="preserve">Γλώσσα</x:String>
<x:String x:Key="Text.Preferences.General.LocalizedDates" xml:space="preserve">Τοπικές ημερομηνίες</x:String>
<x:String x:Key="Text.Preferences.General.MaxHistoryCommits" xml:space="preserve">Commits ιστορικού</x:String>
<x:String x:Key="Text.Preferences.General.ShowChangesPageByDefault" xml:space="preserve">Εμφάνιση της σελίδας `ΤΟΠΙΚΕΣ ΑΛΛΑΓΕΣ` από προεπιλογή</x:String>
<x:String x:Key="Text.Preferences.General.ShowChangesTabInCommitDetailByDefault" xml:space="preserve">Εμφάνιση της καρτέλας `ΑΛΛΑΓΕΣ` στις λεπτομέρειες commit από προεπιλογή</x:String>
Expand Down
4 changes: 4 additions & 0 deletions src/Resources/Locales/en_US.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -682,8 +682,12 @@
<x:String x:Key="Text.Preferences.General" xml:space="preserve">GENERAL</x:String>
<x:String x:Key="Text.Preferences.General.Check4UpdatesOnStartup" xml:space="preserve">Check for updates on startup</x:String>
<x:String x:Key="Text.Preferences.General.DateFormat" xml:space="preserve">Date Format</x:String>
<x:String x:Key="Text.Preferences.General.DayOfWeek.None" xml:space="preserve">No day of week</x:String>
<x:String x:Key="Text.Preferences.General.DayOfWeek.Short" xml:space="preserve">Short day</x:String>
<x:String x:Key="Text.Preferences.General.DayOfWeek.Full" xml:space="preserve">Full day</x:String>
<x:String x:Key="Text.Preferences.General.EnableCompactFolders" xml:space="preserve">Enable compact folders in changes tree</x:String>
<x:String x:Key="Text.Preferences.General.Locale" xml:space="preserve">Language</x:String>
<x:String x:Key="Text.Preferences.General.LocalizedDates" xml:space="preserve">Localized dates</x:String>
<x:String x:Key="Text.Preferences.General.MaxHistoryCommits" xml:space="preserve">History Commits</x:String>
<x:String x:Key="Text.Preferences.General.ShowChangesPageByDefault" xml:space="preserve">Show `LOCAL CHANGES` page by default</x:String>
<x:String x:Key="Text.Preferences.General.ShowChangesTabInCommitDetailByDefault" xml:space="preserve">Show `CHANGES` tab in commit detail by default</x:String>
Expand Down
36 changes: 34 additions & 2 deletions src/ViewModels/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ public string Locale
get => _locale;
set
{
if (SetProperty(ref _locale, value) && !_isLoading)
App.SetLocale(value);
if (SetProperty(ref _locale, value))
{
Models.DateTimeFormat.UseCulture(value);
if (!_isLoading)
App.SetLocale(value);
}
}
}

Expand Down Expand Up @@ -169,6 +173,34 @@ public bool Use24Hours
}
}

public int DayOfWeekStyle
{
get => Models.DateTimeFormat.DayOfWeekStyle;
set
{
if (value != Models.DateTimeFormat.DayOfWeekStyle &&
value >= 0 &&
value <= 2)
{
Models.DateTimeFormat.DayOfWeekStyle = value;
OnPropertyChanged();
}
}
}

public bool DateTimeUseLocalizedCulture
{
get => Models.DateTimeFormat.UseLocalizedCulture;
set
{
if (value != Models.DateTimeFormat.UseLocalizedCulture)
{
Models.DateTimeFormat.UseLocalizedCulture = value;
OnPropertyChanged();
}
}
}

public bool UseFixedTabWidth
{
get => _useFixedTabWidth;
Expand Down
31 changes: 30 additions & 1 deletion src/Views/CommitTimeTextBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ public int DateTimeFormat
set => SetAndRaise(DateTimeFormatProperty, ref _dateTimeFormat, value);
}

public static readonly DirectProperty<CommitTimeTextBlock, int> DayOfWeekStyleProperty =
AvaloniaProperty.RegisterDirect<CommitTimeTextBlock, int>(
nameof(DayOfWeekStyle),
static o => o.DayOfWeekStyle,
static (o, v) => o.DayOfWeekStyle = v);

public int DayOfWeekStyle
{
get => _dayOfWeekStyle;
set => SetAndRaise(DayOfWeekStyleProperty, ref _dayOfWeekStyle, value);
}

public static readonly DirectProperty<CommitTimeTextBlock, bool> UseLocalizedCultureProperty =
AvaloniaProperty.RegisterDirect<CommitTimeTextBlock, bool>(
nameof(UseLocalizedCulture),
static o => o.UseLocalizedCulture,
static (o, v) => o.UseLocalizedCulture = v);

public bool UseLocalizedCulture
{
get => _useLocalizedCulture;
set => SetAndRaise(UseLocalizedCultureProperty, ref _useLocalizedCulture, value);
}

public static readonly DirectProperty<CommitTimeTextBlock, ulong> TimestampProperty =
AvaloniaProperty.RegisterDirect<CommitTimeTextBlock, ulong>(
nameof(Timestamp),
Expand Down Expand Up @@ -83,7 +107,10 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
HorizontalAlignment = HorizontalAlignment.Center;
}
}
else if (change.Property == DateTimeFormatProperty || change.Property == Use24HoursProperty)
else if (change.Property == DateTimeFormatProperty ||
change.Property == Use24HoursProperty ||
change.Property == DayOfWeekStyleProperty ||
change.Property == UseLocalizedCultureProperty)
{
if (ShowAsDateTime)
SetCurrentValue(TextProperty, GetDisplayText());
Expand Down Expand Up @@ -174,6 +201,8 @@ private string GetDisplayText()
private bool _showAsDateTime = true;
private bool _use24Hours = true;
private int _dateTimeFormat = 0;
private int _dayOfWeekStyle = 0;
private bool _useLocalizedCulture = true;
private ulong _timestamp = 0;
private DispatcherTimer _refreshTimer = null;
}
Expand Down
42 changes: 42 additions & 0 deletions src/Views/DateTimePresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,30 @@ public int DateTimeFormat
set => SetAndRaise(DateTimeFormatProperty, ref _dateTimeFormat, value);
}

public static readonly DirectProperty<DateTimePresenter, int> DayOfWeekStyleProperty =
AvaloniaProperty.RegisterDirect<DateTimePresenter, int>(
nameof(DayOfWeekStyle),
static o => o.DayOfWeekStyle,
static (o, v) => o.DayOfWeekStyle = v);

public int DayOfWeekStyle
{
get => _dayOfWeekStyle;
set => SetAndRaise(DayOfWeekStyleProperty, ref _dayOfWeekStyle, value);
}

public static readonly DirectProperty<DateTimePresenter, bool> UseLocalizedCultureProperty =
AvaloniaProperty.RegisterDirect<DateTimePresenter, bool>(
nameof(UseLocalizedCulture),
static o => o.UseLocalizedCulture,
static (o, v) => o.UseLocalizedCulture = v);

public bool UseLocalizedCulture
{
get => _useLocalizedCulture;
set => SetAndRaise(UseLocalizedCultureProperty, ref _useLocalizedCulture, value);
}

public static readonly DirectProperty<DateTimePresenter, ulong> TimestampProperty =
AvaloniaProperty.RegisterDirect<DateTimePresenter, ulong>(
nameof(Timestamp),
Expand Down Expand Up @@ -73,6 +97,20 @@ public DateTimePresenter()
Source = ViewModels.Preferences.Instance,
Path = "DateTimeFormat"
});

Bind(DayOfWeekStyleProperty, new Binding()
{
Mode = BindingMode.OneWay,
Source = ViewModels.Preferences.Instance,
Path = "DayOfWeekStyle"
});

Bind(UseLocalizedCultureProperty, new Binding()
{
Mode = BindingMode.OneWay,
Source = ViewModels.Preferences.Instance,
Path = "DateTimeUseLocalizedCulture"
});
}

protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
Expand All @@ -82,6 +120,8 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
if (change.Property == ShowDateOnlyProperty ||
change.Property == Use24HoursProperty ||
change.Property == DateTimeFormatProperty ||
change.Property == DayOfWeekStyleProperty ||
change.Property == UseLocalizedCultureProperty ||
change.Property == TimestampProperty)
{
var text = Models.DateTimeFormat.Format(Timestamp, ShowDateOnly);
Expand All @@ -92,6 +132,8 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
private bool _showDateOnly = false;
private bool _use24Hours = true;
private int _dateTimeFormat = 0;
private int _dayOfWeekStyle = 0;
private bool _useLocalizedCulture = true;
private ulong _timestamp = 0;
}
}
4 changes: 4 additions & 0 deletions src/Views/Histories.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@
Timestamp="{Binding AuthorTime, Mode=OneWay}"
ShowAsDateTime="{Binding Source={x:Static vm:Preferences.Instance}, Path=!DisplayTimeAsPeriodInHistories, Mode=OneWay}"
DateTimeFormat="{Binding Source={x:Static vm:Preferences.Instance}, Path=DateTimeFormat, Mode=OneWay}"
DayOfWeekStyle="{Binding Source={x:Static vm:Preferences.Instance}, Path=DayOfWeekStyle, Mode=OneWay}"
UseLocalizedCulture="{Binding Source={x:Static vm:Preferences.Instance}, Path=DateTimeUseLocalizedCulture, Mode=OneWay}"
Use24Hours="{Binding Source={x:Static vm:Preferences.Instance}, Path=Use24Hours, Mode=OneWay}"/>
</Border>
</DataTemplate>
Expand All @@ -226,6 +228,8 @@
Timestamp="{Binding CommitterTime, Mode=OneWay}"
ShowAsDateTime="{Binding Source={x:Static vm:Preferences.Instance}, Path=!DisplayTimeAsPeriodInHistories, Mode=OneWay}"
DateTimeFormat="{Binding Source={x:Static vm:Preferences.Instance}, Path=DateTimeFormat, Mode=OneWay}"
DayOfWeekStyle="{Binding Source={x:Static vm:Preferences.Instance}, Path=DayOfWeekStyle, Mode=OneWay}"
UseLocalizedCulture="{Binding Source={x:Static vm:Preferences.Instance}, Path=DateTimeUseLocalizedCulture, Mode=OneWay}"
Use24Hours="{Binding Source={x:Static vm:Preferences.Instance}, Path=Use24Hours, Mode=OneWay}"/>
</Border>
</DataTemplate>
Expand Down
36 changes: 27 additions & 9 deletions src/Views/Preferences.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,27 @@
Text="{DynamicResource Text.Preferences.General.Locale}"
HorizontalAlignment="Right"
Margin="0,0,16,0"/>
<ComboBox Grid.Row="0" Grid.Column="1"
MinHeight="28"
Padding="8,0"
HorizontalAlignment="Stretch"
ItemsSource="{Binding Source={x:Static m:Locale.Supported}}"
DisplayMemberBinding="{Binding Name, x:DataType=m:Locale}"
SelectedItem="{Binding Locale, Mode=TwoWay, Converter={x:Static c:StringConverters.ToLocale}}"/>
<Grid Grid.Row="0" Grid.Column="1" ColumnDefinitions="*,Auto">
<ComboBox Grid.Column="0"
MinHeight="28"
Padding="8,0"
HorizontalAlignment="Stretch"
ItemsSource="{Binding Source={x:Static m:Locale.Supported}}"
DisplayMemberBinding="{Binding Name, x:DataType=m:Locale}"
SelectedItem="{Binding Locale, Mode=TwoWay, Converter={x:Static c:StringConverters.ToLocale}}"/>

<CheckBox Grid.Column="1"
Height="32"
Margin="8,0,0,0"
Content="{DynamicResource Text.Preferences.General.LocalizedDates}"
IsChecked="{Binding DateTimeUseLocalizedCulture, Mode=TwoWay}"/>
</Grid>

<TextBlock Grid.Row="1" Grid.Column="0"
Text="{DynamicResource Text.Preferences.General.DateFormat}"
HorizontalAlignment="Right"
Margin="0,0,16,0"/>
<Grid Grid.Row="1" Grid.Column="1" ColumnDefinitions="*,Auto">
<Grid Grid.Row="1" Grid.Column="1" ColumnDefinitions="*,Auto,Auto">
<ComboBox Grid.Column="0"
MinHeight="28"
Padding="8,0"
Expand All @@ -81,7 +89,17 @@
</ComboBox.ItemTemplate>
</ComboBox>

<CheckBox Grid.Column="1"
<ComboBox Grid.Column="1"
MinHeight="28"
Margin="8,0,0,0"
Padding="8,0"
SelectedIndex="{Binding DayOfWeekStyle, Mode=TwoWay}">
<ComboBoxItem Content="{DynamicResource Text.Preferences.General.DayOfWeek.None}"/>
<ComboBoxItem Content="{DynamicResource Text.Preferences.General.DayOfWeek.Short}"/>
<ComboBoxItem Content="{DynamicResource Text.Preferences.General.DayOfWeek.Full}"/>
</ComboBox>

<CheckBox Grid.Column="2"
Height="32"
Margin="8,0,0,0"
Content="{DynamicResource Text.Preferences.General.Use24Hours}"
Expand Down