Пример #1
0
        public void OnDrawGUI(int index)
        {
            Rect rect;

            if (_repo.InProgress || !_repo.LastOperationSuccess || _hasLocalChanges)
            {
                rect = EditorGUILayout.GetControlRect(GUILayout.Height(50));
            }
            else
            {
                rect = EditorGUILayout.GetControlRect();
            }

            Rect boxRect = rect;

            boxRect.y      -= 1.5f;
            boxRect.height += 3;
            boxRect.x      -= 5;
            boxRect.width  += 10;

            Rect labelRect = rect;

            labelRect.width = rect.x + rect.width - 50 - 15 - 5;
            labelRect.x    += 4;

            Rect updatingLabelRect = labelRect;

            updatingLabelRect.y += 12;

            Rect progressMessageRect = updatingLabelRect;

            progressMessageRect.y    += 16;
            progressMessageRect.width = rect.width;

            Rect buttonRect = rect;

            buttonRect.x      = rect.width - 48;
            buttonRect.width  = 50;
            buttonRect.y     += 1;
            buttonRect.height = 15;

            Rect removeButtonRect = buttonRect;

            removeButtonRect.width = 15;
            removeButtonRect.x     = buttonRect.x - 15;

            Repository.Progress lastProgress = _repo.GetLastProgress();

            Rect progressRectOuter = rect;
            Rect progressRectInner = rect;

            progressRectInner.width = progressRectOuter.width * lastProgress.NormalizedProgress;

            if (index % 2 == 1)
            {
                GUI.Box(boxRect, "");
            }

            if ((_repo.InProgress || !_repo.LastOperationSuccess || _hasLocalChanges))
            {
                GUI.Box(progressRectOuter, "");

                GUI.color = _repo.CancellationPending || !_repo.LastOperationSuccess ? Color.red : Color.green;

                if (_hasLocalChanges)
                {
                    GUI.color = Color.yellow;
                }

                GUI.Box(progressRectInner, "");
                GUI.color = Color.white;

                if (_repo.LastOperationSuccess)
                {
                    if (_hasLocalChanges)
                    {
                        updatingLabelRect.y += 4;
                        GUI.Label(updatingLabelRect, "Local changes\ndetected!", EditorStyles.miniBoldLabel);
                    }
                    else
                    {
                        GUI.Label(updatingLabelRect, (_repo.CancellationPending ? "Cancelling" : "Updating") + GUIUtility.GetLoadingDots(), EditorStyles.miniLabel);
                    }
                }
                else
                {
                    GUI.Label(updatingLabelRect, "Failure", EditorStyles.miniLabel);
                }

                if (_hasLocalChanges)
                {
                    Rect pushChangesRect = progressMessageRect;
                    pushChangesRect.y     -= 5;
                    pushChangesRect.x      = progressMessageRect.x + progressMessageRect.width - 55;
                    pushChangesRect.width  = 50;
                    pushChangesRect.height = 15;

                    Rect deleteChangesRect = pushChangesRect;
                    deleteChangesRect.x -= 50;

                    if (GUI.Button(deleteChangesRect, new GUIContent("Remove", "Remove all local changes"), EditorStyles.miniButton))
                    {
                        if (EditorUtility.DisplayDialog("Confirm local changes removal", "This will permenantly delete any local changes and can not be reversed.", "Remove", "Cancel"))
                        {
                            //TODO: need to update manager window so it can rebuild asset database.
                            OnCopyFinished(CopyRepository(), new RepoPanel[] { this });
                        }
                    }

                    if (GUI.Button(pushChangesRect, new GUIContent("Copy", "This will copy the changes back to the local reposiory, clear the dirty flag, and open a window to allow you to resolve changes back to the remote.\n" +
                                                                   "Caution: any uncommitted changes in the cache could be overridden."), EditorStyles.miniButton))
                    {
                        /*int choice = EditorUtility.DisplayDialogComplex("Resolve local changes", "Please choose what to do with the local changes.", "Commit and Push",  "Cancel", "Open Git Client");
                         * switch(choice)
                         * {
                         *      case 0:
                         *      {
                         *                      Debug.Log("Chose Commit and Push");
                         *              break;
                         *      }
                         *      case 1:
                         *      {
                         *                      Debug.Log("Chose Cancel");
                         *                      break;
                         *      }
                         *      case 2:
                         *      {
                         *                      Debug.Log("Chose Open Git Client");
                         *                      break;
                         *      }
                         * }*/
                        _repo.CopyBackChanges();

                        TakeBaselineSnapshot();

                        _repo.OpenRepositoryDestination();
                    }
                }
                else
                {
                    GUI.Label(progressMessageRect, lastProgress.Message, EditorStyles.miniLabel);
                }

                if (_repo.LastOperationSuccess)
                {
                    //TODO: Cancel not fully implemented due to complexities in libgit2sharp. Hiding for now.

                    /*if (!_repo.CancellationPending && GUI.Button(buttonRect, "Cancel", EditorStyles.miniButton))
                     * {
                     *      _repo.CancelUpdate();
                     * };*/

                    if (_hasLocalChanges)
                    {
                        DrawUpdateButton(buttonRect);
                    }
                }
                else
                {
                    if (GUI.Button(buttonRect, "Retry", EditorStyles.miniButton))
                    {
                        UpdateRepository();
                    }
                    ;
                }
            }
            else
            {
                DrawUpdateButton(buttonRect);
            }

            if (!_repo.InProgress && GUI.Button(removeButtonRect, new GUIContent("x", "Remove the repository from this project."), EditorStyles.miniButton))
            {
                if (EditorUtility.DisplayDialog("Remove " + DependencyInfo.Name + "?", "\nThis will remove the repository from the project.\n" +
                                                ((_hasLocalChanges)?"\nAll local changes will be discarded.\n":"") + "\nThis can not be undone.", "Yes", "Cancel"))
                {
                    OnRemovalRequested(DependencyInfo.Name, DependencyInfo.Url, RepositoryPath(), CopyPath(_repositoryCopyRoot));
                }
            }
            ;

            GUIStyle labelStyle = new GUIStyle(EditorStyles.label);

            labelStyle.richText = true;
            GUI.Label(labelRect, DependencyInfo.Name + "  <b><size=9>" + /*(String.IsNullOrEmpty(DependencyInfo.Branch) ? (DependencyInfo.Tag + " (tag)") :*/ DependencyInfo.Branch /*)*/ + "</size></b>", labelStyle);
        }
Пример #2
0
        public void OnDrawGUI(int index)
        {
            Rect headerRect = EditorGUILayout.GetControlRect(GUILayout.Height(18));
            Rect bottomRect = new Rect();

            Rect fullRect = headerRect;

            //Overlay to darken every second item
            Rect boxRect = fullRect;

            boxRect.y      -= 1.5f;
            boxRect.height += 3;
            boxRect.x      -= 5;
            boxRect.width  += 10;

            //Header rects

            Rect labelRect = headerRect;

            labelRect.width  = headerRect.x + headerRect.width - (90 + 15);
            labelRect.height = 18;
            labelRect.x     += 15;

            Rect pullButtonRect = headerRect;

            pullButtonRect.x     = headerRect.width - 20;
            pullButtonRect.width = 20;

            Rect pushButtonRect = pullButtonRect;

            pushButtonRect.x = headerRect.width - 40;

            //Rect openTerminalRect = pushButtonRect;
            //openTerminalRect.x = headerRect.width - 60;

            Rect editButtonRect = pushButtonRect;

            editButtonRect.x = headerRect.width - 60;

            Rect removeButtonRect = editButtonRect;

            removeButtonRect.x = headerRect.width - 80;

            Rect localChangesRect = removeButtonRect;

            localChangesRect.width = 10;
            localChangesRect.x     = headerRect.width - 90;
            //Expanded rect

            Rect gitBashRect = bottomRect;

            gitBashRect.x      = bottomRect.width - 68;
            gitBashRect.width  = 60;
            gitBashRect.y     += 1;
            gitBashRect.height = 15;

            //Full Rect
            Repository.Progress lastProgress = _repo.GetLastProgress();

            Rect progressRectOuter = fullRect;
            Rect progressRectInner = fullRect;

            progressRectInner.width = progressRectOuter.width * lastProgress.NormalizedProgress;

            if (index % 2 == 1)
            {
                GUI.Box(boxRect, "");
            }

            //_repo.BlockAndUpdateStatus();

            bool updateNeeded  = _repo.HasUncommittedChanges || _repo.AheadOfOrigin;
            bool remoteChanges = _repo.BehindOrigin;

            if (updateNeeded)
            {
                GUI.color = Color.yellow;
                GUI.Label(localChangesRect, new GUIContent("*", $"Local changes detected!\n\n{_repo.PrintableStatus}"), EditorStyles.miniBoldLabel);
                GUI.color = Color.white;
            }
            else if (remoteChanges)
            {
                GUI.color = Color.blue;
                GUI.Label(localChangesRect, new GUIContent("*", $"Remote changes detected!\n\n{_repo.PrintableStatus}"), EditorStyles.miniBoldLabel);
                GUI.color = Color.white;
            }

            if (_repo.InProgress)
            {
                GUI.Box(progressRectOuter, "");

                GUI.color = lastProgress.Error ? Color.red : Color.green;

                GUI.Box(progressRectInner, "");
                GUI.color = Color.white;

                //GUI.Label(updatingLabelRect, ( ) + , EditorStyles.miniLabel);
                //GUI.Label(progressMessageRect, , EditorStyles.miniLabel);
            }
            else if (lastProgress.Error)
            {
                GUIStyle failureStyle = new GUIStyle(EditorStyles.label);
                failureStyle.richText  = true;
                failureStyle.alignment = TextAnchor.MiddleRight;
                GUI.Label(labelRect, new GUIContent("<b><color=red>Failure</color></b>", lastProgress.Message), failureStyle);
            }

            if (!_repo.InProgress)
            {
                DrawUpdateButton(pullButtonRect, updateNeeded);
            }

            GUIStyle iconButtonStyle = new GUIStyle(EditorStyles.miniButton);

            iconButtonStyle.padding = new RectOffset(3, 3, 3, 3);

            GUIStyle toggledIconButtonStyle = new GUIStyle(EditorStyles.miniButton);

            toggledIconButtonStyle.padding = new RectOffset(2, 2, 2, 2);

            if (!_repo.InProgress && GUI.Button(removeButtonRect, new GUIContent(_removeIcon, "Remove the repository from this project."), iconButtonStyle))
            {
                if (EditorUtility.DisplayDialog("Remove " + DependencyInfo.Name + "?", "\nThis will remove the repository from the project.\n" +
                                                ((updateNeeded)?"\nAll local changes will be discarded.\n":"") + "\nThis can not be undone.", "Yes", "Cancel"))
                {
                    OnRemovalRequested(DependencyInfo.Name, DependencyInfo.Url, RelativeRepositoryPath());
                }
            }

            if (!_repo.InProgress && GUI.Button(editButtonRect, new GUIContent(_editIcon, "Edit this repository"), iconButtonStyle))
            {
                OnEditRequested(DependencyInfo, RelativeRepositoryPath());
            }

            if (!updateNeeded)
            {
                GUI.enabled = false;
                ClosePushWindow();
            }

            GUIStyle togglePushButtonStyle = _expandableAreaAnimBool.value?toggledIconButtonStyle:iconButtonStyle;

            if (!_repo.InProgress && GUI.Button(pushButtonRect, new GUIContent(_pushIcon, "Push changes"), togglePushButtonStyle))
            {
                TogglePushWindow();
            }

            GUI.enabled = true;

            GUIStyle labelStyle = new GUIStyle(EditorStyles.label);

            labelStyle.richText = true;

            string repoText = DependencyInfo.Name + "  <b><size=9>" + DependencyInfo.Branch + "</size></b>" +
                              (_repo.InProgress
                                                  ? $" <i><size=9>{lastProgress.Message}{GUIUtility.GetLoadingDots()}</size></i>"
                                                  : "");

            GUI.Label(labelRect, new GUIContent(repoText, DependencyInfo.Url), labelStyle);

            if (_repo.RefreshPending)
            {
                OnRefreshRequested(new[] { this });
                _repo.RefreshPending = false;
            }

            if (EditorGUILayout.BeginFadeGroup(_expandableAreaAnimBool.faded))
            {
                if (_pushPanel == null)
                {
                    _pushPanel = new GUIPushPanel(DependencyInfo.Url, _repo.Branch, DependencyInfo.Name, _repo, (branch, message) =>
                    {
                        ClosePushWindow();
                        _repo.PushChanges(branch, message);
                        PollDirty();
                    }, () =>
                    {
                        _repo.ClearLocalChanges();
                        //PollDirty();
                    });
                }
                _pushPanel.OnDrawGUI();
            }
            EditorGUILayout.EndFadeGroup();

            //TODO: when we edit a repo we want to remove and re-download it.
            //TODO: or re-update it if the url and root folder has not changed
            //TODO: and update the gitignore as expected!
        }