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

Commit df32e61

Browse files
Starting a blank Locks tab/view
1 parent 211471d commit df32e61

File tree

5 files changed

+135
-1
lines changed

5 files changed

+135
-1
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/GitHub.Unity.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
<Compile Include="UI\LoadingView.cs" />
104104
<Compile Include="UI\PublishView.cs" />
105105
<Compile Include="UI\InitProjectView.cs" />
106+
<Compile Include="UI\LocksView.cs" />
106107
<Compile Include="UI\Spinner.cs" />
107108
<Compile Include="UI\TreeControl.cs" />
108109
<Compile Include="UI\UserSettingsView.cs" />

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Runtime.Serialization;
5+
using GitHub.Logging;
46
using UnityEngine;
57

68
namespace GitHub.Unity
@@ -13,6 +15,8 @@ public class SerializableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, IS
1315
[SerializeField] private List<TKey> keys = new List<TKey>();
1416
[SerializeField] private List<TValue> values = new List<TValue>();
1517

18+
[NonSerialized] private ILogging logger = LogHelper.GetLogger("SerializableDictionary");
19+
1620
// save the dictionary to lists
1721
public void OnBeforeSerialize()
1822
{
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
using GitHub.Logging;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text.RegularExpressions;
6+
using UnityEditor;
7+
using UnityEngine;
8+
9+
namespace GitHub.Unity
10+
{
11+
[Serializable]
12+
class LocksView : Subview
13+
{
14+
[NonSerialized] private bool currentLocksHasUpdate;
15+
[NonSerialized] private bool isBusy;
16+
17+
[SerializeField] private CacheUpdateEvent lastLocksChangedEvent;
18+
[SerializeField] private List<GitLock> lockedFiles = new List<GitLock>();
19+
[SerializeField] private int lockedFileSelection = -1;
20+
[SerializeField] private Vector2 scroll;
21+
22+
public override void OnEnable()
23+
{
24+
base.OnEnable();
25+
AttachHandlers(Repository);
26+
27+
if (Repository != null)
28+
{
29+
ValidateCachedData(Repository);
30+
}
31+
}
32+
33+
34+
public override void OnDisable()
35+
{
36+
base.OnDisable();
37+
DetachHandlers(Repository);
38+
}
39+
40+
public override void OnDataUpdate()
41+
{
42+
base.OnDataUpdate();
43+
MaybeUpdateData();
44+
}
45+
46+
public override void OnGUI()
47+
{
48+
scroll = GUILayout.BeginScrollView(scroll);
49+
{
50+
}
51+
52+
GUILayout.EndScrollView();
53+
}
54+
55+
private void AttachHandlers(IRepository repository)
56+
{
57+
if (repository == null)
58+
{
59+
return;
60+
}
61+
62+
repository.LocksChanged += RepositoryOnLocksChanged;
63+
}
64+
65+
private void RepositoryOnLocksChanged(CacheUpdateEvent cacheUpdateEvent)
66+
{
67+
if (!lastLocksChangedEvent.Equals(cacheUpdateEvent))
68+
{
69+
lastLocksChangedEvent = cacheUpdateEvent;
70+
currentLocksHasUpdate = true;
71+
Redraw();
72+
}
73+
}
74+
75+
private void DetachHandlers(IRepository repository)
76+
{
77+
if (repository == null)
78+
{
79+
return;
80+
}
81+
82+
repository.LocksChanged -= RepositoryOnLocksChanged;
83+
}
84+
85+
private void ValidateCachedData(IRepository repository)
86+
{
87+
repository.CheckAndRaiseEventsIfCacheNewer(CacheType.GitLocks, lastLocksChangedEvent);
88+
}
89+
90+
private void MaybeUpdateData()
91+
{
92+
if (lockedFiles == null)
93+
lockedFiles = new List<GitLock>();
94+
95+
if (Repository == null)
96+
return;
97+
98+
if (currentLocksHasUpdate)
99+
{
100+
currentLocksHasUpdate = false;
101+
var repositoryCurrentLocks = Repository.CurrentLocks;
102+
lockedFileSelection = -1;
103+
lockedFiles = repositoryCurrentLocks != null
104+
? repositoryCurrentLocks.ToList()
105+
: new List<GitLock>();
106+
}
107+
}
108+
109+
public override bool IsBusy
110+
{
111+
get { return isBusy; }
112+
}
113+
}
114+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ private void DetachHandlers(IRepository repository)
154154
{
155155
return;
156156
}
157+
158+
repository.CurrentRemoteChanged -= RepositoryOnCurrentRemoteChanged;
159+
repository.LocksChanged -= RepositoryOnLocksChanged;
157160
}
158161

159162
private void ValidateCachedData(IRepository repository)

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Window : BaseWindow
1717
private const string HistoryTitle = "History";
1818
private const string ChangesTitle = "Changes";
1919
private const string BranchesTitle = "Branches";
20+
private const string LocksTitle = "Locks";
2021
private const string SettingsTitle = "Settings";
2122
private const string DefaultRepoUrl = "No remote configured";
2223
private const string Window_RepoUrlTooltip = "Url of the {0} remote";
@@ -40,6 +41,7 @@ class Window : BaseWindow
4041
[SerializeField] private ChangesView changesView = new ChangesView();
4142
[SerializeField] private HistoryView historyView = new HistoryView();
4243
[SerializeField] private SettingsView settingsView = new SettingsView();
44+
[SerializeField] private LocksView locksView = new LocksView();
4345

4446
[SerializeField] private string repoRemote;
4547
[SerializeField] private string repoBranch;
@@ -92,6 +94,7 @@ public override void Initialize(IApplicationManager applicationManager)
9294
ChangesView.InitializeView(this);
9395
BranchesView.InitializeView(this);
9496
SettingsView.InitializeView(this);
97+
LocksView.InitializeView(this);
9598
InitProjectView.InitializeView(this);
9699

97100
titleContent = new GUIContent(Title, Styles.SmallLogo);
@@ -411,6 +414,7 @@ private void DoToolbarGUI()
411414
changeTab = TabButton(SubTab.Changes, ChangesTitle, changeTab);
412415
changeTab = TabButton(SubTab.History, HistoryTitle, changeTab);
413416
changeTab = TabButton(SubTab.Branches, BranchesTitle, changeTab);
417+
changeTab = TabButton(SubTab.Locks, LocksTitle, changeTab);
414418
}
415419
else if (!HasRepository)
416420
{
@@ -536,6 +540,8 @@ private Subview ToView(SubTab tab)
536540
return branchesView;
537541
case SubTab.Settings:
538542
return settingsView;
543+
case SubTab.Locks:
544+
return locksView;
539545
default:
540546
throw new ArgumentOutOfRangeException("tab");
541547
}
@@ -561,6 +567,11 @@ public SettingsView SettingsView
561567
get { return settingsView; }
562568
}
563569

570+
public LocksView LocksView
571+
{
572+
get { return locksView; }
573+
}
574+
564575
public InitProjectView InitProjectView
565576
{
566577
get { return initProjectView; }
@@ -583,7 +594,8 @@ private enum SubTab
583594
History,
584595
Changes,
585596
Branches,
586-
Settings
597+
Settings,
598+
Locks
587599
}
588600
}
589601
}

0 commit comments

Comments
 (0)