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

Commit 84c543f

Browse files
committed
Show a message in the inspector when a file is locked.
1 parent af45a79 commit 84c543f

13 files changed

+192
-8
lines changed

Diff for: GitHub.Unity.sln

+10
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnityTests", "src\UnityExte
3737
EndProject
3838
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExtensionLoader", "src\UnityExtension\Assets\Editor\GitHub.Unity\ExtensionLoader\ExtensionLoader.csproj", "{6B0EAB30-511A-44C1-87FE-D9AB7E34D115}"
3939
EndProject
40+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnityShim", "src\UnityShim\UnityShim.csproj", "{F94F8AE1-C171-4A83-89E8-6557CA91A188}"
41+
EndProject
4042
Global
4143
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4244
Debug|Any CPU = Debug|Any CPU
@@ -161,6 +163,14 @@ Global
161163
{6B0EAB30-511A-44C1-87FE-D9AB7E34D115}.dev|Any CPU.Build.0 = dev|Any CPU
162164
{6B0EAB30-511A-44C1-87FE-D9AB7E34D115}.Release|Any CPU.ActiveCfg = Release|Any CPU
163165
{6B0EAB30-511A-44C1-87FE-D9AB7E34D115}.Release|Any CPU.Build.0 = Release|Any CPU
166+
{F94F8AE1-C171-4A83-89E8-6557CA91A188}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
167+
{F94F8AE1-C171-4A83-89E8-6557CA91A188}.Debug|Any CPU.Build.0 = Debug|Any CPU
168+
{F94F8AE1-C171-4A83-89E8-6557CA91A188}.DebugNoUnity|Any CPU.ActiveCfg = Debug|Any CPU
169+
{F94F8AE1-C171-4A83-89E8-6557CA91A188}.DebugNoUnity|Any CPU.Build.0 = Debug|Any CPU
170+
{F94F8AE1-C171-4A83-89E8-6557CA91A188}.dev|Any CPU.ActiveCfg = dev|Any CPU
171+
{F94F8AE1-C171-4A83-89E8-6557CA91A188}.dev|Any CPU.Build.0 = dev|Any CPU
172+
{F94F8AE1-C171-4A83-89E8-6557CA91A188}.Release|Any CPU.ActiveCfg = Release|Any CPU
173+
{F94F8AE1-C171-4A83-89E8-6557CA91A188}.Release|Any CPU.Build.0 = Release|Any CPU
164174
EndGlobalSection
165175
GlobalSection(SolutionProperties) = preSolution
166176
HideSolutionNode = FALSE

Diff for: src/UnityExtension/Assets/Editor/GitHub.Unity/ExtensionLoader/ExtensionLoader.asmdef

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ExtensionLoader",
3-
"references": [],
3+
"references": ["../../build/GitHub.UnityShim.dll"],
44
"includePlatforms": [
55
"Editor"
66
],

Diff for: src/UnityExtension/Assets/Editor/GitHub.Unity/ExtensionLoader/ExtensionLoader.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ public bool Initialized
3030
private static string[] assemblies20 = { "System.Threading.dll", "AsyncBridge.Net35.dll", "ReadOnlyCollectionsInterfaces.dll", "GitHub.Api.dll", "GitHub.Unity.dll" };
3131
private static string[] assemblies45 = { "GitHub.Api.45.dll", "GitHub.Unity.45.dll" };
3232

33+
private const string GITHUB_UNITY_DISABLE = "GITHUB_UNITY_DISABLE";
34+
private static bool IsDisabled { get { return Environment.GetEnvironmentVariable(GITHUB_UNITY_DISABLE) == "1"; } }
35+
3336
static ExtensionLoader()
3437
{
35-
if (Environment.GetEnvironmentVariable("GITHUB_UNITY_DISABLE") == "1")
38+
if (IsDisabled)
3639
{
3740
return;
3841
}

Diff for: src/UnityExtension/Assets/Editor/GitHub.Unity/ExtensionLoader/ExtensionLoader.csproj

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
<ItemGroup>
5555
<Reference Include="System" />
5656
<Reference Include="System.Core" />
57+
<ProjectReference Include="..\..\..\..\..\UnityShim\UnityShim.csproj">
58+
<Project>{F94F8AE1-C171-4A83-89E8-6557CA91A188}</Project>
59+
<Name>UnityShim</Name>
60+
</ProjectReference>
5761
<Reference Include="UnityEditor">
5862
<HintPath>$(UnityDir)Managed\UnityEditor.dll</HintPath>
5963
<Private>False</Private>
@@ -65,6 +69,7 @@
6569
</ItemGroup>
6670
<ItemGroup>
6771
<Compile Include="ExtensionLoader.cs" />
72+
<Compile Include="UnityAPIWrapper.cs" />
6873
</ItemGroup>
6974
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7075
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
using System.IO;
4+
using System;
5+
6+
namespace GitHub.Unity
7+
{
8+
[InitializeOnLoad]
9+
public class UnityAPIWrapper : ScriptableSingleton<UnityAPIWrapper>
10+
{
11+
static UnityAPIWrapper()
12+
{
13+
#if UNITY_2018_2_OR_NEWER
14+
Editor.finishedDefaultHeaderGUI += editor => {
15+
UnityShim.Raise_Editor_finishedDefaultHeaderGUI(editor);
16+
};
17+
#endif
18+
}
19+
}
20+
}

Diff for: src/UnityExtension/Assets/Editor/GitHub.Unity/GitHub.Unity.45.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
<Project>{bb6a8eda-15d8-471b-a6ed-ee551e0b3ba0}</Project>
7676
<Name>GitHub.Logging</Name>
7777
</ProjectReference>
78+
<ProjectReference Include="..\..\..\..\UnityShim\UnityShim.csproj">
79+
<Project>{F94F8AE1-C171-4A83-89E8-6557CA91A188}</Project>
80+
<Name>UnityShim</Name>
81+
</ProjectReference>
7882
</ItemGroup>
7983
<ItemGroup>
8084
<Compile Include="ApplicationCache.cs" />
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
22
"name": "GitHub.Unity",
3-
"references": [],
3+
"references": [
4+
],
5+
"optionalUnityReferences": [],
46
"includePlatforms": [
57
"Editor"
68
],
7-
"excludePlatforms": []
9+
"excludePlatforms": [],
10+
"allowUnsafeCode": false
811
}

Diff for: src/UnityExtension/Assets/Editor/GitHub.Unity/GitHub.Unity.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@
113113
<Project>{bb6a8eda-15d8-471b-a6ed-ee551e0b3ba0}</Project>
114114
<Name>GitHub.Logging</Name>
115115
</ProjectReference>
116+
<ProjectReference Include="..\..\..\..\UnityShim\UnityShim.csproj">
117+
<Project>{F94F8AE1-C171-4A83-89E8-6557CA91A188}</Project>
118+
<Name>UnityShim</Name>
119+
</ProjectReference>
116120
</ItemGroup>
117121
<ItemGroup>
118122
<EmbeddedResource Include="IconsAndLogos\added%402x.png" />

Diff for: src/UnityExtension/Assets/Editor/GitHub.Unity/UI/LfsLocksModificationProcessor.cs

+44-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using GitHub.Logging;
44
using UnityEditor;
5+
using UnityEngine;
56

67
namespace GitHub.Unity
78
{
@@ -25,6 +26,8 @@ public static void Initialize(IEnvironment env, IPlatform plat)
2526
UserMayHaveChanged();
2627

2728
repository = environment.Repository;
29+
UnityShim.Editor_finishedDefaultHeaderGUI += InspectorHeaderFinished;
30+
2831
if (repository != null)
2932
{
3033
repository.LocksChanged += RepositoryOnLocksChanged;
@@ -51,8 +54,14 @@ public static AssetDeleteResult OnWillDeleteAsset(string assetPath, RemoveAssetO
5154
public static bool IsOpenForEdit(string assetPath, out string message)
5255
{
5356
var lck = GetLock(assetPath);
54-
var canEdit = !IsLockedBySomeoneElse(lck);
55-
message = !canEdit ? "File is locked for editing by " + lck.Value.Owner : null;
57+
bool canEdit = true;
58+
if (assetPath.EndsWith(".meta"))
59+
{
60+
canEdit &= !IsLockedBySomeoneElse(lck);
61+
assetPath = assetPath.TrimEnd(".meta");
62+
}
63+
canEdit &= !IsLockedBySomeoneElse(lck);
64+
message = !canEdit ? string.Format("File is locked for editing by {0}", lck.Value.Owner.Name) : null;
5665
return canEdit;
5766
}
5867

@@ -91,5 +100,38 @@ private static bool IsLockedBySomeoneElse(string assetPath)
91100
return lck;
92101
return null;
93102
}
103+
104+
private static void InspectorHeaderFinished(Editor editor)
105+
{
106+
string message = "";
107+
if (!IsOpenForEdit(AssetDatabase.GetAssetPath(editor.target), out message))
108+
{
109+
var enabled = GUI.enabled;
110+
GUI.enabled = true;
111+
GUILayout.BeginVertical();
112+
{
113+
GUILayout.Space(9);
114+
GUILayout.BeginHorizontal();
115+
{
116+
GUILayout.BeginVertical(GUILayout.Width(32));
117+
{
118+
GUILayout.Label(Utility.GetIcon("big-logo.png", "[email protected]", Utility.IsDarkTheme), GUILayout.Width(32), GUILayout.Height(32));
119+
}
120+
GUILayout.EndVertical();
121+
122+
GUILayout.BeginVertical();
123+
{
124+
GUILayout.Space(9);
125+
GUILayout.Label(message, Styles.HeaderBranchLabelStyle);
126+
}
127+
GUILayout.EndVertical();
128+
}
129+
GUILayout.EndHorizontal();
130+
}
131+
GUILayout.EndVertical();
132+
GUI.enabled = enabled;
133+
}
134+
135+
}
94136
}
95137
}

Diff for: src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ProjectWindowInterface.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private static bool ContextMenu_CanLock()
8888
{
8989
if (!EnsureInitialized())
9090
return false;
91-
if(!Repository.CurrentRemote.HasValue)
91+
if (!Repository.CurrentRemote.HasValue)
9292
return false;
9393
if (isBusy)
9494
return false;
@@ -222,7 +222,8 @@ private static void OnLocksUpdate()
222222
guidsLocks.Add(g);
223223
}
224224

225-
EditorApplication.RepaintProjectWindow();
225+
//EditorApplication.RepaintProjectWindow();
226+
UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
226227
}
227228

228229
private static void OnStatusUpdate()

Diff for: src/UnityShim/UnityShim.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using UnityEditor;
3+
namespace GitHub.Unity
4+
{
5+
public static class UnityShim
6+
{
7+
public static event Action<Editor> Editor_finishedDefaultHeaderGUI;
8+
public static void Raise_Editor_finishedDefaultHeaderGUI(Editor editor)
9+
{
10+
if (Editor_finishedDefaultHeaderGUI != null)
11+
Editor_finishedDefaultHeaderGUI(editor);
12+
}
13+
}
14+
}

Diff for: src/UnityShim/UnityShim.csproj

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{F94F8AE1-C171-4A83-89E8-6557CA91A188}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>GitHub.Unity</RootNamespace>
11+
<AssemblyName>GitHub.UnityShim</AssemblyName>
12+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<TargetFrameworkProfile />
15+
<LangVersion>6</LangVersion>
16+
<NuGetPackageImportStamp>
17+
</NuGetPackageImportStamp>
18+
<OutputPath>..\UnityExtension\Assets\Editor\build\</OutputPath>
19+
</PropertyGroup>
20+
<Import Project="..\..\common\properties.props" />
21+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
22+
<DebugSymbols>true</DebugSymbols>
23+
<DebugType>full</DebugType>
24+
<Optimize>false</Optimize>
25+
<DefineConstants>DEBUG;TRACE;$(BuildDefs)</DefineConstants>
26+
<ErrorReport>prompt</ErrorReport>
27+
<WarningLevel>4</WarningLevel>
28+
<RunCodeAnalysis>false</RunCodeAnalysis>
29+
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
30+
<CodeAnalysisIgnoreGeneratedCode>true</CodeAnalysisIgnoreGeneratedCode>
31+
</PropertyGroup>
32+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
33+
<DebugType>pdbonly</DebugType>
34+
<Optimize>true</Optimize>
35+
<DefineConstants>TRACE;$(BuildDefs)</DefineConstants>
36+
<ErrorReport>prompt</ErrorReport>
37+
<WarningLevel>4</WarningLevel>
38+
<BuildConfig>Release</BuildConfig>
39+
<RunCodeAnalysis>false</RunCodeAnalysis>
40+
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
41+
<CodeAnalysisIgnoreGeneratedCode>true</CodeAnalysisIgnoreGeneratedCode>
42+
</PropertyGroup>
43+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'dev|AnyCPU'">
44+
<DebugSymbols>true</DebugSymbols>
45+
<DebugType>full</DebugType>
46+
<Optimize>false</Optimize>
47+
<DefineConstants>TRACE;DEBUG;DEVELOPER_BUILD;$(BuildDefs)</DefineConstants>
48+
<ErrorReport>prompt</ErrorReport>
49+
<WarningLevel>4</WarningLevel>
50+
<RunCodeAnalysis>false</RunCodeAnalysis>
51+
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
52+
<CodeAnalysisIgnoreGeneratedCode>true</CodeAnalysisIgnoreGeneratedCode>
53+
<CodeAnalysisRuleSet>..\..\common\codeanalysis-debug.ruleset</CodeAnalysisRuleSet>
54+
</PropertyGroup>
55+
<PropertyGroup>
56+
<BuildConfig Condition=" '$(BuildConfig)' == '' ">Debug</BuildConfig>
57+
</PropertyGroup>
58+
<ItemGroup>
59+
<Reference Include="System" />
60+
<Reference Include="UnityEditor">
61+
<HintPath>$(UnityDir)Managed\UnityEditor.dll</HintPath>
62+
<Private>False</Private>
63+
</Reference>
64+
<Reference Include="UnityEngine">
65+
<HintPath>$(UnityDir)Managed\UnityEngine.dll</HintPath>
66+
<Private>False</Private>
67+
</Reference>
68+
</ItemGroup>
69+
<ItemGroup>
70+
<Compile Include="UnityShim.cs" />
71+
</ItemGroup>
72+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
73+
<Import Project="..\..\common\build.targets" />
74+
</Project>

Diff for: src/packaging/CopyLibrariesToPackageProject/CopyLibrariesToPackageProject.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@
7474
<Link>ExtensionLoader.cs</Link>
7575
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
7676
</None>
77+
<None Include="$(SolutionDir)\src\UnityExtension\Assets\Editor\GitHub.Unity\ExtensionLoader\UnityAPIWrapper.cs">
78+
<Link>UnityAPIWrapper.cs</Link>
79+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
80+
</None>
7781
<None Include="$(SolutionDir)\packages\ReadOnlyCollectionInterfaces.1.0.0\lib\NET20\ReadOnlyCollectionsInterfaces.dll">
7882
<Link>ReadOnlyCollectionsInterfaces.dll</Link>
7983
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

0 commit comments

Comments
 (0)