Beispiel #1
0
        private static void DrawLockGUI(string path)
        {
            string text       = string.Empty;
            var    lockedFile = GitLockManager.IsLock(path, out var locked);

            if (!GitLockManager.IsInitialized)
            {
                GUILayout.Button(loadingImages[currentFrame / AnimationSpeed], GUILayout.MaxHeight(32), GUILayout.MaxWidth(32));
                text = "Initializing";
            }
            else if (GitLockManager.IsFileExecuting(path))
            {
                GUILayout.Button(loadingImages[currentFrame / AnimationSpeed], GUILayout.MaxHeight(32), GUILayout.MaxWidth(32));
                text = "Executing command";
            }
            else
            {
                if (locked == GitLockManager.LockState.Locked)
                {
                    GUILayout.Button(lockedIcon, GUILayout.MaxHeight(32), GUILayout.MaxWidth(32));
                    text = $"Locked by {lockedFile.owner.name} at {lockedFile.locked_at}";
                }
                else if (locked == GitLockManager.LockState.LockedByYou)
                {
                    if (GUILayout.Button(lockedByYouIcon, GUILayout.MaxHeight(32), GUILayout.MaxWidth(32)))
                    {
                        GitLockManager.Unlock(path);
                    }
                    text = $"Locked by {lockedFile.owner.name}(You) at {lockedFile.locked_at}";
                }
                else
                {
                    if (GUILayout.Button(unlockIcon, GUILayout.MaxHeight(32), GUILayout.MaxWidth(32)))
                    {
                        GitLockManager.Lock(path);
                    }
                    text = $"Unlocked";
                }
            }
            GUILayout.Label(text, GUILayout.MaxHeight(32));
        }
Beispiel #2
0
    void OnGUI()
    {
        CheckStyles();
        var basicColor = GUI.backgroundColor;

        var oldEnable = GitLockManager.IsEnabled;

        GUI.backgroundColor = oldEnable ? Color.green : Color.red;
        if (GUILayout.Button(oldEnable ? "Enable" : "Disable"))
        {
            GitLockManager.IsEnabled = !oldEnable;
        }

        GUI.backgroundColor = basicColor;

        EditorGUILayout.BeginHorizontal(GUILayout.MaxHeight(16));

        EditorGUILayout.LabelField("Git Username", GUILayout.MaxWidth(90));

        var oldUsername = GitLockManager.Username;
        var newUserName = EditorGUILayout.TextField(oldUsername);

        if (!string.Equals(oldUsername, newUserName))
        {
            GitLockManager.Username = newUserName;
        }

        if (GUILayout.Button(GitLockManager.CollectingUsername ? "Finding" : "Find username", GUILayout.MaxWidth(128)))
        {
            if (!GitLockManager.CollectingUsername)
            {
                GitLockManager.GetGitUserName();
            }
        }

        EditorGUILayout.EndHorizontal();
        //EditorGUILayout.Space();

        EditorGUILayout.BeginHorizontal(GUILayout.MaxHeight(32));
        DrawUILine(Color.gray);
        EditorGUILayout.EndHorizontal();

        int index = 0;

        if (GitLockManager.IsEnabled)
        {
            EditorGUILayout.BeginHorizontal(GUILayout.MaxHeight(32));

            EditorGUILayout.LabelField("Locked files" + (GitLockManager.IsRenewingLocks ? "(Collecting locks...)" : string.Empty), boldLabel, GUILayout.ExpandWidth(true));

            EditorGUILayout.EndHorizontal();

            scrollPoss = EditorGUILayout.BeginScrollView(scrollPoss);
            var pathToRemove = Application.dataPath.Replace("/", "\\").Replace("\\Assets", string.Empty) + "\\";
            foreach (var file in GitLockManager.LockedFiles)
            {
                var normalizedPath = file.path.Replace(pathToRemove, string.Empty);
                tableElementStyle.normal.background = index % 2 == 0 ? Texture2D.grayTexture : Texture2D.whiteTexture;
                EditorGUILayout.BeginHorizontal(tableElementStyle, GUILayout.MaxHeight(50));

                GUILayout.Label(AssetDatabase.GetCachedIcon(normalizedPath),
                                GUILayout.MaxWidth(50), GUILayout.MaxHeight(50));

                EditorGUILayout.BeginVertical(tableElementStyle, GUILayout.MaxHeight(50));

                EditorGUILayout.BeginHorizontal(tableElementStyle, GUILayout.MaxHeight(50));
                EditorGUILayout.LabelField("Path:", GUILayout.MaxWidth(32));
                GUI.enabled = false;
                EditorGUILayout.TextField(normalizedPath);
                GUI.enabled = true;
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal(tableElementStyle, GUILayout.MaxHeight(50));
                EditorGUILayout.LabelField("By", GUILayout.MaxWidth(32));
                GUI.enabled = false;
                EditorGUILayout.TextField(file.owner.name, GUILayout.MaxWidth(128));
                GUI.enabled = true;
                EditorGUILayout.LabelField("at " + file.locked_at);

                bool isWorkingOnFile = GitLockManager.IsFileExecuting(file.path);
                GUI.backgroundColor = isWorkingOnFile ? Color.yellow : Color.red;

                if (GUILayout.Button(isWorkingOnFile ? "Unlocking..." : "Unlock forced", unlockButtonStyle, GUILayout.MaxWidth(128)))
                {
                    if (!isWorkingOnFile)
                    {
                        GitLockManager.Unlock(file.path, true);
                    }
                }

                GUI.backgroundColor = basicColor;

                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();

                EditorGUILayout.EndHorizontal();
                index++;
            }

            EditorGUILayout.EndScrollView();
        }


        this.maxSize = new Vector2(800, 16 + 32 * 3 + index * 50);
    }