Exemplo n.º 1
0
        private void MaybeUpdateData()
        {
            if (firstOnGUI)
            {
                titleContent = new GUIContent(Title, Styles.SmallLogo);
            }
            firstOnGUI = false;

            if (HasRepository && !string.IsNullOrEmpty(Repository.CloneUrl))
            {
                var host = Repository.CloneUrl
                                     .ToRepositoryUri()
                                     .GetComponents(UriComponents.Host, UriFormat.SafeUnescaped);

                connections = Platform.Keychain.Connections.OrderByDescending(x => x.Host == host).ToArray();
            }
            else
            {
                connections = Platform.Keychain.Connections.OrderByDescending(HostAddress.IsGitHubDotCom).ToArray();
            }

            var connectionCount = connections.Length;
            if (connectionCount > 1)
            {
                var connection = connections.First();
                var isGitHubDotCom = HostAddress.IsGitHubDotCom(connection);

                if (isGitHubDotCom)
                {
                    primaryConnectionUsername = "******" + connection.Username;
                }
                else
                {
                    primaryConnectionUsername = connection.Host + ": " + connection.Username;
                }
            }
            else if(connectionCount == 1)
            {
                primaryConnectionUsername = connections.First().Username;
            }
            else
            {
                primaryConnectionUsername = null;
            }


            if (repositoryProgressHasUpdate)
            {
                if (repositoryProgress != null)
                {
                    repositoryProgressMessage = repositoryProgress.Message;
                    repositoryProgressValue = repositoryProgress.Percentage;
                    if (progressMessageClearTime == -1f || progressMessageClearTime < EditorApplication.timeSinceStartup + DefaultNotificationTimeout)
                        progressMessageClearTime = EditorApplication.timeSinceStartup + DefaultNotificationTimeout;
                }
                else
                {
                    repositoryProgressMessage = "";
                    repositoryProgressValue = 0;
                    progressMessageClearTime = -1f;
                }
                repositoryProgressHasUpdate = false;
            }

            if (appManagerProgressHasUpdate)
            {
                if (appManagerProgress != null)
                {
                    appManagerProgressValue = appManagerProgress.Percentage;
                    appManagerProgressMessage = appManagerProgress.Message;
                }
                else
                {
                    appManagerProgressValue = 0;
                    appManagerProgressMessage = "";
                }
                appManagerProgressHasUpdate = false;
            }

            string updatedRepoRemote = null;
            string updatedRepoUrl = Localization.DefaultRepoUrl;

            var shouldUpdateContentFields = false;

            if (currentTrackingStatusHasUpdate)
            {
                currentTrackingStatusHasUpdate = false;
                statusAhead = Repository.CurrentAhead;
                statusBehind = Repository.CurrentBehind;
            }

            if (currentStatusEntriesHasUpdate)
            {
                currentStatusEntriesHasUpdate = false;
                var currentChanges = Repository.CurrentChanges;
                hasItemsToCommit = currentChanges != null &&
                    currentChanges.Any(entry => entry.Status != GitFileStatus.Ignored && !entry.Staged);
            }

            if (currentBranchAndRemoteHasUpdate)
            {
                hasRemote = false;
            }

            if (Repository != null)
            {
                if (currentBranch == null || currentRemoteName == null || currentBranchAndRemoteHasUpdate)
                {
                    currentBranchAndRemoteHasUpdate = false;

                    var repositoryCurrentBranch = Repository.CurrentBranch;
                    string updatedRepoBranch;
                    if (repositoryCurrentBranch.HasValue)
                    {
                        updatedRepoBranch = repositoryCurrentBranch.Value.Name;
                        isTrackingRemoteBranch = !string.IsNullOrEmpty(repositoryCurrentBranch.Value.Tracking);
                    }
                    else
                    {
                        updatedRepoBranch = null;
                        isTrackingRemoteBranch = false;
                    }

                    var repositoryCurrentRemote = Repository.CurrentRemote;
                    if (repositoryCurrentRemote.HasValue)
                    {
                        hasRemote = true;
                        updatedRepoRemote = repositoryCurrentRemote.Value.Name;
                        if (!string.IsNullOrEmpty(repositoryCurrentRemote.Value.Url))
                        {
                            updatedRepoUrl = repositoryCurrentRemote.Value.Url;
                        }
                    }

                    if (currentRemoteName != updatedRepoRemote)
                    {
                        currentRemoteName = updatedRepoRemote;
                        shouldUpdateContentFields = true;
                    }

                    if (currentBranch != updatedRepoBranch)
                    {
                        currentBranch = updatedRepoBranch;
                        shouldUpdateContentFields = true;
                    }

                    if (currentRemoteUrl != updatedRepoUrl)
                    {
                        currentRemoteUrl = updatedRepoUrl;
                        shouldUpdateContentFields = true;
                    }
                }
            }
            else
            {
                isTrackingRemoteBranch = false;

                if (currentRemoteName != null)
                {
                    currentRemoteName = null;
                    shouldUpdateContentFields = true;
                }

                if (currentBranch != null)
                {
                    currentBranch = null;
                    shouldUpdateContentFields = true;
                }

                if (currentRemoteUrl != Localization.DefaultRepoUrl)
                {
                    currentRemoteUrl = Localization.DefaultRepoUrl;
                    shouldUpdateContentFields = true;
                }
            }

            if (shouldUpdateContentFields || currentBranchContent == null || currentRemoteUrlContent == null)
            {
                currentBranchContent = new GUIContent(currentBranch, Localization.Window_RepoBranchTooltip);

                if (currentRemoteName != null)
                {
                    currentRemoteUrlContent = new GUIContent(currentRemoteUrl, string.Format(Localization.Window_RepoUrlTooltip, currentRemoteName));
                }
                else
                {
                    currentRemoteUrlContent = new GUIContent(currentRemoteUrl, Localization.Window_RepoNoUrlTooltip);
                }
            }
        }