Exemplo n.º 1
0
        public static ContextMenu Build(SiteExplorerNodeViewModel node, MaterialExplorer explorer)
        {
            if (node == null)
            {
                return(null);
            }

            ContextMenuBuilder builder = new ContextMenuBuilder(null);

            if (explorer.tabMaterial.SelectedIndex != 0)
            {
                builder.New("Show in Contents").Handler(() => {
                    explorer.ShowInContents(node);
                }).End();
                builder.Separator();
            }

            builder.New("Refresh").Handler(() => { explorer.Refresh(); }).End();

            builder.Separator();

            builder.New("Rename").Handler(() => { node.IsRenaming = true; }).End();

            if (!node.IsTemplate)
            {
                var addMenu = CreateAddMenu(node, explorer);
                builder.AddMenuItem(addMenu);

                builder.Separator();
            }

            var type = NodeType(node);

            builder.New("Delete").Handler(() => {
                switch (type)
                {
                case SiteExplorerNodeType.Region: explorer.DeleteRegion(node);
                    break;

                case SiteExplorerNodeType.SiteGroup: explorer.DeleteSiteGroup(node);
                    break;

                case SiteExplorerNodeType.Site: explorer.DeleteSite(node);
                    break;

                case SiteExplorerNodeType.SiteVisit: explorer.DeleteSiteVisit(node);
                    break;

                case SiteExplorerNodeType.Trap: explorer.DeleteTrap(node);
                    break;

                case SiteExplorerNodeType.Material: explorer.DeleteMaterial(node);
                    break;

                default:
                    throw new Exception("[Delete] Unhandled site explorer element type: " + node.ElemType);
                }
            });

            if (!node.IsTemplate)
            {
                var pinnable = explorer.CreatePinnable(node);
                if (pinnable != null)
                {
                    builder.Separator();
                    builder.New("_Pin to pin board").Handler(() => { PluginManager.Instance.PinObject(pinnable); });
                }

                builder.Separator();
                builder.AddMenuItem(CreateFavoriteMenuItems(explorer, node));

                var mnuReports = CreateReportMenuItems(node, explorer);
                if (mnuReports.HasItems)
                {
                    builder.Separator();
                    builder.AddMenuItem(mnuReports);
                }

                builder.Separator();
                builder.AddMenuItem(CreateTemplateItems(explorer));
            }


            if (type != SiteExplorerNodeType.SiteGroup)
            {
                builder.Separator();
                builder.New("Edit Details...").Handler(() => {
                    explorer.EditNode(node);
                }).End();

                var rdeNodeTypes = new List <SiteExplorerNodeType>(new SiteExplorerNodeType[] { SiteExplorerNodeType.Material, SiteExplorerNodeType.Site, SiteExplorerNodeType.SiteVisit });
                if (node != null && rdeNodeTypes.Contains(node.NodeType))
                {
                    builder.New("Open in Rapid Data Entry...").Handler(() => { explorer.EditRDE(node); }).Enabled(!node.IsTemplate).End();
                }
                else
                {
                    builder.New("Rapid Data Entry...").Handler(() => { explorer.EditRDE(node); }).End();
                }
            }

            return(builder.ContextMenu);
        }
Exemplo n.º 2
0
        public static ContextMenu Build(SiteExplorerNodeViewModel node, MaterialExplorer explorer)
        {
            if (node == null) {
                return null;
            }

            ContextMenuBuilder builder = new ContextMenuBuilder(null);

            if (explorer.tabMaterial.SelectedIndex != 0) {
                builder.New("Show in Contents").Handler(() => {
                    explorer.ShowInContents(node);
                }).End();
                builder.Separator();
            }

            builder.New("Refresh").Handler(() => { explorer.Refresh(); }).End();

            builder.Separator();

            builder.New("Rename").Handler(() => { node.IsRenaming = true; }).End();

            if (!node.IsTemplate) {
                var addMenu = CreateAddMenu(node, explorer);
                builder.AddMenuItem(addMenu);

                builder.Separator();
            }

            var type = NodeType(node);

            builder.New("Delete").Handler(() => {
                switch (type) {
                    case SiteExplorerNodeType.Region: explorer.DeleteRegion(node);
                        break;
                    case SiteExplorerNodeType.SiteGroup: explorer.DeleteSiteGroup(node);
                        break;
                    case SiteExplorerNodeType.Site: explorer.DeleteSite(node);
                        break;
                    case SiteExplorerNodeType.SiteVisit: explorer.DeleteSiteVisit(node);
                        break;
                    case SiteExplorerNodeType.Trap: explorer.DeleteTrap(node);
                        break;
                    case SiteExplorerNodeType.Material: explorer.DeleteMaterial(node);
                        break;
                    default:
                        throw new Exception("[Delete] Unhandled site explorer element type: " + node.ElemType);
                }
            });

            if (!node.IsTemplate) {
                var pinnable = explorer.CreatePinnable(node);
                if (pinnable != null) {
                    builder.Separator();
                    builder.New("_Pin to pin board").Handler(() => { PluginManager.Instance.PinObject(pinnable); });
                }

                builder.Separator();
                builder.AddMenuItem(CreateFavoriteMenuItems(explorer, node));

                var mnuReports = CreateReportMenuItems(node, explorer);
                if (mnuReports.HasItems) {
                    builder.Separator();
                    builder.AddMenuItem(mnuReports);
                }

                builder.Separator();
                builder.AddMenuItem(CreateTemplateItems(explorer));
            }

            if (type != SiteExplorerNodeType.SiteGroup) {
                builder.Separator();
                builder.New("Edit Details...").Handler(() => {
                    explorer.EditNode(node);
                }).End();

                var rdeNodeTypes = new List<SiteExplorerNodeType>(new SiteExplorerNodeType[] { SiteExplorerNodeType.Material, SiteExplorerNodeType.Site, SiteExplorerNodeType.SiteVisit });
                if (node != null && rdeNodeTypes.Contains(node.NodeType)) {
                    builder.New("Open in Rapid Data Entry...").Handler(() => { explorer.EditRDE(node); }).Enabled(!node.IsTemplate).End();
                } else {
                    builder.New("Rapid Data Entry...").Handler(() => { explorer.EditRDE(node); }).End();
                }

            }

            return builder.ContextMenu;
        }