Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class BranchesView : Subview
[NonSerialized] private List<GitBranch> newLocalBranches;
[NonSerialized] private BranchTreeNode newNodeSelection;
[NonSerialized] private BranchesMode targetMode;
[NonSerialized] private bool favouritesHasChanged;

[SerializeField] private BranchTreeNode activeBranchNode;
[SerializeField] private BranchTreeNode localRoot;
Expand All @@ -51,6 +52,7 @@ class BranchesView : Subview
[SerializeField] private List<Remote> remotes = new List<Remote>();
[SerializeField] private Vector2 scroll;
[SerializeField] private BranchTreeNode selectedNode;
private List<string> favouritesList;

public override void InitializeView(IView parent)
{
Expand All @@ -62,6 +64,7 @@ public override void OnEnable()
{
base.OnEnable();
AttachHandlers(Repository);
favouritesHasChanged = true;
}

public override void OnDisable()
Expand All @@ -70,6 +73,21 @@ public override void OnDisable()
DetachHandlers(Repository);
}

public override void OnDataUpdate()
{
base.OnDataUpdate();
MaybeUpdateData();
}

private void MaybeUpdateData()
{
if (favouritesHasChanged)
{
favouritesList = Manager.LocalSettings.Get(FavoritesSetting, new List<string>());
favouritesHasChanged = false;
}
}

public override void OnRepositoryChanged(IRepository oldRepository)
{
base.OnRepositoryChanged(oldRepository);
Expand Down Expand Up @@ -246,12 +264,12 @@ public void OnEmbeddedGUI()

private int CompareBranches(GitBranch a, GitBranch b)
{
if (GetFavourite(a.Name))
if (IsFavourite(a.Name))
{
return -1;
}

if (GetFavourite(b.Name))
if (IsFavourite(b.Name))
{
return 1;
}
Expand All @@ -269,19 +287,9 @@ private int CompareBranches(GitBranch a, GitBranch b)
return 0;
}

private bool GetFavourite(BranchTreeNode branch)
{
return GetFavourite(branch.Name);
}

private bool GetFavourite(string branchName)
private bool IsFavourite(string branchName)
{
if (string.IsNullOrEmpty(branchName))
{
return false;
}

return Manager.LocalSettings.Get(FavoritesSetting, new List<string>()).Contains(branchName);
return !String.IsNullOrEmpty(branchName) && favouritesList.Contains(branchName);
}

private void OnLocalBranchesUpdate(IEnumerable<GitBranch> list)
Expand Down Expand Up @@ -312,7 +320,6 @@ private void BuildTree(IEnumerable<GitBranch> local, IEnumerable<GitBranch> remo

// Prepare for updated favourites listing
favourites.Clear();
var cachedFavs = Manager.LocalSettings.Get<List<string>>(FavoritesSetting, new List<string>());

// Just build directly on the local root, keep track of active branch
localRoot = new BranchTreeNode("", NodeType.Folder, false);
Expand Down Expand Up @@ -342,7 +349,7 @@ private void BuildTree(IEnumerable<GitBranch> local, IEnumerable<GitBranch> remo
}

// Add to favourites
if (cachedFavs.Contains(branch.Name))
if (favouritesList.Contains(branch.Name))
{
favourites.Add(node);
}
Expand Down Expand Up @@ -386,7 +393,7 @@ private void BuildTree(IEnumerable<GitBranch> local, IEnumerable<GitBranch> remo
}

// Add to favourites
if (cachedFavs.Contains(branch.Name))
if (favouritesList.Contains(branch.Name))
{
favourites.Add(node);
}
Expand Down Expand Up @@ -597,7 +604,7 @@ private void OnTreeNodeGUI(BranchTreeNode node)

if (node.Type != NodeType.Folder)
{
var favourite = GetFavourite(node);
var favourite = IsFavourite(node.Name);
if (Event.current.type == EventType.Repaint)
{
GUI.DrawTexture(favouriteRect, favourite ? Styles.FavouriteIconOn : Styles.FavouriteIconOff);
Expand All @@ -610,7 +617,7 @@ private void OnTreeNodeGUI(BranchTreeNode node)
}
}
// Favourite status
else if (Event.current.type == EventType.Repaint && node.Type != NodeType.Folder && GetFavourite(node.Name))
else if (Event.current.type == EventType.Repaint && node.Type != NodeType.Folder && IsFavourite(node.Name))
{
GUI.DrawTexture(favouriteRect, Styles.FavouriteIconOn);
}
Expand Down
18 changes: 12 additions & 6 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/SettingsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,24 @@ class SettingsView : Subview
[SerializeField] private bool isBusy;
[SerializeField] private int lockedFileSelection = -1;
[SerializeField] private bool hasRemote;
[SerializeField] private bool remoteHasChanged;
[NonSerialized] private bool remoteHasChanged;
[NonSerialized] private bool userDataHasChanged;

[SerializeField] private string newGitName;
[SerializeField] private string newGitEmail;
[SerializeField] private string newRepositoryRemoteUrl;
[SerializeField] private User cachedUser;

[SerializeField] private bool metricsEnabled;
[NonSerialized] private bool metricsHasChanged;

public override void OnEnable()
{
base.OnEnable();
AttachHandlers(Repository);

remoteHasChanged = true;
metricsHasChanged = true;
}

public override void OnDisable()
Expand Down Expand Up @@ -141,6 +145,12 @@ public override void OnGUI()

private void MaybeUpdateData()
{
if (metricsHasChanged)
{
metricsEnabled = Manager.UsageTracker.Enabled;
metricsHasChanged = false;
}

if (lockedFiles == null)
lockedFiles = new List<GitLock>();

Expand Down Expand Up @@ -477,13 +487,10 @@ private void OnInstallPathGUI()

private void OnPrivacyGui()
{
var service = Manager != null ? Manager.UsageTracker : null;

GUILayout.Label(PrivacyTitle, EditorStyles.boldLabel);

EditorGUI.BeginDisabledGroup(isBusy || service == null);
EditorGUI.BeginDisabledGroup(isBusy);
{
var metricsEnabled = service != null && service.Enabled;
EditorGUI.BeginChangeCheck();
{
metricsEnabled = GUILayout.Toggle(metricsEnabled, MetricsOptInLabel);
Expand All @@ -492,7 +499,6 @@ private void OnPrivacyGui()
{
Manager.UsageTracker.Enabled = metricsEnabled;
}

}
EditorGUI.EndDisabledGroup();
}
Expand Down