Skip to content

Commit 18aaa0a

Browse files
committed
style: add .editorconfig for code formatting. see issu #25
1 parent a8eeea4 commit 18aaa0a

File tree

225 files changed

+7768
-3898
lines changed

Some content is hidden

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

225 files changed

+7768
-3898
lines changed

.editorconfig

Lines changed: 364 additions & 0 deletions
Large diffs are not rendered by default.

src/App.axaml.cs

Lines changed: 69 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
using System;
2+
using System.IO;
3+
using System.Reflection;
4+
using System.Text;
5+
16
using Avalonia;
27
using Avalonia.Controls;
38
using Avalonia.Controls.ApplicationLifetimes;
@@ -6,19 +11,21 @@
611
using Avalonia.Media;
712
using Avalonia.Media.Fonts;
813
using Avalonia.Styling;
9-
using System;
10-
using System.IO;
11-
using System.Reflection;
12-
using System.Text;
1314

14-
namespace SourceGit {
15-
public partial class App : Application {
15+
namespace SourceGit
16+
{
17+
public partial class App : Application
18+
{
1619

1720
[STAThread]
18-
public static void Main(string[] args) {
19-
try {
21+
public static void Main(string[] args)
22+
{
23+
try
24+
{
2025
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
21-
} catch (Exception ex) {
26+
}
27+
catch (Exception ex)
28+
{
2229
var builder = new StringBuilder();
2330
builder.Append("Crash: ");
2431
builder.Append(ex.Message);
@@ -36,14 +43,16 @@ public static void Main(string[] args) {
3643
"SourceGit",
3744
$"crash_{time}.log");
3845
File.WriteAllText(file, builder.ToString());
39-
}
46+
}
4047
}
4148

42-
public static AppBuilder BuildAvaloniaApp() {
49+
public static AppBuilder BuildAvaloniaApp()
50+
{
4351
var builder = AppBuilder.Configure<App>();
4452
builder.UsePlatformDetect();
4553
builder.LogToTrace();
46-
builder.ConfigureFonts(manager => {
54+
builder.ConfigureFonts(manager =>
55+
{
4756
var monospace = new EmbeddedFontCollection(
4857
new Uri("fonts:SourceGit", UriKind.Absolute),
4958
new Uri("avares://SourceGit/Resources/Fonts", UriKind.Absolute));
@@ -54,60 +63,78 @@ public static AppBuilder BuildAvaloniaApp() {
5463
return builder;
5564
}
5665

57-
public static void RaiseException(string context, string message) {
58-
if (Current is App app && app._notificationReceiver != null) {
66+
public static void RaiseException(string context, string message)
67+
{
68+
if (Current is App app && app._notificationReceiver != null)
69+
{
5970
var notice = new Models.Notification() { IsError = true, Message = message };
6071
app._notificationReceiver.OnReceiveNotification(context, notice);
6172
}
6273
}
6374

64-
public static void SendNotification(string context, string message) {
65-
if (Current is App app && app._notificationReceiver != null) {
75+
public static void SendNotification(string context, string message)
76+
{
77+
if (Current is App app && app._notificationReceiver != null)
78+
{
6679
var notice = new Models.Notification() { IsError = false, Message = message };
6780
app._notificationReceiver.OnReceiveNotification(context, notice);
6881
}
6982
}
7083

71-
public static void SetLocale(string localeKey) {
84+
public static void SetLocale(string localeKey)
85+
{
7286
var app = Current as App;
7387
var targetLocale = app.Resources[localeKey] as ResourceDictionary;
74-
if (targetLocale == null || targetLocale == app._activeLocale) {
88+
if (targetLocale == null || targetLocale == app._activeLocale)
89+
{
7590
return;
7691
}
7792

78-
if (app._activeLocale != null) {
93+
if (app._activeLocale != null)
94+
{
7995
app.Resources.MergedDictionaries.Remove(app._activeLocale);
8096
}
8197

8298
app.Resources.MergedDictionaries.Add(targetLocale);
8399
app._activeLocale = targetLocale;
84100
}
85101

86-
public static void SetTheme(string theme) {
87-
if (theme.Equals("Light", StringComparison.OrdinalIgnoreCase)) {
102+
public static void SetTheme(string theme)
103+
{
104+
if (theme.Equals("Light", StringComparison.OrdinalIgnoreCase))
105+
{
88106
Current.RequestedThemeVariant = ThemeVariant.Light;
89-
} else if (theme.Equals("Dark", StringComparison.OrdinalIgnoreCase)) {
107+
}
108+
else if (theme.Equals("Dark", StringComparison.OrdinalIgnoreCase))
109+
{
90110
Current.RequestedThemeVariant = ThemeVariant.Dark;
91-
} else {
111+
}
112+
else
113+
{
92114
Current.RequestedThemeVariant = ThemeVariant.Default;
93115
}
94116
}
95117

96-
public static async void CopyText(string data) {
97-
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
98-
if (desktop.MainWindow.Clipboard is { } clipbord) {
118+
public static async void CopyText(string data)
119+
{
120+
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
121+
{
122+
if (desktop.MainWindow.Clipboard is { } clipbord)
123+
{
99124
await clipbord.SetTextAsync(data);
100125
}
101126
}
102127
}
103128

104-
public static string Text(string key, params object[] args) {
129+
public static string Text(string key, params object[] args)
130+
{
105131
var fmt = Current.FindResource($"Text.{key}") as string;
106132
if (string.IsNullOrWhiteSpace(fmt)) return $"Text.{key}";
107133
return string.Format(fmt, args);
108134
}
109135

110-
public static Avalonia.Controls.Shapes.Path CreateMenuIcon(string key) {
136+
public static Avalonia.Controls.Shapes.Path CreateMenuIcon(string key)
137+
{
111138
var icon = new Avalonia.Controls.Shapes.Path();
112139
icon.Width = 12;
113140
icon.Height = 12;
@@ -116,29 +143,36 @@ public static Avalonia.Controls.Shapes.Path CreateMenuIcon(string key) {
116143
return icon;
117144
}
118145

119-
public static TopLevel GetTopLevel() {
120-
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
146+
public static TopLevel GetTopLevel()
147+
{
148+
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
149+
{
121150
return desktop.MainWindow;
122151
}
123152
return null;
124153
}
125154

126-
public static void Quit() {
127-
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
155+
public static void Quit()
156+
{
157+
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
158+
{
128159
desktop.MainWindow.Close();
129160
desktop.Shutdown();
130161
}
131162
}
132163

133-
public override void Initialize() {
164+
public override void Initialize()
165+
{
134166
AvaloniaXamlLoader.Load(this);
135167

136168
SetLocale(ViewModels.Preference.Instance.Locale);
137169
SetTheme(ViewModels.Preference.Instance.Theme);
138170
}
139171

140-
public override void OnFrameworkInitializationCompleted() {
141-
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
172+
public override void OnFrameworkInitializationCompleted()
173+
{
174+
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
175+
{
142176
BindingPlugins.DataValidators.RemoveAt(0);
143177

144178
var launcher = new Views.Launcher();

src/Commands/Add.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
using System.Collections.Generic;
22
using System.Text;
33

4-
namespace SourceGit.Commands {
5-
public class Add : Command {
6-
public Add(string repo, List<Models.Change> changes = null) {
4+
namespace SourceGit.Commands
5+
{
6+
public class Add : Command
7+
{
8+
public Add(string repo, List<Models.Change> changes = null)
9+
{
710
WorkingDirectory = repo;
811
Context = repo;
912

10-
if (changes == null || changes.Count == 0) {
13+
if (changes == null || changes.Count == 0)
14+
{
1115
Args = "add .";
12-
} else {
16+
}
17+
else
18+
{
1319
var builder = new StringBuilder();
1420
builder.Append("add --");
15-
foreach (var c in changes) {
21+
foreach (var c in changes)
22+
{
1623
builder.Append(" \"");
1724
builder.Append(c.Path);
1825
builder.Append("\"");
@@ -21,4 +28,4 @@ public Add(string repo, List<Models.Change> changes = null) {
2128
}
2229
}
2330
}
24-
}
31+
}

src/Commands/Apply.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
namespace SourceGit.Commands {
2-
public class Apply : Command {
3-
public Apply(string repo, string file, bool ignoreWhitespace, string whitespaceMode, string extra) {
1+
namespace SourceGit.Commands
2+
{
3+
public class Apply : Command
4+
{
5+
public Apply(string repo, string file, bool ignoreWhitespace, string whitespaceMode, string extra)
6+
{
47
WorkingDirectory = repo;
58
Context = repo;
69
Args = "apply ";
@@ -10,4 +13,4 @@ public Apply(string repo, string file, bool ignoreWhitespace, string whitespaceM
1013
Args += $"\"{file}\"";
1114
}
1215
}
13-
}
16+
}

src/Commands/Archive.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
using System;
22

3-
namespace SourceGit.Commands {
4-
public class Archive : Command {
5-
public Archive(string repo, string revision, string saveTo, Action<string> outputHandler) {
3+
namespace SourceGit.Commands
4+
{
5+
public class Archive : Command
6+
{
7+
public Archive(string repo, string revision, string saveTo, Action<string> outputHandler)
8+
{
69
WorkingDirectory = repo;
710
Context = repo;
811
Args = $"archive --format=zip --verbose --output=\"{saveTo}\" {revision}";
912
TraitErrorAsOutput = true;
1013
_outputHandler = outputHandler;
1114
}
1215

13-
protected override void OnReadline(string line) {
16+
protected override void OnReadline(string line)
17+
{
1418
_outputHandler?.Invoke(line);
1519
}
1620

17-
private Action<string> _outputHandler;
21+
private readonly Action<string> _outputHandler;
1822
}
19-
}
23+
}

src/Commands/AssumeUnchanged.cs

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,47 @@
11
using System.Collections.Generic;
22
using System.Text.RegularExpressions;
33

4-
namespace SourceGit.Commands {
5-
public partial class AssumeUnchanged {
6-
partial class ViewCommand : Command {
7-
4+
namespace SourceGit.Commands
5+
{
6+
public partial class AssumeUnchanged
7+
{
8+
partial class ViewCommand : Command
9+
{
10+
811
[GeneratedRegex(@"^(\w)\s+(.+)$")]
912
private static partial Regex REG();
1013

11-
public ViewCommand(string repo) {
14+
public ViewCommand(string repo)
15+
{
1216
WorkingDirectory = repo;
1317
Args = "ls-files -v";
1418
RaiseError = false;
1519
}
1620

17-
public List<string> Result() {
21+
public List<string> Result()
22+
{
1823
Exec();
1924
return _outs;
2025
}
2126

22-
protected override void OnReadline(string line) {
27+
protected override void OnReadline(string line)
28+
{
2329
var match = REG().Match(line);
2430
if (!match.Success) return;
2531

26-
if (match.Groups[1].Value == "h") {
32+
if (match.Groups[1].Value == "h")
33+
{
2734
_outs.Add(match.Groups[2].Value);
2835
}
2936
}
3037

31-
private List<string> _outs = new List<string>();
38+
private readonly List<string> _outs = new List<string>();
3239
}
3340

34-
class ModCommand : Command {
35-
public ModCommand(string repo, string file, bool bAdd) {
41+
class ModCommand : Command
42+
{
43+
public ModCommand(string repo, string file, bool bAdd)
44+
{
3645
var mode = bAdd ? "--assume-unchanged" : "--no-assume-unchanged";
3746

3847
WorkingDirectory = repo;
@@ -41,22 +50,26 @@ public ModCommand(string repo, string file, bool bAdd) {
4150
}
4251
}
4352

44-
public AssumeUnchanged(string repo) {
53+
public AssumeUnchanged(string repo)
54+
{
4555
_repo = repo;
4656
}
4757

48-
public List<string> View() {
58+
public List<string> View()
59+
{
4960
return new ViewCommand(_repo).Result();
5061
}
5162

52-
public void Add(string file) {
63+
public void Add(string file)
64+
{
5365
new ModCommand(_repo, file, true).Exec();
5466
}
5567

56-
public void Remove(string file) {
68+
public void Remove(string file)
69+
{
5770
new ModCommand(_repo, file, false).Exec();
5871
}
5972

60-
private string _repo;
73+
private readonly string _repo;
6174
}
62-
}
75+
}

0 commit comments

Comments
 (0)