Skip to content

Commit bd79999

Browse files
feature: use Ctrl + -/= to zoom in/out window content (#1810)
Co-authored-by: Danielku15 <danielku15@coderline.net> Signed-off-by: leo <longshuang@msn.cn>
1 parent c91fea3 commit bd79999

File tree

7 files changed

+65
-18
lines changed

7 files changed

+65
-18
lines changed

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@
478478
<x:String x:Key="Text.Hotkeys.Global.OpenPreferences" xml:space="preserve">Open Preferences dialog</x:String>
479479
<x:String x:Key="Text.Hotkeys.Global.ShowWorkspaceDropdownMenu" xml:space="preserve">Show workspace dropdown menu</x:String>
480480
<x:String x:Key="Text.Hotkeys.Global.SwitchTab" xml:space="preserve">Switch active tab</x:String>
481+
<x:String x:Key="Text.Hotkeys.Global.Zoom" xml:space="preserve">Zoom in/out</x:String>
481482
<x:String x:Key="Text.Hotkeys.Repo" xml:space="preserve">REPOSITORY</x:String>
482483
<x:String x:Key="Text.Hotkeys.Repo.Commit" xml:space="preserve">Commit staged changes</x:String>
483484
<x:String x:Key="Text.Hotkeys.Repo.CommitAndPush" xml:space="preserve">Commit and push staged changes</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@
482482
<x:String x:Key="Text.Hotkeys.Global.OpenPreferences" xml:space="preserve">打开偏好设置面板</x:String>
483483
<x:String x:Key="Text.Hotkeys.Global.ShowWorkspaceDropdownMenu" xml:space="preserve">显示工作区下拉菜单</x:String>
484484
<x:String x:Key="Text.Hotkeys.Global.SwitchTab" xml:space="preserve">切换显示页面</x:String>
485+
<x:String x:Key="Text.Hotkeys.Global.Zoom" xml:space="preserve">缩放内容</x:String>
485486
<x:String x:Key="Text.Hotkeys.Repo" xml:space="preserve">仓库页面快捷键</x:String>
486487
<x:String x:Key="Text.Hotkeys.Repo.Commit" xml:space="preserve">提交暂存区更改</x:String>
487488
<x:String x:Key="Text.Hotkeys.Repo.CommitAndPush" xml:space="preserve">提交暂存区更改并推送</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@
482482
<x:String x:Key="Text.Hotkeys.Global.OpenPreferences" xml:space="preserve">開啟偏好設定面板</x:String>
483483
<x:String x:Key="Text.Hotkeys.Global.ShowWorkspaceDropdownMenu" xml:space="preserve">顯示工作區的下拉式選單</x:String>
484484
<x:String x:Key="Text.Hotkeys.Global.SwitchTab" xml:space="preserve">切換目前頁面</x:String>
485+
<x:String x:Key="Text.Hotkeys.Global.Zoom" xml:space="preserve">放大/縮小內容</x:String>
485486
<x:String x:Key="Text.Hotkeys.Repo" xml:space="preserve">存放庫頁面快速鍵</x:String>
486487
<x:String x:Key="Text.Hotkeys.Repo.Commit" xml:space="preserve">提交暫存區變更</x:String>
487488
<x:String x:Key="Text.Hotkeys.Repo.CommitAndPush" xml:space="preserve">提交暫存區變更並推送</x:String>

src/Resources/Styles.axaml

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,20 @@
3434
ClipToBounds="True">
3535
<Border Margin="{TemplateBinding Padding}">
3636
<VisualLayerManager>
37-
<Border>
38-
<ContentPresenter Name="PART_ContentPresenter"
39-
ContentTemplate="{TemplateBinding ContentTemplate}"
40-
Content="{TemplateBinding Content}"
41-
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
42-
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
43-
</Border>
37+
<LayoutTransformControl>
38+
<LayoutTransformControl.LayoutTransform>
39+
<ScaleTransform ScaleX="{Binding Source={x:Static vm:Preferences.Instance}, Path=Zoom, Mode=OneWay}"
40+
ScaleY="{Binding Source={x:Static vm:Preferences.Instance}, Path=Zoom, Mode=OneWay}"/>
41+
</LayoutTransformControl.LayoutTransform>
42+
43+
<Border>
44+
<ContentPresenter Name="PART_ContentPresenter"
45+
ContentTemplate="{TemplateBinding ContentTemplate}"
46+
Content="{TemplateBinding Content}"
47+
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
48+
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
49+
</Border>
50+
</LayoutTransformControl>
4451
</VisualLayerManager>
4552
</Border>
4653
</Border>
@@ -129,13 +136,20 @@
129136
BorderThickness="1"
130137
CornerRadius="{TemplateBinding CornerRadius}">
131138
<VisualLayerManager>
132-
<Border CornerRadius="{TemplateBinding CornerRadius}" ClipToBounds="True">
133-
<ContentPresenter Name="PART_ContentPresenter"
134-
ContentTemplate="{TemplateBinding ContentTemplate}"
135-
Content="{TemplateBinding Content}"
136-
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
137-
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
138-
</Border>
139+
<LayoutTransformControl>
140+
<LayoutTransformControl.LayoutTransform>
141+
<ScaleTransform ScaleX="{Binding Source={x:Static vm:Preferences.Instance}, Path=Zoom, Mode=OneWay}"
142+
ScaleY="{Binding Source={x:Static vm:Preferences.Instance}, Path=Zoom, Mode=OneWay}"/>
143+
</LayoutTransformControl.LayoutTransform>
144+
145+
<Border CornerRadius="{TemplateBinding CornerRadius}" ClipToBounds="True">
146+
<ContentPresenter Name="PART_ContentPresenter"
147+
ContentTemplate="{TemplateBinding ContentTemplate}"
148+
Content="{TemplateBinding Content}"
149+
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
150+
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
151+
</Border>
152+
</LayoutTransformControl>
139153
</VisualLayerManager>
140154
</Border>
141155
</Grid>

src/ViewModels/Preferences.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ public int EditorTabWidth
104104
set => SetProperty(ref _editorTabWidth, value);
105105
}
106106

107+
public double Zoom
108+
{
109+
get => _zoom;
110+
set => SetProperty(ref _zoom, value);
111+
}
112+
107113
public LayoutInfo Layout
108114
{
109115
get => _layout;
@@ -770,6 +776,7 @@ private bool RemoveInvalidRepositoriesRecursive(List<RepositoryNode> collection)
770776
private double _defaultFontSize = 13;
771777
private double _editorFontSize = 13;
772778
private int _editorTabWidth = 4;
779+
private double _zoom = 1.0;
773780
private LayoutInfo _layout = new();
774781

775782
private int _maxHistoryCommits = 20000;

src/Views/ChromelessWindow.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,30 @@ protected override void OnKeyDown(KeyEventArgs e)
9797
{
9898
base.OnKeyDown(e);
9999

100-
if (e is { Handled: false, Key: Key.Escape, KeyModifiers: KeyModifiers.None } && CloseOnESC)
100+
if (e.Handled)
101+
return;
102+
103+
if (e is { Key: Key.Escape, KeyModifiers: KeyModifiers.None } && CloseOnESC)
101104
{
102105
Close();
103106
e.Handled = true;
107+
return;
108+
}
109+
110+
if (e.KeyModifiers == (OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control))
111+
{
112+
if (e.Key == Key.OemPlus)
113+
{
114+
var zoom = Math.Min(ViewModels.Preferences.Instance.Zoom + 0.05, 2.5);
115+
ViewModels.Preferences.Instance.Zoom = zoom;
116+
e.Handled = true;
117+
}
118+
else if (e.Key == Key.OemMinus)
119+
{
120+
var zoom = Math.Max(ViewModels.Preferences.Instance.Zoom - 0.05, 1);
121+
ViewModels.Preferences.Instance.Zoom = zoom;
122+
e.Handled = true;
123+
}
104124
}
105125
}
106126

src/Views/Hotkeys.axaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Increase}}"
4646
Margin="0,0,0,8"/>
4747

48-
<Grid RowDefinitions="20,20,20,20,20,20,20,20,20" ColumnDefinitions="150,*">
48+
<Grid RowDefinitions="20,20,20,20,20,20,20,20,20,20" ColumnDefinitions="150,*">
4949
<TextBlock Grid.Row="0" Grid.Column="0" Classes="bold" Text="{OnPlatform Ctrl+\,, macOS=⌘+\,}"/>
5050
<TextBlock Grid.Row="0" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.OpenPreferences}"/>
5151

@@ -70,8 +70,11 @@
7070
<TextBlock Grid.Row="7" Grid.Column="0" Classes="bold" Text="{OnPlatform Ctrl+P, macOS=⌘+P}"/>
7171
<TextBlock Grid.Row="7" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.SwitchTab}" />
7272

73-
<TextBlock Grid.Row="8" Grid.Column="0" Classes="bold" Text="{OnPlatform Ctrl+Q, macOS=⌘+Q}"/>
74-
<TextBlock Grid.Row="8" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Quit}" />
73+
<TextBlock Grid.Row="8" Grid.Column="0" Classes="bold" Text="{OnPlatform 'Ctrl+-/=', macOS='⌘+-/='}"/>
74+
<TextBlock Grid.Row="8" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.Zoom}" />
75+
76+
<TextBlock Grid.Row="9" Grid.Column="0" Classes="bold" Text="{OnPlatform Ctrl+Q, macOS=⌘+Q}"/>
77+
<TextBlock Grid.Row="9" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Quit}" />
7578
</Grid>
7679

7780
<TextBlock Text="{DynamicResource Text.Hotkeys.Repo}"

0 commit comments

Comments
 (0)