Exemplo n.º 1
0
        private void LoadContextMenus(ObjectTreeNode node)
        {
            SelectedObjects = new List <object>();
            SelectedNodes   = new List <ObjectTreeNode>();
            foreach (var t in GetSelectedObjects())
            {
                SelectedObjects.Add(t.Tag);
                SelectedNodes.Add(t);
            }

            List <ToolStripItem> items = new List <ToolStripItem>();

            int counter = 0;

            var tag = node.Tag;

            foreach (var type in ObjectViewWrapperHandler.Handlers)
            {
                if (type.Key.IsAssignableFrom(tag.GetType()))
                {
                    if (items.Count > 0)
                    {
                        items.Add(new STToolStripSeparator());
                    }

                    type.Value.ActiveObject = tag;
                    foreach (var menu in type.Value.GetContextMenuItems())
                    {
                        items.Add(new STToolStipMenuItem(menu.Name, null, menu.Click)
                        {
                            Enabled = menu.Enabled,
                        });
                    }
                }
            }

            if (node is ArchiveHiearchy)
            {
                items.Add(new STToolStipMenuItem("Export Raw Data", null, ArchiveExport));
            }

            if (tag is IModelFormat)
            {
                items.Add(new STToolStipMenuItem("Export Model", null, ExportModel));
            }
            if (tag is IFileFormat)
            {
                if (File.Exists(((IFileFormat)tag).FileInfo.FilePath))
                {
                    items.Add(new STToolStipMenuItem("Open In Explorer", null, SelectFileInExplorer, Keys.Control | Keys.Q));
                }
            }
            if (tag is IModelSceneFormat)
            {
            }

            var menus = node.GetContextMenuItems();

            foreach (var menu in menus)
            {
                if (menu is ToolMenuItemSeparator)
                {
                    items.Add(new STToolStripSeparator());
                }
                else
                {
                    items.Add(new STToolStipMenuItem(menu.Name, null, menu.Click)
                    {
                        Enabled = menu.Enabled,
                    });
                }
            }

            if (items.Count > 0)
            {
                treeNodeContextMenu.Items.Clear();
                treeNodeContextMenu.Items.AddRange(items.ToArray());
                treeNodeContextMenu.Show(Cursor.Position);
            }
        }