Skip to content

Commit 0a91ad2

Browse files
committed
Clean up
1 parent 088813f commit 0a91ad2

21 files changed

+314
-167
lines changed

Editor/Extensions.cs

+20-40
Original file line numberDiff line numberDiff line change
@@ -21,63 +21,43 @@ public static T GetResultOrDefault<T>(this Task<T> task, T defaultValue = defaul
2121
}
2222
return defaultValue;
2323
}
24-
public static string WrapUp(this string self, string wrapLeft = "\"", string wrapRight = null)
25-
{
26-
return wrapLeft + self + (wrapRight ?? wrapLeft);
27-
}
28-
public static string[] SplitLines(this string self)
29-
{
30-
return self.Split(new[] { '\n', '\r' }, RemoveEmptyEntries);
31-
}
32-
public static string Join(this IEnumerable<string> values)
33-
{
34-
return string.Join(string.Empty, values);
35-
}
36-
public static string Join(this IEnumerable<string> values, char separator)
37-
{
38-
return string.Join(separator, values);
39-
}
40-
public static string Join(this IEnumerable<string> values, string separator)
41-
{
42-
return string.Join(separator, values);
43-
}
24+
25+
public static string WrapUp(this string self, string wrapLeft = "\"", string wrapRight = null) => wrapLeft + self + (wrapRight ?? wrapLeft);
26+
27+
public static string[] SplitLines(this string self) => self.Split(new[] { '\n', '\r' }, RemoveEmptyEntries);
28+
29+
public static string Join(this IEnumerable<string> values) => string.Join(string.Empty, values);
30+
public static string Join(this IEnumerable<string> values, char separator) => string.Join(separator, values);
31+
public static string Join(this IEnumerable<string> values, string separator) => string.Join(separator, values);
32+
4433
public static int GetCombinedHashCode(this IEnumerable<object> values)
4534
{
4635
int hash = 0;
4736
foreach (var value in values)
4837
hash ^= value.GetHashCode();
4938
return hash;
5039
}
40+
5141
public static string AfterLast(this string self, char separator)
5242
{
5343
var index = self.LastIndexOf(separator);
5444
return index == -1 ? self : self[(index + 1)..];
5545
}
46+
5647
public static string AfterFirst(this string self, char separator)
5748
{
5849
var index = self.IndexOf(separator);
5950
return index == -1 ? self : self[(index + 1)..];
6051
}
61-
public static string NormalizeSlashes(this string self)
62-
{
63-
return self.Replace('\\', '/');
64-
}
65-
public static T When<T>(this T self, bool condition)
66-
{
67-
return condition ? self : default;
68-
}
69-
public static Vector2 To0Y(this int self)
70-
{
71-
return new Vector2(0, self);
72-
}
73-
public static Rect Move(this Rect rect, float x, float y)
74-
{
75-
return new Rect(rect.x + x, rect.y + y, rect.width, rect.height);
76-
}
77-
public static Rect Resize(this Rect rect, float width, float height)
78-
{
79-
return new Rect(rect.x, rect.y, width, height);
80-
}
52+
53+
public static string NormalizeSlashes(this string self) => self.Replace('\\', '/');
54+
55+
public static T When<T>(this T self, bool condition) => condition ? self : default;
56+
57+
public static Vector2 To0Y(this int self) => new Vector2(0, self);
58+
59+
public static Rect Move(this Rect rect, float x, float y) => new Rect(rect.x + x, rect.y + y, rect.width, rect.height);
60+
public static Rect Resize(this Rect rect, float width, float height) => new Rect(rect.x, rect.y, width, height);
8161

8262
public static async Task<T> AfterCompletion<T>(this Task<T> task, params Action[] actions)
8363
{

Editor/GUIUtils.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public class ListState : List<string>
2626
public static class GUIUtils
2727
{
2828
static Dictionary<string, Vector2> logScrollPositions = new();
29-
3029
static int reloadAssembliesStack = 0;
3130

3231
static void PushReloadAssembliesLock()
@@ -157,7 +156,7 @@ public static Module ModuleGuidToolbar(IReadOnlyList<Module> modules, string gui
157156
tab = modules.Count() > 1 ? GUILayout.Toolbar(tab, modules.Select(x => x.DisplayName).ToArray()) : 0;
158157
return modules[tab];
159158
}
160-
159+
161160
public static void DrawProcessLogs(IReadOnlyList<Module> modules, ref string guid, Vector2 size, Dictionary<string, int> localProcessIds = null)
162161
{
163162
if (modules.Count == 0)

Editor/GitBameWindow.cs

+10-6
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88

99
public static class GitBameWindow
1010
{
11-
[MenuItem("Assets/Git Blame", true)]
11+
class BlameLineItem : TreeViewItem
12+
{
13+
public BlameLine BlameLine { get; set; }
14+
}
15+
16+
[MenuItem("Assets/Git File Blame", true)]
1217
public static bool Check() => true;
1318

14-
[MenuItem("Assets/Git Blame", priority = 200)]
19+
[MenuItem("Assets/Git File Blame", priority = 200)]
1520
public static async void Invoke()
1621
{
1722
var scrollPosition = Vector2.zero;
@@ -21,6 +26,7 @@ public static async void Invoke()
2126
return;
2227
await ShowBlame(module, assetInfo.FullPath);
2328
}
29+
2430
public static async Task ShowBlame(Module module, string fullPath)
2531
{
2632
var blame = await module.BlameFile(fullPath);
@@ -50,6 +56,7 @@ public static async Task ShowBlame(Module module, string fullPath)
5056
});
5157
});
5258
}
59+
5360
static void DrawCell(TreeViewItem item, int columnIndex, Rect rect)
5461
{
5562
if (item is BlameLineItem { } blameLineItem)
@@ -63,10 +70,7 @@ static void DrawCell(TreeViewItem item, int columnIndex, Rect rect)
6370
}, Style.RichTextLabel.Value);
6471
}
6572
}
66-
class BlameLineItem : TreeViewItem
67-
{
68-
public BlameLine BlameLine { get; set; }
69-
}
73+
7074
static List<TreeViewItem> GenerateBlameItems(IEnumerable<BlameLine> blameLines)
7175
{
7276
return blameLines.Select(x => new BlameLineItem { BlameLine = x, id = x.GetHashCode() } as TreeViewItem).ToList();

Editor/GitBranchesWindow.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Mono.Cecil;
21
using System;
32
using System.Collections.Generic;
43
using System.Linq;
@@ -41,8 +40,7 @@ class GitBranchesWindow : DefaultWindow
4140
bool showAllBranches = false;
4241
Task task = null;
4342
LazyTreeView<Reference[]> simpleTreeView;
44-
[SerializeField]
45-
TreeViewState treeViewState;
43+
[SerializeField] TreeViewState treeViewState;
4644

4745
protected override void OnGUI()
4846
{
@@ -108,6 +106,7 @@ protected override void OnGUI()
108106

109107
base.OnGUI();
110108
}
109+
111110
static async void CreateOrRenameBranch(string oldName = null)
112111
{
113112
string newName = oldName;
@@ -129,6 +128,7 @@ static async void CreateOrRenameBranch(string oldName = null)
129128
}
130129
});
131130
}
131+
132132
void ShowContextMenu(IEnumerable<Module> modules, Reference selectedReference)
133133
{
134134
var menu = new GenericMenu();
@@ -202,6 +202,7 @@ void ShowContextMenu(IEnumerable<Module> modules, Reference selectedReference)
202202
menu.AddItem(new GUIContent($"New Tag"), false, () => GUIUtils.MakeTag());
203203
menu.ShowAsContext();
204204
}
205+
205206
List<TreeViewItem> GenerateItems(IEnumerable<Reference[]> branchesPerRepo)
206207
{
207208
var modules = Utils.GetSelectedGitModules();
@@ -219,6 +220,7 @@ List<TreeViewItem> GenerateItems(IEnumerable<Reference[]> branchesPerRepo)
219220
BranchesToItems(modules, references, x => x is Stash, 1, items);
220221
return items;
221222
}
223+
222224
List<TreeViewItem> BranchesToItems(IEnumerable<Module> modules, IEnumerable<Reference> branches, Func<Reference, bool> filter, int rootDepth, List<TreeViewItem> items)
223225
{
224226
string currentPath = "";

Editor/GitConfigWindow.cs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55
using UnityEditor;
6-
using UnityEditor.PackageManager.UI;
76
using UnityEngine;
87

98
public class GitConfigWindow : MonoBehaviour

Editor/GitDiffWindow.cs

+13-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Collections.Generic;
32
using System.Linq;
43
using System.Text.RegularExpressions;
@@ -14,12 +13,13 @@ public class GitDiff
1413
{
1514
[MenuItem("Assets/Git File Diff", true)]
1615
public static bool Check() => Selection.assetGUIDs.Any(x => Utils.GetAssetGitInfo(x) != null);
17-
[MenuItem("Window/Git GUI/Diff")]
18-
[MenuItem("Assets/Git File Diff", priority = 200)]
16+
17+
[MenuItem("Assets/Git File Diff", priority = 200), MenuItem("Window/Git GUI/Diff")]
1918
public static void Invoke()
2019
{
2120
ShowDiff();
2221
}
22+
2323
public static void ShowDiff()
2424
{
2525
if (EditorWindow.GetWindow<GitDiffWindow>() is { } window && window)
@@ -38,8 +38,7 @@ public class GitDiffWindow : DefaultWindow
3838
const int maxChangesDisplay = 1000;
3939

4040
static Regex hunkStartRegex = new Regex(@"@@ -(\d+),?(\d+)?.*?\+(\d+),?(\d+)?.*?@@");
41-
[SerializeField]
42-
bool staged;
41+
[SerializeField] bool staged;
4342
Vector2 scrollPosition;
4443
GUIContent[] toolbarContent;
4544
string[] diffLines;
@@ -138,6 +137,7 @@ protected override void OnGUI()
138137

139138
base.OnGUI();
140139
}
140+
141141
public void DrawGitDiff(Vector2 size, HunkAction stageHunk, HunkAction unstageHunk, HunkAction discardHunk, bool staged, bool showButtons, ref Vector2 scrollPosition)
142142
{
143143
diffUnchanged ??= new() {
@@ -236,6 +236,7 @@ public void DrawGitDiff(Vector2 size, HunkAction stageHunk, HunkAction unstageHu
236236
GUILayoutUtility.GetRect(width, currentOffset);
237237
scrollPosition = scroll.scrollPosition;
238238
}
239+
239240
void HandleSelection(bool previouslySelected, int index)
240241
{
241242
if (Event.current.control)
@@ -260,23 +261,17 @@ void HandleSelection(bool previouslySelected, int index)
260261
}
261262
lastSelectedLine = index;
262263
}
264+
263265
void CopySelected()
264266
{
265267
var selectedText = string.Join("\n", selectedLines.Select(x => diffLines[x][1..]));
266268
EditorGUIUtility.systemCopyBuffer = selectedText;
267269
}
268-
async void DiscardHunk(FileStatus file, int id)
269-
{
270-
await GitPatch("checkout -q --patch", file, id);
271-
}
272-
async void StageHunk(FileStatus file, int id)
273-
{
274-
await GitPatch("add --patch", file, id);
275-
}
276-
async void UnstageHunk(FileStatus file, int id)
277-
{
278-
await GitPatch("reset -q --patch", file, id);
279-
}
270+
271+
async void DiscardHunk(FileStatus file, int id) => await GitPatch("checkout -q --patch", file, id);
272+
async void StageHunk(FileStatus file, int id) => await GitPatch("add --patch", file, id);
273+
async void UnstageHunk(FileStatus file, int id) => await GitPatch("reset -q --patch", file, id);
274+
280275
async Task GitPatch(string args, FileStatus file, int id)
281276
{
282277
bool inputApplied = false;
@@ -294,6 +289,7 @@ await module.RunProcess("git", $"{args} -- {file.FullPath}", data => {
294289
});
295290
UpdateSelection(module);
296291
}
292+
297293
void UpdateSelection(params Module[] modules)
298294
{
299295
foreach (var module in modules)

0 commit comments

Comments
 (0)