Skip to content

Commit

Permalink
Merge pull request #28 from spoiledcat/fixes/misc
Browse files Browse the repository at this point in the history
Hierarchy Icons feature, Project icons visibility toggle, difftool support, Settings UI cleanup, NRE fix in the settings view.
  • Loading branch information
shana authored Feb 24, 2024
2 parents 07a3c33 + a9190d3 commit 342a955
Show file tree
Hide file tree
Showing 34 changed files with 950 additions and 598 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Reflection;

namespace Unity.VersionControl.Git
{
public static class ApplicationConfiguration
Expand All @@ -8,5 +6,29 @@ public static class ApplicationConfiguration
public const int DefaultGitTimeout = 5000;
public static int WebTimeout { get; set; } = DefaultWebTimeout;
public static int GitTimeout { get; set; } = DefaultGitTimeout;
public static bool HierarchyIconsEnabled { get; set; } = true;
public static bool HierarchyIconsIndented { get; set; } = false;
public static int HierarchyIconsOffsetRight { get; set; } = 0;
public static int HierarchyIconsOffsetLeft { get; set; } = 0;
public static HierarchyIconAlignment HierarchyIconsAlignment { get; set; } = HierarchyIconAlignment.Right;
public static bool ProjectIconsEnabled { get; set; } = true;

public static void Initialize(ISettings settings)
{
WebTimeout = settings.Get(Constants.WebTimeoutKey, WebTimeout);
GitTimeout = settings.Get(Constants.GitTimeoutKey, GitTimeout);
HierarchyIconsEnabled = settings.Get(Constants.HierarchyIconsEnabledKey, HierarchyIconsEnabled);
HierarchyIconsIndented = settings.Get(Constants.HierarchyIconsIndentedKey, HierarchyIconsIndented);
HierarchyIconsOffsetRight = settings.Get(Constants.HierarchyIconsOffsetRightKey, HierarchyIconsOffsetRight);
HierarchyIconsOffsetLeft = settings.Get(Constants.HierarchyIconsOffsetLeftKey, HierarchyIconsOffsetLeft);
HierarchyIconsAlignment = (HierarchyIconAlignment) settings.Get(Constants.HierarchyIconsAlignmentKey, (int)HierarchyIconsAlignment);
ProjectIconsEnabled = settings.Get(Constants.ProjectIconsEnabledKey, ProjectIconsEnabled);
}

public enum HierarchyIconAlignment
{
Right = 0,
Left = 1,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public ApplicationManagerBase(SynchronizationContext synchronizationContext, IGi
public void Initialize()
{
LogHelper.TracingEnabled = UserSettings.Get(Constants.TraceLoggingKey, false);
ApplicationConfiguration.WebTimeout = UserSettings.Get(Constants.WebTimeoutKey, ApplicationConfiguration.WebTimeout);
ApplicationConfiguration.GitTimeout = UserSettings.Get(Constants.GitTimeoutKey, ApplicationConfiguration.GitTimeout);
ApplicationConfiguration.Initialize(UserSettings);
progress.OnProgress += progressReporter.UpdateProgress;
}

Expand Down
9 changes: 6 additions & 3 deletions src/com.spoiledcat.git.api/Api/Helpers/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ namespace Unity.VersionControl.Git
{
public static class Constants
{
public const string GuidKey = "Guid";
public const string MetricsKey = "MetricsEnabled";
public const string UsageFile = "metrics.json";
public const string GitInstallPathKey = "GitInstallPath";
public const string TraceLoggingKey = "EnableTraceLogging";
public const string WebTimeoutKey = "WebTimeout";
public const string GitTimeoutKey = "GitTimeout";
public const string HierarchyIconsEnabledKey = "HierarchyIconsEnabled";
public const string HierarchyIconsIndentedKey = "HierarchyIconsIndented";
public const string HierarchyIconsOffsetRightKey = "HierarchyIconsOffsetRight";
public const string HierarchyIconsOffsetLeftKey = "HierarchyIconsOffsetLeft";
public const string HierarchyIconsAlignmentKey = "HierarchyIconsAlignment";
public const string ProjectIconsEnabledKey = "ProjectIconsEnabled";
public const string Iso8601Format = @"yyyy-MM-dd\THH\:mm\:ss.fffzzz";
public const string Iso8601FormatZ = @"yyyy-MM-dd\THH\:mm\:ss\Z";
public static readonly string[] Iso8601Formats = {
Expand Down
3 changes: 1 addition & 2 deletions src/com.spoiledcat.git.api/Api/Platform/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,8 @@ protected virtual void LoadFromCache(string path)
if (c != null)
{
// upgrade from old format
if (c.ContainsKey("GitHubUnity"))
if (c.TryGetValue("GitHubUnity", out var oldRoot))
{
var oldRoot = c["GitHubUnity"];
cacheData = oldRoot.FromObject<Dictionary<string, object>>();
SaveToCache(path);
}
Expand Down
3 changes: 2 additions & 1 deletion src/com.spoiledcat.git.ui/Editor/ApplicationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.Reflection;
using System.Threading;
using Unity.Editor.Tasks;
using Unity.VersionControl.Git.UI;
using UnityEditor;
using UnityEngine;
using UnityEngine.Events;

namespace Unity.VersionControl.Git
Expand Down Expand Up @@ -34,6 +34,7 @@ public override void InitializeUI()
isBusy = false;
LfsLocksModificationProcessor.Initialize(Environment, Platform);
ProjectWindowInterface.Initialize(this);
HierarchyWindowInterface.Initialize();
var window = Window.GetWindow();
if (window != null)
window.InitializeWindow(this);
Expand Down
91 changes: 87 additions & 4 deletions src/com.spoiledcat.git.ui/Editor/Misc/Styles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using UnityEditor.IMGUI.Controls;
using UnityEngine;

namespace Unity.VersionControl.Git
namespace Unity.VersionControl.Git.UI
{
class Styles
{
Expand All @@ -30,8 +30,6 @@ class Styles
CommitAreaPadding = 5f,
PublishViewSpacingHeight = 5f,
MinCommitTreePadding = 20f,
FoldoutWidth = 11f,
FoldoutIndentation = -2f,
TreePadding = 12f,
TreeIndentation = 12f,
TreeRootIndentation = -5f,
Expand All @@ -51,6 +49,11 @@ class Styles
GitIgnoreRulesFileRatio = .3f,
GitIgnoreRulesLineRatio = .5f;

const int
FoldoutContentRightPadding = 6,
FoldoutContentBottomPadding = 4,
FoldoutIndentation = 15;

public const int HalfSpacing = (int)(BaseSpacing / 2);

private const string WarningLabel = "<b>Warning:</b> {0}";
Expand Down Expand Up @@ -752,7 +755,7 @@ public static GUIStyle BoldCenteredLabel
return boldCenteredLabel;
}
}

public static GUIStyle CommitDescriptionFieldStyle
{
get
Expand Down Expand Up @@ -1168,6 +1171,86 @@ public static GUIStyle LockMetaDataStyle
}
}

private static GUIStyle indentedBox;
public static GUIStyle IndentedBox
{
get
{
if (indentedBox == null)
{
indentedBox = new GUIStyle
{
padding = new RectOffset(FoldoutIndentation, 0, 0, 0),
};
}

return indentedBox;
}
}

private static GUIStyle foldoutContent;
public static GUIStyle FoldoutContent
{
get
{
if (foldoutContent == null)
{
foldoutContent = new GUIStyle
{
padding = new RectOffset(FoldoutIndentation, FoldoutContentRightPadding, 0, FoldoutContentBottomPadding),
};
}

return foldoutContent;
}
}

private static string GetIconName(string name) => Utility.IsDarkTheme ? name + "-light" : name;
}

public static partial class Controls
{
public static bool Foldout(bool value, string label)
{
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
EditorGUILayout.BeginHorizontal();

var ret = EditorGUILayout.Toggle(value, Styles.Foldout);

EditorGUILayout.EndHorizontal();
EditorGUILayout.EndVertical();

var rect = GUILayoutUtility.GetLastRect();
rect.x += 20;
rect.width -= 20;

EditorGUI.LabelField(rect, label, Styles.BoldLabel);

return ret;
}

public static bool FoldoutScope(bool open, string title, Action draw)
{
var ret = Foldout(open, title);

if (ret)
{
GUILayout.BeginVertical(Styles.FoldoutContent, GUILayout.ExpandWidth(true));
draw();
GUILayout.EndVertical();
}

return ret;
}

public static void DoControl<T>(T val, Func<T, T> draw, Action<T> update)
{
EditorGUI.BeginChangeCheck();
T updated = draw(val);
if (EditorGUI.EndChangeCheck())
{
update(updated);
}
}
}
}
10 changes: 10 additions & 0 deletions src/com.spoiledcat.git.ui/Editor/Misc/UnityExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using UnityObject=UnityEngine.Object;

namespace Unity.VersionControl.Git.Extensions
{
public static class UnityExtensions
{

public static T Ref<T>(this T obj) where T : UnityObject => obj != null ? obj : null;
}
}
11 changes: 11 additions & 0 deletions src/com.spoiledcat.git.ui/Editor/Misc/UnityExtensions.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions src/com.spoiledcat.git.ui/Editor/Misc/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using UnityEngine;
using System.Collections.Generic;
using Unity.Editor.Tasks.Logging;
using Unity.VersionControl.Git.UI;

namespace Unity.VersionControl.Git
{
Expand All @@ -31,12 +32,12 @@ public static Texture2D GetIcon(string filename, string filename2x = null, bool

if (!filename.EndsWith(".png"))
filename += ".png";

var key = invertColors ? "dark_" + filename : "light_" + filename;

if (iconCache.ContainsKey(key))
if (iconCache.TryGetValue(key, out var icon))
{
return iconCache[key];
return icon;
}

Texture2D texture2D;
Expand Down
3 changes: 1 addition & 2 deletions src/com.spoiledcat.git.ui/Editor/UI/BaseWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Unity.VersionControl.Git;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -7,7 +6,7 @@
using UnityEditor;
using UnityEngine;

namespace Unity.VersionControl.Git
namespace Unity.VersionControl.Git.UI
{
public abstract class BaseWindow : EditorWindow, IView
{
Expand Down
3 changes: 1 addition & 2 deletions src/com.spoiledcat.git.ui/Editor/UI/BranchesView.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using SpoiledCat.Git;
Expand All @@ -8,7 +7,7 @@
using UnityEditor;
using UnityEngine;

namespace Unity.VersionControl.Git
namespace Unity.VersionControl.Git.UI
{
[Serializable]
class BranchesView : Subview
Expand Down
1 change: 1 addition & 0 deletions src/com.spoiledcat.git.ui/Editor/UI/ChangesTreeControl.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Unity.VersionControl.Git.UI;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
Expand Down
53 changes: 26 additions & 27 deletions src/com.spoiledcat.git.ui/Editor/UI/ChangesView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using UnityEditor;
using UnityEngine;

namespace Unity.VersionControl.Git
namespace Unity.VersionControl.Git.UI
{
using IO;

Expand Down Expand Up @@ -171,7 +171,7 @@ private void OnTreeGUI(Rect rect)

var treeRenderRect = treeChanges.Render(rect, treeScroll,
node => { },
node => { },
ShowDiff,
node => {
var menu = CreateContextMenu(node);
menu.ShowAsContext();
Expand All @@ -188,31 +188,7 @@ private GenericMenu CreateContextMenu(ChangesTreeNode node)
{
var genericMenu = new GenericMenu();

genericMenu.AddItem(new GUIContent("Show Diff"), false, () =>
{
ITask<SPath[]> calculateDiff = null;
if (node.IsFolder)
{
calculateDiff = CalculateFolderDiff(node);
}
else
{
calculateDiff = CalculateFileDiff(node);
}
calculateDiff.FinallyInUI((s, ex, leftRight) =>
{
if (s)
EditorUtility.InvokeDiffTool(
leftRight[0].IsInitialized ? leftRight[0].FileName : null,
leftRight[0].IsInitialized ? leftRight[0].MakeAbsolute().ToString() : null,
leftRight[1].IsInitialized ? leftRight[1].FileName : null,
leftRight[1].IsInitialized ? leftRight[1].MakeAbsolute().ToString() : null,
null, null);
else
ex.Rethrow();
})
.Start();
});
genericMenu.AddItem(new GUIContent("Show Diff"), false, () => ShowDiff(node));

genericMenu.AddSeparator("");

Expand Down Expand Up @@ -250,6 +226,29 @@ private GenericMenu CreateContextMenu(ChangesTreeNode node)
return genericMenu;
}

private void ShowDiff(ChangesTreeNode node)
{
ITask<SPath[]> calculateDiff = null;
if (node.IsFolder)
{
calculateDiff = CalculateFolderDiff(node);
}
else
{
calculateDiff = CalculateFileDiff(node);
}

calculateDiff.FinallyInUI((s, ex, leftRight) => {
if (s)
EditorUtility.InvokeDiffTool(leftRight[0].IsInitialized ? leftRight[0].FileName : null,
leftRight[0].IsInitialized ? leftRight[0].MakeAbsolute().ToString() : null,
leftRight[1].IsInitialized ? leftRight[1].FileName : null,
leftRight[1].IsInitialized ? leftRight[1].MakeAbsolute().ToString() : null, null, null);
else
ex.Rethrow();
}).Start();
}

private ITask<SPath[]> CalculateFolderDiff(ChangesTreeNode node)
{
var rightFile = node.Path.ToSPath();
Expand Down
2 changes: 1 addition & 1 deletion src/com.spoiledcat.git.ui/Editor/UI/FileHistoryWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using UnityEditor;
using UnityEngine;

namespace Unity.VersionControl.Git
namespace Unity.VersionControl.Git.UI
{
using IO;

Expand Down
Loading

0 comments on commit 342a955

Please sign in to comment.