Exemplo n.º 1
0
        private void InitializePrecisionSubMenu(ContextualMenuPopulateEvent evt)
        {
            // Default the menu buttons to disabled
            DropdownMenuAction.Status inheritPrecisionAction = DropdownMenuAction.Status.Disabled;
            DropdownMenuAction.Status floatPrecisionAction   = DropdownMenuAction.Status.Disabled;
            DropdownMenuAction.Status halfPrecisionAction    = DropdownMenuAction.Status.Disabled;

            // Check which precisions are available to switch to
            foreach (MaterialNodeView selectedNode in selection.Where(x => x is MaterialNodeView).Select(x => x as MaterialNodeView))
            {
                if (selectedNode.node.precision != Precision.Inherit)
                {
                    inheritPrecisionAction = DropdownMenuAction.Status.Normal;
                }
                if (selectedNode.node.precision != Precision.Float)
                {
                    floatPrecisionAction = DropdownMenuAction.Status.Normal;
                }
                if (selectedNode.node.precision != Precision.Half)
                {
                    halfPrecisionAction = DropdownMenuAction.Status.Normal;
                }
            }

            // Create the menu options
            evt.menu.AppendAction("Precision/Inherit", _ => SetNodePrecisionOnSelection(Precision.Inherit), (a) => inheritPrecisionAction);
            evt.menu.AppendAction("Precision/Float", _ => SetNodePrecisionOnSelection(Precision.Float), (a) => floatPrecisionAction);
            evt.menu.AppendAction("Precision/Half", _ => SetNodePrecisionOnSelection(Precision.Half), (a) => halfPrecisionAction);
        }
        private void SetItemStatus(VisualElement ve, DropdownMenuAction.Status status)
        {
            switch (status)
            {
            case DropdownMenuAction.Status.None:
                ve.AddToClassList(hiddenItemClassname);
                ve.RemoveFromClassList(checkedItemClassname);
                ve.RemoveFromClassList(disabledItemClassname);
                break;

            case DropdownMenuAction.Status.Normal:
                ve.RemoveFromClassList(hiddenItemClassname);
                ve.RemoveFromClassList(checkedItemClassname);
                ve.RemoveFromClassList(disabledItemClassname);
                break;

            case DropdownMenuAction.Status.Disabled:
                ve.RemoveFromClassList(hiddenItemClassname);
                ve.AddToClassList(disabledItemClassname);
                break;

            case DropdownMenuAction.Status.Checked:
                ve.RemoveFromClassList(hiddenItemClassname);
                ve.AddToClassList(checkedItemClassname);
                break;

            case DropdownMenuAction.Status.Hidden:
                ve.AddToClassList(hiddenItemClassname);
                break;

            default:
                break;
            }
        }
        private void InitializeViewSubMenu(ContextualMenuPopulateEvent evt)
        {
            // Default the menu buttons to disabled
            DropdownMenuAction.Status expandPreviewAction   = DropdownMenuAction.Status.Disabled;
            DropdownMenuAction.Status collapsePreviewAction = DropdownMenuAction.Status.Disabled;
            DropdownMenuAction.Status minimizeAction        = DropdownMenuAction.Status.Disabled;
            DropdownMenuAction.Status maximizeAction        = DropdownMenuAction.Status.Disabled;

            // Initialize strings
            string expandPreviewText   = "View/Expand Previews";
            string collapsePreviewText = "View/Collapse Previews";
            string expandPortText      = "View/Expand Ports";
            string collapsePortText    = "View/Collapse Ports";

            if (selection.Count == 1)
            {
                collapsePreviewText = "View/Collapse Preview";
                expandPreviewText   = "View/Expand Preview";
            }

            // Check if we can expand or collapse the ports/previews
            foreach (MaterialNodeView selectedNode in selection.Where(x => x is MaterialNodeView).Select(x => x as MaterialNodeView))
            {
                if (selectedNode.node.hasPreview)
                {
                    if (selectedNode.node.previewExpanded)
                    {
                        collapsePreviewAction = DropdownMenuAction.Status.Normal;
                    }
                    else
                    {
                        expandPreviewAction = DropdownMenuAction.Status.Normal;
                    }
                }

                if (selectedNode.CanToggleExpanded())
                {
                    if (selectedNode.expanded)
                    {
                        minimizeAction = DropdownMenuAction.Status.Normal;
                    }
                    else
                    {
                        maximizeAction = DropdownMenuAction.Status.Normal;
                    }
                }
            }

            // Create the menu options
            evt.menu.AppendAction(collapsePortText, _ => SetNodeExpandedOnSelection(false), (a) => minimizeAction);
            evt.menu.AppendAction(expandPortText, _ => SetNodeExpandedOnSelection(true), (a) => maximizeAction);

            evt.menu.AppendSeparator("View/");

            evt.menu.AppendAction(expandPreviewText, _ => SetPreviewExpandedOnSelection(true), (a) => expandPreviewAction);
            evt.menu.AppendAction(collapsePreviewText, _ => SetPreviewExpandedOnSelection(false), (a) => collapsePreviewAction);

            evt.menu.AppendSeparator();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Add an item that will execute an action in the drop-down menu. The item is added at the end of the specified index in the list.
 /// </summary>
 /// <param name="atIndex">Index where the item should be inserted.</param>
 /// <param name="actionName">Name of the item. This name will be displayed in the drop-down menu.</param>
 /// <param name="action">Callback to execute when the user selects this item in the menu.</param>
 /// <param name="status">The status of the item.</param>
 public void InsertAction(int atIndex, string actionName, Action <DropdownMenuAction> action, DropdownMenuAction.Status status = DropdownMenuAction.Status.Normal)
 {
     if (status == DropdownMenuAction.Status.Normal)
     {
         InsertAction(atIndex, actionName, action, DropdownMenuAction.AlwaysEnabled);
     }
     else if (status == DropdownMenuAction.Status.Disabled)
     {
         InsertAction(atIndex, actionName, action, DropdownMenuAction.AlwaysDisabled);
     }
     else
     {
         InsertAction(atIndex, actionName, action, e => status);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Add an item that will execute an action in the drop-down menu. The item is added at the end of the current item list.
 /// </summary>
 /// <param name="actionName">Name of the item. This name will be displayed in the drop-down menu.</param>
 /// <param name="action">Callback to execute when the user selects this item in the menu.</param>
 /// <param name="status">The status of the item.</param>
 public void AppendAction(string actionName, Action <DropdownMenuAction> action, DropdownMenuAction.Status status = DropdownMenuAction.Status.Normal)
 {
     if (status == DropdownMenuAction.Status.Normal)
     {
         AppendAction(actionName, action, DropdownMenuAction.AlwaysEnabled);
     }
     else if (status == DropdownMenuAction.Status.Disabled)
     {
         AppendAction(actionName, action, DropdownMenuAction.AlwaysDisabled);
     }
     else
     {
         AppendAction(actionName, action, e => status);
     }
 }
 public static void AppendAction(this DropdownMenu contextualMenu, string actionName, Action action, DropdownMenuAction.Status statusFlags)
 {
     Debug.Assert(action != null);
     contextualMenu.AppendAction(actionName, e => action(), e => statusFlags);
 }
        static void AddMarkerMenu(ContextualMenuPopulateEvent evt, Action <DropdownMenuAction> action, DropdownMenuAction.Status menuStatus)
        {
            const string prefix = "Add Marker /";

            foreach (var markerType in MarkerAttribute.GetMarkerTypes())
            {
                evt.menu.AppendAction($"{prefix}{MarkerAttribute.GetDescription(markerType)}", action, a => menuStatus, markerType);
            }
        }
        static void AddTagMenu(ContextualMenuPopulateEvent evt, Action <DropdownMenuAction> action, DropdownMenuAction.Status menuStatus)
        {
            const string prefix = "Add Tag/";

            foreach (var tagType in TagAttribute.GetVisibleTypesInInspector())
            {
                evt.menu.AppendAction($"{prefix}{TagAttribute.GetDescription(tagType)}", action, a => menuStatus, tagType);
            }
        }
Exemplo n.º 9
0
        public void InsertAction(int atIndex, string actionName, Action <DropdownMenuAction> action, DropdownMenuAction.Status status = DropdownMenuAction.Status.Normal)
        {
            bool flag = status == DropdownMenuAction.Status.Normal;

            if (flag)
            {
                this.InsertAction(atIndex, actionName, action, new Func <DropdownMenuAction, DropdownMenuAction.Status>(DropdownMenuAction.AlwaysEnabled), null);
            }
            else
            {
                bool flag2 = status == DropdownMenuAction.Status.Disabled;
                if (flag2)
                {
                    this.InsertAction(atIndex, actionName, action, new Func <DropdownMenuAction, DropdownMenuAction.Status>(DropdownMenuAction.AlwaysDisabled), null);
                }
                else
                {
                    this.InsertAction(atIndex, actionName, action, (DropdownMenuAction e) => status, null);
                }
            }
        }