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

Commit 701285d

Browse files
Moving locked file list to LocksView
1 parent df32e61 commit 701285d

File tree

3 files changed

+75
-111
lines changed

3 files changed

+75
-111
lines changed

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

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

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

18-
[NonSerialized] private ILogging logger = LogHelper.GetLogger("SerializableDictionary");
19-
2016
// save the dictionary to lists
2117
public void OnBeforeSerialize()
2218
{

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

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ public override void OnGUI()
4747
{
4848
scroll = GUILayout.BeginScrollView(scroll);
4949
{
50+
if (Repository != null)
51+
{
52+
OnGitLfsLocksGUI();
53+
}
54+
55+
GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
5056
}
5157

5258
GUILayout.EndScrollView();
@@ -106,6 +112,75 @@ private void MaybeUpdateData()
106112
}
107113
}
108114

115+
private void OnGitLfsLocksGUI()
116+
{
117+
EditorGUI.BeginDisabledGroup(IsBusy || Repository == null);
118+
{
119+
GUILayout.BeginVertical();
120+
{
121+
GUILayout.Label("Locked files", EditorStyles.boldLabel);
122+
123+
scroll = EditorGUILayout.BeginScrollView(scroll, Styles.GenericTableBoxStyle,
124+
GUILayout.Height(125));
125+
{
126+
GUILayout.BeginVertical();
127+
{
128+
var lockedFilesCount = lockedFiles.Count;
129+
for (var index = 0; index < lockedFilesCount; ++index)
130+
{
131+
GUIStyle rowStyle = (lockedFileSelection == index)
132+
? Styles.LockedFileRowSelectedStyle
133+
: Styles.LockedFileRowStyle;
134+
GUILayout.Box(lockedFiles[index].Path, rowStyle);
135+
136+
if (Event.current.type == EventType.MouseDown &&
137+
GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
138+
{
139+
var currentEvent = Event.current;
140+
141+
if (currentEvent.button == 0)
142+
{
143+
lockedFileSelection = index;
144+
}
145+
146+
Event.current.Use();
147+
}
148+
}
149+
}
150+
151+
GUILayout.EndVertical();
152+
}
153+
154+
EditorGUILayout.EndScrollView();
155+
156+
if (lockedFileSelection > -1)
157+
{
158+
GUILayout.BeginVertical();
159+
{
160+
var lck = lockedFiles[lockedFileSelection];
161+
GUILayout.Label(lck.Path, EditorStyles.boldLabel);
162+
163+
GUILayout.BeginHorizontal();
164+
{
165+
GUILayout.Label("Locked by " + lck.User);
166+
GUILayout.FlexibleSpace();
167+
if (GUILayout.Button("Unlock"))
168+
{
169+
Repository.ReleaseLock(lck.Path, true).Start();
170+
}
171+
}
172+
GUILayout.EndHorizontal();
173+
}
174+
GUILayout.EndVertical();
175+
}
176+
}
177+
178+
GUILayout.EndVertical();
179+
180+
}
181+
EditorGUI.EndDisabledGroup();
182+
}
183+
109184
public override bool IsBusy
110185
{
111186
get { return isBusy; }

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

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,13 @@ class SettingsView : Subview
2222
private const string MetricsOptInLabel = "Help us improve by sending anonymous usage data";
2323
private const string DefaultRepositoryRemoteName = "origin";
2424

25-
[NonSerialized] private bool currentLocksHasUpdate;
2625
[NonSerialized] private bool currentRemoteHasUpdate;
2726
[NonSerialized] private bool isBusy;
2827
[NonSerialized] private bool metricsHasChanged;
2928

3029
[SerializeField] private GitPathView gitPathView = new GitPathView();
3130
[SerializeField] private bool hasRemote;
3231
[SerializeField] private CacheUpdateEvent lastCurrentRemoteChangedEvent;
33-
[SerializeField] private CacheUpdateEvent lastLocksChangedEvent;
34-
[SerializeField] private List<GitLock> lockedFiles = new List<GitLock>();
35-
[SerializeField] private int lockedFileSelection = -1;
36-
[SerializeField] private Vector2 lockScrollPos;
3732
[SerializeField] private bool metricsEnabled;
3833
[SerializeField] private string newRepositoryRemoteUrl;
3934
[SerializeField] private string repositoryRemoteName;
@@ -64,7 +59,6 @@ public override void OnEnable()
6459
metricsHasChanged = true;
6560
}
6661

67-
6862
public override void OnDisable()
6963
{
7064
base.OnDisable();
@@ -100,11 +94,6 @@ public override void OnGUI()
10094
if (Repository != null)
10195
{
10296
OnRepositorySettingsGUI();
103-
104-
GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
105-
106-
OnGitLfsLocksGUI();
107-
10897
GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
10998
}
11099

@@ -125,17 +114,6 @@ private void AttachHandlers(IRepository repository)
125114
}
126115

127116
repository.CurrentRemoteChanged += RepositoryOnCurrentRemoteChanged;
128-
repository.LocksChanged += RepositoryOnLocksChanged;
129-
}
130-
131-
private void RepositoryOnLocksChanged(CacheUpdateEvent cacheUpdateEvent)
132-
{
133-
if (!lastLocksChangedEvent.Equals(cacheUpdateEvent))
134-
{
135-
lastLocksChangedEvent = cacheUpdateEvent;
136-
currentLocksHasUpdate = true;
137-
Redraw();
138-
}
139117
}
140118

141119
private void RepositoryOnCurrentRemoteChanged(CacheUpdateEvent cacheUpdateEvent)
@@ -156,13 +134,11 @@ private void DetachHandlers(IRepository repository)
156134
}
157135

158136
repository.CurrentRemoteChanged -= RepositoryOnCurrentRemoteChanged;
159-
repository.LocksChanged -= RepositoryOnLocksChanged;
160137
}
161138

162139
private void ValidateCachedData(IRepository repository)
163140
{
164141
repository.CheckAndRaiseEventsIfCacheNewer(CacheType.RepositoryInfo, lastCurrentRemoteChangedEvent);
165-
repository.CheckAndRaiseEventsIfCacheNewer(CacheType.GitLocks, lastLocksChangedEvent);
166142
}
167143

168144
private void MaybeUpdateData()
@@ -173,9 +149,6 @@ private void MaybeUpdateData()
173149
metricsHasChanged = false;
174150
}
175151

176-
if (lockedFiles == null)
177-
lockedFiles = new List<GitLock>();
178-
179152
if (Repository == null)
180153
return;
181154

@@ -195,16 +168,6 @@ private void MaybeUpdateData()
195168
newRepositoryRemoteUrl = repositoryRemoteUrl = currentRemote.Value.Url;
196169
}
197170
}
198-
199-
if (currentLocksHasUpdate)
200-
{
201-
currentLocksHasUpdate = false;
202-
var repositoryCurrentLocks = Repository.CurrentLocks;
203-
lockedFileSelection = -1;
204-
lockedFiles = repositoryCurrentLocks != null
205-
? repositoryCurrentLocks.ToList()
206-
: new List<GitLock>();
207-
}
208171
}
209172

210173
private void OnRepositorySettingsGUI()
@@ -241,75 +204,6 @@ private void OnRepositorySettingsGUI()
241204
EditorGUI.EndDisabledGroup();
242205
}
243206

244-
private void OnGitLfsLocksGUI()
245-
{
246-
EditorGUI.BeginDisabledGroup(IsBusy || Repository == null);
247-
{
248-
GUILayout.BeginVertical();
249-
{
250-
GUILayout.Label("Locked files", EditorStyles.boldLabel);
251-
252-
lockScrollPos = EditorGUILayout.BeginScrollView(lockScrollPos, Styles.GenericTableBoxStyle,
253-
GUILayout.Height(125));
254-
{
255-
GUILayout.BeginVertical();
256-
{
257-
var lockedFilesCount = lockedFiles.Count;
258-
for (var index = 0; index < lockedFilesCount; ++index)
259-
{
260-
GUIStyle rowStyle = (lockedFileSelection == index)
261-
? Styles.LockedFileRowSelectedStyle
262-
: Styles.LockedFileRowStyle;
263-
GUILayout.Box(lockedFiles[index].Path, rowStyle);
264-
265-
if (Event.current.type == EventType.MouseDown &&
266-
GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
267-
{
268-
var currentEvent = Event.current;
269-
270-
if (currentEvent.button == 0)
271-
{
272-
lockedFileSelection = index;
273-
}
274-
275-
Event.current.Use();
276-
}
277-
}
278-
}
279-
280-
GUILayout.EndVertical();
281-
}
282-
283-
EditorGUILayout.EndScrollView();
284-
285-
if (lockedFileSelection > -1)
286-
{
287-
GUILayout.BeginVertical();
288-
{
289-
var lck = lockedFiles[lockedFileSelection];
290-
GUILayout.Label(lck.Path, EditorStyles.boldLabel);
291-
292-
GUILayout.BeginHorizontal();
293-
{
294-
GUILayout.Label("Locked by " + lck.User);
295-
GUILayout.FlexibleSpace();
296-
if (GUILayout.Button("Unlock"))
297-
{
298-
Repository.ReleaseLock(lck.Path, true).Start();
299-
}
300-
}
301-
GUILayout.EndHorizontal();
302-
}
303-
GUILayout.EndVertical();
304-
}
305-
}
306-
307-
GUILayout.EndVertical();
308-
309-
}
310-
EditorGUI.EndDisabledGroup();
311-
}
312-
313207
private void OnPrivacyGui()
314208
{
315209
GUILayout.Label(PrivacyTitle, EditorStyles.boldLabel);
@@ -371,7 +265,6 @@ private void OnGeneralSettingsGui()
371265
EditorGUI.EndDisabledGroup();
372266
}
373267

374-
375268
public override bool IsBusy
376269
{
377270
get { return isBusy || userSettingsView.IsBusy || gitPathView.IsBusy; }

0 commit comments

Comments
 (0)