From 475088075f8b97e360eb2392d7f0e2d4f01bcab0 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 30 Oct 2017 14:08:52 -0400 Subject: [PATCH 1/2] Removing branch favorite functionality --- .../Editor/GitHub.Unity/ApplicationCache.cs | 50 ---------- .../Editor/GitHub.Unity/UI/BranchesView.cs | 96 +------------------ 2 files changed, 1 insertion(+), 145 deletions(-) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationCache.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationCache.cs index 5200df7ec..d7a4df91b 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationCache.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationCache.cs @@ -123,56 +123,6 @@ public List RemoteBranches } } - [Location("views/branches.yaml", LocationAttribute.Location.LibraryFolder)] - sealed class Favorites : ScriptObjectSingleton - { - [SerializeField] private List favoriteBranches; - public List FavoriteBranches - { - get - { - if (favoriteBranches == null) - FavoriteBranches = new List(); - return favoriteBranches; - } - set - { - favoriteBranches = value; - Save(true); - } - } - - public void SetFavorite(string branchName) - { - if (FavoriteBranches.Contains(branchName)) - return; - FavoriteBranches.Add(branchName); - Save(true); - } - - public void UnsetFavorite(string branchName) - { - if (!FavoriteBranches.Contains(branchName)) - return; - FavoriteBranches.Remove(branchName); - Save(true); - } - - public void ToggleFavorite(string branchName) - { - if (FavoriteBranches.Contains(branchName)) - FavoriteBranches.Remove(branchName); - else - FavoriteBranches.Add(branchName); - Save(true); - } - - public bool IsFavorite(string branchName) - { - return FavoriteBranches.Contains(branchName); - } - } - [Location("cache/gitlog.yaml", LocationAttribute.Location.LibraryFolder)] sealed class GitLogCache : ScriptObjectSingleton { diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs index 8c00a6f63..c3174362c 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs @@ -24,8 +24,6 @@ class BranchesView : Subview private const string WarningCheckoutBranchExistsOK = "Ok"; private const string NewBranchCancelButton = "x"; private const string NewBranchConfirmButton = "Create"; - private const string FavoritesSetting = "Favorites"; - private const string FavoritesTitle = "Favorites"; private const string CreateBranchTitle = "Create Branch"; private const string LocalTitle = "Local branches"; private const string RemoteTitle = "Remote branches"; @@ -38,11 +36,9 @@ class BranchesView : Subview private bool showLocalBranches = true; private bool showRemoteBranches = true; - [NonSerialized] private List favorites = new List(); [NonSerialized] private int listID = -1; [NonSerialized] private BranchTreeNode newNodeSelection; [NonSerialized] private BranchesMode targetMode; - [NonSerialized] private bool favoritesHasChanged; [SerializeField] private BranchTreeNode activeBranchNode; [SerializeField] private BranchTreeNode localRoot; @@ -51,7 +47,6 @@ class BranchesView : Subview [SerializeField] private List remotes = new List(); [SerializeField] private Vector2 scroll; [SerializeField] private BranchTreeNode selectedNode; - [SerializeField] private List favoritesList = new List(); public override void InitializeView(IView parent) { @@ -63,7 +58,6 @@ public override void OnEnable() { base.OnEnable(); AttachHandlers(Repository); - favoritesHasChanged = true; Refresh(); } @@ -81,11 +75,6 @@ public override void OnDataUpdate() private void MaybeUpdateData() { - if (favoritesHasChanged) - { - favoritesList = Manager.LocalSettings.Get(FavoritesSetting, new List()); - favoritesHasChanged = false; - } } public override void OnRepositoryChanged(IRepository oldRepository) @@ -158,28 +147,6 @@ public void OnEmbeddedGUI() GUILayout.BeginVertical(Styles.CommitFileAreaStyle); { - // Favorites list - if (favorites.Count > 0) - { - GUILayout.Label(FavoritesTitle); - GUILayout.BeginHorizontal(); - { - GUILayout.BeginVertical(); - { - for (var index = 0; index < favorites.Count; ++index) - { - OnTreeNodeGUI(favorites[index]); - } - } - - GUILayout.EndVertical(); - } - - GUILayout.EndHorizontal(); - - GUILayout.Space(Styles.BranchListSeperation); - } - // Local branches and "create branch" button showLocalBranches = EditorGUILayout.Foldout(showLocalBranches, LocalTitle); if (showLocalBranches) @@ -262,16 +229,6 @@ public void OnEmbeddedGUI() private int CompareBranches(GitBranch a, GitBranch b) { - if (IsFavorite(a.Name)) - { - return -1; - } - - if (IsFavorite(b.Name)) - { - return 1; - } - if (a.Name.Equals("master")) { return -1; @@ -285,11 +242,6 @@ private int CompareBranches(GitBranch a, GitBranch b) return 0; } - private bool IsFavorite(string branchName) - { - return !String.IsNullOrEmpty(branchName) && favoritesList.Contains(branchName); - } - private void BuildTree(IEnumerable local, IEnumerable remote) { //Clear the selected node @@ -305,9 +257,6 @@ private void BuildTree(IEnumerable local, IEnumerable remo var tracking = new List>(); var localBranchNodes = new List(); - // Prepare for updated favorites listing - favorites.Clear(); - // Just build directly on the local root, keep track of active branch localRoot = new BranchTreeNode("", NodeType.Folder, false); for (var index = 0; index < localBranches.Count; ++index) @@ -335,12 +284,6 @@ private void BuildTree(IEnumerable local, IEnumerable remo } } - // Add to favorites - if (favoritesList.Contains(branch.Name)) - { - favorites.Add(node); - } - // Build into tree BuildTree(localRoot, node); } @@ -379,12 +322,6 @@ private void BuildTree(IEnumerable local, IEnumerable remo } } - // Add to favorites - if (favoritesList.Contains(branch.Name)) - { - favorites.Add(node); - } - // Build on the root of the remote, just like with locals BuildTree(remotes[remoteIndex].Root, node); } @@ -417,26 +354,6 @@ private void BuildTree(BranchTreeNode parent, BranchTreeNode child) BuildTree(folder, child); } - private void SetFavorite(BranchTreeNode branch, bool favorite) - { - if (string.IsNullOrEmpty(branch.Name)) - { - return; - } - - if (!favorite) - { - favorites.Remove(branch); - Manager.LocalSettings.Set(FavoritesSetting, favorites.Select(x => x.Name).ToList()); - } - else - { - favorites.Remove(branch); - favorites.Add(branch); - Manager.LocalSettings.Set(FavoritesSetting, favorites.Select(x => x.Name).ToList()); - } - } - private void OnButtonBarGUI() { if (mode == BranchesMode.Default) @@ -591,23 +508,12 @@ private void OnTreeNodeGUI(BranchTreeNode node) if (node.Type != NodeType.Folder) { - var favorite = IsFavorite(node.Name); if (Event.current.type == EventType.Repaint) { - GUI.DrawTexture(favoriteRect, favorite ? Styles.FavoriteIconOn : Styles.FavoriteIconOff); - } - else if (Event.current.type == EventType.MouseDown && favoriteRect.Contains(Event.current.mousePosition)) - { - SetFavorite(node, !favorite); - Event.current.Use(); + GUI.DrawTexture(favoriteRect, Styles.FavoriteIconOff); } } } - // Favorite status - else if (Event.current.type == EventType.Repaint && node.Type != NodeType.Folder && IsFavorite(node.Name)) - { - GUI.DrawTexture(favoriteRect, Styles.FavoriteIconOn); - } // The actual icon and label if (Event.current.type == EventType.Repaint) From 95315d73957cb5e43e29d42aeac9ca6c14e5bb6e Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Tue, 31 Oct 2017 08:31:06 -0400 Subject: [PATCH 2/2] Removing additional unused parts of favorites --- .../Assets/Editor/GitHub.Unity/UI/BranchesView.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs index c3174362c..9cd70d371 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs @@ -493,7 +493,6 @@ private void OnTreeNodeGUI(BranchTreeNode node) var style = node.Active ? Styles.BoldLabel : Styles.Label; var rect = GUILayoutUtility.GetRect(content, style, GUILayout.MaxHeight(EditorGUIUtility.singleLineHeight)); var clickRect = new Rect(0f, rect.y, Position.width, rect.height); - var favoriteRect = new Rect(clickRect.xMax - clickRect.height * 2f, clickRect.y, clickRect.height, clickRect.height); var selected = selectedNode == node; var keyboardFocus = GUIUtility.keyboardControl == listID; @@ -505,14 +504,6 @@ private void OnTreeNodeGUI(BranchTreeNode node) { style.Draw(clickRect, GUIContent.none, false, false, true, keyboardFocus); } - - if (node.Type != NodeType.Folder) - { - if (Event.current.type == EventType.Repaint) - { - GUI.DrawTexture(favoriteRect, Styles.FavoriteIconOff); - } - } } // The actual icon and label