Skip to content

Commit 4659fbd

Browse files
committed
code_review: code review for PR #33
* use PNG instead of SVG for external tool icons and remove dependency `Avalonia.SVG` * remove unused property `IsVSCodeFound` and `IsFleetFound` * find VS from registry first * remove compile warning CA1416 * remove unused enum `OS.Platforms`
1 parent 370b9bd commit 4659fbd

File tree

10 files changed

+85
-162
lines changed

10 files changed

+85
-162
lines changed

src/SourceGit/Native/OS.cs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
using Avalonia;
55

6-
// ReSharper disable InconsistentNaming
7-
86
namespace SourceGit.Native
97
{
108
public static class OS
@@ -29,27 +27,24 @@ public interface IBackend
2927

3028
public static string FleetExecutableFile { get; set; }
3129

32-
public enum Platforms
33-
{
34-
Unknown = 0,
35-
Windows = 1,
36-
MacOS = 2,
37-
Linux
38-
}
39-
40-
public static Platforms Platform => OperatingSystem.IsWindows() ? Platforms.Windows : OperatingSystem.IsMacOS() ? Platforms.MacOS : OperatingSystem.IsLinux() ? Platforms.Linux : Platforms.Unknown;
41-
4230
static OS()
4331
{
44-
_backend = Platform switch
32+
if (OperatingSystem.IsWindows())
33+
{
34+
_backend = new Windows();
35+
}
36+
else if (OperatingSystem.IsMacOS())
37+
{
38+
_backend = new MacOS();
39+
}
40+
else if (OperatingSystem.IsLinux())
4541
{
46-
#pragma warning disable CA1416
47-
Platforms.Windows => new Windows(),
48-
Platforms.MacOS => new MacOS(),
49-
Platforms.Linux => new Linux(),
50-
#pragma warning restore CA1416
51-
_ => throw new Exception("Platform unsupported!!!")
52-
};
42+
_backend = new Linux();
43+
}
44+
else
45+
{
46+
throw new Exception("Platform unsupported!!!");
47+
}
5348

5449
VSCodeExecutableFile = _backend.FindVSCode();
5550
FleetExecutableFile = _backend.FindFleet();
@@ -95,7 +90,10 @@ public static void OpenInVSCode(string repo)
9590

9691
Process.Start(new ProcessStartInfo()
9792
{
98-
WorkingDirectory = repo, FileName = VSCodeExecutableFile, Arguments = $"\"{repo}\"", UseShellExecute = false,
93+
WorkingDirectory = repo,
94+
FileName = VSCodeExecutableFile,
95+
Arguments = $"\"{repo}\"",
96+
UseShellExecute = false,
9997
});
10098
}
10199

@@ -111,7 +109,10 @@ public static void OpenInFleet(string repo)
111109

112110
Process.Start(new ProcessStartInfo()
113111
{
114-
WorkingDirectory = repo, FileName = FleetExecutableFile, Arguments = $"\"{repo}\"", UseShellExecute = false,
112+
WorkingDirectory = repo,
113+
FileName = FleetExecutableFile,
114+
Arguments = $"\"{repo}\"",
115+
UseShellExecute = false,
115116
});
116117
}
117118
}

src/SourceGit/Native/Windows.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,21 @@ public string FindGitExecutable()
103103

104104
public string FindVSCode()
105105
{
106+
var root = Microsoft.Win32.RegistryKey.OpenBaseKey(
107+
Microsoft.Win32.RegistryHive.LocalMachine,
108+
Environment.Is64BitOperatingSystem ? Microsoft.Win32.RegistryView.Registry64 : Microsoft.Win32.RegistryView.Registry32);
109+
110+
var vscode = root.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{EA457B21-F73E-494C-ACAB-524FDE069978}_is1");
111+
if (vscode != null)
112+
{
113+
return vscode.GetValue("DisplayIcon") as string;
114+
}
115+
106116
var toolPath = Environment.ExpandEnvironmentVariables($"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe");
107117
if (File.Exists(toolPath)) return toolPath;
108118
return string.Empty;
109119
}
110-
120+
111121
public string FindFleet()
112122
{
113123
var toolPath = Environment.ExpandEnvironmentVariables($"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\\AppData\\Local\\Programs\\Fleet\\Fleet.exe");
5.1 KB
Loading

src/SourceGit/Resources/ExternalToolIcons/fleet_icon.svg

Lines changed: 0 additions & 50 deletions
This file was deleted.
2.5 KB
Loading

src/SourceGit/Resources/ExternalToolIcons/vscode_icon.svg

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/SourceGit/SourceGit.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<ItemGroup>
2424
<AvaloniaResource Include="App.ico" />
2525
<AvaloniaResource Include="Resources/Fonts/*" />
26+
<AvaloniaResource Include="Resources/ExternalToolIcons/*" />
2627
</ItemGroup>
2728

2829
<ItemGroup>
@@ -44,7 +45,6 @@
4445
<ItemGroup>
4546
<PackageReference Include="Avalonia" Version="11.0.10" />
4647
<PackageReference Include="Avalonia.Desktop" Version="11.0.10" />
47-
<PackageReference Include="Avalonia.Svg" Version="11.0.0.16" />
4848
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.10" />
4949
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.0.10" />
5050
<PackageReference Include="Avalonia.AvaloniaEdit" Version="11.0.6" />
@@ -58,8 +58,4 @@
5858
<TrimmerRootAssembly Include="SourceGit" />
5959
<TrimmerRootAssembly Include="Avalonia.Themes.Fluent" />
6060
</ItemGroup>
61-
62-
<ItemGroup>
63-
<AvaloniaResource Include="Resources\ExternalToolIcons\*" />
64-
</ItemGroup>
6561
</Project>

src/SourceGit/ViewModels/Repository.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,6 @@ public AvaloniaList<string> CommitMessages
4949
set;
5050
} = new AvaloniaList<string>();
5151

52-
[JsonIgnore]
53-
public bool IsVSCodeFound
54-
{
55-
get => !string.IsNullOrEmpty(Native.OS.VSCodeExecutableFile);
56-
}
57-
58-
[JsonIgnore]
59-
public bool IsFleetFound
60-
{
61-
get => !string.IsNullOrEmpty(Native.OS.FleetExecutableFile);
62-
}
63-
6452
[JsonIgnore]
6553
public Models.GitFlow GitFlow
6654
{
@@ -291,7 +279,7 @@ public void OpenInVSCode()
291279
{
292280
Native.OS.OpenInVSCode(_fullpath);
293281
}
294-
282+
295283
public void OpenInFleet()
296284
{
297285
Native.OS.OpenInFleet(_fullpath);

src/SourceGit/Views/Repository.axaml

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,33 @@
1818
<Path Width="15" Height="13" Data="{StaticResource Icons.Folder.Open}"/>
1919
</Button>
2020
<Button Classes="icon_button" Width="32" Command="{Binding OpenInTerminal}" ToolTip.Tip="{DynamicResource Text.Repository.Terminal}">
21-
<Path Width="13" Height="13" Data="{StaticResource Icons.Terminal}"/>
21+
<Path Width="13" Height="13" Data="{StaticResource Icons.Terminal}"/>
2222
</Button>
2323

2424
<Button Classes="icon_button" Width="32" ToolTip.Tip="{DynamicResource Text.Repository.OpenWith}">
25-
<Path Width="13" Height="13" Data="{StaticResource Icons.OpenWith}"/>
26-
<Button.Flyout>
27-
<MenuFlyout Placement="BottomEdgeAlignedLeft" VerticalOffset="-8">
28-
<MenuItem Header="{DynamicResource Text.Repository.Fleet}" Click="OpenInFleet">
29-
<MenuItem.Icon>
30-
<Svg Path="/Resources/ExternalToolIcons/fleet_icon.svg" Width="13" Height="13" />
31-
</MenuItem.Icon>
32-
</MenuItem>
33-
<MenuItem Header="{DynamicResource Text.Repository.VSCode}" Click="OpenInVSCode">
34-
<MenuItem.Icon>
35-
<Svg Path="/Resources/ExternalToolIcons/vscode_icon.svg" Width="13" Height="13" />
36-
</MenuItem.Icon>
37-
</MenuItem>
25+
<Path Width="13" Height="13" Data="{StaticResource Icons.OpenWith}"/>
26+
<Button.Flyout>
27+
<MenuFlyout Placement="BottomEdgeAlignedLeft" VerticalOffset="-8">
28+
<MenuItem Header="{DynamicResource Text.Repository.Fleet}" Command="{Binding OpenInFleet}">
29+
<MenuItem.Icon>
30+
<Image Source="/Resources/ExternalToolIcons/fleet.png" Width="13" Height="13" />
31+
</MenuItem.Icon>
32+
</MenuItem>
33+
<MenuItem Header="{DynamicResource Text.Repository.VSCode}" Command="{Binding OpenInVSCode}">
34+
<MenuItem.Icon>
35+
<Image Source="/Resources/ExternalToolIcons/vscode.png" Width="13" Height="13" />
36+
</MenuItem.Icon>
37+
</MenuItem>
3838
</MenuFlyout>
39-
</Button.Flyout>
40-
</Button>
41-
<ToggleButton Width="32"
42-
Background="Transparent"
43-
IsChecked="{Binding IsSearching, Mode=TwoWay}"
44-
ToolTip.Tip="{DynamicResource Text.Repository.Search}">
45-
<Path Width="14" Height="14" Data="{StaticResource Icons.Search}"/>
46-
</ToggleButton>
47-
39+
</Button.Flyout>
40+
</Button>
41+
<ToggleButton Width="32"
42+
Background="Transparent"
43+
IsChecked="{Binding IsSearching, Mode=TwoWay}"
44+
ToolTip.Tip="{DynamicResource Text.Repository.Search}">
45+
<Path Width="14" Height="14" Data="{StaticResource Icons.Search}"/>
46+
</ToggleButton>
47+
4848
</StackPanel>
4949

5050
<StackPanel Grid.Column="1" Orientation="Horizontal">
@@ -83,7 +83,7 @@
8383
</StackPanel>
8484

8585
<StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0,4,0">
86-
<ToggleButton Classes="layout_direction"
86+
<ToggleButton Classes="layout_direction"
8787
Width="32" Height="26"
8888
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=UseTwoColumnsLayoutInHistories, Mode=TwoWay}"
8989
IsVisible="{Binding SelectedViewIndex, Converter={x:Static c:IntConverters.IsZero}}"
@@ -198,12 +198,12 @@
198198
<TextBlock Classes="monospace" FontSize="10" HorizontalAlignment="Center" Margin="9,0" Text="{Binding UpstreamTrackStatus}"/>
199199
</Border>
200200

201-
<ToggleButton Grid.Column="3"
202-
Classes="filter"
203-
Margin="0,0,8,0"
204-
Background="Transparent"
205-
IsVisible="{Binding IsBranch}"
206-
Checked="OnToggleFilter"
201+
<ToggleButton Grid.Column="3"
202+
Classes="filter"
203+
Margin="0,0,8,0"
204+
Background="Transparent"
205+
IsVisible="{Binding IsBranch}"
206+
Checked="OnToggleFilter"
207207
Unchecked="OnToggleFilter"
208208
IsChecked="{Binding IsFiltered}"/>
209209
</Grid>
@@ -230,22 +230,22 @@
230230
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
231231
</Style>
232232
</TreeView.Styles>
233-
233+
234234
<TreeView.ItemTemplate>
235235
<TreeDataTemplate ItemsSource="{Binding Children}" x:DataType="{x:Type m:BranchTreeNode}">
236236
<Grid Height="24" ColumnDefinitions="Auto,*,Auto" Background="Transparent" ContextRequested="OnRemoteBranchContextMenuRequested">
237237
<Path Grid.Column="0" Classes="folder_icon" Width="10" Height="10" Margin="0,2,0,0" IsVisible="{Binding IsFolder}" VerticalAlignment="Center"/>
238238
<Path Grid.Column="0" Width="10" Height="10" Margin="0,4,0,0" Data="{StaticResource Icons.Remote}" IsVisible="{Binding IsRemote}" VerticalAlignment="Center"/>
239239
<Path Grid.Column="0" Width="10" Height="10" Data="{StaticResource Icons.Branch}" IsVisible="{Binding IsBranch}" VerticalAlignment="Center"/>
240-
240+
241241
<TextBlock Grid.Column="1" Text="{Binding Name}" Classes="monospace" Margin="8,0,4,0"/>
242-
243-
<ToggleButton Grid.Column="2"
244-
Classes="filter"
245-
Margin="0,0,8,0"
246-
Background="Transparent"
247-
Checked="OnToggleFilter"
248-
Unchecked="OnToggleFilter"
242+
243+
<ToggleButton Grid.Column="2"
244+
Classes="filter"
245+
Margin="0,0,8,0"
246+
Background="Transparent"
247+
Checked="OnToggleFilter"
248+
Unchecked="OnToggleFilter"
249249
IsVisible="{Binding IsBranch}"
250250
IsChecked="{Binding IsFiltered}"/>
251251
</Grid>
@@ -301,10 +301,10 @@
301301
<DataGridTemplateColumn Header="FILTER">
302302
<DataGridTemplateColumn.CellTemplate>
303303
<DataTemplate x:DataType="{x:Type m:Tag}">
304-
<ToggleButton Classes="filter"
305-
Margin="0,0,8,0"
306-
Background="Transparent"
307-
Checked="OnToggleFilter"
304+
<ToggleButton Classes="filter"
305+
Margin="0,0,8,0"
306+
Background="Transparent"
307+
Checked="OnToggleFilter"
308308
Unchecked="OnToggleFilter"
309309
IsChecked="{Binding IsFiltered}"/>
310310
</DataTemplate>
@@ -318,10 +318,10 @@
318318
<Grid ColumnDefinitions="Auto,*,Auto,Auto">
319319
<TextBlock Grid.Column="0" Classes="group_header_label" Margin="4,0,0,0" Text="{DynamicResource Text.Repository.Submodules}"/>
320320
<TextBlock Grid.Column="1" Text="{Binding Submodules, Converter={x:Static c:ListConverters.ToCount}}" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold"/>
321-
<Button Grid.Column="2"
322-
Classes="icon_button"
323-
Width="14"
324-
Margin="8,0"
321+
<Button Grid.Column="2"
322+
Classes="icon_button"
323+
Width="14"
324+
Margin="8,0"
325325
Click="UpdateSubmodules"
326326
IsVisible="{Binding Submodules, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}"
327327
ToolTip.Tip="{DynamicResource Text.Repository.Submodules.Update}">
@@ -371,7 +371,7 @@
371371
<!-- Left Search Mode -->
372372
<Grid Grid.Column="0" RowDefinitions="32,*" IsVisible="{Binding IsSearching}" PropertyChanged="OnSearchCommitPanelPropertyChanged">
373373
<!-- Search -->
374-
<TextBox Grid.Row="0"
374+
<TextBox Grid.Row="0"
375375
x:Name="txtSearchCommitsBox"
376376
Margin="4,2"
377377
Height="24"
@@ -445,7 +445,7 @@
445445
</DataGridTemplateColumn>
446446
</DataGrid.Columns>
447447
</DataGrid>
448-
448+
449449
<Path Grid.Row="1"
450450
HorizontalAlignment="Center" VerticalAlignment="Center"
451451
Width="48" Height="48"

0 commit comments

Comments
 (0)