From 2c06435b06dfd393d4795e3618288cbd040e9d1f Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 31 Jul 2017 15:50:53 -0400 Subject: [PATCH] Splicing out ReSharper changes and reformatting of Styles and RepositoryManager --- GitHub.Unity.sln.DotSettings | 23 +- src/GitHub.Api/Git/RepositoryManager.cs | 70 +- .../Assets/Editor/GitHub.Unity/Misc/Styles.cs | 754 ++++++++---------- 3 files changed, 392 insertions(+), 455 deletions(-) diff --git a/GitHub.Unity.sln.DotSettings b/GitHub.Unity.sln.DotSettings index d131030cf..ee988de68 100644 --- a/GitHub.Unity.sln.DotSettings +++ b/GitHub.Unity.sln.DotSettings @@ -1,5 +1,6 @@  <?xml version="1.0" encoding="utf-16"?><Profile name="C#"><CSReorderTypeMembers>True</CSReorderTypeMembers><CSUpdateFileHeader>True</CSUpdateFileHeader><CSCodeStyleAttributes ArrangeTypeAccessModifier="True" ArrangeTypeMemberAccessModifier="True" SortModifiers="True" RemoveRedundantParentheses="True" AddMissingParentheses="True" ArrangeBraces="True" ArrangeAttributes="True" ArrangeArgumentsStyle="True" /><CSEnforceVarKeywordUsageSettings>True</CSEnforceVarKeywordUsageSettings><CSArrangeQualifiers>True</CSArrangeQualifiers><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSShortenReferences>True</CSShortenReferences><CSReformatCode>True</CSReformatCode></Profile> + <?xml version="1.0" encoding="utf-16"?><Profile name="Relayout"><CSReorderTypeMembers>True</CSReorderTypeMembers></Profile> C# C# Required @@ -262,17 +263,6 @@ <ImplementsInterface Immediate="True" /> </Entry.SortBy> </Entry> - <Entry DisplayName="Other Static Methods" Priority="49"> - <Entry.Match> - <And> - <Kind Is="Method" /> - <Static /> - </And> - </Entry.Match> - <Entry.SortBy> - <Access /> - </Entry.SortBy> - </Entry> <Entry DisplayName="Other Instance Methods" Priority="39"> <Entry.Match> <And> @@ -300,6 +290,17 @@ <ImplementsInterface Immediate="True" /> </Entry.SortBy> </Entry> + <Entry DisplayName="Other Static Methods" Priority="49"> + <Entry.Match> + <And> + <Kind Is="Method" /> + <Static /> + </And> + </Entry.Match> + <Entry.SortBy> + <Access /> + </Entry.SortBy> + </Entry> <Entry DisplayName="Dispose Implementation" Priority="100"> <Entry.Match> <Or> diff --git a/src/GitHub.Api/Git/RepositoryManager.cs b/src/GitHub.Api/Git/RepositoryManager.cs index f5ccb4a79..5883fddf6 100644 --- a/src/GitHub.Api/Git/RepositoryManager.cs +++ b/src/GitHub.Api/Git/RepositoryManager.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -11,21 +10,13 @@ interface IRepositoryManager : IDisposable { event Action OnActiveBranchChanged; event Action OnActiveRemoteChanged; - event Action OnRemoteBranchListChanged; + event Action OnIsBusyChanged; event Action OnLocalBranchListChanged; - event Action OnStatusUpdated; event Action OnHeadChanged; - event Action OnIsBusyChanged; - event Action OnRemoteOrTrackingChanged; + event Action OnStatusUpdated; event Action> OnLocksUpdated; - Dictionary LocalBranches { get; } - Dictionary> RemoteBranches { get; } - IRepository Repository { get; } - IGitConfig Config { get; } - ConfigBranch? ActiveBranch { get; } - ConfigRemote? ActiveRemote { get; } - IGitClient GitClient { get; } - bool IsBusy { get; } + event Action OnRemoteBranchListChanged; + event Action OnRemoteOrTrackingChanged; Task Initialize(); void Start(); void Stop(); @@ -44,6 +35,14 @@ interface IRepositoryManager : IDisposable ITask ListLocks(bool local); ITask LockFile(string file); ITask UnlockFile(string file, bool force); + Dictionary LocalBranches { get; } + Dictionary> RemoteBranches { get; } + IRepository Repository { get; } + IGitConfig Config { get; } + ConfigBranch? ActiveBranch { get; } + ConfigRemote? ActiveRemote { get; } + IGitClient GitClient { get; } + bool IsBusy { get; } } interface IRepositoryPathConfiguration @@ -91,8 +90,8 @@ public RepositoryPathConfiguration(NPath repositoryPath) class RepositoryManagerFactory { - public RepositoryManager CreateRepositoryManager(IPlatform platform, ITaskManager taskManager, IUsageTracker usageTracker, - IGitClient gitClient, NPath repositoryRoot) + public RepositoryManager CreateRepositoryManager(IPlatform platform, ITaskManager taskManager, + IUsageTracker usageTracker, IGitClient gitClient, NPath repositoryRoot) { var repositoryPathConfiguration = new RepositoryPathConfiguration(repositoryRoot); string filePath = repositoryPathConfiguration.DotGitConfig; @@ -100,8 +99,8 @@ public RepositoryManager CreateRepositoryManager(IPlatform platform, ITaskManage var repositoryWatcher = new RepositoryWatcher(platform, repositoryPathConfiguration, taskManager.Token); - return new RepositoryManager(platform, taskManager, usageTracker, gitConfig, repositoryWatcher, - gitClient, repositoryPathConfiguration, taskManager.Token); + return new RepositoryManager(platform, taskManager, usageTracker, gitConfig, repositoryWatcher, gitClient, + repositoryPathConfiguration, taskManager.Token); } } @@ -110,34 +109,34 @@ class RepositoryManager : IRepositoryManager private readonly Dictionary branches = new Dictionary(); private readonly CancellationToken cancellationToken; private readonly IGitConfig config; + private readonly IGitClient gitClient; private readonly IPlatform platform; + private readonly IRepositoryPathConfiguration repositoryPaths; private readonly ITaskManager taskManager; private readonly IUsageTracker usageTracker; - private IRepository repository; - private readonly IRepositoryPathConfiguration repositoryPaths; - private readonly IGitClient gitClient; private readonly IRepositoryWatcher watcher; private ConfigBranch? activeBranch; private ConfigRemote? activeRemote; private string head; private bool isBusy; + private IEnumerable locks; private Dictionary> remoteBranches = new Dictionary>(); private Dictionary remotes; - private IEnumerable locks; + private IRepository repository; public event Action OnActiveBranchChanged; public event Action OnActiveRemoteChanged; - public event Action OnRemoteBranchListChanged; - public event Action OnLocalBranchListChanged; - public event Action OnStatusUpdated; public event Action OnHeadChanged; public event Action OnIsBusyChanged; - public event Action OnRemoteOrTrackingChanged; + public event Action OnLocalBranchListChanged; public event Action> OnLocksUpdated; + public event Action OnRemoteBranchListChanged; + public event Action OnRemoteOrTrackingChanged; + public event Action OnStatusUpdated; - public RepositoryManager(IPlatform platform, ITaskManager taskManager, IUsageTracker usageTracker, IGitConfig gitConfig, - IRepositoryWatcher repositoryWatcher, IGitClient gitClient, + public RepositoryManager(IPlatform platform, ITaskManager taskManager, IUsageTracker usageTracker, + IGitConfig gitConfig, IRepositoryWatcher repositoryWatcher, IGitClient gitClient, IRepositoryPathConfiguration repositoryPaths, CancellationToken cancellationToken) { this.repositoryPaths = repositoryPaths; @@ -163,9 +162,11 @@ public RepositoryManager(IPlatform platform, ITaskManager taskManager, IUsageTra var remote = config.GetRemote("origin"); if (!remote.HasValue) + { remote = config.GetRemotes() - .Where(x => HostAddress.Create(new UriString(x.Url).ToRepositoryUri()).IsGitHubDotCom()) - .FirstOrDefault(); + .Where(x => HostAddress.Create(new UriString(x.Url).ToRepositoryUri()).IsGitHubDotCom()) + .FirstOrDefault(); + } UriString cloneUrl = ""; if (remote.Value.Url != null) { @@ -398,8 +399,7 @@ private void Watcher_OnHeadChanged(string contents) } private void Watcher_OnIndexChanged() - { - } + { } private void Watcher_OnLocalBranchCreated(string name) { @@ -436,6 +436,7 @@ private async Task InitializeRepository() { throw new InvalidOperationException("No user configured"); } + user.Email = res; repository.User = user; return repository; @@ -599,6 +600,7 @@ private void RemoveRemoteBranch(string remote, string name) } private bool disposed; + private void Dispose(bool disposing) { if (disposed) return; @@ -628,7 +630,8 @@ public ConfigBranch? ActiveBranch get { return activeBranch; } private set { - if (activeBranch.HasValue != value.HasValue || (activeBranch.HasValue && !activeBranch.Value.Equals(value.Value))) + if (activeBranch.HasValue != value.HasValue || + activeBranch.HasValue && !activeBranch.Value.Equals(value.Value)) { activeBranch = value; Logger.Trace("OnActiveBranchChanged: {0}", value?.ToString() ?? "NULL"); @@ -642,7 +645,8 @@ public ConfigRemote? ActiveRemote get { return activeRemote; } private set { - if (activeRemote.HasValue != value.HasValue || (activeRemote.HasValue && !activeRemote.Value.Equals(value.Value))) + if (activeRemote.HasValue != value.HasValue || + activeRemote.HasValue && !activeRemote.Value.Equals(value.Value)) { activeRemote = value; Logger.Trace("OnActiveRemoteChanged: {0}", value?.ToString() ?? "NULL"); diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/Misc/Styles.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/Misc/Styles.cs index 6912478e5..086ba6913 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/Misc/Styles.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/Misc/Styles.cs @@ -1,117 +1,189 @@ -using UnityEngine; -using UnityEditor; using System; - +using UnityEditor; +using UnityEngine; namespace GitHub.Unity { class Styles { - public const float - BaseSpacing = 10f, - BroadModeLimit = 500f, - NarrowModeLimit = 300f, - ModeNotificationDelay = .5f, - BroadModeBranchesMinWidth = 200f, - BroadModeBranchesRatio = .4f, - InitialStateAreaWidth = 200f, - HistoryEntryHeight = 40f, - HistorySummaryHeight = 16f, - HistoryDetailsHeight = 16f, - HistoryEntryPadding = 16f, - HistoryChangesIndentation = 17f, - CommitAreaMinHeight = 16f, - CommitAreaDefaultRatio = .4f, - CommitAreaMaxHeight = 12 * 15f, - CommitAreaPadding = 5f, - MinCommitTreePadding = 20f, - FoldoutWidth = 11f, - FoldoutIndentation = -2f, - TreeIndentation = 12f, - TreeRootIndentation = -5f, - TreeVerticalSpacing = 3f, - CommitIconSize = 16f, - CommitIconHorizontalPadding = -5f, - BranchListIndentation = 20f, - BranchListSeperation = 15f, - RemotesTotalHorizontalMargin = 37f, - RemotesNameRatio = .2f, - RemotesUserRatio = .2f, - RemotesHostRation = .5f, - RemotesAccessRatio = .1f, - GitIgnoreRulesTotalHorizontalMargin = 33f, - GitIgnoreRulesSelectorWidth = 14f, - GitIgnoreRulesEffectRatio = .2f, - GitIgnoreRulesFileRatio = .3f, - GitIgnoreRulesLineRatio = .5f; - - public const int - HalfSpacing = (int)(BaseSpacing / 2); - - - const string - BrowseButton = "...", - WarningLabel = "Warning: {0}"; - - static Color - headerGreyColor = new Color(0.878f,0.878f,0.878f,1.0f); - - static GUIStyle - label, - boldLabel, - errorLabel, - deletedFileLabel, - longMessageStyle, - headerBoxStyle, - headerBranchLabelStyle, - headerRepoLabelStyle, - headerTitleStyle, - headerDescriptionStyle, - historyToolbarButtonStyle, - historyLockStyle, - historyEntryDetailsStyle, - historyEntryDetailsRightStyle, - historyFileTreeBoxStyle, - commitFileAreaStyle, - commitButtonStyle, - textFieldStyle, - centeredLabel, - commitDescriptionFieldStyle, - toggleMixedStyle, - authHeaderBoxStyle, - lockedFileRowSelectedStyle, - lockedFileRowStyle, - genericTableBoxStyle, - historyDetailsTitleStyle, - historyDetailsMetaInfoStyle, - genericBoxStyle; - static Texture2D - modifiedStatusIcon, - addedStatusIcon, - deletedStatusIcon, - renamedStatusIcon, - untrackedStatusIcon, - branchIcon, - trackedStatusIcon, - lockedStatusIcon, - lockedModifiedStatusIcon, - activeBranchIcon, - trackingBranchIcon, - favouriteIconOn, - favouriteIconOff, - smallLogoIcon, - bigLogoIcon, - defaultAssetIcon, - folderIcon, - mergeIcon, - dotIcon, - localCommitIcon, - repoIcon, - lockIcon, - dropdownListIcon; - - static Color - timelineBarColor; + public const float BaseSpacing = 10f, + BroadModeLimit = 500f, + NarrowModeLimit = 300f, + ModeNotificationDelay = .5f, + BroadModeBranchesMinWidth = 200f, + BroadModeBranchesRatio = .4f, + InitialStateAreaWidth = 200f, + HistoryEntryHeight = 40f, + HistorySummaryHeight = 16f, + HistoryDetailsHeight = 16f, + HistoryEntryPadding = 16f, + HistoryChangesIndentation = 17f, + CommitAreaMinHeight = 16f, + CommitAreaDefaultRatio = .4f, + CommitAreaMaxHeight = 12 * 15f, + CommitAreaPadding = 5f, + MinCommitTreePadding = 20f, + FoldoutWidth = 11f, + FoldoutIndentation = -2f, + TreeIndentation = 12f, + TreeRootIndentation = -5f, + TreeVerticalSpacing = 3f, + CommitIconSize = 16f, + CommitIconHorizontalPadding = -5f, + BranchListIndentation = 20f, + BranchListSeperation = 15f, + RemotesTotalHorizontalMargin = 37f, + RemotesNameRatio = .2f, + RemotesUserRatio = .2f, + RemotesHostRation = .5f, + RemotesAccessRatio = .1f, + GitIgnoreRulesTotalHorizontalMargin = 33f, + GitIgnoreRulesSelectorWidth = 14f, + GitIgnoreRulesEffectRatio = .2f, + GitIgnoreRulesFileRatio = .3f, + GitIgnoreRulesLineRatio = .5f; + + public const int HalfSpacing = (int)(BaseSpacing / 2); + + private const string BrowseButton = "..."; + private const string WarningLabel = "Warning: {0}"; + + private static Color headerGreyColor = new Color(0.878f, 0.878f, 0.878f, 1.0f); + + private static GUIStyle label, + boldLabel, + errorLabel, + deletedFileLabel, + longMessageStyle, + headerBoxStyle, + headerBranchLabelStyle, + headerRepoLabelStyle, + headerTitleStyle, + headerDescriptionStyle, + historyToolbarButtonStyle, + historyLockStyle, + historyEntryDetailsStyle, + historyEntryDetailsRightStyle, + historyFileTreeBoxStyle, + commitFileAreaStyle, + commitButtonStyle, + textFieldStyle, + centeredLabel, + commitDescriptionFieldStyle, + toggleMixedStyle, + authHeaderBoxStyle, + lockedFileRowSelectedStyle, + lockedFileRowStyle, + genericTableBoxStyle, + historyDetailsTitleStyle, + historyDetailsMetaInfoStyle, + genericBoxStyle; + + private static Texture2D branchIcon, + activeBranchIcon, + trackingBranchIcon, + favouriteIconOn, + favouriteIconOff, + smallLogoIcon, + bigLogoIcon, + defaultAssetIcon, + folderIcon, + mergeIcon, + dotIcon, + localCommitIcon, + repoIcon, + lockIcon, + dropdownListIcon; + + private static Color timelineBarColor; + + public static Texture2D GetFileStatusIcon(GitFileStatus status, bool isLocked) + { + if (isLocked) + { + switch (status) + { + case GitFileStatus.Modified: + return Utility.GetIcon("locked.png", "locked@2x.png"); + + default: + return Utility.GetIcon("locked-by-person.png", "locked-by-person@2x.png"); + } + } + + switch (status) + { + case GitFileStatus.Modified: + return Utility.GetIcon("modified.png", "modified@2x.png"); + case GitFileStatus.Added: + return Utility.GetIcon("added.png", "added@2x.png"); + case GitFileStatus.Deleted: + return Utility.GetIcon("removed.png", "removed@2x.png"); + case GitFileStatus.Renamed: + return Utility.GetIcon("renamed.png", "renamed@2x.png"); + case GitFileStatus.Untracked: + return Utility.GetIcon("untracked.png", "untracked@2x.png"); + } + + return null; + } + + public static void BeginInitialStateArea(string title, string message) + { + GUILayout.BeginVertical(); + GUILayout.FlexibleSpace(); + GUILayout.BeginHorizontal(); + GUILayout.FlexibleSpace(); + GUILayout.BeginVertical(GUILayout.MaxWidth(InitialStateAreaWidth)); + GUILayout.Label(title, EditorStyles.boldLabel); + GUILayout.Label(message, LongMessageStyle); + } + + public static void EndInitialStateArea() + { + GUILayout.EndVertical(); + GUILayout.FlexibleSpace(); + GUILayout.EndHorizontal(); + GUILayout.FlexibleSpace(); + GUILayout.EndVertical(); + } + + public static bool InitialStateActionButton(string label) + { + bool result; + + GUILayout.BeginHorizontal(); + GUILayout.FlexibleSpace(); + result = GUILayout.Button(label, GUILayout.ExpandWidth(false)); + GUILayout.EndHorizontal(); + + return result; + } + + public static void Warning(string message) + { + GUILayout.BeginHorizontal(EditorStyles.helpBox); + GUILayout.Label(string.Format(WarningLabel, message), LongMessageStyle); + GUILayout.FlexibleSpace(); + GUILayout.EndHorizontal(); + } + + public static void PathField(ref string path, Func browseFunction, Func validationFunction) + { + GUILayout.BeginHorizontal(); + path = EditorGUILayout.TextField("Path to Git", path); + if (GUILayout.Button(BrowseButton, EditorStyles.miniButton, GUILayout.Width(25))) + { + var newValue = browseFunction(); + if (!string.IsNullOrEmpty(newValue) && validationFunction(newValue)) + { + path = newValue; + GUIUtility.keyboardControl = GUIUtility.hotControl = 0; + GUI.changed = true; + } + } + GUILayout.EndHorizontal(); + } public static GUIStyle HistoryFileTreeBoxStyle { @@ -138,94 +210,88 @@ public static GUIStyle Label label = new GUIStyle(GUI.skin.label); label.name = "CustomLabel"; - GUIStyle hierarchyStyle = GUI.skin.FindStyle("PR Label"); + var hierarchyStyle = GUI.skin.FindStyle("PR Label"); label.onNormal.background = hierarchyStyle.onNormal.background; label.onNormal.textColor = hierarchyStyle.onNormal.textColor; label.onFocused.background = hierarchyStyle.onFocused.background; label.onFocused.textColor = hierarchyStyle.onFocused.textColor; } - return label; } } - public static GUIStyle HeaderBranchLabelStyle - { - get - { - if (headerBranchLabelStyle == null) - { - headerBranchLabelStyle = new GUIStyle(EditorStyles.label); - headerBranchLabelStyle.name = "HeaderBranchLabelStyle"; - headerBranchLabelStyle.margin = new RectOffset(0,0,0,0); - } - - return headerBranchLabelStyle; - } - } - - public static GUIStyle HeaderRepoLabelStyle - { - get - { - if (headerRepoLabelStyle == null) - { - headerRepoLabelStyle = new GUIStyle(EditorStyles.boldLabel); - headerRepoLabelStyle.name = "HeaderRepoLabelStyle"; - headerRepoLabelStyle.margin = new RectOffset(0,0,0,0); - } - - return headerRepoLabelStyle; - } - } - - public static GUIStyle HeaderTitleStyle - { - get - { - if (headerTitleStyle == null) + public static GUIStyle HeaderBranchLabelStyle { - headerTitleStyle = new GUIStyle(EditorStyles.boldLabel); - headerTitleStyle.name = "HeaderTitleStyle"; - headerTitleStyle.margin = new RectOffset(0,0,0,0); - headerTitleStyle.wordWrap = true; + get + { + if (headerBranchLabelStyle == null) + { + headerBranchLabelStyle = new GUIStyle(EditorStyles.label); + headerBranchLabelStyle.name = "HeaderBranchLabelStyle"; + headerBranchLabelStyle.margin = new RectOffset(0, 0, 0, 0); + } + return headerBranchLabelStyle; + } } - return headerTitleStyle; - } - } + public static GUIStyle HeaderRepoLabelStyle + { + get + { + if (headerRepoLabelStyle == null) + { + headerRepoLabelStyle = new GUIStyle(EditorStyles.boldLabel); + headerRepoLabelStyle.name = "HeaderRepoLabelStyle"; + headerRepoLabelStyle.margin = new RectOffset(0, 0, 0, 0); + } + return headerRepoLabelStyle; + } + } - public static GUIStyle HeaderDescriptionStyle - { - get - { - if (headerDescriptionStyle == null) + public static GUIStyle HeaderTitleStyle { - headerDescriptionStyle = new GUIStyle(EditorStyles.label); - headerDescriptionStyle.name = "HeaderDescriptionStyle"; - headerDescriptionStyle.margin = new RectOffset(0,0,0,0); - headerDescriptionStyle.wordWrap = true; + get + { + if (headerTitleStyle == null) + { + headerTitleStyle = new GUIStyle(EditorStyles.boldLabel); + headerTitleStyle.name = "HeaderTitleStyle"; + headerTitleStyle.margin = new RectOffset(0, 0, 0, 0); + headerTitleStyle.wordWrap = true; + } + return headerTitleStyle; + } } - return headerDescriptionStyle; - } - } + public static GUIStyle HeaderDescriptionStyle + { + get + { + if (headerDescriptionStyle == null) + { + headerDescriptionStyle = new GUIStyle(EditorStyles.label); + headerDescriptionStyle.name = "HeaderDescriptionStyle"; + headerDescriptionStyle.margin = new RectOffset(0, 0, 0, 0); + headerDescriptionStyle.wordWrap = true; + } + return headerDescriptionStyle; + } + } - public static GUIStyle HeaderBoxStyle - { - get - { - if (headerBoxStyle == null) - { - headerBoxStyle = new GUIStyle("IN BigTitle"); - headerBoxStyle.name = "HeaderBoxStyle"; - headerBoxStyle.padding = new RectOffset(5,5,5,5); - headerBoxStyle.margin = new RectOffset(0,0,0,0); - } - - return headerBoxStyle; - } - } + public static GUIStyle HeaderBoxStyle + { + get + { + if (headerBoxStyle == null) + { + headerBoxStyle = new GUIStyle("IN BigTitle"); + headerBoxStyle.name = "HeaderBoxStyle"; + headerBoxStyle.padding = new RectOffset(5, 5, 5, 5); + headerBoxStyle.margin = new RectOffset(0, 0, 0, 0); + } + return headerBoxStyle; + } + } public static GUIStyle BoldLabel { @@ -238,41 +304,38 @@ public static GUIStyle BoldLabel boldLabel.fontStyle = FontStyle.Bold; } - return boldLabel; } } - public static GUIStyle DeletedFileLabel - { - get - { - if (deletedFileLabel == null) - { - deletedFileLabel = new GUIStyle(EditorStyles.label); - deletedFileLabel.name = "DeletedFileLabel"; - deletedFileLabel.normal.textColor = Color.gray; - } - - return deletedFileLabel; - } - } - - public static GUIStyle ErrorLabel - { - get - { - if (errorLabel == null) + public static GUIStyle DeletedFileLabel { - errorLabel = new GUIStyle(EditorStyles.label); - errorLabel.name = "ErrorLabel"; - errorLabel.wordWrap = true; - errorLabel.normal.textColor = Color.red; + get + { + if (deletedFileLabel == null) + { + deletedFileLabel = new GUIStyle(EditorStyles.label); + deletedFileLabel.name = "DeletedFileLabel"; + deletedFileLabel.normal.textColor = Color.gray; + } + return deletedFileLabel; + } } - return errorLabel; - } - } + public static GUIStyle ErrorLabel + { + get + { + if (errorLabel == null) + { + errorLabel = new GUIStyle(EditorStyles.label); + errorLabel.name = "ErrorLabel"; + errorLabel.wordWrap = true; + errorLabel.normal.textColor = Color.red; + } + return errorLabel; + } + } public static GUIStyle LongMessageStyle { @@ -285,12 +348,10 @@ public static GUIStyle LongMessageStyle longMessageStyle.richText = true; longMessageStyle.wordWrap = true; } - return longMessageStyle; } } - public static GUIStyle HistoryToolbarButtonStyle { get @@ -302,12 +363,10 @@ public static GUIStyle HistoryToolbarButtonStyle historyToolbarButtonStyle.richText = true; historyToolbarButtonStyle.wordWrap = true; } - return historyToolbarButtonStyle; } } - public static GUIStyle HistoryLockStyle { get @@ -317,14 +376,11 @@ public static GUIStyle HistoryLockStyle historyLockStyle = new GUIStyle(GUI.skin.FindStyle("IN LockButton")); historyLockStyle.name = "HistoryLockStyle"; } - historyLockStyle.margin = new RectOffset(3, 3, 2, 2); - return historyLockStyle; } } - public static GUIStyle HistoryEntryDetailsStyle { get @@ -333,7 +389,7 @@ public static GUIStyle HistoryEntryDetailsStyle { historyEntryDetailsStyle = new GUIStyle(EditorStyles.miniLabel); historyEntryDetailsStyle.name = "HistoryEntryDetailsStyle"; - Color c = EditorStyles.miniLabel.normal.textColor; + var c = EditorStyles.miniLabel.normal.textColor; historyEntryDetailsStyle.normal.textColor = new Color(c.r, c.g, c.b, c.a * 0.7f); historyEntryDetailsStyle.onNormal.background = Label.onNormal.background; @@ -341,12 +397,10 @@ public static GUIStyle HistoryEntryDetailsStyle historyEntryDetailsStyle.onFocused.background = Label.onFocused.background; historyEntryDetailsStyle.onFocused.textColor = Label.onFocused.textColor; } - return historyEntryDetailsStyle; } } - public static GUIStyle HistoryEntryDetailsRightStyle { get @@ -356,9 +410,7 @@ public static GUIStyle HistoryEntryDetailsRightStyle historyEntryDetailsRightStyle = new GUIStyle(HistoryEntryDetailsStyle); historyEntryDetailsRightStyle.name = "HistoryEntryDetailsRightStyle"; } - historyEntryDetailsRightStyle.alignment = TextAnchor.MiddleRight; - return historyEntryDetailsRightStyle; } } @@ -373,7 +425,6 @@ public static GUIStyle LockedFileRowStyle lockedFileRowStyle.name = "LockedFileRowStyle"; lockedFileRowStyle.padding = new RectOffset(2, 2, 1, 1); } - return lockedFileRowStyle; } } @@ -384,13 +435,12 @@ public static GUIStyle LockedFileRowSelectedStyle { if (lockedFileRowSelectedStyle == null) { - GUIStyle hierarchyStyle = GUI.skin.FindStyle("PR Label"); + var hierarchyStyle = GUI.skin.FindStyle("PR Label"); lockedFileRowSelectedStyle = new GUIStyle(LockedFileRowStyle); lockedFileRowSelectedStyle.name = "LockedFileRowSelectedStyle"; lockedFileRowSelectedStyle.normal.background = hierarchyStyle.onFocused.background; lockedFileRowSelectedStyle.normal.textColor = hierarchyStyle.onFocused.textColor; } - return lockedFileRowSelectedStyle; } } @@ -404,7 +454,6 @@ public static GUIStyle GenericTableBoxStyle genericTableBoxStyle = new GUIStyle(GUI.skin.box); genericTableBoxStyle.name = "GenericTableBoxStyle"; } - return genericTableBoxStyle; } } @@ -419,7 +468,6 @@ public static GUIStyle HistoryDetailsTitleStyle historyDetailsTitleStyle.name = "HistoryDetailsTitleStyle"; historyDetailsTitleStyle.wordWrap = true; } - return historyDetailsTitleStyle; } } @@ -434,7 +482,6 @@ public static GUIStyle HistoryDetailsMetaInfoStyle historyDetailsMetaInfoStyle.name = "HistoryDetailsMetaInfoStyle"; historyDetailsMetaInfoStyle.normal.textColor = new Color(0f, 0f, 0f, 0.6f); } - return historyDetailsMetaInfoStyle; } } @@ -449,12 +496,10 @@ public static GUIStyle CommitFileAreaStyle commitFileAreaStyle.name = "CommitFileAreaStyle"; commitFileAreaStyle.margin = new RectOffset(0, 0, 0, 0); } - return commitFileAreaStyle; } } - public static GUIStyle CommitButtonStyle { get @@ -466,39 +511,36 @@ public static GUIStyle CommitButtonStyle commitButtonStyle.richText = true; commitButtonStyle.wordWrap = true; } - return commitButtonStyle; } } - public static GUIStyle TextFieldStyle - { - get - { - if (textFieldStyle == null) - { - textFieldStyle = new GUIStyle(GUI.skin.textField); - textFieldStyle.name = "TextFieldStyle"; - textFieldStyle.fixedHeight = 21; - textFieldStyle.padding = new RectOffset(HalfSpacing, HalfSpacing, 4, 0); - } - - return textFieldStyle; - } - } + public static GUIStyle TextFieldStyle + { + get + { + if (textFieldStyle == null) + { + textFieldStyle = new GUIStyle(GUI.skin.textField); + textFieldStyle.name = "TextFieldStyle"; + textFieldStyle.fixedHeight = 21; + textFieldStyle.padding = new RectOffset(HalfSpacing, HalfSpacing, 4, 0); + } + return textFieldStyle; + } + } public static GUIStyle CenteredLabel { - get - { - if (centeredLabel == null) + get { - centeredLabel = new GUIStyle(EditorStyles.wordWrappedLabel); - centeredLabel.alignment = TextAnchor.MiddleCenter; + if (centeredLabel == null) + { + centeredLabel = new GUIStyle(EditorStyles.wordWrappedLabel); + centeredLabel.alignment = TextAnchor.MiddleCenter; + } + return centeredLabel; } - - return centeredLabel; - } } public static GUIStyle CommitDescriptionFieldStyle @@ -512,12 +554,10 @@ public static GUIStyle CommitDescriptionFieldStyle commitDescriptionFieldStyle.padding = new RectOffset(HalfSpacing, HalfSpacing, HalfSpacing, HalfSpacing); commitDescriptionFieldStyle.wordWrap = true; } - return commitDescriptionFieldStyle; } } - public static GUIStyle ToggleMixedStyle { get @@ -526,53 +566,48 @@ public static GUIStyle ToggleMixedStyle { toggleMixedStyle = GUI.skin.FindStyle("ToggleMixed"); } - return toggleMixedStyle; } } public static GUIStyle AuthHeaderBoxStyle { - get - { - if (authHeaderBoxStyle == null) + get { - authHeaderBoxStyle = new GUIStyle(HeaderBoxStyle); - authHeaderBoxStyle.name = "AuthHeaderBoxStyle"; - authHeaderBoxStyle.padding = new RectOffset(10,10,0,5); + if (authHeaderBoxStyle == null) + { + authHeaderBoxStyle = new GUIStyle(HeaderBoxStyle); + authHeaderBoxStyle.name = "AuthHeaderBoxStyle"; + authHeaderBoxStyle.padding = new RectOffset(10, 10, 0, 5); + } + return authHeaderBoxStyle; } - - return authHeaderBoxStyle; - } } public static GUIStyle GenericBoxStyle { - get - { - if (genericBoxStyle == null) + get { - genericBoxStyle = new GUIStyle(); - genericBoxStyle.padding = new RectOffset(5,5,5,5); + if (genericBoxStyle == null) + { + genericBoxStyle = new GUIStyle(); + genericBoxStyle.padding = new RectOffset(5, 5, 5, 5); + } + return genericBoxStyle; } - - return genericBoxStyle; - } } - public static Color TimelineBarColor - { - get - { - if (timelineBarColor == null) - { - timelineBarColor = new Color(0.51F, 0.51F, 0.51F, 0.2F); - } - - return timelineBarColor; - } - } - + public static Color TimelineBarColor + { + get + { + if (timelineBarColor == null) + { + timelineBarColor = new Color(0.51F, 0.51F, 0.51F, 0.2F); + } + return timelineBarColor; + } + } public static Texture2D ActiveBranchIcon { @@ -582,7 +617,6 @@ public static Texture2D ActiveBranchIcon { activeBranchIcon = Utility.GetIcon("current-branch-indicator.png", "current-branch-indicator@2x.png"); } - return activeBranchIcon; } } @@ -595,7 +629,6 @@ public static Texture2D BranchIcon { branchIcon = Utility.GetIcon("branch.png", "branch@2x.png"); } - return branchIcon; } } @@ -613,7 +646,6 @@ public static Texture2D TrackingBranchIcon } } - public static Texture2D FavouriteIconOn { get @@ -627,7 +659,6 @@ public static Texture2D FavouriteIconOn } } - public static Texture2D FavouriteIconOff { get @@ -641,7 +672,6 @@ public static Texture2D FavouriteIconOff } } - public static Texture2D SmallLogo { get @@ -668,31 +698,31 @@ public static Texture2D BigLogo } } - public static Texture2D MergeIcon - { - get - { - if (mergeIcon == null) - { - mergeIcon = Utility.GetIcon("git-merge.png", "git-merge@2x.png"); - } + public static Texture2D MergeIcon + { + get + { + if (mergeIcon == null) + { + mergeIcon = Utility.GetIcon("git-merge.png", "git-merge@2x.png"); + } - return mergeIcon; - } - } + return mergeIcon; + } + } - public static Texture2D DotIcon - { - get - { - if (dotIcon == null) - { - dotIcon = Utility.GetIcon("dot.png", "dot@2x.png"); - } + public static Texture2D DotIcon + { + get + { + if (dotIcon == null) + { + dotIcon = Utility.GetIcon("dot.png", "dot@2x.png"); + } - return dotIcon; - } - } + return dotIcon; + } + } public static Texture2D LocalCommitIcon { @@ -720,7 +750,6 @@ public static Texture2D DefaultAssetIcon } } - public static Texture2D FolderIcon { get @@ -734,7 +763,6 @@ public static Texture2D FolderIcon } } - public static Texture2D RepoIcon { get @@ -743,7 +771,6 @@ public static Texture2D RepoIcon { repoIcon = Utility.GetIcon("repo.png", "repo@2x.png"); } - return repoIcon; } } @@ -754,9 +781,8 @@ public static Texture2D LockIcon { if (lockIcon == null) { - lockIcon = Utility.GetIcon("lock.png", "lock@2x.png"); + lockIcon = Utility.GetIcon("lock.png", "lock@2x.png"); } - return lockIcon; } } @@ -767,104 +793,10 @@ public static Texture2D DropdownListIcon { if (dropdownListIcon == null) { - dropdownListIcon = Utility.GetIcon("dropdown-list-icon.png", "dropdown-list-icon@2x.png"); + dropdownListIcon = Utility.GetIcon("dropdown-list-icon.png", "dropdown-list-icon@2x.png"); } - return dropdownListIcon; } } - - public static Texture2D GetFileStatusIcon(GitFileStatus status, bool isLocked) - { - if (isLocked) - { - switch (status) - { - case GitFileStatus.Modified: - return Utility.GetIcon("locked.png", "locked@2x.png"); - - default: - return Utility.GetIcon("locked-by-person.png", "locked-by-person@2x.png"); - } - } - - switch (status) - { - case GitFileStatus.Modified: - return Utility.GetIcon("modified.png", "modified@2x.png"); - case GitFileStatus.Added: - return Utility.GetIcon("added.png", "added@2x.png"); - case GitFileStatus.Deleted: - return Utility.GetIcon("removed.png", "removed@2x.png"); - case GitFileStatus.Renamed: - return Utility.GetIcon("renamed.png", "renamed@2x.png"); - case GitFileStatus.Untracked: - return Utility.GetIcon("untracked.png", "untracked@2x.png"); - } - - return null; - } - - - public static void BeginInitialStateArea(string title, string message) - { - GUILayout.BeginVertical(); - GUILayout.FlexibleSpace(); - GUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - GUILayout.BeginVertical(GUILayout.MaxWidth(Styles.InitialStateAreaWidth)); - GUILayout.Label(title, EditorStyles.boldLabel); - GUILayout.Label(message, Styles.LongMessageStyle); - } - - - public static void EndInitialStateArea() - { - GUILayout.EndVertical(); - GUILayout.FlexibleSpace(); - GUILayout.EndHorizontal(); - GUILayout.FlexibleSpace(); - GUILayout.EndVertical(); - } - - - public static bool InitialStateActionButton(string label) - { - bool result; - - GUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - result = GUILayout.Button(label, GUILayout.ExpandWidth(false)); - GUILayout.EndHorizontal(); - - return result; - } - - - public static void Warning(string message) - { - GUILayout.BeginHorizontal(EditorStyles.helpBox); - GUILayout.Label(String.Format(WarningLabel, message), Styles.LongMessageStyle); - GUILayout.FlexibleSpace(); - GUILayout.EndHorizontal(); - } - - - public static void PathField(ref string path, Func browseFunction, Func validationFunction) - { - GUILayout.BeginHorizontal(); - path = EditorGUILayout.TextField("Path to Git", path); - if (GUILayout.Button(BrowseButton, EditorStyles.miniButton, GUILayout.Width(25))) - { - string newValue = browseFunction(); - if (!string.IsNullOrEmpty(newValue) && validationFunction(newValue)) - { - path = newValue; - GUIUtility.keyboardControl = GUIUtility.hotControl = 0; - GUI.changed = true; - } - } - GUILayout.EndHorizontal(); - } } }