void RibbonSubGroupAddItemsRecursive(EditorRibbonDefaultConfiguration.Group subGroup, KryptonContextMenuCollection contextMenuItems)
        {
            var items = new List <KryptonContextMenuItemBase>();

            foreach (var child in subGroup.Children)
            {
                //!!!!impl
                ////sub group
                //var subGroup = child as EditorRibbonDefaultConfiguration.Group;
                //if( subGroup != null )
                //{
                //	var tripple = new KryptonRibbonGroupTriple();
                //	ribbonGroup.Items.Add( tripple );

                //	var button = new KryptonRibbonGroupButton();
                //	//button.Tag = action;
                //	button.TextLine1 = subGroup.DropDownGroupText.Item1;
                //	button.TextLine2 = subGroup.DropDownGroupText.Item2;
                //	//button.ImageSmall = action.imageSmall;
                //	button.ImageLarge = subGroup.DropDownGroupImage;
                //	button.ToolTipBody = subGroup.Name;
                //	button.ButtonType = GroupButtonType.DropDown;

                //	button.KryptonContextMenu = new KryptonContextMenu();
                //	RibbonSubGroupAddItemsRecursive( subGroup, button.KryptonContextMenu.Items );

                //	tripple.Items.Add( button );
                //}

                //action
                var action = child as EditorAction;
                if (action == null)
                {
                    var actionName = child as string;
                    if (actionName != null)
                    {
                        action = EditorActions.GetByName(actionName);
                    }
                }
                if (action != null)
                {
                    if (!action.CompletelyDisabled)
                    {
                        EventHandler clickHandler = delegate(object s, EventArgs e2)
                        {
                            var item2 = (KryptonContextMenuItem)s;

                            var action2 = item2.Tag as EditorAction;
                            if (action2 != null)
                            {
                                EditorAPI.EditorActionClick(EditorAction.HolderEnum.RibbonQAT, action2.Name);
                            }
                        };

                        var item = new KryptonContextMenuItem(action.GetContextMenuText(), null, clickHandler);
                        //var item = new KryptonContextMenuItem( action.GetContextMenuText(), action.imageSmall, clickHandler );
                        item.Tag = action;
                        items.Add(item);
                    }
                }
                //separator
                else if (child == null)
                {
                    items.Add(new KryptonContextMenuSeparator());
                }
            }

            if (items.Count != 0)
            {
                contextMenuItems.Add(new KryptonContextMenuItems(items.ToArray()));
            }
        }
 /// <summary>
 /// Should the sub menu be shown at fixed screen location for this menu item.
 /// </summary>
 /// <param name="menuItem">Menu item that needs to show sub menu.</param>
 /// <returns>True if the sub menu should be a fixed size.</returns>
 public bool ProviderShowSubMenuFixed(KryptonContextMenuItem menuItem)
 {
     return((FixedViewBase != null) && _menuCollection.Contains(menuItem));
 }
示例#3
0
        void ShowContextMenu()
        {
            var items = new List <KryptonContextMenuItemBase>();

            Component oneSelectedComponent = ObjectOfWindow as Component;

            //Editor
            {
                var item = new KryptonContextMenuItem(TranslateContextMenu("Editor"), EditorResourcesCache.Edit, delegate(object s, EventArgs e2)
                {
                    EditorAPI.OpenDocumentWindowForObject(Document, oneSelectedComponent);
                });
                item.Enabled = oneSelectedComponent != null && EditorAPI.IsDocumentObjectSupport(oneSelectedComponent);
                items.Add(item);
            }

            //Settings
            {
                var item = new KryptonContextMenuItem(TranslateContextMenu("Settings"), EditorResourcesCache.Settings, delegate(object s, EventArgs e2)
                {
                    EditorAPI.SelectDockWindow(EditorAPI.FindWindow <SettingsWindow>());
                });
                items.Add(item);
            }

            //Separate Settings
            if (EditorUtility.AllowSeparateSettings)
            {
                var item = new KryptonContextMenuItem(TranslateContextMenu("Separate Settings"), EditorResourcesCache.Settings, delegate(object s, EventArgs e2)
                {
                    var obj = oneSelectedComponent ?? ObjectOfWindow;
                    bool canUseAlreadyOpened = !ModifierKeys.HasFlag(Keys.Shift);
                    EditorAPI.ShowObjectSettingsWindow(Document, obj, canUseAlreadyOpened);
                });
                item.Enabled = oneSelectedComponent != null || SelectedObjects.Length == 0;
                items.Add(item);
            }

            items.Add(new KryptonContextMenuSeparator());

            //New object
            {
                EditorContextMenuWinForms.AddNewObjectItem(items, CanNewObject(out _), delegate(Metadata.TypeInfo type)
                {
                    TryNewObject(type);
                });
            }

            //separator
            items.Add(new KryptonContextMenuSeparator());

            //Cut
            {
                var item = new KryptonContextMenuItem(TranslateContextMenu("Cut"), EditorResourcesCache.Cut,
                                                      delegate(object s, EventArgs e2)
                {
                    //Cut();
                });
                item.ShortcutKeyDisplayString = EditorActions.GetFirstShortcutKeyString("Cut");
                item.Enabled = false;                // CanCut();
                items.Add(item);
            }

            //Copy
            {
                var item = new KryptonContextMenuItem(TranslateContextMenu("Copy"), EditorResourcesCache.Copy,
                                                      delegate(object s, EventArgs e2)
                {
                    Copy();
                });
                item.ShortcutKeyDisplayString = EditorActions.GetFirstShortcutKeyString("Copy");
                item.Enabled = CanCopy();
                items.Add(item);
            }

            //Paste
            {
                var item = new KryptonContextMenuItem(TranslateContextMenu("Paste"), EditorResourcesCache.Paste,
                                                      delegate(object s, EventArgs e2)
                {
                    Paste();
                });
                item.ShortcutKeyDisplayString = EditorActions.GetFirstShortcutKeyString("Paste");
                item.Enabled = CanPaste(out _);
                items.Add(item);
            }

            //Clone
            {
                var item = new KryptonContextMenuItem(TranslateContextMenu("Duplicate"), EditorResourcesCache.Clone,
                                                      delegate(object s, EventArgs e2)
                {
                    //TryCloneObjects();
                });
                item.ShortcutKeyDisplayString = EditorActions.GetFirstShortcutKeyString("Duplicate");
                item.Enabled = false;                // CanCloneObjects( out List<Component> dummy );
                items.Add(item);
            }

            //separator
            items.Add(new KryptonContextMenuSeparator());

            //Delete
            {
                var item = new KryptonContextMenuItem(TranslateContextMenu("Delete"), EditorResourcesCache.Delete,
                                                      delegate(object s, EventArgs e2)
                {
                    //TryDeleteObjects();
                });
                item.Enabled = false;                // CanDeleteObjects( out List<Component> dummy );
                items.Add(item);
            }

            //Rename
            {
                var item = new KryptonContextMenuItem(TranslateContextMenu("Rename"), null, delegate(object s, EventArgs e2)
                {
                    EditorUtility.ShowRenameComponentDialog(oneSelectedComponent);
                });
                item.ShortcutKeyDisplayString = EditorActions.GetFirstShortcutKeyString("Rename");
                //!!!!!
                item.Enabled = oneSelectedComponent != null;
                items.Add(item);
            }

            EditorContextMenuWinForms.AddActionsToMenu(EditorContextMenuWinForms.MenuTypeEnum.Document, items);              //, this );

            EditorContextMenuWinForms.Show(items, this);
        }
示例#4
0
        /// <summary>
        /// Show the context menu for column box
        /// </summary>
        private void ShowColumnBoxContextMenu()
        {
            if (_menuItems == null)
            {
                // Create individual items
                _menuSortAscending              = new KryptonContextMenuItem(LanguageManager.Instance.GetStringGB("SORTASCENDING"), Properties.Resources.sort_az_ascending2, new EventHandler(OnSortAscending));
                _menuSortDescending             = new KryptonContextMenuItem(LanguageManager.Instance.GetStringGB("SORTDESCENDING"), Properties.Resources.sort_az_descending2, new EventHandler(OnSortDescending));
                _menuSeparator1                 = new KryptonContextMenuSeparator();
                _menuExpand                     = new KryptonContextMenuItem(LanguageManager.Instance.GetStringGB("EXPAND"), Properties.Resources.element_plus_16, new EventHandler(OnGroupExpand));
                _menuCollapse                   = new KryptonContextMenuItem(LanguageManager.Instance.GetStringGB("COLLAPSE"), Properties.Resources.element_minus_16, new EventHandler(OnGroupCollapse));
                _menuUnGroup                    = new KryptonContextMenuItem(LanguageManager.Instance.GetStringGB("UNGROUP"), Properties.Resources.element_delete, new EventHandler(OnUngroup));
                _menuSeparator2                 = new KryptonContextMenuSeparator();
                _menuFullExpand                 = new KryptonContextMenuItem(LanguageManager.Instance.GetStringGB("FULLEXPAND"), Properties.Resources.elements_plus_16, new EventHandler(OnFullExpand));
                _menuFullCollapse               = new KryptonContextMenuItem(LanguageManager.Instance.GetStringGB("FULLCOLLAPSE"), Properties.Resources.elements_minus_16, new EventHandler(OnFullCollapse));
                _menuSeparator3                 = new KryptonContextMenuSeparator();
                _menuClearGrouping              = new KryptonContextMenuItem(LanguageManager.Instance.GetStringGB("CLEARGROUPING"), Properties.Resources.element_selection_delete, new EventHandler(OnClearGrouping));
                _menuHideGroupBox               = new KryptonContextMenuItem(LanguageManager.Instance.GetStringGB("HIDEGROUPBOX"), null, new EventHandler(OnHideGroupBox));
                _menuGroupInterval              = new KryptonContextMenuItem(LanguageManager.Instance.GetStringGB("GROUPINTERVAL"));
                _menuSortBySummary              = new KryptonContextMenuItem(LanguageManager.Instance.GetStringGB("SORTBYSUMMARYCOUNT"), null, new EventHandler(OnSortBySummaryCount));
                _menuSortBySummary.CheckOnClick = true;

                //Group Interval
                KryptonContextMenuItems _GroupIntervalItems;
                KryptonContextMenuItem  it = null;
                string[] names             = Enum.GetNames(typeof(OutlookGridDateTimeGroup.DateInterval));
                KryptonContextMenuItemBase[] arrayOptions = new KryptonContextMenuItemBase[names.Length];
                for (int i = 0; i < names.Length; i++)
                {
                    it              = new KryptonContextMenuItem(LanguageManager.Instance.GetStringGB(names[i]));
                    it.Tag          = names[i];
                    it.Click       += OnGroupIntervalClick;
                    arrayOptions[i] = it;
                }
                _GroupIntervalItems = new KryptonContextMenuItems(arrayOptions);
                _menuGroupInterval.Items.Add(_GroupIntervalItems);

                // Add items inside an items collection (apart from separator1 which is only added if required)
                _menuItems = new KryptonContextMenuItems(new KryptonContextMenuItemBase[] { _menuSortAscending,
                                                                                            _menuSortDescending,
                                                                                            _menuSortBySummary,
                                                                                            _menuSeparator1,
                                                                                            _menuGroupInterval,
                                                                                            _menuExpand,
                                                                                            _menuCollapse,
                                                                                            _menuUnGroup,
                                                                                            _menuSeparator2,
                                                                                            _menuFullExpand,
                                                                                            _menuFullCollapse,
                                                                                            _menuSeparator3,
                                                                                            _menuClearGrouping,
                                                                                            _menuHideGroupBox });
            }

            // Ensure we have a krypton context menu if not already present
            if (this.KCtxMenu == null)
            {
                KCtxMenu = new KryptonContextMenu();
            }


            // Update the individual menu options
            OutlookGridGroupBoxColumn col = null;

            if (indexselected > -1)
            {
                col = columnsList[indexselected];
            }

            _menuSortAscending.Visible  = col != null;
            _menuSortDescending.Visible = col != null;
            _menuSortAscending.Checked  = col != null && col.SortDirection == SortOrder.Ascending;
            _menuSortDescending.Checked = col != null && col.SortDirection == SortOrder.Descending;
            _menuSortBySummary.Visible  = col != null;
            _menuSortBySummary.Checked  = col != null && col.SortBySummaryCount;
            _menuExpand.Visible         = col != null;
            _menuCollapse.Visible       = col != null;
            _menuGroupInterval.Visible  = col != null && col.GroupingType == typeof(OutlookGridDateTimeGroup).Name;
            if (_menuGroupInterval.Visible)
            {
                foreach (KryptonContextMenuItem item in ((KryptonContextMenuItems)_menuGroupInterval.Items[0]).Items)
                {
                    item.Checked = item.Tag.ToString() == col.GroupInterval;
                }
            }
            _menuUnGroup.Visible       = col != null;
            _menuFullExpand.Enabled    = columnsList.Count > 0;
            _menuFullCollapse.Enabled  = columnsList.Count > 0;
            _menuClearGrouping.Enabled = columnsList.Count > 0;

            _menuSeparator1.Visible = (_menuSortAscending.Visible || _menuSortDescending.Visible);
            _menuSeparator2.Visible = (_menuExpand.Visible || _menuCollapse.Visible || _menuUnGroup.Visible);
            _menuSeparator3.Visible = (_menuFullExpand.Visible || _menuFullCollapse.Visible);

            if (!KCtxMenu.Items.Contains(_menuItems))
            {
                KCtxMenu.Items.Add(_menuItems);
            }

            // Show the menu!
            KCtxMenu.Show(this);
        }
 /// <summary>
 /// Should the sub menu be shown at fixed screen location for this menu item.
 /// </summary>
 /// <param name="menuItem">Menu item that needs to show sub menu.</param>
 /// <returns>Screen rectangle to use as display rectangle.</returns>
 public Rectangle ProviderShowSubMenuFixedRect(KryptonContextMenuItem menuItem) =>
 HasParentProvider?_parent.ProviderShowSubMenuFixedRect(menuItem) : Rectangle.Empty;
示例#6
0
        public override void Register()
        {
            //Add Collision
            {
                const string bodyName = "Collision Body";

                var a = new EditorAction();
                a.Name        = "Add Collision";
                a.Description = "Adds a collision body to selected objects.";
                a.ImageSmall  = Properties.Resources.Add_16;
                a.ImageBig    = Properties.Resources.MeshCollision_32;
                a.ActionType  = EditorAction.ActionTypeEnum.DropDown;
                a.QatSupport  = true;
                //a.qatAddByDefault = true;
                a.ContextMenuSupport = EditorContextMenu.MenuTypeEnum.Document;

                a.GetState += delegate(EditorAction.GetStateContext context)
                {
                    if (context.ObjectsInFocus.DocumentWindow != null)
                    {
                        object[] selectedObjects = context.ObjectsInFocus.Objects;
                        if (selectedObjects.Length != 0 && Array.TrueForAll(selectedObjects, obj => obj is Component_MeshInSpace))
                        {
                            context.Enabled = Array.Exists(selectedObjects, delegate(object obj)
                            {
                                var c = ((Component)obj).GetComponent(bodyName);
                                if (c != null)
                                {
                                    if (c is Component_RigidBody)
                                    {
                                        return(false);
                                    }
                                    if (c is Component_RigidBody2D)
                                    {
                                        return(false);
                                    }
                                }
                                return(true);
                            });
                        }

                        a.DropDownContextMenu.Tag = (context.ObjectsInFocus.DocumentWindow.Document, selectedObjects);
                    }
                };

                //context menu
                {
                    a.DropDownContextMenu = new KryptonContextMenu();

                    a.DropDownContextMenu.Opening += delegate(object sender, CancelEventArgs e)
                    {
                        var menu  = (KryptonContextMenu)sender;
                        var tuple = ((DocumentInstance, object[]))menu.Tag;

                        //"Collision Body of the Mesh"
                        {
                            var items2 = (KryptonContextMenuItems)menu.Items[0];
                            var item2  = (KryptonContextMenuItem)items2.Items[0];

                            bool enabled = false;

                            foreach (var obj in tuple.Item2)
                            {
                                var meshInSpace = obj as Component_MeshInSpace;
                                if (meshInSpace != null)
                                {
                                    Component_RigidBody collisionDefinition = null;
                                    {
                                        var mesh = meshInSpace.Mesh.Value;
                                        if (mesh != null)
                                        {
                                            collisionDefinition = mesh.GetComponent("Collision Definition") as Component_RigidBody;
                                        }
                                    }

                                    if (collisionDefinition != null)
                                    {
                                        enabled = true;
                                    }
                                }
                            }

                            item2.Enabled = enabled;
                        }
                    };

                    EventHandler clickHandler = delegate(object s, EventArgs e2)
                    {
                        var item          = (KryptonContextMenuItem)s;
                        var itemTag       = ((KryptonContextMenu, string))item.Tag;
                        var menu          = itemTag.Item1;
                        var collisionName = itemTag.Item2;

                        var menuTag         = ((DocumentInstance, object[]))menu.Tag;
                        var document        = menuTag.Item1;
                        var selectedObjects = menuTag.Item2;

                        List <UndoSystem.Action> undoActions = new List <UndoSystem.Action>();

                        foreach (var obj in selectedObjects)
                        {
                            if (obj is Component_MeshInSpace meshInSpace && meshInSpace.GetComponent(bodyName) as Component_RigidBody == null && meshInSpace.GetComponent(bodyName) as Component_RigidBody2D == null)
                            {
                                var mesh = meshInSpace.MeshOutput;
                                if (mesh == null)
                                {
                                    continue;
                                }

                                Component body = null;
                                bool      skip = false;

                                if (collisionName == "Use Collision of the Mesh")
                                {
                                    var collisionDefinition = mesh.GetComponent("Collision Definition") as Component_RigidBody;
                                    if (collisionDefinition != null)
                                    {
                                        var body2 = (Component_RigidBody)collisionDefinition.Clone();
                                        body             = body2;
                                        body2.Enabled    = false;
                                        body2.Name       = bodyName;
                                        body2.MotionType = Component_RigidBody.MotionTypeEnum.Static;
                                        body2.Transform  = meshInSpace.Transform;

                                        meshInSpace.AddComponent(body2);
                                    }
                                    else
                                    {
                                        skip = true;
                                    }
                                }
                                else
                                {
                                    Component_RigidBody CreateRigidBody()
                                    {
                                        var body2 = meshInSpace.CreateComponent <Component_RigidBody>(enabled: false);

                                        body2.Name      = bodyName;
                                        body2.Transform = meshInSpace.Transform;
                                        return(body2);
                                    }

                                    Component_RigidBody2D CreateRigidBody2D()
                                    {
                                        var body2 = meshInSpace.CreateComponent <Component_RigidBody2D>(enabled: false);

                                        body2.Name      = bodyName;
                                        body2.Transform = meshInSpace.Transform;
                                        return(body2);
                                    }

                                    switch (collisionName)
                                    {
                                    case "Box":
                                    {
                                        body = CreateRigidBody();
                                        var shape  = body.CreateComponent <Component_CollisionShape_Box>();
                                        var bounds = mesh.Result.SpaceBounds.CalculatedBoundingBox;
                                        shape.TransformRelativeToParent = new Transform(bounds.GetCenter(), Quaternion.Identity);
                                        shape.Dimensions = bounds.GetSize();
                                    }
                                    break;

                                    case "Sphere":
                                    {
                                        body = CreateRigidBody();
                                        var shape  = body.CreateComponent <Component_CollisionShape_Sphere>();
                                        var sphere = mesh.Result.SpaceBounds.CalculatedBoundingSphere;
                                        shape.TransformRelativeToParent = new Transform(sphere.Origin, Quaternion.Identity);
                                        shape.Radius = sphere.Radius;
                                    }
                                    break;

                                    case "Capsule":
                                    {
                                        body = CreateRigidBody();
                                        var shape  = body.CreateComponent <Component_CollisionShape_Capsule>();
                                        var bounds = mesh.Result.SpaceBounds.CalculatedBoundingBox;
                                        shape.TransformRelativeToParent = new Transform(bounds.GetCenter(), Quaternion.Identity);
                                        shape.Radius = Math.Max(bounds.GetSize().X, bounds.GetSize().Y) / 2;
                                        shape.Height = Math.Max(bounds.GetSize().Z - shape.Radius * 2, 0);
                                    }
                                    break;

                                    case "Cylinder":
                                    {
                                        body = CreateRigidBody();
                                        var shape  = body.CreateComponent <Component_CollisionShape_Cylinder>();
                                        var bounds = mesh.Result.SpaceBounds.CalculatedBoundingBox;
                                        shape.TransformRelativeToParent = new Transform(bounds.GetCenter(), Quaternion.Identity);
                                        shape.Radius = Math.Max(bounds.GetSize().X, bounds.GetSize().Y) / 2;
                                        shape.Height = bounds.GetSize().Z;
                                    }
                                    break;

                                    case "Convex":
                                    {
                                        body = CreateRigidBody();
                                        var shape = body.CreateComponent <Component_CollisionShape_Mesh>();
                                        shape.ShapeType = Component_CollisionShape_Mesh.ShapeTypeEnum.Convex;
                                        shape.Mesh      = ReferenceUtility.MakeThisReference(shape, meshInSpace, "Mesh");
                                    }
                                    break;

                                    case "Convex Decomposition":
                                    {
                                        body = CreateRigidBody();

                                        var settings = new ConvexDecomposition.Settings();

                                        var form = new SpecifyParametersForm("Convex Decomposition", settings);
                                        form.CheckHandler = delegate(ref string error2)
                                        {
                                            return(true);
                                        };
                                        if (form.ShowDialog() != DialogResult.OK)
                                        {
                                            skip = true;
                                        }
                                        else
                                        {
                                            var clusters = ConvexDecomposition.Decompose(mesh.Result.ExtractedVerticesPositions, mesh.Result.ExtractedIndices, settings);

                                            if (clusters == null)
                                            {
                                                Log.Warning("Unable to decompose.");
                                                skip = true;
                                            }
                                            else
                                            {
                                                foreach (var cluster in clusters)
                                                {
                                                    var shape = body.CreateComponent <Component_CollisionShape_Mesh>();
                                                    shape.Vertices  = cluster.Vertices;
                                                    shape.Indices   = cluster.Indices;
                                                    shape.ShapeType = Component_CollisionShape_Mesh.ShapeTypeEnum.Convex;
                                                }
                                            }
                                        }
                                    }
                                    break;

                                    case "Mesh":
                                    {
                                        body = CreateRigidBody();
                                        var shape = body.CreateComponent <Component_CollisionShape_Mesh>();
                                        shape.Mesh = ReferenceUtility.MakeThisReference(shape, meshInSpace, "Mesh");
                                    }
                                    break;

                                    case "Box 2D":
                                    {
                                        body = CreateRigidBody2D();
                                        var shape  = body.CreateComponent <Component_CollisionShape2D_Box>();
                                        var bounds = mesh.Result.SpaceBounds.CalculatedBoundingBox;
                                        shape.TransformRelativeToParent = new Transform(bounds.GetCenter(), Quaternion.Identity);
                                        shape.Dimensions = bounds.GetSize().ToVector2();
                                    }
                                    break;

                                    case "Circle 2D":
                                    {
                                        body = CreateRigidBody2D();
                                        var shape  = body.CreateComponent <Component_CollisionShape2D_Ellipse>();
                                        var bounds = mesh.Result.SpaceBounds.CalculatedBoundingBox;
                                        shape.TransformRelativeToParent = new Transform(bounds.GetCenter(), Quaternion.Identity);
                                        var size = bounds.GetSize().ToVector2().MaxComponent();
                                        shape.Dimensions = new Vector2(size, size);
                                    }
                                    break;

                                    case "Ellipse 2D":
                                    {
                                        body = CreateRigidBody2D();
                                        var shape  = body.CreateComponent <Component_CollisionShape2D_Ellipse>();
                                        var bounds = mesh.Result.SpaceBounds.CalculatedBoundingBox;
                                        shape.TransformRelativeToParent = new Transform(bounds.GetCenter(), Quaternion.Identity);
                                        shape.Dimensions = bounds.GetSize().ToVector2();
                                    }
                                    break;

                                    case "Capsule 2D":
                                    {
                                        body = CreateRigidBody2D();
                                        var shape  = body.CreateComponent <Component_CollisionShape2D_Capsule>();
                                        var bounds = mesh.Result.SpaceBounds.CalculatedBoundingBox;
                                        shape.TransformRelativeToParent = new Transform(bounds.GetCenter(), Quaternion.Identity);

                                        var size = bounds.GetSize();

                                        if (size.X > size.Y)
                                        {
                                            shape.Axis   = 0;
                                            shape.Radius = size.Y / 2;
                                            shape.Height = Math.Max(size.X - shape.Radius * 2, 0);
                                        }
                                        else
                                        {
                                            shape.Axis   = 0;
                                            shape.Radius = size.X / 2;
                                            shape.Height = Math.Max(size.Y - shape.Radius * 2, 0);
                                        }
                                    }
                                    break;

                                    case "Convex 2D":
                                    {
                                        body = CreateRigidBody2D();

                                        var meshPoints = new Vector2[mesh.Result.ExtractedVerticesPositions.Length];
                                        for (int n = 0; n < meshPoints.Length; n++)
                                        {
                                            meshPoints[n] = mesh.Result.ExtractedVerticesPositions[n].ToVector2();
                                        }
                                        var points = MathAlgorithms.GetConvexByPoints(meshPoints);

                                        var vertices = new Vector3F[points.Count];
                                        var indices  = new int[(points.Count - 2) * 3];
                                        {
                                            for (int n = 0; n < points.Count; n++)
                                            {
                                                vertices[n] = new Vector3F(points[n].ToVector2F(), 0);
                                            }

                                            for (int nTriangle = 0; nTriangle < points.Count - 2; nTriangle++)
                                            {
                                                indices[nTriangle * 3 + 0] = 0;
                                                indices[nTriangle * 3 + 1] = nTriangle + 1;
                                                indices[nTriangle * 3 + 2] = nTriangle + 2;
                                            }
                                        }

                                        var shape = body.CreateComponent <Component_CollisionShape2D_Mesh>();
                                        shape.Vertices  = vertices;
                                        shape.Indices   = indices;
                                        shape.ShapeType = Component_CollisionShape2D_Mesh.ShapeTypeEnum.Convex;

                                        //var polygons = new List<List<Vector2>>();
                                        //{
                                        //	var currentList = new List<Vector2>();

                                        //	for( int vertex = 0; vertex < points.Count; vertex++ )
                                        //	{
                                        //		currentList.Add( points[ vertex ] );

                                        //		if( currentList.Count == Settings.MaxPolygonVertices )
                                        //		{
                                        //			polygons.Add( currentList );

                                        //			currentList = new List<Vector2>();
                                        //			currentList.Add( points[ 0 ] );
                                        //			currentList.Add( points[ vertex ] );
                                        //		}
                                        //	}

                                        //	if( currentList.Count >= 3 )
                                        //		polygons.Add( currentList );
                                        //}

                                        //foreach( var points2 in polygons )
                                        //{
                                        //	var vertices = new Vector3F[ points2.Count ];
                                        //	var indices = new int[ ( points2.Count - 2 ) * 3 ];
                                        //	{
                                        //		for( int n = 0; n < points2.Count; n++ )
                                        //			vertices[ n ] = new Vector3F( points2[ n ].ToVector2F(), 0 );

                                        //		for( int nTriangle = 0; nTriangle < points2.Count - 2; nTriangle++ )
                                        //		{
                                        //			indices[ nTriangle * 3 + 0 ] = 0;
                                        //			indices[ nTriangle * 3 + 1 ] = nTriangle + 1;
                                        //			indices[ nTriangle * 3 + 2 ] = nTriangle + 2;
                                        //		}
                                        //	}

                                        //	var shape = body.CreateComponent<Component_CollisionShape2D_Mesh>();
                                        //	shape.Vertices = vertices;
                                        //	shape.Indices = indices;
                                        //	shape.ShapeType = Component_CollisionShape2D_Mesh.ShapeTypeEnum.Convex;
                                        //}
                                    }
                                    break;

                                    //case "Convex Decomposition 2D":
                                    //	{
                                    //		body = CreateRigidBody2D();

                                    //		var settings = new ConvexDecomposition.Settings();

                                    //		var form = new SpecifyParametersForm( "Convex Decomposition 2D", settings );
                                    //		form.CheckHandler = delegate ( ref string error2 )
                                    //		{
                                    //			return true;
                                    //		};
                                    //		if( form.ShowDialog() != DialogResult.OK )
                                    //			skip = true;
                                    //		else
                                    //		{
                                    //			//var sourceVertices = (Vector3F[])mesh.Result.ExtractedVerticesPositions.Clone();
                                    //			////reset Z
                                    //			//for( int n = 0; n < sourceVertices.Length; n++ )
                                    //			//	sourceVertices[ n ] = new Vector3F( sourceVertices[ n ].ToVector2(), 0 );

                                    //			//var sourceIndices = mesh.Result.ExtractedIndices;

                                    //			//var epsilon = 0.0001f;
                                    //			//MathAlgorithms.MergeEqualVerticesRemoveInvalidTriangles( sourceVertices, sourceIndices, epsilon, out var processedVertices, out var processedIndices, out var processedTrianglesToSourceIndex );

                                    //			//var vertices = new Vector3F[ mesh.Result.ExtractedVerticesPositions.Length ];
                                    //			////reset Z
                                    //			//for( int n = 0; n < vertices.Length; n++ )
                                    //			//	vertices[ n ] = new Vector3F( mesh.Result.ExtractedVerticesPositions[ n ].ToVector2(), 0 );

                                    //			//var clusters = ConvexDecomposition.Decompose( processedVertices, processedIndices, settings );


                                    //			var vertices = new Vector3F[ mesh.Result.ExtractedVerticesPositions.Length ];
                                    //			//reset Z
                                    //			for( int n = 0; n < vertices.Length; n++ )
                                    //				vertices[ n ] = new Vector3F( mesh.Result.ExtractedVerticesPositions[ n ].ToVector2(), 0 );

                                    //			var clusters = ConvexDecomposition.Decompose( vertices, mesh.Result.ExtractedIndices, settings );

                                    //			if( clusters == null )
                                    //			{
                                    //				Log.Warning( "Unable to decompose." );
                                    //				skip = true;
                                    //			}
                                    //			else
                                    //			{
                                    //				foreach( var cluster in clusters )
                                    //				{
                                    //					var shape = body.CreateComponent<Component_CollisionShape2D_Mesh>();
                                    //					shape.Vertices = cluster.Vertices;
                                    //					shape.Indices = cluster.Indices;
                                    //					shape.ShapeType = Component_CollisionShape2D_Mesh.ShapeTypeEnum.Convex;
                                    //				}
                                    //			}
                                    //		}



                                    //		//var sourceVertices = new Vertices();
                                    //		//foreach( var p in mesh.Result.ExtractedVerticesPositions )
                                    //		//	sourceVertices.Add( Physics2DUtility.Convert( p.ToVector2() ) );

                                    //		//var list = Triangulate.ConvexPartition( sourceVertices, TriangulationAlgorithm.Seidel, tolerance: 0.001f );

                                    //		//body = CreateRigidBody2D();

                                    //		//foreach( var convexVertices in list )
                                    //		//{
                                    //		//	var shape = body.CreateComponent<Component_CollisionShape2D_Mesh>();

                                    //		//	var points = new List<Vector2>();
                                    //		//	foreach( var p in convexVertices )
                                    //		//		points.Add( Physics2DUtility.Convert( p ) );

                                    //		//	//var meshPoints = new Vector2[ mesh.Result.ExtractedVerticesPositions.Length ];
                                    //		//	//for( int n = 0; n < meshPoints.Length; n++ )
                                    //		//	//	meshPoints[ n ] = mesh.Result.ExtractedVerticesPositions[ n ].ToVector2();
                                    //		//	//var points = MathAlgorithms.GetConvexByPoints( meshPoints );

                                    //		//	var vertices = new Vector3F[ points.Count + 1 ];
                                    //		//	var indices = new int[ points.Count * 3 ];
                                    //		//	{
                                    //		//		var center = Vector2.Zero;
                                    //		//		foreach( var p in points )
                                    //		//			center += p;
                                    //		//		center /= points.Count;
                                    //		//		vertices[ 0 ] = new Vector3F( center.ToVector2F(), 0 );

                                    //		//		for( int n = 0; n < points.Count; n++ )
                                    //		//		{
                                    //		//			vertices[ 1 + n ] = new Vector3F( points[ n ].ToVector2F(), 0 );

                                    //		//			indices[ n * 3 + 0 ] = 0;
                                    //		//			indices[ n * 3 + 1 ] = 1 + n;
                                    //		//			indices[ n * 3 + 2 ] = 1 + ( ( n + 1 ) % points.Count );
                                    //		//		}
                                    //		//	}

                                    //		//	shape.Vertices = vertices;
                                    //		//	shape.Indices = indices;
                                    //		//	shape.ShapeType = Component_CollisionShape2D_Mesh.ShapeTypeEnum.Convex;
                                    //		//}



                                    //		//body = CreateRigidBody2D();
                                    //		//var shape = body.CreateComponent<Component_CollisionShape2D_Mesh>();

                                    //		//var meshPoints = new Vector2[ mesh.Result.ExtractedVerticesPositions.Length ];
                                    //		//for( int n = 0; n < meshPoints.Length; n++ )
                                    //		//	meshPoints[ n ] = mesh.Result.ExtractedVerticesPositions[ n ].ToVector2();
                                    //		//var points = MathAlgorithms.GetConvexByPoints( meshPoints );

                                    //		//var vertices = new Vector3F[ points.Count + 1 ];
                                    //		//var indices = new int[ points.Count * 3 ];
                                    //		//{
                                    //		//	var center = Vector2.Zero;
                                    //		//	foreach( var p in points )
                                    //		//		center += p;
                                    //		//	center /= points.Count;
                                    //		//	vertices[ 0 ] = new Vector3F( center.ToVector2F(), 0 );

                                    //		//	for( int n = 0; n < points.Count; n++ )
                                    //		//	{
                                    //		//		vertices[ 1 + n ] = new Vector3F( points[ n ].ToVector2F(), 0 );

                                    //		//		indices[ n * 3 + 0 ] = 0;
                                    //		//		indices[ n * 3 + 1 ] = 1 + n;
                                    //		//		indices[ n * 3 + 2 ] = 1 + ( ( n + 1 ) % points.Count );
                                    //		//	}
                                    //		//}

                                    //		//shape.Vertices = vertices;
                                    //		//shape.Indices = indices;
                                    //		//shape.ShapeType = Component_CollisionShape2D_Mesh.ShapeTypeEnum.Convex;

                                    //		//var bounds = mesh.Result.SpaceBounds.CalculatedBoundingBox;
                                    //		//shape.TransformRelativeToParent = new Transform( bounds.GetCenter(), Quaternion.Identity );

                                    //		//shape.Mesh = ReferenceUtility.MakeThisReference( shape, meshInSpace, "Mesh" );

                                    //		//var shapeVertices = new Vector3F[ points.Count ];
                                    //		//for( int n = 0; n < shapeVertices.Length; n++ )
                                    //		//	shapeVertices[ n ] = new Vector3F( points[ n ].ToVector2F(), 0 );
                                    //		//shape.Vertices = shapeVertices;
                                    //	}
                                    //	break;

                                    case "Mesh 2D":
                                    {
                                        body = CreateRigidBody2D();
                                        var shape = body.CreateComponent <Component_CollisionShape2D_Mesh>();
                                        shape.Mesh      = ReferenceUtility.MakeThisReference(shape, meshInSpace, "Mesh");
                                        shape.ShapeType = Component_CollisionShape2D_Mesh.ShapeTypeEnum.TriangleMesh;

                                        //var bounds = mesh.Result.SpaceBounds.CalculatedBoundingBox;
                                        //shape.TransformRelativeToParent = new Transform( bounds.GetCenter(), Quaternion.Identity );

                                        //var halfSize = bounds.GetSize().ToVector2() * 0.5;

                                        //var meshPoints = new List<Vector2>( mesh.Result.ExtractedVerticesPositions.Length );
                                        //foreach( var p in mesh.Result.ExtractedVerticesPositions )
                                        //	meshPoints.Add( p.ToVector2() );
                                        //var convexPoints = MathAlgorithms.GetConvexByPoints( meshPoints );

                                        //var points = shape.PropertyGet( "Points" );
                                        //foreach( var p in convexPoints )
                                        //	points.MethodInvoke( "Add", p );

                                        //points.MethodInvoke( "Add", new Vector2( -halfSize.X, -halfSize.Y ) );
                                        //points.MethodInvoke( "Add", new Vector2( halfSize.X, -halfSize.Y ) );
                                        //points.MethodInvoke( "Add", new Vector2( halfSize.X, halfSize.Y ) );
                                        //points.MethodInvoke( "Add", new Vector2( -halfSize.X, halfSize.Y ) );
                                    }
                                    break;

                                    //case "Polygon 2D":
                                    //	{
                                    //		body = CreateRigidBody2D();
                                    //		if( body != null )
                                    //		{
                                    //			var shapeType = MetadataManager.GetType( "NeoAxis.Component_CollisionShape2D_Polygon" );
                                    //			if( shapeType != null )
                                    //			{
                                    //				var shape = body.CreateComponent( shapeType );
                                    //				var bounds = mesh.Result.SpaceBounds.CalculatedBoundingBox;
                                    //				shape.PropertySet( "TransformRelativeToParent", new Transform( bounds.GetCenter(), Quaternion.Identity ) );

                                    //				var halfSize = bounds.GetSize().ToVector2() * 0.5;

                                    //				var meshPoints = new List<Vector2>( mesh.Result.ExtractedVerticesPositions.Length );
                                    //				foreach( var p in mesh.Result.ExtractedVerticesPositions )
                                    //					meshPoints.Add( p.ToVector2() );
                                    //				var convexPoints = MathAlgorithms.GetConvexByPoints( meshPoints );

                                    //				var points = shape.PropertyGet( "Points" );
                                    //				foreach( var p in convexPoints )
                                    //					points.MethodInvoke( "Add", p );

                                    //				//points.MethodInvoke( "Add", new Vector2( -halfSize.X, -halfSize.Y ) );
                                    //				//points.MethodInvoke( "Add", new Vector2( halfSize.X, -halfSize.Y ) );
                                    //				//points.MethodInvoke( "Add", new Vector2( halfSize.X, halfSize.Y ) );
                                    //				//points.MethodInvoke( "Add", new Vector2( -halfSize.X, halfSize.Y ) );
                                    //			}
                                    //			else
                                    //				skip = true;
                                    //		}
                                    //	}
                                    //	break;

                                    default:
                                        Log.Warning("No implementation.");
                                        skip = true;
                                        continue;
                                    }
                                }

                                if (skip)
                                {
                                    body?.Dispose();
                                    continue;
                                }

                                if (body != null)
                                {
                                    body.Enabled = true;

                                    undoActions.Add(new UndoActionComponentCreateDelete(document, new Component[] { body }, true));

                                    //change Transform
                                    {
                                        //undo action
                                        var property = (Metadata.Property)meshInSpace.MetadataGetMemberBySignature("property:Transform");
                                        var undoItem = new UndoActionPropertiesChange.Item(meshInSpace, property, meshInSpace.Transform, new object[0]);
                                        undoActions.Add(new UndoActionPropertiesChange(new UndoActionPropertiesChange.Item[] { undoItem }));

                                        //configure reference
                                        meshInSpace.Transform = ReferenceUtility.MakeReference <Transform>(null, ReferenceUtility.CalculateThisReference(meshInSpace, body, "Transform"));
                                    }
                                }
                            }
                        }

                        if (undoActions.Count != 0)
                        {
                            document.UndoSystem.CommitAction(new UndoMultiAction(undoActions));
                            document.Modified = true;
                            ScreenNotifications.Show(Translate("The collision was added successfully."));
                        }
                    };

                    var items = new List <KryptonContextMenuItemBase>();
                    var names = new string[] { "Use Collision of the Mesh", "", "Box", "Sphere", "Capsule", "Cylinder", "Convex", "Convex Decomposition", "Mesh", "", "Box 2D", "Circle 2D", "Ellipse 2D", "Capsule 2D", "Convex 2D", /*"Convex Decomposition 2D", */ "Mesh 2D" };
                    foreach (var name in names)
                    {
                        if (name == "")
                        {
                            items.Add(new KryptonContextMenuSeparator());
                        }
                        else
                        {
                            var item = new KryptonContextMenuItem(name, null, clickHandler);
                            item.Tag = (a.DropDownContextMenu, name);
                            items.Add(item);
                        }
                    }

                    a.DropDownContextMenu.Items.Add(new KryptonContextMenuItems(items.ToArray()));
                }

                EditorActions.Register(a);
            }

            //Delete Collision
            {
                const string bodyName = "Collision Body";

                var a = new EditorAction();
                a.Name        = "Delete Collision";
                a.Description = "Deletes the collision body of selected objects.";
                a.ImageSmall  = Properties.Resources.Delete_16;
                a.ImageBig    = Properties.Resources.Delete_32;
                a.QatSupport  = true;
                //a.qatAddByDefault = true;
                a.ContextMenuSupport = EditorContextMenu.MenuTypeEnum.Document;

                a.GetState += delegate(EditorAction.GetStateContext context)
                {
                    if (context.ObjectsInFocus.DocumentWindow != null)
                    {
                        object[] selectedObjects = context.ObjectsInFocus.Objects;
                        if (selectedObjects.Length != 0 && Array.TrueForAll(selectedObjects, obj => obj is Component_MeshInSpace))
                        {
                            context.Enabled = Array.Exists(selectedObjects, delegate(object obj)
                            {
                                var c = ((Component)obj).GetComponent(bodyName);
                                if (c != null)
                                {
                                    if (c is Component_RigidBody)
                                    {
                                        return(true);
                                    }
                                    if (c is Component_RigidBody2D)
                                    {
                                        return(true);
                                    }
                                }
                                return(false);
                            });
                        }
                    }
                };

                a.Click += delegate(EditorAction.ClickContext context)
                {
                    var text = string.Format(Translate("Delete \'{0}\'?"), bodyName);
                    if (EditorMessageBox.ShowQuestion(text, MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        List <UndoSystem.Action> undoActions = new List <UndoSystem.Action>();

                        foreach (Component_MeshInSpace meshInSpace in context.ObjectsInFocus.Objects)
                        {
                            Component body = null;
                            {
                                var c = meshInSpace.GetComponent(bodyName);
                                if (c != null && (c is Component_RigidBody || c is Component_RigidBody2D))
                                {
                                    body = c;
                                }
                            }

                            if (body != null)
                            {
                                var restoreValue = meshInSpace.Transform;

                                undoActions.Add(new UndoActionComponentCreateDelete(context.ObjectsInFocus.DocumentWindow.Document, new Component[] { body }, false));

                                //change Transform
                                if (meshInSpace.Transform.GetByReference == string.Format("this:${0}\\Transform", bodyName))
                                {
                                    //undo action
                                    var property = (Metadata.Property)meshInSpace.MetadataGetMemberBySignature("property:Transform");
                                    var undoItem = new UndoActionPropertiesChange.Item(meshInSpace, property, restoreValue, new object[0]);
                                    undoActions.Add(new UndoActionPropertiesChange(new UndoActionPropertiesChange.Item[] { undoItem }));

                                    //reset reference
                                    meshInSpace.Transform = restoreValue.Value;
                                }
                            }
                        }

                        if (undoActions.Count != 0)
                        {
                            context.ObjectsInFocus.DocumentWindow.Document.UndoSystem.CommitAction(new UndoMultiAction(undoActions));
                            context.ObjectsInFocus.DocumentWindow.Document.Modified = true;
                            ScreenNotifications.Show(Translate("The collision was deleted."));
                        }
                    }
                };

                EditorActions.Register(a);
            }
        }
示例#7
0
        private void Editor_ContextMenuOpening(object sender, System.Windows.Controls.ContextMenuEventArgs e)
        {
            e.Handled = true;

            var items = new List <KryptonContextMenuItemBase>();

            //Find
            {
                var item = new KryptonContextMenuItem(TranslateContextMenu("Find and Replace"), null,
                                                      delegate(object s, EventArgs e2)
                {
                    SearchReplacePanel?.ShowFindOrReplace(false);
                });
                item.ShortcutKeyDisplayString = EditorActions.ConvertShortcutKeysToString(new Keys[] { Keys.Control | Keys.F });
                //item.ShortcutKeyDisplayString = EditorActions.GetFirstShortcutKeyString( "Find" );
                items.Add(item);
            }

            //separator
            items.Add(new KryptonContextMenuSeparator());

            //Cut
            {
                var item = new KryptonContextMenuItem(TranslateContextMenu("Cut"), EditorResourcesCache.Cut,
                                                      delegate(object s, EventArgs e2)
                {
                    editor.Cut();
                });
                item.ShortcutKeyDisplayString = EditorActions.GetFirstShortcutKeyString("Cut");
                item.Enabled = true;                // editor.CanCut();
                items.Add(item);
            }

            //Copy
            {
                var item = new KryptonContextMenuItem(TranslateContextMenu("Copy"), EditorResourcesCache.Copy,
                                                      delegate(object s, EventArgs e2)
                {
                    editor.Copy();
                });
                item.ShortcutKeyDisplayString = EditorActions.GetFirstShortcutKeyString("Copy");
                item.Enabled = true;                // CanCopy();
                items.Add(item);
            }

            //Paste
            {
                var item = new KryptonContextMenuItem(TranslateContextMenu("Paste"), EditorResourcesCache.Paste,
                                                      delegate(object s, EventArgs e2)
                {
                    editor.Paste();
                });
                item.ShortcutKeyDisplayString = EditorActions.GetFirstShortcutKeyString("Paste");
                item.Enabled = true;                // CanPaste( out _ );
                items.Add(item);
            }

            EditorContextMenu.AddActionsToMenu(EditorContextMenu.MenuTypeEnum.General, items);

            EditorContextMenu.Show(items, this);
        }
 /// <summary>
 /// Should the sub menu be shown at fixed screen location for this menu item.
 /// </summary>
 /// <param name="menuItem">Menu item that needs to show sub menu.</param>
 /// <returns>True if the sub menu should be a fixed size.</returns>
 public bool ProviderShowSubMenuFixed(KryptonContextMenuItem menuItem) => HasParentProvider && _parent.ProviderShowSubMenuFixed(menuItem);
        public static void AddNewResourceItem(IList <KryptonContextMenuItemBase> items, bool enabled, TryNewObjectDelegate select)
        {
            //New Resource
            {
                var newObjectItem = new KryptonContextMenuItem(Translate("New Resource"), EditorResourcesCache.New, null);
                newObjectItem.Enabled = enabled;

                var items2 = new List <KryptonContextMenuItemBase>();

                //Select
                {
                    var item2 = new KryptonContextMenuItem(Translate("Select..."), null,
                                                           delegate(object s, EventArgs e2)
                    {
                        select(null);
                    });
                    items2.Add(item2);
                }

                //separator
                items2.Add(new KryptonContextMenuSeparator());

                //ResourcesWindowItems
                {
                    ResourcesWindowItems.PrepareItems();

                    var menuItems = new Dictionary <string, KryptonContextMenuItem>();

                    KryptonContextMenuItem GetBrowserItemByPath(string path)
                    {
                        menuItems.TryGetValue(path, out var item);
                        return(item);
                    }

                    foreach (var item in ResourcesWindowItems.Items)
                    {
                        //custom filtering
                        if (!EditorUtility.PerformResourcesWindowItemVisibleFilter(item))
                        {
                            continue;
                        }

                        ////skip
                        //if( !typeof( Component ).IsAssignableFrom( item.type ) )
                        //	continue;

                        //remove Base prefix from items
                        var itemPathFixed = item.Path;
                        {
                            var prefix = "Base\\";
                            if (itemPathFixed.Length > prefix.Length && itemPathFixed.Substring(0, prefix.Length) == prefix)
                            {
                                itemPathFixed = itemPathFixed.Substring(prefix.Length);
                            }
                        }

                        var strings = itemPathFixed.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);

                        string path = "";
                        for (int n = 0; n < strings.Length; n++)
                        {
                            path = Path.Combine(path, strings[n]);

                            //get parent item
                            KryptonContextMenuItem parentItem = null;
                            if (n != 0)
                            {
                                parentItem = GetBrowserItemByPath(Path.GetDirectoryName(path));
                            }

                            if (GetBrowserItemByPath(path) == null)
                            {
                                //add item

                                KryptonContextMenuItem menuItem = null;

                                //is folder
                                bool isFolder = n < strings.Length - 1;
                                if (isFolder)
                                {
                                    menuItem = new KryptonContextMenuItem(strings[n], null, null);

                                    //ResourcesWindowItems.GroupDescriptions.TryGetValue( path, out var description );
                                    //if( !string.IsNullOrEmpty( description ) )
                                    //	menuItem2.Description = description;
                                }
                                else
                                {
                                    var type = MetadataManager.GetTypeOfNetType(item.Type);
                                    menuItem = new KryptonContextMenuItem(strings[n], EditorResourcesCache.Type,
                                                                          delegate(object s, EventArgs e2)
                                    {
                                        var type2 = (Metadata.TypeInfo)((KryptonContextMenuItem)s).Tag;
                                        select(type2);
                                        //TryNewObject( mouse, type2 );
                                    });
                                    menuItem.Tag = type;

                                    //menuItem2.imageKey = GetTypeImageKey( type );

                                    menuItem.Enabled = !item.Disabled;
                                }

                                if (parentItem != null)
                                {
                                    if (parentItem.Items.Count == 0)
                                    {
                                        parentItem.Items.Add(new KryptonContextMenuItems(new KryptonContextMenuItemBase[0]));
                                    }
                                    var list = (KryptonContextMenuItems)parentItem.Items[0];
                                    list.Items.Add(menuItem);
                                    //parentItem.children.Add( menuItem );
                                }

                                menuItems.Add(path, menuItem);
                                if (n == 0)
                                {
                                    items2.Add(menuItem);
                                }
                            }
                        }
                    }
                }

                newObjectItem.Items.Add(new KryptonContextMenuItems(items2.ToArray()));
                items.Add(newObjectItem);
            }
        }
        public static void AddActionsToMenu(MenuTypeEnum menuType, ICollection <KryptonContextMenuItemBase> items)         //, DocumentWindow documentWindow )
        {
            bool firstItem = true;

            foreach (var action in EditorActions.Actions)
            {
                if (!action.CompletelyDisabled && action.ContextMenuSupport != MenuTypeEnum.None && action.ContextMenuSupport == menuType)
                {
                    var state = EditorAPI.EditorActionGetState(EditorAction.HolderEnum.ContextMenu, action);
                    //bool enabled = false;
                    //action.PerformUpdateContextMenuEvent( documentWindow, ref enabled );

                    if (state.Enabled)
                    {
                        if (firstItem)
                        {
                            if (items.Count != 0)
                            {
                                items.Add(new KryptonContextMenuSeparator());
                            }

                            firstItem = false;
                        }

                        var image = EditorAPI.GetImageForDispalyScale(action.GetImageSmall(), action.GetImageBig());
                        var item  = new KryptonContextMenuItem(Translate(action.GetContextMenuText()), image, delegate(object s, EventArgs e2)
                        {
                            ////var a = (EditorAction)item.Tag;

                            ////!!!!так?
                            var state2 = EditorAPI.EditorActionGetState(EditorAction.HolderEnum.ContextMenu, action);
                            //check still enabled
                            if (state2.Enabled)
                            {
                                EditorAPI.EditorActionClick(EditorAction.HolderEnum.ContextMenu, action.Name);
                            }

                            //action.PerformClickContextMenuEvent( documentWindow );
                        });

                        if (action.ActionType == EditorAction.ActionTypeEnum.DropDown)
                        {
                            var args = new CancelEventArgs();
                            action.DropDownContextMenu.PerformOpening(args);
                            //!!!!?
                            //if( !args.Cancel)
                            //{

                            foreach (var child in action.DropDownContextMenu.Items)
                            {
                                item.Items.Add(child);
                            }
                        }

                        //!!!!
                        //item.Enabled = !rootNodeSelected;
                        item.Tag = action;
                        item.ShortcutKeyDisplayString = EditorActions.GetFirstShortcutKeyString(action.Name);
                        items.Add(item);
                    }
                }
            }
        }
        public static void AddTransformToolToMenu(ICollection <KryptonContextMenuItemBase> items, TransformTool transformTool)
        //public static void AddTransformToolToMenu( ICollection<KryptonContextMenuItemBase> items, string workareaModeName )// TransformTool transformTool )
        {
            KryptonContextMenuItem item;
            string text;

            //Select
            text = Translate("Select");
            item = new KryptonContextMenuItem(text, null, delegate(object sender, EventArgs e)
            {
                EditorAPI.EditorActionClick(EditorAction.HolderEnum.ContextMenu, "Select");
            });
            item.Checked = transformTool.Mode == TransformTool.ModeEnum.None;
            //item.Checked = workareaModeName == "Transform Select";
            item.Image = EditorResourcesCache.Select;
            item.ShortcutKeyDisplayString = EditorActions.GetFirstShortcutKeyString("Select");
            items.Add(item);

            //Move & Rotate
            text = Translate("Move && Rotate");
            item = new KryptonContextMenuItem(text, null, delegate(object sender, EventArgs e)
            {
                EditorAPI.EditorActionClick(EditorAction.HolderEnum.ContextMenu, "Move & Rotate");
            });
            item.Checked = transformTool.Mode == TransformTool.ModeEnum.PositionRotation;
            //item.Checked = workareaModeName == "Transform Move";
            item.Image = EditorResourcesCache.MoveRotate;
            item.ShortcutKeyDisplayString = EditorActions.GetFirstShortcutKeyString("Move & Rotate");
            items.Add(item);

            //Move
            text = Translate("Move");
            item = new KryptonContextMenuItem(text, null, delegate(object sender, EventArgs e)
            {
                EditorAPI.EditorActionClick(EditorAction.HolderEnum.ContextMenu, "Move");
            });
            item.Checked = transformTool.Mode == TransformTool.ModeEnum.Position;
            //item.Checked = workareaModeName == "Transform Move";
            item.Image = EditorResourcesCache.Move;
            item.ShortcutKeyDisplayString = EditorActions.GetFirstShortcutKeyString("Move");
            items.Add(item);

            //Rotate
            text = Translate("Rotate");
            item = new KryptonContextMenuItem(text, null, delegate(object sender, EventArgs e)
            {
                EditorAPI.EditorActionClick(EditorAction.HolderEnum.ContextMenu, "Rotate");
            });
            item.Checked = transformTool.Mode == TransformTool.ModeEnum.Rotation;
            //item.Checked = workareaModeName == "Transform Rotate";
            item.Image = EditorResourcesCache.Rotate;
            item.ShortcutKeyDisplayString = EditorActions.GetFirstShortcutKeyString("Rotate");
            items.Add(item);

            //Scale
            text = Translate("Scale");
            item = new KryptonContextMenuItem(text, null, delegate(object sender, EventArgs e)
            {
                EditorAPI.EditorActionClick(EditorAction.HolderEnum.ContextMenu, "Scale");
            });
            item.Checked = transformTool.Mode == TransformTool.ModeEnum.Scale;
            //item.Checked = workareaModeName == "Transform Scale";
            item.Image = EditorResourcesCache.Scale;
            item.ShortcutKeyDisplayString = EditorActions.GetFirstShortcutKeyString("Scale");
            items.Add(item);
        }
        private void MenuPluginClick(object sender, EventArgs e)
        {
            KryptonContextMenuItem item = (KryptonContextMenuItem)sender;

            this.ImportData((DataPlugin)item.Tag);
        }
示例#13
0
        private void ContextMenu_Opening(object sender, System.ComponentModel.CancelEventArgs e)
        {
            var sourceControl = (Control)contextMenu.Caller;

            contextMenu.Items.Clear();

            if (sourceControl == null)
            {
                e.Cancel = true;
                return;
            }

            var items = new KryptonContextMenuItems();

            if (sourceControl.Name == projectListBox.Name)
            {
                var deleteProjectStripItem = new KryptonContextMenuItem("Delete Project");

                var deleteClick = Observable.FromEventPattern <EventArgs>(deleteProjectStripItem, "Click");
                deleteClick
                .Select(ea => (Guid)projectListBox.SelectedValue)
                .InvokeCommand(ViewModel.DeleteProjectCommand);

                items.Items.Add(deleteProjectStripItem);

                var editProjectStripItem = new KryptonContextMenuItem("Edit Project");

                var editClick = Observable.FromEventPattern <EventArgs>(editProjectStripItem, "Click");
                editClick
                .Select(ea => (Guid)projectListBox.SelectedValue)
                .InvokeCommand(ViewModel.EditProjectCommand);

                items.Items.Add(editProjectStripItem);
            }
            else if (sourceControl.Name == projectItemsTree.Name)
            {
                var selectedNode = projectItemsTree.SelectedNodes.Count > 1 ?
                                   projectItemsTree.SelectedNodes.Where(a => !a.Name.StartsWith("node-")).FirstOrDefault() ?? projectItemsTree.SelectedNode : projectItemsTree.SelectedNode;
                if (selectedNode != null && !selectedNode.Name.StartsWith("node-"))
                {
                    var selectedItems = projectItemsTree.SelectedNodes
                                        .Where(a => !a.Name.StartsWith("node-"))
                                        .ToList();

                    if (selectedItems.Count() != 0)
                    {
                        var deleteItemStripItem = new KryptonContextMenuItem($"Remove Asset{(selectedItems.Count() == 1 ? "" : "s")}");

                        var deleteClick = Observable.FromEventPattern <EventArgs>(deleteItemStripItem, "Click");
                        deleteClick
                        .Select(ea => selectedItems.Select(i => new Guid(i.Name)).ToList())
                        .InvokeCommand <List <Guid> >(ViewModel.DeleteAssetsCommand);

                        deleteClick
                        .Subscribe(ea => {
                            projectItemsTree.SelectedNode  = null;
                            projectItemsTree.SelectedNodes = null;
                        });

                        items.Items.Add(deleteItemStripItem);
                    }
                }
                else
                {
                    var addAssetsItemStripItem = new KryptonContextMenuItem("Add Assets");

                    var deleteClick = Observable.FromEventPattern <EventArgs>(addAssetsItemStripItem, "Click");
                    deleteClick
                    .Select(ea => Unit.Default)
                    .InvokeCommand(ViewModel.AddAssetsCommand);

                    items.Items.Add(addAssetsItemStripItem);
                }
            }
            else
            {
                items.Items.Add(new KryptonContextMenuLinkLabel("Source: " + sourceControl.Name));
            }

            contextMenu.Items.Add(items);

            e.Cancel = false;
        }