Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 9832cfe

Browse files
Merge branch 'enhancements/git-path-save-button' into enhancements/git-path-view
2 parents 52271d9 + 66f0876 commit 9832cfe

File tree

6 files changed

+116
-93
lines changed

6 files changed

+116
-93
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Notices
44

5-
From version 0.19 onwards, the location of the plugin has moved to `Assets/Plugins/GitHub`. If you have version 0.18 or lower, you need to delete the `Assets/Editor/GitHub` folder before you install newer versions. You should exit Unity and delete the folder from Explorer/Finder, as Unity will not unload native libraries while it's running.
5+
From version 0.19 onwards, the location of the plugin has moved to `Assets/Plugins/GitHub`. If you have version 0.18 or lower, you need to delete the `Assets/Editor/GitHub` folder before you install newer versions. You should exit Unity and delete the folder from Explorer/Finder, as Unity will not unload native libraries while it's running. Also, remember to update your `.gitignore` file.
66

77
![Build Status](https://ci.appveyor.com/api/projects/status/github/github-for-unity/Unity?branch=master&svg=true)
88

@@ -81,7 +81,11 @@ Once the extension is installed, you can open a command line with the same Git a
8181

8282
### Installation
8383

84-
To install the extension, download the latest package from [the releases page](https://github.com/github-for-unity/Unity/releases) and double click on it.
84+
This extensions needs to be installed (and updated) for each Unity project that you want to version control.
85+
First step is to download the latest package from [the releases page](https://github.com/github-for-unity/Unity/releases);
86+
it will be saved as a file with the extension `.unitypackage`.
87+
To install it, open Unity, then open the project you want to version control, and then double click on the downloaded package.
88+
Alternatively, import the package by clicking Assets, Import Package, Custom Package, then select the downloaded package.
8589

8690
#### Log files
8791

src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationCache.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -126,52 +126,52 @@ public List<GitBranch> RemoteBranches
126126
}
127127

128128
[Location("views/branches.yaml", LocationAttribute.Location.LibraryFolder)]
129-
sealed class Favourites : ScriptObjectSingleton<Favourites>
129+
sealed class Favorites : ScriptObjectSingleton<Favorites>
130130
{
131-
[SerializeField] private List<string> favouriteBranches;
132-
public List<string> FavouriteBranches
131+
[SerializeField] private List<string> favoriteBranches;
132+
public List<string> FavoriteBranches
133133
{
134134
get
135135
{
136-
if (favouriteBranches == null)
137-
FavouriteBranches = new List<string>();
138-
return favouriteBranches;
136+
if (favoriteBranches == null)
137+
FavoriteBranches = new List<string>();
138+
return favoriteBranches;
139139
}
140140
set
141141
{
142-
favouriteBranches = value;
142+
favoriteBranches = value;
143143
Save(true);
144144
}
145145
}
146146

147-
public void SetFavourite(string branchName)
147+
public void SetFavorite(string branchName)
148148
{
149-
if (FavouriteBranches.Contains(branchName))
149+
if (FavoriteBranches.Contains(branchName))
150150
return;
151-
FavouriteBranches.Add(branchName);
151+
FavoriteBranches.Add(branchName);
152152
Save(true);
153153
}
154154

155-
public void UnsetFavourite(string branchName)
155+
public void UnsetFavorite(string branchName)
156156
{
157-
if (!FavouriteBranches.Contains(branchName))
157+
if (!FavoriteBranches.Contains(branchName))
158158
return;
159-
FavouriteBranches.Remove(branchName);
159+
FavoriteBranches.Remove(branchName);
160160
Save(true);
161161
}
162162

163-
public void ToggleFavourite(string branchName)
163+
public void ToggleFavorite(string branchName)
164164
{
165-
if (FavouriteBranches.Contains(branchName))
166-
FavouriteBranches.Remove(branchName);
165+
if (FavoriteBranches.Contains(branchName))
166+
FavoriteBranches.Remove(branchName);
167167
else
168-
FavouriteBranches.Add(branchName);
168+
FavoriteBranches.Add(branchName);
169169
Save(true);
170170
}
171171

172-
public bool IsFavourite(string branchName)
172+
public bool IsFavorite(string branchName)
173173
{
174-
return FavouriteBranches.Contains(branchName);
174+
return FavoriteBranches.Contains(branchName);
175175
}
176176
}
177177

src/UnityExtension/Assets/Editor/GitHub.Unity/Misc/Styles.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ class Styles
8383
private static Texture2D branchIcon,
8484
activeBranchIcon,
8585
trackingBranchIcon,
86-
favouriteIconOn,
87-
favouriteIconOff,
86+
favoriteIconOn,
87+
favoriteIconOff,
8888
smallLogoIcon,
8989
bigLogoIcon,
9090
defaultAssetIcon,
@@ -645,29 +645,29 @@ public static Texture2D TrackingBranchIcon
645645
}
646646
}
647647

648-
public static Texture2D FavouriteIconOn
648+
public static Texture2D FavoriteIconOn
649649
{
650650
get
651651
{
652-
if (favouriteIconOn == null)
652+
if (favoriteIconOn == null)
653653
{
654-
favouriteIconOn = Utility.GetIcon("favorite-branch-indicator.png");
654+
favoriteIconOn = Utility.GetIcon("favorite-branch-indicator.png");
655655
}
656656

657-
return favouriteIconOn;
657+
return favoriteIconOn;
658658
}
659659
}
660660

661-
public static Texture2D FavouriteIconOff
661+
public static Texture2D FavoriteIconOff
662662
{
663663
get
664664
{
665-
if (favouriteIconOff == null)
665+
if (favoriteIconOff == null)
666666
{
667-
favouriteIconOff = FolderIcon;
667+
favoriteIconOff = FolderIcon;
668668
}
669669

670-
return favouriteIconOff;
670+
return favoriteIconOff;
671671
}
672672
}
673673

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ class BranchesView : Subview
3838
private bool showLocalBranches = true;
3939
private bool showRemoteBranches = true;
4040

41-
[NonSerialized] private List<BranchTreeNode> favourites = new List<BranchTreeNode>();
41+
[NonSerialized] private List<BranchTreeNode> favorites = new List<BranchTreeNode>();
4242
[NonSerialized] private int listID = -1;
4343
[NonSerialized] private List<GitBranch> newLocalBranches;
4444
[NonSerialized] private BranchTreeNode newNodeSelection;
4545
[NonSerialized] private BranchesMode targetMode;
46+
[NonSerialized] private bool favoritesHasChanged;
4647

4748
[SerializeField] private BranchTreeNode activeBranchNode;
4849
[SerializeField] private BranchTreeNode localRoot;
@@ -51,6 +52,7 @@ class BranchesView : Subview
5152
[SerializeField] private List<Remote> remotes = new List<Remote>();
5253
[SerializeField] private Vector2 scroll;
5354
[SerializeField] private BranchTreeNode selectedNode;
55+
private List<string> favoritesList;
5456

5557
public override void InitializeView(IView parent)
5658
{
@@ -62,6 +64,7 @@ public override void OnEnable()
6264
{
6365
base.OnEnable();
6466
AttachHandlers(Repository);
67+
favoritesHasChanged = true;
6568
}
6669

6770
public override void OnDisable()
@@ -70,6 +73,21 @@ public override void OnDisable()
7073
DetachHandlers(Repository);
7174
}
7275

76+
public override void OnDataUpdate()
77+
{
78+
base.OnDataUpdate();
79+
MaybeUpdateData();
80+
}
81+
82+
private void MaybeUpdateData()
83+
{
84+
if (favoritesHasChanged)
85+
{
86+
favoritesList = Manager.LocalSettings.Get(FavoritesSetting, new List<string>());
87+
favoritesHasChanged = false;
88+
}
89+
}
90+
7391
public override void OnRepositoryChanged(IRepository oldRepository)
7492
{
7593
base.OnRepositoryChanged(oldRepository);
@@ -147,17 +165,17 @@ public void OnEmbeddedGUI()
147165

148166
GUILayout.BeginVertical(Styles.CommitFileAreaStyle);
149167
{
150-
// Favourites list
151-
if (favourites.Count > 0)
168+
// Favorites list
169+
if (favorites.Count > 0)
152170
{
153171
GUILayout.Label(FavoritesTitle);
154172
GUILayout.BeginHorizontal();
155173
{
156174
GUILayout.BeginVertical();
157175
{
158-
for (var index = 0; index < favourites.Count; ++index)
176+
for (var index = 0; index < favorites.Count; ++index)
159177
{
160-
OnTreeNodeGUI(favourites[index]);
178+
OnTreeNodeGUI(favorites[index]);
161179
}
162180
}
163181

@@ -251,12 +269,12 @@ public void OnEmbeddedGUI()
251269

252270
private int CompareBranches(GitBranch a, GitBranch b)
253271
{
254-
if (GetFavourite(a.Name))
272+
if (IsFavorite(a.Name))
255273
{
256274
return -1;
257275
}
258276

259-
if (GetFavourite(b.Name))
277+
if (IsFavorite(b.Name))
260278
{
261279
return 1;
262280
}
@@ -274,19 +292,9 @@ private int CompareBranches(GitBranch a, GitBranch b)
274292
return 0;
275293
}
276294

277-
private bool GetFavourite(BranchTreeNode branch)
278-
{
279-
return GetFavourite(branch.Name);
280-
}
281-
282-
private bool GetFavourite(string branchName)
295+
private bool IsFavorite(string branchName)
283296
{
284-
if (string.IsNullOrEmpty(branchName))
285-
{
286-
return false;
287-
}
288-
289-
return Manager.LocalSettings.Get(FavoritesSetting, new List<string>()).Contains(branchName);
297+
return !String.IsNullOrEmpty(branchName) && favoritesList.Contains(branchName);
290298
}
291299

292300
private void OnLocalBranchesUpdate(IEnumerable<GitBranch> list)
@@ -315,9 +323,8 @@ private void BuildTree(IEnumerable<GitBranch> local, IEnumerable<GitBranch> remo
315323
var tracking = new List<KeyValuePair<int, int>>();
316324
var localBranchNodes = new List<BranchTreeNode>();
317325

318-
// Prepare for updated favourites listing
319-
favourites.Clear();
320-
var cachedFavs = Manager.LocalSettings.Get<List<string>>(FavoritesSetting, new List<string>());
326+
// Prepare for updated favorites listing
327+
favorites.Clear();
321328

322329
// Just build directly on the local root, keep track of active branch
323330
localRoot = new BranchTreeNode("", NodeType.Folder, false);
@@ -346,10 +353,10 @@ private void BuildTree(IEnumerable<GitBranch> local, IEnumerable<GitBranch> remo
346353
}
347354
}
348355

349-
// Add to favourites
350-
if (cachedFavs.Contains(branch.Name))
356+
// Add to favorites
357+
if (favoritesList.Contains(branch.Name))
351358
{
352-
favourites.Add(node);
359+
favorites.Add(node);
353360
}
354361

355362
// Build into tree
@@ -390,10 +397,10 @@ private void BuildTree(IEnumerable<GitBranch> local, IEnumerable<GitBranch> remo
390397
}
391398
}
392399

393-
// Add to favourites
394-
if (cachedFavs.Contains(branch.Name))
400+
// Add to favorites
401+
if (favoritesList.Contains(branch.Name))
395402
{
396-
favourites.Add(node);
403+
favorites.Add(node);
397404
}
398405

399406
// Build on the root of the remote, just like with locals
@@ -428,23 +435,23 @@ private void BuildTree(BranchTreeNode parent, BranchTreeNode child)
428435
BuildTree(folder, child);
429436
}
430437

431-
private void SetFavourite(BranchTreeNode branch, bool favourite)
438+
private void SetFavorite(BranchTreeNode branch, bool favorite)
432439
{
433440
if (string.IsNullOrEmpty(branch.Name))
434441
{
435442
return;
436443
}
437444

438-
if (!favourite)
445+
if (!favorite)
439446
{
440-
favourites.Remove(branch);
441-
Manager.LocalSettings.Set(FavoritesSetting, favourites.Select(x => x.Name).ToList());
447+
favorites.Remove(branch);
448+
Manager.LocalSettings.Set(FavoritesSetting, favorites.Select(x => x.Name).ToList());
442449
}
443450
else
444451
{
445-
favourites.Remove(branch);
446-
favourites.Add(branch);
447-
Manager.LocalSettings.Set(FavoritesSetting, favourites.Select(x => x.Name).ToList());
452+
favorites.Remove(branch);
453+
favorites.Add(branch);
454+
Manager.LocalSettings.Set(FavoritesSetting, favorites.Select(x => x.Name).ToList());
448455
}
449456
}
450457

@@ -587,12 +594,12 @@ private void OnTreeNodeGUI(BranchTreeNode node)
587594
var style = node.Active ? Styles.BoldLabel : Styles.Label;
588595
var rect = GUILayoutUtility.GetRect(content, style, GUILayout.MaxHeight(EditorGUIUtility.singleLineHeight));
589596
var clickRect = new Rect(0f, rect.y, Position.width, rect.height);
590-
var favouriteRect = new Rect(clickRect.xMax - clickRect.height * 2f, clickRect.y, clickRect.height, clickRect.height);
597+
var favoriteRect = new Rect(clickRect.xMax - clickRect.height * 2f, clickRect.y, clickRect.height, clickRect.height);
591598

592599
var selected = selectedNode == node;
593600
var keyboardFocus = GUIUtility.keyboardControl == listID;
594601

595-
// Selection highlight and favourite toggle
602+
// Selection highlight and favorite toggle
596603
if (selected)
597604
{
598605
if (Event.current.type == EventType.Repaint)
@@ -602,22 +609,22 @@ private void OnTreeNodeGUI(BranchTreeNode node)
602609

603610
if (node.Type != NodeType.Folder)
604611
{
605-
var favourite = GetFavourite(node);
612+
var favorite = IsFavorite(node.Name);
606613
if (Event.current.type == EventType.Repaint)
607614
{
608-
GUI.DrawTexture(favouriteRect, favourite ? Styles.FavouriteIconOn : Styles.FavouriteIconOff);
615+
GUI.DrawTexture(favoriteRect, favorite ? Styles.FavoriteIconOn : Styles.FavoriteIconOff);
609616
}
610-
else if (Event.current.type == EventType.MouseDown && favouriteRect.Contains(Event.current.mousePosition))
617+
else if (Event.current.type == EventType.MouseDown && favoriteRect.Contains(Event.current.mousePosition))
611618
{
612-
SetFavourite(node, !favourite);
619+
SetFavorite(node, !favorite);
613620
Event.current.Use();
614621
}
615622
}
616623
}
617-
// Favourite status
618-
else if (Event.current.type == EventType.Repaint && node.Type != NodeType.Folder && GetFavourite(node.Name))
624+
// Favorite status
625+
else if (Event.current.type == EventType.Repaint && node.Type != NodeType.Folder && IsFavorite(node.Name))
619626
{
620-
GUI.DrawTexture(favouriteRect, Styles.FavouriteIconOn);
627+
GUI.DrawTexture(favoriteRect, Styles.FavoriteIconOn);
621628
}
622629

623630
// The actual icon and label

0 commit comments

Comments
 (0)