Example #1
0
        private void LoadOwners()
        {
            var keychainConnections = Platform.Keychain.Connections;

            //TODO: ONE_USER_LOGIN This assumes only ever one user can login

            isBusy = true;

            //TODO: ONE_USER_LOGIN This assumes only ever one user can login
            username = keychainConnections.First().Username;

            Client.GetOrganizations(orgs =>
            {
                publishOwners = orgs
                                .OrderBy(organization => organization.Login)
                                .Select(organization => organization.Login)
                                .ToArray();

                owners = new[] { OwnersDefaultText, username }.Union(publishOwners).ToArray();

                isBusy = false;

                Redraw();
            },
                                    exception =>
            {
                isBusy = false;

                var keychainEmptyException = exception as KeychainEmptyException;
                if (keychainEmptyException != null)
                {
                    PopupWindow.OpenWindow(PopupWindow.PopupViewType.AuthenticationView);
                    return;
                }

                Logger.Error(exception, "Unhandled Exception");
            });
        }
Example #2
0
        public override void OnGUI()
        {
            // History toolbar
            GUILayout.BeginHorizontal(EditorStyles.toolbar);
            {
                GUILayout.FlexibleSpace();

                if (hasRemote)
                {
                    EditorGUI.BeginDisabledGroup(currentRemoteName == null);
                    {
                        // Fetch button
                        var fetchClicked = GUILayout.Button(FetchButtonText, Styles.HistoryToolbarButtonStyle);
                        if (fetchClicked)
                        {
                            Fetch();
                        }

                        // Pull button
                        var pullButtonText = statusBehind > 0 ? String.Format(PullButtonCount, statusBehind) : PullButton;
                        var pullClicked    = GUILayout.Button(pullButtonText, Styles.HistoryToolbarButtonStyle);

                        if (pullClicked &&
                            EditorUtility.DisplayDialog(PullConfirmTitle,
                                                        String.Format(PullConfirmDescription, currentRemoteName),
                                                        PullConfirmYes,
                                                        PullConfirmCancel)
                            )
                        {
                            Pull();
                        }
                    }
                    EditorGUI.EndDisabledGroup();

                    // Push button
                    EditorGUI.BeginDisabledGroup(currentRemoteName == null || statusBehind != 0);
                    {
                        var pushButtonText = statusAhead > 0 ? String.Format(PushButtonCount, statusAhead) : PushButton;
                        var pushClicked    = GUILayout.Button(pushButtonText, Styles.HistoryToolbarButtonStyle);

                        if (pushClicked &&
                            EditorUtility.DisplayDialog(PushConfirmTitle,
                                                        String.Format(PushConfirmDescription, currentRemoteName),
                                                        PushConfirmYes,
                                                        PushConfirmCancel)
                            )
                        {
                            Push();
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }
                else
                {
                    // Publishing a repo
                    var publishedClicked = GUILayout.Button(PublishButton, Styles.HistoryToolbarButtonStyle);
                    if (publishedClicked)
                    {
                        PopupWindow.OpenWindow(PopupWindow.PopupViewType.PublishView);
                    }
                }
            }
            GUILayout.EndHorizontal();

            var rect = GUILayoutUtility.GetLastRect();

            if (historyControl != null)
            {
                var historyControlRect = new Rect(0f, 0f, Position.width, Position.height - rect.height);

                var requiresRepaint = historyControl.Render(historyControlRect,
                                                            entry => {
                    selectedEntry = entry;
                    BuildTree();
                },
                                                            entry => { },
                                                            entry => { });

                if (requiresRepaint)
                {
                    Redraw();
                }
            }

            if (!selectedEntry.Equals(GitLogEntry.Default))
            {
                // Top bar for scrolling to selection or clearing it
                GUILayout.BeginHorizontal(EditorStyles.toolbar);
                {
                    if (GUILayout.Button(CommitDetailsTitle, Styles.HistoryToolbarButtonStyle))
                    {
                        historyControl.ScrollTo(historyControl.SelectedIndex);
                    }
                    if (GUILayout.Button(ClearSelectionButton, Styles.HistoryToolbarButtonStyle, GUILayout.ExpandWidth(false)))
                    {
                        selectedEntry = GitLogEntry.Default;
                        historyControl.SelectedIndex = -1;
                    }
                }
                GUILayout.EndHorizontal();

                // Log entry details - including changeset tree (if any changes are found)
                detailsScroll = GUILayout.BeginScrollView(detailsScroll, GUILayout.Height(250));
                {
                    HistoryDetailsEntry(selectedEntry);

                    GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
                    GUILayout.Label("Files changed", EditorStyles.boldLabel);
                    GUILayout.Space(-5);

                    rect = GUILayoutUtility.GetLastRect();
                    GUILayout.BeginHorizontal(Styles.HistoryFileTreeBoxStyle);
                    GUILayout.BeginVertical();
                    {
                        var borderLeft      = Styles.Label.margin.left;
                        var treeControlRect = new Rect(rect.x + borderLeft, rect.y, Position.width - borderLeft * 2, Position.height - rect.height + Styles.CommitAreaPadding);
                        var treeRect        = Rect.zero;
                        if (treeChanges != null)
                        {
                            treeChanges.FolderStyle                = Styles.Foldout;
                            treeChanges.TreeNodeStyle              = Styles.TreeNode;
                            treeChanges.ActiveTreeNodeStyle        = Styles.ActiveTreeNode;
                            treeChanges.FocusedTreeNodeStyle       = Styles.FocusedTreeNode;
                            treeChanges.FocusedActiveTreeNodeStyle = Styles.FocusedActiveTreeNode;

                            treeRect = treeChanges.Render(treeControlRect, detailsScroll,
                                                          node => { },
                                                          node => {
                            },
                                                          node => {
                            });

                            if (treeChanges.RequiresRepaint)
                            {
                                Redraw();
                            }
                        }

                        GUILayout.Space(treeRect.y - treeControlRect.y);
                    }
                    GUILayout.EndVertical();
                    GUILayout.EndHorizontal();

                    GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
                }
                GUILayout.EndScrollView();
            }
        }
Example #3
0
 private void SignIn(object obj)
 {
     PopupWindow.OpenWindow(PopupWindow.PopupViewType.AuthenticationView);
 }
Example #4
0
        public void OnEmbeddedGUI()
        {
            // History toolbar
            GUILayout.BeginHorizontal(EditorStyles.toolbar);
            {
                GUILayout.FlexibleSpace();

                if (hasRemote)
                {
                    EditorGUI.BeginDisabledGroup(currentRemoteName == null);
                    {
                        // Fetch button
                        var fetchClicked = GUILayout.Button(FetchButtonText, Styles.HistoryToolbarButtonStyle);
                        if (fetchClicked)
                        {
                            Fetch();
                        }

                        // Pull button
                        var pullButtonText = statusBehind > 0 ? String.Format(PullButtonCount, statusBehind) : PullButton;
                        var pullClicked    = GUILayout.Button(pullButtonText, Styles.HistoryToolbarButtonStyle);

                        if (pullClicked &&
                            EditorUtility.DisplayDialog(PullConfirmTitle,
                                                        String.Format(PullConfirmDescription, currentRemoteName),
                                                        PullConfirmYes,
                                                        PullConfirmCancel)
                            )
                        {
                            Pull();
                        }
                    }
                    EditorGUI.EndDisabledGroup();

                    // Push button
                    EditorGUI.BeginDisabledGroup(currentRemoteName == null || statusBehind != 0);
                    {
                        var pushButtonText = statusAhead > 0 ? String.Format(PushButtonCount, statusAhead) : PushButton;
                        var pushClicked    = GUILayout.Button(pushButtonText, Styles.HistoryToolbarButtonStyle);

                        if (pushClicked &&
                            EditorUtility.DisplayDialog(PushConfirmTitle,
                                                        String.Format(PushConfirmDescription, currentRemoteName),
                                                        PushConfirmYes,
                                                        PushConfirmCancel)
                            )
                        {
                            Push();
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }
                else
                {
                    // Publishing a repo
                    var publishedClicked = GUILayout.Button(PublishButton, Styles.HistoryToolbarButtonStyle);
                    if (publishedClicked)
                    {
                        PopupWindow.OpenWindow(PopupWindow.PopupViewType.PublishView);
                    }
                }
            }
            GUILayout.EndHorizontal();

            // When history scroll actually changes, store time value of topmost visible entry. This is the value we use to reposition scroll on log update - not the pixel value.
            if (history.Any())
            {
                listID = GUIUtility.GetControlID(FocusType.Keyboard);

                // Only update time scroll
                var lastScroll = scroll;
                scroll = GUILayout.BeginScrollView(scroll);
                if (lastScroll != scroll && !currentLogHasUpdate)
                {
                    scrollTime    = history[historyStartIndex].Time;
                    scrollOffset  = scroll.y - historyStartIndex * EntryHeight;
                    useScrollTime = true;
                }
                // Handle only the selected range of history items - adding spacing for the rest
                var start = Mathf.Max(0, historyStartIndex - HistoryExtraItemCount);
                var stop  = Mathf.Min(historyStopIndex + HistoryExtraItemCount, history.Count);
                GUILayout.Space(start * EntryHeight);
                for (var index = start; index < stop; ++index)
                {
                    if (HistoryEntry(history[index], GetEntryState(index), selectionIndex == index))
                    {
                        newSelectionIndex          = index;
                        GUIUtility.keyboardControl = listID;
                    }
                }

                GUILayout.Space((history.Count - stop) * EntryHeight);

                // Keyboard control
                if (GUIUtility.keyboardControl == listID && Event.current.type == EventType.KeyDown)
                {
                    var change = 0;

                    if (Event.current.keyCode == KeyCode.DownArrow)
                    {
                        change = 1;
                    }
                    else if (Event.current.keyCode == KeyCode.UpArrow)
                    {
                        change = -1;
                    }

                    if (change != 0)
                    {
                        newSelectionIndex = (selectionIndex + change) % history.Count;
                        if (newSelectionIndex < historyStartIndex || newSelectionIndex > historyStopIndex)
                        {
                            ScrollTo(newSelectionIndex,
                                     (Position.height - Position.height * MaxChangelistHeightRatio - 30f - EntryHeight) * -.5f);
                        }
                        Event.current.Use();
                    }
                }
            }
            else
            {
                GUILayout.BeginScrollView(scroll);
            }

            GUILayout.EndScrollView();

            // Selection info
            if (selectionIndex >= 0 && history.Count > selectionIndex)
            {
                var selection = history[selectionIndex];

                // Top bar for scrolling to selection or clearing it
                GUILayout.BeginHorizontal(EditorStyles.toolbar);
                {
                    if (GUILayout.Button(CommitDetailsTitle, Styles.HistoryToolbarButtonStyle))
                    {
                        ScrollTo(selectionIndex);
                    }
                    if (GUILayout.Button(ClearSelectionButton, Styles.HistoryToolbarButtonStyle, GUILayout.ExpandWidth(false)))
                    {
                        newSelectionIndex = -2;
                    }
                }
                GUILayout.EndHorizontal();

                // Log entry details - including changeset tree (if any changes are found)
                if (changesetTree.Entries.Any())
                {
                    detailsScroll = GUILayout.BeginScrollView(detailsScroll, GUILayout.Height(250));
                    {
                        HistoryDetailsEntry(selection);

                        GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
                        GUILayout.Label("Files changed", EditorStyles.boldLabel);
                        GUILayout.Space(-5);

                        GUILayout.BeginHorizontal(Styles.HistoryFileTreeBoxStyle);
                        {
                            changesetTree.OnGUI();
                        }
                        GUILayout.EndHorizontal();

                        GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
                    }
                    GUILayout.EndScrollView();
                }
                else
                {
                    detailsScroll = GUILayout.BeginScrollView(detailsScroll, GUILayout.Height(246));
                    HistoryDetailsEntry(selection);
                    GUILayout.EndScrollView();
                }
            }

            // Handle culling and selection changes at the end of the last GUI frame
            if (Event.current.type == EventType.Repaint)
            {
                CullHistory();
                currentLogHasUpdate = false;

                if (newSelectionIndex >= 0 || newSelectionIndex == -2)
                {
                    selectionIndex    = newSelectionIndex == -2 ? -1 : newSelectionIndex;
                    newSelectionIndex = -1;
                    detailsScroll     = Vector2.zero;

                    if (selectionIndex >= 0)
                    {
                        changesetTree.UpdateEntries(history[selectionIndex].Changes);
                    }

                    Redraw();
                }
            }
        }
Example #5
0
        private void DoActionbarGUI()
        {
            GUILayout.BeginHorizontal(EditorStyles.toolbar);
            {
                if (hasRemote)
                {
                    EditorGUI.BeginDisabledGroup(currentRemoteName == null);
                    {
                        // Fetch button
                        var fetchClicked = GUILayout.Button(fetchButtonContent, Styles.ToolbarButtonStyle);
                        if (fetchClicked)
                        {
                            Fetch();
                        }

                        // Pull button
                        var pullButtonText = statusBehind > 0 ? new GUIContent(String.Format(Localization.PullButtonCount, statusBehind)) : pullButtonContent;
                        var pullClicked    = GUILayout.Button(pullButtonText, Styles.ToolbarButtonStyle);

                        if (pullClicked &&
                            EditorUtility.DisplayDialog(Localization.PullConfirmTitle,
                                                        String.Format(Localization.PullConfirmDescription, currentRemoteName),
                                                        Localization.PullConfirmYes,
                                                        Localization.Cancel)
                            )
                        {
                            Pull();
                        }
                    }
                    EditorGUI.EndDisabledGroup();

                    // Push button
                    EditorGUI.BeginDisabledGroup(currentRemoteName == null || isTrackingRemoteBranch && statusAhead == 0);
                    {
                        var pushButtonText = statusAhead > 0 ? new GUIContent(String.Format(Localization.PushButtonCount, statusAhead)) : pushButtonContent;
                        var pushClicked    = GUILayout.Button(pushButtonText, Styles.ToolbarButtonStyle);

                        if (pushClicked &&
                            EditorUtility.DisplayDialog(Localization.PushConfirmTitle,
                                                        String.Format(Localization.PushConfirmDescription, currentRemoteName),
                                                        Localization.PushConfirmYes,
                                                        Localization.Cancel)
                            )
                        {
                            Push();
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }
                else
                {
                    // Publishing a repo
                    if (GUILayout.Button(Localization.PublishButton, Styles.ToolbarButtonStyle))
                    {
                        PopupWindow.OpenWindow(PopupWindow.PopupViewType.PublishView);
                    }
                }

                if (GUILayout.Button(refreshButtonContent, Styles.ToolbarButtonStyle))
                {
                    Refresh();
                }

                GUILayout.FlexibleSpace();

                if (connection == null)
                {
                    if (GUILayout.Button("Sign in", EditorStyles.toolbarButton))
                    {
                        SignIn(null);
                    }
                }
                else
                {
                    if (GUILayout.Button(connection.Username, EditorStyles.toolbarDropDown))
                    {
                        DoAccountDropdown();
                    }
                }
            }
            EditorGUILayout.EndHorizontal();
        }