@@ -18,14 +18,15 @@ class ProjectWindowInterface : AssetPostprocessor
18
18
private static List < GitLock > locks = new List < GitLock > ( ) ;
19
19
private static List < string > guids = new List < string > ( ) ;
20
20
private static List < string > guidsLocks = new List < string > ( ) ;
21
- private static string loggedInUser ;
21
+ private static string currentUsername ;
22
22
23
23
private static IApplicationManager manager ;
24
24
private static bool isBusy = false ;
25
25
private static ILogging logger ;
26
26
private static ILogging Logger { get { return logger = logger ?? LogHelper . GetLogger < ProjectWindowInterface > ( ) ; } }
27
27
private static CacheUpdateEvent lastRepositoryStatusChangedEvent ;
28
28
private static CacheUpdateEvent lastLocksChangedEvent ;
29
+ private static CacheUpdateEvent lastCurrentRemoteChangedEvent ;
29
30
private static IRepository Repository { get { return manager != null ? manager . Environment . Repository : null ; } }
30
31
private static IPlatform Platform { get { return manager != null ? manager . Platform : null ; } }
31
32
private static bool IsInitialized { get { return Repository != null ; } }
@@ -37,13 +38,14 @@ public static void Initialize(IApplicationManager theManager)
37
38
38
39
manager = theManager ;
39
40
40
- Platform . Keychain . ConnectionsChanged += KeychainMayHaveChanged ;
41
- KeychainMayHaveChanged ( ) ;
41
+ Platform . Keychain . ConnectionsChanged += UpdateCurrentUsername ;
42
+ UpdateCurrentUsername ( ) ;
42
43
43
44
if ( IsInitialized )
44
45
{
45
46
Repository . StatusEntriesChanged += RepositoryOnStatusEntriesChanged ;
46
47
Repository . LocksChanged += RepositoryOnLocksChanged ;
48
+ Repository . CurrentRemoteChanged += RepositoryOnCurrentRemoteChanged ;
47
49
ValidateCachedData ( ) ;
48
50
}
49
51
}
@@ -88,9 +90,39 @@ private static void RepositoryOnLocksChanged(CacheUpdateEvent cacheUpdateEvent)
88
90
}
89
91
}
90
92
91
- private static void KeychainMayHaveChanged ( )
93
+ private static void RepositoryOnCurrentRemoteChanged ( CacheUpdateEvent cacheUpdateEvent )
92
94
{
93
- loggedInUser = Platform . Keychain . Connections . Select ( x => x . Username ) . FirstOrDefault ( ) ;
95
+ if ( ! lastCurrentRemoteChangedEvent . Equals ( cacheUpdateEvent ) )
96
+ {
97
+ lastCurrentRemoteChangedEvent = cacheUpdateEvent ;
98
+ }
99
+ }
100
+
101
+ private static void UpdateCurrentUsername ( )
102
+ {
103
+ var username = String . Empty ;
104
+ if ( Repository != null )
105
+ {
106
+ Connection [ ] connections ;
107
+ if ( ! string . IsNullOrEmpty ( Repository . CloneUrl ) )
108
+ {
109
+ var host = Repository . CloneUrl . ToRepositoryUri ( )
110
+ . GetComponents ( UriComponents . Host , UriFormat . SafeUnescaped ) ;
111
+
112
+ connections = Platform . Keychain . Connections . OrderByDescending ( x => x . Host == host ) . ToArray ( ) ;
113
+ }
114
+ else
115
+ {
116
+ connections = Platform . Keychain . Connections . OrderByDescending ( HostAddress . IsGitHubDotCom ) . ToArray ( ) ;
117
+ }
118
+
119
+ if ( connections . Any ( ) )
120
+ {
121
+ username = connections . First ( ) . Username ;
122
+ }
123
+ }
124
+
125
+ currentUsername = username ;
94
126
}
95
127
96
128
[ MenuItem ( AssetsMenuRequestLock , true , 10000 ) ]
@@ -202,7 +234,7 @@ private static bool IsObjectLocked(Object selected, bool isLockedByCurrentUser)
202
234
NPath assetPath = AssetDatabase . GetAssetPath ( selected . GetInstanceID ( ) ) . ToNPath ( ) ;
203
235
NPath repositoryPath = manager . Environment . GetRepositoryPath ( assetPath ) ;
204
236
205
- return locks . Any ( x => repositoryPath == x . Path && ( ! isLockedByCurrentUser || x . Owner . Name == loggedInUser ) ) ;
237
+ return locks . Any ( x => repositoryPath == x . Path && ( ! isLockedByCurrentUser || x . Owner . Name == currentUsername ) ) ;
206
238
}
207
239
208
240
private static ITask CreateUnlockObjectTask ( Object selected , bool force )
0 commit comments