Beispiel #1
0
        public void OpenContextMenu(DragList dropList)
        {
            var itemGetter = _contextMenuHandlers.TryGetValue(dropList.ListType);

            if (itemGetter != null)
            {
                ImguiUtil.OpenContextMenu(itemGetter());
            }
        }
Beispiel #2
0
        public void OnGUI(Rect fullRect)
        {
            GUI.skin = _pmSettings.GUISkin;

            if (IsBlocked)
            {
                // Do not allow any input processing when running an async task
                GUI.enabled = false;
            }

            DrawArrowColumns(fullRect);

            var windowRect = Rect.MinMaxRect(
                _settings.ListVerticalSpacing + _settings.ArrowWidth,
                _settings.MarginTop,
                fullRect.width - _settings.ListVerticalSpacing - _settings.ArrowWidth,
                fullRect.height - _settings.MarginBottom);

            if (_split1 >= 0.1f)
            {
                DrawReleasePane(windowRect);
            }

            if (_split2 >= 0.1f)
            {
                DrawPackagesPane(windowRect);
            }

            if (_split2 <= 0.92f)
            {
                DrawProjectPane(windowRect);
            }

            GUI.enabled = true;

            if (IsBlocked)
            {
                if (ShowBlockedPopup || !_popupHandlers.IsEmpty())
                {
                    ImguiUtil.DrawColoredQuad(fullRect, _settings.Theme.LoadingOverlayColor);

                    if (_popupHandlers.IsEmpty())
                    {
                        DisplayGenericProcessingDialog(fullRect);
                    }
                    else
                    {
                        foreach (var info in _popupHandlers)
                        {
                            info.Handler(fullRect);
                        }
                    }
                }
            }
        }
Beispiel #3
0
        IEnumerator OpenMoreInfoPopup(ReleaseInfo info)
        {
            bool isDone = false;

            var     skin      = _pmSettings.ReleaseMoreInfoDialog;
            Vector2 scrollPos = Vector2.zero;

            var popupId = _view.AddPopup(delegate(Rect fullRect)
            {
                var popupRect = ImguiUtil.CenterRectInRect(fullRect, skin.PopupSize);

                _view.DrawPopupCommon(fullRect, popupRect);

                var contentRect = ImguiUtil.CreateContentRectWithPadding(
                    popupRect, skin.PanelPadding);

                GUILayout.BeginArea(contentRect);
                {
                    GUILayout.Label("Release Info", skin.HeadingStyle);

                    GUILayout.Space(skin.HeadingBottomPadding);

                    scrollPos = GUILayout.BeginScrollView(scrollPos, false, true, GUI.skin.horizontalScrollbar, GUI.skin.verticalScrollbar, skin.ScrollViewStyle, GUILayout.Height(skin.ListHeight));
                    {
                        GUILayout.Space(skin.ListPaddingTop);

                        PmViewHandlerCommon.AddReleaseInfoMoreInfoRows(info, skin);
                    }
                    GUI.EndScrollView();
                }
                GUILayout.EndArea();

                var okButtonRect = new Rect(
                    contentRect.xMin + 0.5f * contentRect.width - 0.5f * skin.OkButtonWidth,
                    contentRect.yMax - skin.MarginBottom - skin.OkButtonHeight,
                    skin.OkButtonWidth,
                    skin.OkButtonHeight);

                if (GUI.Button(okButtonRect, "Ok") || Event.current.keyCode == KeyCode.Escape)
                {
                    isDone = true;
                }
            });

            while (!isDone)
            {
                yield return(null);
            }

            _view.RemovePopup(popupId);
        }
Beispiel #4
0
        void DisplayGenericProcessingDialog(Rect fullRect)
        {
            var skin      = _pmSettings.AsyncPopupPane;
            var popupRect = ImguiUtil.CenterRectInRect(fullRect, skin.PopupSize);

            DrawPopupCommon(fullRect, popupRect);

            var contentRect = ImguiUtil.CreateContentRectWithPadding(
                popupRect, skin.PanelPadding);

            GUILayout.BeginArea(contentRect);
            {
                string title;

                if (string.IsNullOrEmpty(BlockedStatusTitle))
                {
                    title = "Processing";
                }
                else
                {
                    title = BlockedStatusTitle;
                }

                GUILayout.Label(title, skin.HeadingTextStyle, GUILayout.ExpandWidth(true));
                GUILayout.Space(skin.HeadingBottomPadding);

                string statusMessage = "";

                if (!string.IsNullOrEmpty(BlockedStatusMessage))
                {
                    statusMessage = BlockedStatusMessage;

                    int numExtraDots = (int)(Time.realtimeSinceStartup * skin.DotRepeatRate) % 4;

                    statusMessage += new String('.', numExtraDots);

                    // This is very hacky but the only way I can figure out how to keep the message a fixed length
                    // so that the text doesn't jump around as the number of dots change
                    // I tried using spaces instead of _ but that didn't work
                    statusMessage += ImguiUtil.WrapWithColor(new String('_', 3 - numExtraDots), _settings.Theme.LoadingOverlapPopupColor);
                }

                GUILayout.Label(statusMessage, skin.StatusMessageTextStyle, GUILayout.ExpandWidth(true));
            }

            GUILayout.EndArea();
        }
Beispiel #5
0
        DragList.ItemDescriptor CreateListItemForVsProject(string name)
        {
            string caption;

            if (_model.HasAssetItem(name) || _model.HasPluginItem(name))
            {
                caption = ImguiUtil.WrapWithColor(
                    name, _pmSettings.View.Theme.DraggableItemAlreadyAddedColor);
            }
            else
            {
                caption = name;
            }

            return(new DragList.ItemDescriptor()
            {
                Caption = caption,
                Model = name
            });
        }
Beispiel #6
0
        DragList.ItemDescriptor CreateListItem(PackageInfo info)
        {
            string caption;

            if (_view.ViewState == PmViewStates.ReleasesAndPackages)
            {
                var releaseInfo = info.InstallInfo.ReleaseInfo;
                if (!string.IsNullOrEmpty(releaseInfo.Name))
                {
                    caption = "{0} ({1}{2})".Fmt(
                        info.Name,
                        ImguiUtil.WrapWithColor(releaseInfo.Name, _pmSettings.View.Theme.DraggableItemAlreadyAddedColor),
                        string.IsNullOrEmpty(releaseInfo.Version) ? "" : ImguiUtil.WrapWithColor(" v" + releaseInfo.Version, _pmSettings.View.Theme.VersionColor));
                }
                else
                {
                    caption = info.Name;
                }
            }
            else
            {
                // this isn't always the case since it can be rendered when interpolating
                //Assert.IsEqual(_model.ViewState, PmViewStates.PackagesAndProject);

                if (_model.IsPackageAddedToProject(info.Name))
                {
                    caption = ImguiUtil.WrapWithColor(
                        info.Name, _pmSettings.View.Theme.DraggableItemAlreadyAddedColor);
                }
                else
                {
                    caption = info.Name;
                }
            }

            return(new DragList.ItemDescriptor()
            {
                Caption = caption,
                Model = info
            });
        }
Beispiel #7
0
        DragList.ItemDescriptor CreateListItemForProjectItem(string name)
        {
            string caption;

            if (_view.ViewState == PmViewStates.PackagesAndProject ||
                (_view.ViewState == PmViewStates.ProjectAndVisualStudio && _model.HasVsProject(name)))
            {
                caption = ImguiUtil.WrapWithColor(name, _pmSettings.View.Theme.DraggableItemAlreadyAddedColor);
            }
            else
            {
                // this isn't always the case since it can be rendered when interpolating
                //Assert.That(_viewState == PmViewStates.Project);
                caption = name;
            }

            return(new DragList.ItemDescriptor()
            {
                Caption = caption,
                Model = name
            });
        }
Beispiel #8
0
        DragList.ItemDescriptor CreateListItem(ReleaseInfo info)
        {
            string caption;

            if (_model.IsReleaseInstalled(info))
            {
                caption = ImguiUtil.WrapWithColor(
                    info.Name, _pmSettings.View.Theme.DraggableItemAlreadyAddedColor);
            }
            else
            {
                caption = info.Name;
            }

            caption = string.IsNullOrEmpty(info.Version) ? caption : "{0} {1}"
                      .Fmt(caption, ImguiUtil.WrapWithColor("v" + info.Version, _pmSettings.View.Theme.VersionColor));

            return(new DragList.ItemDescriptor()
            {
                Caption = caption,
                Model = info,
            });
        }
Beispiel #9
0
        public void Draw(Rect fullRect)
        {
            Rect listRect;

            if (ShowSortPane)
            {
                var releaseSkin = _pmSettings.ReleasesPane;
                var searchRect  = new Rect(fullRect.xMin, fullRect.yMin, fullRect.width, releaseSkin.IconRowHeight);
                DrawSearchPane(searchRect);

                listRect = Rect.MinMaxRect(
                    fullRect.xMin, fullRect.yMin + releaseSkin.IconRowHeight, fullRect.xMax, fullRect.yMax);
            }
            else
            {
                listRect = fullRect;
            }

            var searchFilter   = _model.SearchFilter.Trim().ToLowerInvariant();
            var visibleEntries = _entries.Where(x => x.Name.ToLowerInvariant().Contains(searchFilter)).ToList();

            var viewRect = new Rect(0, 0, listRect.width - 30.0f, visibleEntries.Count * _settings.ItemHeight);

            var isListUnderMouse = listRect.Contains(Event.current.mousePosition);

            ImguiUtil.DrawColoredQuad(listRect, GetListBackgroundColor(isListUnderMouse));

            switch (Event.current.type)
            {
            case EventType.MouseUp:
            {
                // Clear our drag info in DragAndDrop so that we know that we are not dragging
                DragAndDrop.PrepareStartDrag();
                break;
            }

            case EventType.DragPerform:
                // Drag has completed
            {
                if (isListUnderMouse)
                {
                    DragAndDrop.AcceptDrag();

                    var receivedDragData = DragAndDrop.GetGenericData(DragId) as DragData;

                    if (receivedDragData != null)
                    {
                        DragAndDrop.PrepareStartDrag();
                        _manager.OnDragDrop(receivedDragData, this);
                    }
                }

                break;
            }

            case EventType.MouseDrag:
            {
                if (isListUnderMouse)
                {
                    var existingDragData = DragAndDrop.GetGenericData(DragId) as DragData;

                    if (existingDragData != null)
                    {
                        DragAndDrop.StartDrag("Dragging List Element");
                        Event.current.Use();
                    }
                }

                break;
            }

            case EventType.DragUpdated:
            {
                if (isListUnderMouse)
                {
                    var existingDragData = DragAndDrop.GetGenericData(DragId) as DragData;

                    if (existingDragData != null && (_manager != null && _manager.IsDragAllowed(existingDragData, this)))
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                        Event.current.Use();
                    }
                    else
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                    }
                }

                break;
            }

            case EventType.ContextClick:
            {
                if (isListUnderMouse)
                {
                    _manager.OpenContextMenu(this);
                    Event.current.Use();
                }

                break;
            }
            }

            bool clickedItem = false;

            float yPos = 0;

            _model.ScrollPos = GUI.BeginScrollView(listRect, _model.ScrollPos, viewRect);
            {
                foreach (var entry in visibleEntries)
                {
                    var labelRect = new Rect(0, yPos, listRect.width, _settings.ItemHeight);

                    bool isItemUnderMouse = labelRect.Contains(Event.current.mousePosition);

                    Color itemColor;

                    if (entry.IsSelected)
                    {
                        itemColor = _settings.Theme.ListItemSelectedColor;
                    }
                    else
                    {
                        itemColor = GUI.enabled && isItemUnderMouse ? _settings.Theme.ListItemHoverColor : _settings.Theme.ListItemColor;
                    }

                    ImguiUtil.DrawColoredQuad(labelRect, itemColor);

                    switch (Event.current.type)
                    {
                    case EventType.MouseUp:
                    {
                        if (isItemUnderMouse && Event.current.button == 0)
                        {
                            if (!Event.current.shift && !Event.current.control)
                            {
                                _manager.ClearSelected();
                                ClickSelect(entry);
                            }
                        }

                        break;
                    }

                    case EventType.MouseDown:
                    {
                        if (isItemUnderMouse)
                        {
                            // Unfocus on text field
                            GUI.FocusControl(null);

                            clickedItem = true;
                            ClickSelect(entry);

                            if (Event.current.button == 0)
                            {
                                DragAndDrop.PrepareStartDrag();

                                var dragData = new DragData()
                                {
                                    Entries    = GetSelected(),
                                    SourceList = this,
                                };

                                DragAndDrop.SetGenericData(DragId, dragData);
                                DragAndDrop.objectReferences = new UnityEngine.Object[0];
                            }

                            Event.current.Use();
                        }
                        break;
                    }
                    }

                    GUI.Label(labelRect, entry.Name, _settings.ItemTextStyle);

                    yPos += _settings.ItemHeight;
                }
            }
            GUI.EndScrollView();

            if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && !clickedItem && isListUnderMouse)
            {
                // Unfocus on text field
                GUI.FocusControl(null);

                _manager.ClearSelected();
            }
        }
Beispiel #10
0
        void DrawSearchPane(Rect rect)
        {
            Assert.That(ShowSortPane);

            var startX = rect.xMin;
            var endX   = rect.xMax;
            var startY = rect.yMin;
            var endY   = rect.yMax;

            var skin = _pmSettings.ReleasesPane;

            ImguiUtil.DrawColoredQuad(rect, skin.IconRowBackgroundColor);

            endX = rect.xMax - 2 * skin.ButtonWidth;

            var searchBarRect = Rect.MinMaxRect(startX, startY, endX, endY);

            if (GUI.enabled && searchBarRect.Contains(Event.current.mousePosition))
            {
                ImguiUtil.DrawColoredQuad(searchBarRect, skin.MouseOverBackgroundColor);
            }

            GUI.Label(new Rect(startX + skin.SearchIconOffset.x, startY + skin.SearchIconOffset.y, skin.SearchIconSize.x, skin.SearchIconSize.y), skin.SearchIcon);

            this.SearchFilter = GUI.TextField(
                searchBarRect, this.SearchFilter, skin.SearchTextStyle);

            startX = endX;
            endX   = startX + skin.ButtonWidth;

            Rect buttonRect;

            buttonRect = Rect.MinMaxRect(startX, startY, endX, endY);
            if (buttonRect.Contains(Event.current.mousePosition))
            {
                ImguiUtil.DrawColoredQuad(buttonRect, skin.MouseOverBackgroundColor);

                if (Event.current.type == EventType.MouseDown)
                {
                    SortDescending = !SortDescending;
                    this.UpdateIndices();
                }
            }
            GUI.DrawTexture(buttonRect, SortDescending ? skin.SortDirUpIcon : skin.SortDirDownIcon);

            startX = endX;
            endX   = startX + skin.ButtonWidth;

            buttonRect = Rect.MinMaxRect(startX, startY, endX, endY);
            if (buttonRect.Contains(Event.current.mousePosition))
            {
                ImguiUtil.DrawColoredQuad(buttonRect, skin.MouseOverBackgroundColor);

                if (Event.current.type == EventType.MouseDown && !_sortMethodCaptions.IsEmpty())
                {
                    var startPos = new Vector2(buttonRect.xMin, buttonRect.yMax);
                    ImguiUtil.OpenContextMenu(startPos, CreateSortMethodContextMenuItems());
                }
            }
            GUI.DrawTexture(buttonRect, skin.SortIcon);
        }
Beispiel #11
0
        public IEnumerator <string> PromptForInput(string label, string defaultValue)
        {
            string            userInput = defaultValue;
            InputDialogStates state     = InputDialogStates.None;

            bool isFirst = true;

            var popupId = AddPopup(delegate(Rect fullRect)
            {
                if (Event.current.type == EventType.KeyDown)
                {
                    switch (Event.current.keyCode)
                    {
                    case KeyCode.Return:
                        {
                            state = InputDialogStates.Submitted;
                            break;
                        }

                    case KeyCode.Escape:
                        {
                            state = InputDialogStates.Cancelled;
                            break;
                        }
                    }
                }

                var popupRect = ImguiUtil.CenterRectInRect(fullRect, _pmSettings.InputDialog.PopupSize);

                DrawPopupCommon(fullRect, popupRect);

                var contentRect = ImguiUtil.CreateContentRectWithPadding(
                    popupRect, _pmSettings.InputDialog.PanelPadding);

                GUILayout.BeginArea(contentRect);
                {
                    GUILayout.Label(label, _pmSettings.InputDialog.LabelStyle);

                    GUI.SetNextControlName("PopupTextField");
                    userInput = GUILayout.TextField(userInput, 100);
                    GUI.SetNextControlName("");

                    GUILayout.Space(5);

                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.FlexibleSpace();

                        if (GUILayout.Button("Submit", GUILayout.MaxWidth(100)))
                        {
                            state = InputDialogStates.Submitted;
                        }

                        if (GUILayout.Button("Cancel", GUILayout.MaxWidth(100)))
                        {
                            state = InputDialogStates.Cancelled;
                        }
                    }
                    GUILayout.EndHorizontal();
                }
                GUILayout.EndArea();

                if (isFirst)
                {
                    isFirst = false;
                    // Need to remove focus then regain focus on the text box for it to select the whole contents
                    GUI.FocusControl("");
                }
                else if (string.IsNullOrEmpty(GUI.GetNameOfFocusedControl()))
                {
                    GUI.FocusControl("PopupTextField");
                }
            });

            while (state == InputDialogStates.None)
            {
                yield return(null);
            }

            RemovePopup(popupId);

            if (state == InputDialogStates.Submitted)
            {
                yield return(userInput);
            }
            else
            {
                // Just return null
            }
        }
Beispiel #12
0
 public void DrawPopupCommon(Rect fullRect, Rect popupRect)
 {
     ImguiUtil.DrawColoredQuad(popupRect, _settings.Theme.LoadingOverlapPopupColor);
 }
        IEnumerator OpenMoreInfoPopup(PackageInfo info)
        {
            bool isDone = false;

            var     skin      = _pmSettings.ReleaseMoreInfoDialog;
            Vector2 scrollPos = Vector2.zero;

            var popupId = _view.AddPopup(delegate(Rect fullRect)
            {
                var popupRect = ImguiUtil.CenterRectInRect(fullRect, skin.PopupSize);

                _view.DrawPopupCommon(fullRect, popupRect);

                var contentRect = ImguiUtil.CreateContentRectWithPadding(
                    popupRect, skin.PanelPadding);

                var scrollViewRect = new Rect(
                    contentRect.xMin, contentRect.yMin, contentRect.width, contentRect.height - skin.MarginBottom - skin.OkButtonHeight - skin.OkButtonTopPadding);

                GUILayout.BeginArea(scrollViewRect);
                {
                    scrollPos = GUILayout.BeginScrollView(scrollPos, false, true, GUI.skin.horizontalScrollbar, GUI.skin.verticalScrollbar, skin.ScrollViewStyle, GUILayout.ExpandHeight(true));
                    {
                        GUILayout.Space(skin.ListPaddingTop);
                        GUILayout.Label("Package Info", skin.HeadingStyle);
                        GUILayout.Space(skin.HeadingBottomPadding);

                        PmViewHandlerCommon.DrawMoreInfoRow(skin, "Name", info.Name);
                        GUILayout.Space(skin.RowSpacing);
                        PmViewHandlerCommon.DrawMoreInfoRow(skin, "Path", info.Path);
                        GUILayout.Space(skin.RowSpacing);
                        PmViewHandlerCommon.DrawMoreInfoRow(skin, "Creation Date", !string.IsNullOrEmpty(info.InstallInfo.InstallDate) ? info.InstallInfo.InstallDate : PmViewHandlerCommon.NotAvailableLabel);

                        GUILayout.Space(skin.ListPaddingTop);
                        GUILayout.Space(skin.ListPaddingTop);
                        GUILayout.Label("Release Info", skin.HeadingStyle);
                        GUILayout.Space(skin.HeadingBottomPadding);

                        if (string.IsNullOrEmpty(info.InstallInfo.ReleaseInfo.Id))
                        {
                            GUI.color = skin.ValueStyle.normal.textColor;
                            GUILayout.Label("No release is associated with this package", skin.HeadingStyle);
                            GUI.color = Color.white;
                        }
                        else
                        {
                            PmViewHandlerCommon.AddReleaseInfoMoreInfoRows(info.InstallInfo.ReleaseInfo, skin);
                        }

                        GUILayout.Space(skin.RowSpacing);
                    }
                    GUI.EndScrollView();
                }
                GUILayout.EndArea();

                var okButtonRect = new Rect(
                    contentRect.xMin + 0.5f * contentRect.width - 0.5f * skin.OkButtonWidth,
                    contentRect.yMax - skin.MarginBottom - skin.OkButtonHeight,
                    skin.OkButtonWidth,
                    skin.OkButtonHeight);

                if (GUI.Button(okButtonRect, "Ok") || Event.current.keyCode == KeyCode.Escape)
                {
                    isDone = true;
                }
            });

            while (!isDone)
            {
                yield return(null);
            }

            _view.RemovePopup(popupId);
        }
        IEnumerator <PopupChoices> ShowPopup()
        {
            var label = "Enter new project name:";

            var choices = new PopupChoices();

            choices.NewProjectName = "Untitled";
            PmView.InputDialogStates state = PmView.InputDialogStates.None;

            bool isFirst = true;

            var popupId = _view.AddPopup(delegate(Rect fullRect)
            {
                if (Event.current.type == EventType.KeyDown)
                {
                    switch (Event.current.keyCode)
                    {
                    case KeyCode.Return:
                        {
                            state = PmView.InputDialogStates.Submitted;
                            break;
                        }

                    case KeyCode.Escape:
                        {
                            state = PmView.InputDialogStates.Cancelled;
                            break;
                        }
                    }
                }

                var popupRect = ImguiUtil.CenterRectInRect(fullRect, _settings.PopupSize);

                _view.DrawPopupCommon(fullRect, popupRect);

                var contentRect = ImguiUtil.CreateContentRectWithPadding(
                    popupRect, _pmSettings.InputDialog.PanelPadding);

                GUILayout.BeginArea(contentRect);
                {
                    GUILayout.Label(label, _pmSettings.InputDialog.LabelStyle);

                    GUI.SetNextControlName("PopupTextField");
                    choices.NewProjectName = GUILayout.TextField(choices.NewProjectName, 100);
                    GUI.SetNextControlName("");

                    GUILayout.Space(5);

                    GUILayout.BeginHorizontal();
                    {
                        choices.DuplicateSettings = GUILayout.Toggle(choices.DuplicateSettings, "", GUILayout.Height(_settings.CheckboxHeight));
                        GUILayout.Label("Share Project Settings with '{0}'".Fmt(ProjenyEditorUtil.GetCurrentProjectName()));
                        GUILayout.FlexibleSpace();
                    }
                    GUILayout.EndHorizontal();

                    GUILayout.Space(5);

                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.FlexibleSpace();

                        if (GUILayout.Button("Submit", GUILayout.MaxWidth(100)))
                        {
                            state = PmView.InputDialogStates.Submitted;
                        }

                        if (GUILayout.Button("Cancel", GUILayout.MaxWidth(100)))
                        {
                            state = PmView.InputDialogStates.Cancelled;
                        }
                    }
                    GUILayout.EndHorizontal();
                }
                GUILayout.EndArea();

                if (isFirst)
                {
                    isFirst = false;
                    // Need to remove focus then regain focus on the text box for it to select the whole contents
                    GUI.FocusControl("");
                }
                else if (string.IsNullOrEmpty(GUI.GetNameOfFocusedControl()))
                {
                    GUI.FocusControl("PopupTextField");
                }
            });

            while (state == PmView.InputDialogStates.None)
            {
                yield return(null);
            }

            _view.RemovePopup(popupId);

            if (state == PmView.InputDialogStates.Submitted)
            {
                yield return(choices);
            }
            else
            {
                // Just return null
            }
        }