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
2 changes: 2 additions & 0 deletions src/Resources/Locales/en_US.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
<x:String x:Key="Text.CommitDetail.Info.SHA" xml:space="preserve">SHA</x:String>
<x:String x:Key="Text.CommitDetail.Info.Signer" xml:space="preserve">Signer:</x:String>
<x:String x:Key="Text.CommitDetail.Info.WebLinks" xml:space="preserve">Open in Browser</x:String>
<x:String x:Key="Text.CommitMessageTextBox.DescriptionCount" xml:space="preserve">DESCRIPTION</x:String>
<x:String x:Key="Text.CommitMessageTextBox.Placeholder" xml:space="preserve">Enter commit message. Please use an empty-line to separate subject and description!</x:String>
<x:String x:Key="Text.CommitMessageTextBox.SubjectCount" xml:space="preserve">SUBJECT</x:String>
<x:String x:Key="Text.Compare" xml:space="preserve">Compare</x:String>
Expand Down Expand Up @@ -696,6 +697,7 @@
<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.DescriptionGuideLength" xml:space="preserve">Description Guide Length</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.MaxHistoryCommits" xml:space="preserve">History Commits</x:String>
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/Locales/zh_CN.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
<x:String x:Key="Text.CommitDetail.Info.SHA" xml:space="preserve">提交指纹</x:String>
<x:String x:Key="Text.CommitDetail.Info.Signer" xml:space="preserve">签名者 :</x:String>
<x:String x:Key="Text.CommitDetail.Info.WebLinks" xml:space="preserve">浏览器中查看</x:String>
<x:String x:Key="Text.CommitMessageTextBox.DescriptionCount" xml:space="preserve">描述</x:String>
<x:String x:Key="Text.CommitMessageTextBox.Placeholder" xml:space="preserve">请输入提交的信息。注意:主题与具体描述中间需要空白行分隔!</x:String>
<x:String x:Key="Text.CommitMessageTextBox.SubjectCount" xml:space="preserve">主题</x:String>
<x:String x:Key="Text.Compare" xml:space="preserve">比较</x:String>
Expand Down Expand Up @@ -700,6 +701,7 @@
<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.DescriptionGuideLength" xml:space="preserve">DESCRIPTION字数检测</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.MaxHistoryCommits" xml:space="preserve">最大历史提交数</x:String>
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/Locales/zh_TW.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
<x:String x:Key="Text.CommitDetail.Info.SHA" xml:space="preserve">提交編號</x:String>
<x:String x:Key="Text.CommitDetail.Info.Signer" xml:space="preserve">簽署人:</x:String>
<x:String x:Key="Text.CommitDetail.Info.WebLinks" xml:space="preserve">在瀏覽器中檢視</x:String>
<x:String x:Key="Text.CommitMessageTextBox.DescriptionCount" xml:space="preserve">描述</x:String>
<x:String x:Key="Text.CommitMessageTextBox.Placeholder" xml:space="preserve">請輸入提交訊息,標題與詳細描述之間請使用單行空白區隔。</x:String>
<x:String x:Key="Text.CommitMessageTextBox.SubjectCount" xml:space="preserve">標題</x:String>
<x:String x:Key="Text.Compare" xml:space="preserve">比較</x:String>
Expand Down Expand Up @@ -690,6 +691,7 @@
<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.DescriptionGuideLength" 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.MaxHistoryCommits" xml:space="preserve">最大歷史提交數</x:String>
Expand Down
7 changes: 7 additions & 0 deletions src/ViewModels/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ public int SubjectGuideLength
set => SetProperty(ref _subjectGuideLength, value);
}

public int DescriptionGuideLength
{
get => _descriptionGuideLength;
set => SetProperty(ref _descriptionGuideLength, value);
}

public int DateTimeFormat
{
get => Models.DateTimeFormat.ActiveIndex;
Expand Down Expand Up @@ -820,6 +826,7 @@ private bool RemoveInvalidRepositoriesRecursive(List<RepositoryNode> collection)

private int _maxHistoryCommits = 20000;
private int _subjectGuideLength = 50;
private int _descriptionGuideLength = 80;
private bool _useFixedTabWidth = true;
private bool _useAutoHideScrollBars = true;
private bool _useGitHubStyleAvatar = true;
Expand Down
18 changes: 18 additions & 0 deletions src/Views/CommitMessageToolBox.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
Text="{Binding #ThisControl.CommitMessage, Mode=TwoWay}"
Watermark="{DynamicResource Text.CommitMessageTextBox.Placeholder}"
SubjectGuideLength="{Binding Source={x:Static vm:Preferences.Instance}, Path=SubjectGuideLength, Mode=OneWay}"
DescriptionGuideLength="{Binding Source={x:Static vm:Preferences.Instance}, Path=DescriptionGuideLength, Mode=OneWay}"
GuideLineBrush="{DynamicResource Brush.Border2}"
FontFamily="{DynamicResource Fonts.Monospace}">
<v:CommitMessageTextBox.Styles>
Expand Down Expand Up @@ -138,6 +139,23 @@
Text="{Binding #Editor.SubjectGuideLength, Mode=OneWay}"
VerticalAlignment="Center"/>
<Path Width="10" Height="10" Margin="4,0,0,0" Data="{StaticResource Icons.Error}" Fill="DarkGoldenrod" IsVisible="{Binding #Editor.WarnSubjectLength, Mode=OneWay}"/>
<TextBlock Classes="info_label"
Margin="12,0,0,0"
FontSize="13"
HorizontalAlignment="Left"
Text="{DynamicResource Text.CommitMessageTextBox.DescriptionCount}"/>
<TextBlock Margin="8,0,0,0"
FontSize="11"
Text="{Binding #Editor.DescriptionLength}"
Foreground="{Binding #Editor.WarnDescriptionLength, Converter={x:Static c:BoolConverters.IsWarningToBrush}, Mode=OneWay}"
VerticalAlignment="Center"/>
<TextBlock FontSize="11"
Text="/"
VerticalAlignment="Center"/>
<TextBlock FontSize="11"
Text="{Binding #Editor.DescriptionGuideLength, Mode=OneWay}"
VerticalAlignment="Center"/>
<Path Width="10" Height="10" Margin="4,0,0,0" Data="{StaticResource Icons.Error}" Fill="DarkGoldenrod" IsVisible="{Binding #Editor.WarnDescriptionLength, Mode=OneWay}"/>
</StackPanel>
</Grid>
</Border>
Expand Down
72 changes: 71 additions & 1 deletion src/Views/CommitMessageToolBox.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,40 @@ public bool WarnSubjectLength
set => SetAndRaise(WarnSubjectLengthProperty, ref _warnSubjectLen, value);
}

public static readonly DirectProperty<CommitMessageTextBox, int> DescriptionLengthProperty =
AvaloniaProperty.RegisterDirect<CommitMessageTextBox, int>(
nameof(DescriptionLength),
static o => o.DescriptionLength);

public int DescriptionLength
{
get => _descriptionLen;
set => SetAndRaise(DescriptionLengthProperty, ref _descriptionLen, value);
}

public static readonly DirectProperty<CommitMessageTextBox, int> DescriptionGuideLengthProperty =
AvaloniaProperty.RegisterDirect<CommitMessageTextBox, int>(
nameof(DescriptionGuideLength),
static o => o.DescriptionGuideLength,
static (o, v) => o.DescriptionGuideLength = v);

public int DescriptionGuideLength
{
get => _descriptionGuideLen;
set => SetAndRaise(DescriptionGuideLengthProperty, ref _descriptionGuideLen, value);
}

public static readonly DirectProperty<CommitMessageTextBox, bool> WarnDescriptionLengthProperty =
AvaloniaProperty.RegisterDirect<CommitMessageTextBox, bool>(
nameof(WarnDescriptionLength),
static o => o.WarnDescriptionLength);

public bool WarnDescriptionLength
{
get => _warnDescriptionLen;
set => SetAndRaise(WarnDescriptionLengthProperty, ref _warnDescriptionLen, value);
}

public static readonly DirectProperty<CommitMessageTextBox, List<CommitMessageTextBoxSuggestion>> SuggestionsProperty =
AvaloniaProperty.RegisterDirect<CommitMessageTextBox, List<CommitMessageTextBoxSuggestion>>(
nameof(Suggestions),
Expand Down Expand Up @@ -173,7 +207,7 @@ public override void Render(DrawingContext context)
new Typeface(font),
ViewModels.Preferences.Instance.DefaultFontSize,
Brushes.White);
var columnGuideX = columnTest.WidthIncludingTrailingWhitespace * 80 + 5.5;
var columnGuideX = columnTest.WidthIncludingTrailingWhitespace * _descriptionGuideLen + 5.5;
context.DrawLine(pen, new Point(columnGuideX, Math.Max(0, y)), new Point(columnGuideX, Bounds.Height));
}

Expand Down Expand Up @@ -209,10 +243,12 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
{
_subjectEndCharIdx = -1;
SubjectLength = 0;
DescriptionLength = 0;
return;
}

var subjectLen = 0;
var descriptionLen = 0;
var lastNonLineBreakCharIdx = 0;
var lastLineStart = 0;
for (var i = 0; i < text.Length; i++)
Expand All @@ -226,7 +262,10 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
if (string.IsNullOrWhiteSpace(line))
{
if (subjectLen > 0)
{
descriptionLen = GetMaxLineLength(text, lastLineStart);
break;
}

continue;
}
Expand All @@ -253,12 +292,18 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
}

SubjectLength = subjectLen;
DescriptionLength = descriptionLen;
_subjectEndCharIdx = lastNonLineBreakCharIdx;
}
else if (change.Property == SubjectLengthProperty || change.Property == SubjectGuideLengthProperty)
{
WarnSubjectLength = _subjectLen > _subjectGuideLen;
}
else if (change.Property == DescriptionLengthProperty || change.Property == DescriptionGuideLengthProperty)
{
WarnDescriptionLength = _descriptionLen > _descriptionGuideLen;
InvalidateVisual();
}
else if (change.Property == SubjectEndYProperty)
{
InvalidateVisual();
Expand Down Expand Up @@ -377,6 +422,28 @@ protected override void OnKeyDown(KeyEventArgs e)
base.OnKeyDown(e);
}

private static int GetMaxLineLength(string text, int start)
{
var maxLen = 0;
var lineStart = start;
for (var i = start; i <= text.Length; i++)
{
if (i == text.Length || text[i] == '\n')
{
var lineLen = i - lineStart;
while (lineLen > 0 && char.IsWhiteSpace(text[lineStart + lineLen - 1]))
lineLen--;

if (lineLen > maxLen)
maxLen = lineLen;

lineStart = i + 1;
}
}

return maxLen;
}

private void OnLayoutUpdated(object sender, EventArgs e)
{
if (_textPresenter == null || !IsEffectivelyVisible)
Expand Down Expand Up @@ -447,6 +514,9 @@ private void OnLayoutUpdated(object sender, EventArgs e)
private int _subjectEndCharIdx = -1;
private double _subjectEndY = 0;
private bool _warnSubjectLen = false;
private int _descriptionLen = 0;
private int _descriptionGuideLen = 80;
private bool _warnDescriptionLen = false;
private int _suggestionMatchStartIdx = -1;
private List<CommitMessageTextBoxSuggestion> _suggestions = null;
private int _selectedSuggestionIdx = 0;
Expand Down
39 changes: 29 additions & 10 deletions src/Views/Preferences.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<TabItem.Header>
<TextBlock Classes="tab_header" Text="{DynamicResource Text.Preferences.General}"/>
</TabItem.Header>
<Grid Margin="8" RowDefinitions="32,32,32,32,32,32,32,32,32,32,32,32,Auto" ColumnDefinitions="Auto,*">
<Grid Margin="8" RowDefinitions="32,32,32,32,32,32,32,32,32,32,32,32,32,Auto" ColumnDefinitions="Auto,*">
<TextBlock Grid.Row="0" Grid.Column="0"
Text="{DynamicResource Text.Preferences.General.Locale}"
HorizontalAlignment="Right"
Expand Down Expand Up @@ -123,10 +123,29 @@
</Grid>

<TextBlock Grid.Row="4" Grid.Column="0"
Text="{DynamicResource Text.Preferences.General.MaxHistoryCommits}"
Text="{DynamicResource Text.Preferences.General.DescriptionGuideLength}"
HorizontalAlignment="Right"
Margin="0,0,16,0"/>
<Grid Grid.Row="4" Grid.Column="1" ColumnDefinitions="*,64">
<Slider Grid.Column="0"
Minimum="50" Maximum="200"
TickPlacement="BottomRight" TickFrequency="10"
IsSnapToTickEnabled="False"
VerticalAlignment="Center"
Foreground="{DynamicResource Brush.Border1}"
Value="{Binding DescriptionGuideLength, Mode=TwoWay}"/>

<TextBlock Grid.Column="1"
HorizontalAlignment="Right" VerticalAlignment="Center"
Foreground="{DynamicResource Brush.FG1}"
Text="{Binding DescriptionGuideLength, Mode=OneWay}"/>
</Grid>

<TextBlock Grid.Row="5" Grid.Column="0"
Text="{DynamicResource Text.Preferences.General.MaxHistoryCommits}"
HorizontalAlignment="Right"
Margin="0,0,16,0"/>
<Grid Grid.Row="5" Grid.Column="1" ColumnDefinitions="*,64">
<Slider Grid.Column="0"
Minimum="5000" Maximum="100000"
TickPlacement="BottomRight" TickFrequency="5000"
Expand All @@ -141,42 +160,42 @@
Text="{Binding MaxHistoryCommits}"/>
</Grid>

<CheckBox Grid.Row="5" Grid.Column="1"
<CheckBox Grid.Row="6" Grid.Column="1"
Height="32"
Content="{DynamicResource Text.Preferences.General.ShowChangesPageByDefault}"
IsChecked="{Binding ShowLocalChangesByDefault, Mode=TwoWay}"/>

<CheckBox Grid.Row="6" Grid.Column="1"
<CheckBox Grid.Row="7" Grid.Column="1"
Height="32"
Content="{DynamicResource Text.Preferences.General.ShowChangesTabInCommitDetailByDefault}"
IsChecked="{Binding ShowChangesInCommitDetailByDefault, Mode=TwoWay}"/>

<CheckBox Grid.Row="7" Grid.Column="1"
<CheckBox Grid.Row="8" Grid.Column="1"
Height="32"
Content="{DynamicResource Text.Preferences.General.ShowTagsInGraph}"
IsChecked="{Binding ShowTagsInGraph, Mode=TwoWay}"/>

<CheckBox Grid.Row="8" Grid.Column="1"
<CheckBox Grid.Row="9" Grid.Column="1"
Height="32"
Content="{DynamicResource Text.Preferences.General.ShowRelativeTimeInGraph}"
IsChecked="{Binding DisplayTimeAsPeriodInHistories, Mode=TwoWay}"/>

<CheckBox Grid.Row="9" Grid.Column="1"
<CheckBox Grid.Row="10" Grid.Column="1"
Height="32"
Content="{DynamicResource Text.Preferences.General.UseCompactBranchNames}"
IsChecked="{Binding UseCompactBranchNamesInGraph, Mode=TwoWay}"/>

<CheckBox Grid.Row="10" Grid.Column="1"
<CheckBox Grid.Row="11" Grid.Column="1"
Height="32"
Content="{DynamicResource Text.Preferences.General.EnableCompactFolders}"
IsChecked="{Binding EnableCompactFoldersInChangesTree, Mode=TwoWay}"/>

<CheckBox Grid.Row="11" Grid.Column="1"
<CheckBox Grid.Row="12" Grid.Column="1"
Height="32"
Content="{DynamicResource Text.Preferences.General.UseGitHubStyleAvatar}"
IsChecked="{Binding UseGitHubStyleAvatar, Mode=TwoWay}"/>

<CheckBox Grid.Row="12" Grid.Column="1"
<CheckBox Grid.Row="13" Grid.Column="1"
Height="32"
Content="{DynamicResource Text.Preferences.General.Check4UpdatesOnStartup}"
IsVisible="{x:Static s:App.IsCheckForUpdateCommandVisible}"
Expand Down
Loading