Esempio n. 1
0
        public override void OnGUI()
        {
            GUILayout.BeginHorizontal(Styles.AuthHeaderBoxStyle);
            {
                GUILayout.Label(PublishToGithubLabel, EditorStyles.boldLabel);
            }
            GUILayout.EndHorizontal();

            EditorGUI.BeginDisabledGroup(isBusy);
            {
                if (connections.Length > 1)
                {
                    EditorGUI.BeginChangeCheck();
                    {
                        selectedConnection = EditorGUILayout.Popup("Connections:", selectedConnection, connectionLabels);
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        selectedClient    = GetApiClient(connections[selectedConnection]);
                        ownersNeedLoading = true;
                        Redraw();
                    }
                }

                selectedOwner   = EditorGUILayout.Popup(SelectedOwnerLabel, selectedOwner, owners);
                repoName        = EditorGUILayout.TextField(RepositoryNameLabel, repoName);
                repoDescription = EditorGUILayout.TextField(DescriptionLabel, repoDescription);

                togglePrivate = EditorGUILayout.Toggle(CreatePrivateRepositoryLabel, togglePrivate);

                var repoPrivacyExplanation = togglePrivate ? PrivateRepoMessage : PublicRepoMessage;
                EditorGUILayout.HelpBox(repoPrivacyExplanation, MessageType.None);

                GUILayout.BeginHorizontal();
                {
                    GUILayout.FlexibleSpace();
                    EditorGUI.BeginDisabledGroup(!IsFormValid);
                    if (GUILayout.Button(PublishViewCreateButton))
                    {
                        GUI.FocusControl(null);
                        isBusy = true;

                        var organization = owners[selectedOwner] == connections[selectedConnection].Username ? null : owners[selectedOwner];

                        var cleanRepoDescription = repoDescription.Trim();
                        cleanRepoDescription = string.IsNullOrEmpty(cleanRepoDescription) ? null : cleanRepoDescription;

                        selectedClient.CreateRepository(repoName, cleanRepoDescription, togglePrivate, (repository, ex) =>
                        {
                            if (ex != null)
                            {
                                Logger.Error(ex, "Repository Create Error Type:{0}", ex.GetType().ToString());
                                error  = GetPublishErrorMessage(ex);
                                isBusy = false;
                                return;
                            }

                            UsageTracker.IncrementPublishViewButtonPublish();

                            if (repository == null)
                            {
                                Logger.Warning("Returned Repository is null");
                                isBusy = false;
                                return;
                            }
                            Repository.RemoteAdd("origin", repository.CloneUrl)
                            .Then(Repository.Push("origin"))
                            .ThenInUI(Finish)
                            .Start();
                        }, organization);
                    }
                    EditorGUI.EndDisabledGroup();
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(10);

                if (error != null)
                {
                    EditorGUILayout.HelpBox(error, MessageType.Error);
                }

                GUILayout.FlexibleSpace();
            }
            EditorGUI.EndDisabledGroup();
        }