Skip to content

Commit a807aa9

Browse files
committed
code_style: remove all IDE warnings
1 parent 9ac5502 commit a807aa9

File tree

94 files changed

+785
-807
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+785
-807
lines changed

src/App.axaml.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Reflection;
66
using System.Text;
77
using System.Text.Json;
8-
using System.Text.RegularExpressions;
98
using System.Threading.Tasks;
109
using System.Windows.Input;
1110

@@ -45,12 +44,12 @@ public partial class App : Application
4544
[STAThread]
4645
public static void Main(string[] args)
4746
{
48-
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
47+
AppDomain.CurrentDomain.UnhandledException += (_, e) =>
4948
{
5049
LogException(e.ExceptionObject as Exception);
5150
};
5251

53-
TaskScheduler.UnobservedTaskException += (sender, e) =>
52+
TaskScheduler.UnobservedTaskException += (_, e) =>
5453
{
5554
LogException(e.Exception);
5655
e.SetObserved();
@@ -333,7 +332,8 @@ public override void OnFrameworkInitializationCompleted()
333332

334333
private static void LogException(Exception ex)
335334
{
336-
if (ex == null) return;
335+
if (ex == null)
336+
return;
337337

338338
var builder = new StringBuilder();
339339
builder.Append($"Crash::: {ex.GetType().FullName}: {ex.Message}\n\n");
@@ -467,7 +467,7 @@ private bool TryLaunchedAsCoreEditor(IClassicDesktopStyleApplicationLifetime des
467467
if (!File.Exists(file))
468468
Environment.Exit(-1);
469469

470-
desktop.MainWindow = new Views.CodeEditor(file);
470+
desktop.MainWindow = new Views.StandaloneCommitMessageEditor(file);
471471
return true;
472472
}
473473

src/Commands/CompareRevisions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Text.RegularExpressions;
34

45
namespace SourceGit.Commands
@@ -18,7 +19,7 @@ public CompareRevisions(string repo, string start, string end)
1819
public List<Models.Change> Result()
1920
{
2021
Exec();
21-
_changes.Sort((l, r) => l.Path.CompareTo(r.Path));
22+
_changes.Sort((l, r) => string.Compare(l.Path, r.Path, StringComparison.Ordinal));
2223
return _changes;
2324
}
2425

src/Resources/Styles.axaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@
169169
<Setter Property="MaxWidth" Value="1024"/>
170170
<Setter Property="MaxHeight" Value="768"/>
171171
</Style>
172+
173+
<Style Selector="Grid.repository_leftpanel">
174+
</Style>
172175

173176
<Style Selector="Path">
174177
<Setter Property="Fill" Value="{DynamicResource Brush.FG1}"/>
@@ -178,6 +181,7 @@
178181
</Style>
179182
<Style Selector="Path[IsVisible=True].rotating">
180183
<Setter Property="Opacity" Value="0"/>
184+
<Setter Property="Data" Value="{StaticResource Icons.Loading}"/>
181185
<Style.Animations>
182186
<Animation Duration="0:0:1" IterationCount="Infinite">
183187
<KeyFrame Cue="0%">
@@ -193,6 +197,7 @@
193197
</Style>
194198
<Style Selector="Path[IsVisible=True].waiting">
195199
<Setter Property="Opacity" Value="0"/>
200+
<Setter Property="Data" Value="{StaticResource Icons.Waiting}"/>
196201
<Style.Animations>
197202
<Animation Duration="0:0:1" IterationCount="Infinite">
198203
<KeyFrame Cue="0%">
@@ -1191,6 +1196,17 @@
11911196
<Style Selector="ToggleButton.toggle_untracked:pointerover /template/ Path#PART_IndicatorIcon">
11921197
<Setter Property="Opacity" Value="1"/>
11931198
</Style>
1199+
1200+
<Style Selector="Slider">
1201+
<Style.Resources>
1202+
<Thickness x:Key="SliderTopHeaderMargin">0,0,0,4</Thickness>
1203+
<GridLength x:Key="SliderPreContentMargin">0</GridLength>
1204+
<GridLength x:Key="SliderPostContentMargin">0</GridLength>
1205+
<CornerRadius x:Key="SliderThumbCornerRadius">8</CornerRadius>
1206+
<x:Double x:Key="SliderHorizontalThumbWidth">16</x:Double>
1207+
<x:Double x:Key="SliderHorizontalThumbHeight">16</x:Double>
1208+
</Style.Resources>
1209+
</Style>
11941210

11951211
<Style Selector="TabItem">
11961212
<Setter Property="FontSize" Value="14"/>

src/ViewModels/ChangeTreeNode.cs

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
using Avalonia.Collections;
5+
6+
using CommunityToolkit.Mvvm.ComponentModel;
7+
8+
namespace SourceGit.ViewModels
9+
{
10+
public class ChangeTreeNode : ObservableObject
11+
{
12+
public string FullPath { get; set; } = string.Empty;
13+
public int Depth { get; private set; } = 0;
14+
public Models.Change Change { get; set; } = null;
15+
public List<ChangeTreeNode> Children { get; set; } = new List<ChangeTreeNode>();
16+
17+
public bool IsFolder
18+
{
19+
get => Change == null;
20+
}
21+
22+
public bool IsExpanded
23+
{
24+
get => _isExpanded;
25+
set => SetProperty(ref _isExpanded, value);
26+
}
27+
28+
public ChangeTreeNode(Models.Change c, int depth)
29+
{
30+
FullPath = c.Path;
31+
Depth = depth;
32+
Change = c;
33+
IsExpanded = false;
34+
}
35+
36+
public ChangeTreeNode(string path, bool isExpanded, int depth)
37+
{
38+
FullPath = path;
39+
Depth = depth;
40+
IsExpanded = isExpanded;
41+
}
42+
43+
public static List<ChangeTreeNode> Build(IList<Models.Change> changes, HashSet<string> folded)
44+
{
45+
var nodes = new List<ChangeTreeNode>();
46+
var folders = new Dictionary<string, ChangeTreeNode>();
47+
48+
foreach (var c in changes)
49+
{
50+
var sepIdx = c.Path.IndexOf('/', StringComparison.Ordinal);
51+
if (sepIdx == -1)
52+
{
53+
nodes.Add(new ChangeTreeNode(c, 0));
54+
}
55+
else
56+
{
57+
ChangeTreeNode lastFolder = null;
58+
var start = 0;
59+
var depth = 0;
60+
61+
while (sepIdx != -1)
62+
{
63+
var folder = c.Path.Substring(0, sepIdx);
64+
if (folders.TryGetValue(folder, out var value))
65+
{
66+
lastFolder = value;
67+
}
68+
else if (lastFolder == null)
69+
{
70+
lastFolder = new ChangeTreeNode(folder, !folded.Contains(folder), depth);
71+
folders.Add(folder, lastFolder);
72+
InsertFolder(nodes, lastFolder);
73+
}
74+
else
75+
{
76+
var cur = new ChangeTreeNode(folder, !folded.Contains(folder), depth);
77+
folders.Add(folder, cur);
78+
InsertFolder(lastFolder.Children, cur);
79+
lastFolder = cur;
80+
}
81+
82+
start = sepIdx + 1;
83+
depth++;
84+
sepIdx = c.Path.IndexOf('/', start);
85+
}
86+
87+
lastFolder.Children.Add(new ChangeTreeNode(c, depth));
88+
}
89+
}
90+
91+
Sort(nodes);
92+
93+
folders.Clear();
94+
return nodes;
95+
}
96+
97+
private static void InsertFolder(List<ChangeTreeNode> collection, ChangeTreeNode subFolder)
98+
{
99+
for (int i = 0; i < collection.Count; i++)
100+
{
101+
if (!collection[i].IsFolder)
102+
{
103+
collection.Insert(i, subFolder);
104+
return;
105+
}
106+
}
107+
108+
collection.Add(subFolder);
109+
}
110+
111+
private static void Sort(List<ChangeTreeNode> nodes)
112+
{
113+
foreach (var node in nodes)
114+
{
115+
if (node.IsFolder)
116+
Sort(node.Children);
117+
}
118+
119+
nodes.Sort((l, r) =>
120+
{
121+
if (l.IsFolder)
122+
return r.IsFolder ? string.Compare(l.FullPath, r.FullPath, StringComparison.Ordinal) : -1;
123+
return r.IsFolder ? 1 : string.Compare(l.FullPath, r.FullPath, StringComparison.Ordinal);
124+
});
125+
}
126+
127+
private bool _isExpanded = true;
128+
}
129+
130+
public class ChangeCollectionAsTree
131+
{
132+
public List<ChangeTreeNode> Tree { get; set; } = new List<ChangeTreeNode>();
133+
public AvaloniaList<ChangeTreeNode> Rows { get; set; } = new AvaloniaList<ChangeTreeNode>();
134+
}
135+
136+
public class ChangeCollectionAsGrid
137+
{
138+
public AvaloniaList<Models.Change> Changes { get; set; } = new AvaloniaList<Models.Change>();
139+
}
140+
141+
public class ChangeCollectionAsList
142+
{
143+
public AvaloniaList<Models.Change> Changes { get; set; } = new AvaloniaList<Models.Change>();
144+
}
145+
}

src/ViewModels/Preference.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ public static void AddNode(RepositoryNode node, RepositoryNode to = null)
349349
{
350350
if (l.IsRepository != r.IsRepository)
351351
return l.IsRepository ? 1 : -1;
352-
else
353-
return l.Name.CompareTo(r.Name);
352+
353+
return string.Compare(l.Name, r.Name, StringComparison.Ordinal);
354354
});
355355

356356
collection.Clear();
@@ -413,13 +413,9 @@ public static void SortByRenamedNode(RepositoryNode node)
413413
list.Sort((l, r) =>
414414
{
415415
if (l.IsRepository != r.IsRepository)
416-
{
417416
return l.IsRepository ? 1 : -1;
418-
}
419-
else
420-
{
421-
return l.Name.CompareTo(r.Name);
422-
}
417+
418+
return string.Compare(l.Name, r.Name, StringComparison.Ordinal);
423419
});
424420

425421
container.Clear();
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
4+
using CommunityToolkit.Mvvm.ComponentModel;
5+
6+
namespace SourceGit.ViewModels
7+
{
8+
public class RevisionFileTreeNode : ObservableObject
9+
{
10+
public Models.Object Backend { get; set; } = null;
11+
public int Depth { get; set; } = 0;
12+
public List<RevisionFileTreeNode> Children { get; set; } = new List<RevisionFileTreeNode>();
13+
14+
public string Name
15+
{
16+
get => Backend == null ? string.Empty : Path.GetFileName(Backend.Path);
17+
}
18+
19+
public bool IsFolder
20+
{
21+
get => Backend != null && Backend.Type == Models.ObjectType.Tree;
22+
}
23+
24+
public bool IsExpanded
25+
{
26+
get => _isExpanded;
27+
set => SetProperty(ref _isExpanded, value);
28+
}
29+
30+
private bool _isExpanded = false;
31+
}
32+
}

src/Views/About.axaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5-
xmlns:vm="using:SourceGit.ViewModels"
65
xmlns:v="using:SourceGit.Views"
76
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
87
x:Class="SourceGit.Views.About"

src/Views/About.axaml.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,42 @@ public string Version
1616
public About()
1717
{
1818
var ver = Assembly.GetExecutingAssembly().GetName().Version;
19-
Version = $"{ver.Major}.{ver.Minor}";
19+
if (ver != null)
20+
Version = $"{ver.Major}.{ver.Minor}";
21+
2022
DataContext = this;
2123
InitializeComponent();
2224
}
2325

24-
private void BeginMoveWindow(object sender, PointerPressedEventArgs e)
26+
private void BeginMoveWindow(object _, PointerPressedEventArgs e)
2527
{
2628
BeginMoveDrag(e);
2729
}
2830

29-
private void CloseWindow(object sender, RoutedEventArgs e)
31+
private void CloseWindow(object _1, RoutedEventArgs _2)
3032
{
3133
Close();
3234
}
3335

34-
private void OnVisitAvaloniaUI(object sender, PointerPressedEventArgs e)
36+
private void OnVisitAvaloniaUI(object _, PointerPressedEventArgs e)
3537
{
3638
Native.OS.OpenBrowser("https://www.avaloniaui.net/");
3739
e.Handled = true;
3840
}
3941

40-
private void OnVisitAvaloniaEdit(object sender, PointerPressedEventArgs e)
42+
private void OnVisitAvaloniaEdit(object _, PointerPressedEventArgs e)
4143
{
4244
Native.OS.OpenBrowser("https://github.com/AvaloniaUI/AvaloniaEdit");
4345
e.Handled = true;
4446
}
4547

46-
private void OnVisitJetBrainsMonoFont(object sender, PointerPressedEventArgs e)
48+
private void OnVisitJetBrainsMonoFont(object _, PointerPressedEventArgs e)
4749
{
4850
Native.OS.OpenBrowser("https://www.jetbrains.com/lp/mono/");
4951
e.Handled = true;
5052
}
5153

52-
private void OnVisitSourceCode(object sender, PointerPressedEventArgs e)
54+
private void OnVisitSourceCode(object _, PointerPressedEventArgs e)
5355
{
5456
Native.OS.OpenBrowser("https://github.com/sourcegit-scm/sourcegit");
5557
e.Handled = true;

src/Views/AddRemote.axaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5-
xmlns:m="using:SourceGit.Models"
65
xmlns:vm="using:SourceGit.ViewModels"
76
xmlns:v="using:SourceGit.Views"
8-
xmlns:c="using:SourceGit.Converters"
97
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
108
x:Class="SourceGit.Views.AddRemote"
119
x:DataType="vm:AddRemote">
@@ -44,7 +42,7 @@
4442
Text="{DynamicResource Text.SSHKey}"
4543
IsVisible="{Binding UseSSH}"/>
4644
<TextBox Grid.Row="2" Grid.Column="1"
47-
x:Name="txtSSHKey"
45+
x:Name="TxtSshKey"
4846
Height="28"
4947
CornerRadius="3"
5048
IsVisible="{Binding UseSSH}"

0 commit comments

Comments
 (0)