Exemplo n.º 1
0
 public TaxonMenuFactory(TaxonViewModel taxon, TaxonExplorer explorer, MessageFormatterFunc formatter)
 {
     this.Taxon         = taxon;
     this.Explorer      = explorer;
     this.FormatterFunc = formatter;
     _builder           = new MenuItemBuilder(formatter);
 }
Exemplo n.º 2
0
 public TaxonMenuFactory(TaxonViewModel taxon, TaxonExplorer explorer, MessageFormatterFunc formatter)
 {
     this.Taxon = taxon;
     this.Explorer = explorer;
     this.FormatterFunc = formatter;
     _builder = new MenuItemBuilder(formatter);
 }
        private void ShowPhraseContextMenu()
        {
            PhraseViewModel phrase = lvwPhrases.SelectedItem as PhraseViewModel;

            if (phrase == null)
            {
                return;
            }

            ContextMenu menu = new ContextMenu();

            MenuItemBuilder builder = new MenuItemBuilder();

            menu.Items.Add(builder.New("Delete").Handler(() => {
                DeletePhrase(phrase);
            }).MenuItem);

            menu.Items.Add(builder.New("Rename").Handler(() => {
                RenamePhrase(phrase);
            }).MenuItem);

            menu.Items.Add(new Separator());

            menu.Items.Add(builder.New("Add new phrase value").Handler(() => {
                AddNewPhraseValue();
            }).MenuItem);

            lvwPhrases.ContextMenu = menu;
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获取标签生成器
        /// </summary>
        protected override TagBuilder GetTagBuilder()
        {
            var builder = new MenuItemBuilder();

            Config(builder);
            return(builder);
        }
        public MenuItemBuilderTests()
        {
            var viewContext = TestHelper.CreateViewContext();

            item    = new MenuItem();
            builder = new MenuItemBuilder(item, viewContext);
        }
        public void MenuBuilder_AddPortion_PortionAdded()
        {
            var menuItem = MenuItemBuilder.Create("Hamburger")
                           .AddPortion("Adet", 5)
                           .Build();

            Assert.AreEqual(1, menuItem.Portions.Count);
        }
Exemplo n.º 7
0
        private static MenuItem CreateFavoriteMenuItems(MaterialExplorer explorer, SiteExplorerNodeViewModel node)
        {
            MenuItemBuilder builder = new MenuItemBuilder();
            MenuItem        add     = builder.New("Add to favorites").MenuItem;

            add.Items.Add(builder.New("User specific").Handler(() => { explorer.Favorites.AddToFavorites(node, false); }).MenuItem);
            add.Items.Add(builder.New("Global").Handler(() => { explorer.Favorites.AddToFavorites(node, true); }).MenuItem);
            return(add);
        }
        public void CanAddOrders()
        {
            var kola   = MenuItemBuilder.Create("Kola").AddPortion("Adet", 5).Build();
            var ticket = TicketBuilder.Create(TicketType.Default, Department.Default)
                         .AddOrder().ForMenuItem(kola).Do(2)
                         .Build();

            Assert.AreEqual(2, ticket.Orders.Count);
        }
        public void MenuItemBuilder_UpdateProductTag_ProductTagAssigned()
        {
            var menuItem = MenuItemBuilder.Create("Tost")
                           .AddPortion("Küçük", 2)
                           .WithProductTag("NoSale")
                           .Build();

            Assert.AreEqual("NoSale", menuItem.Tag);
        }
        public void MenuItemBuilder_AddGroupCode_GroupCodeAssigned()
        {
            var menuItem = MenuItemBuilder.Create("Hamburger")
                           .AddPortion("Küçük", 5)
                           .WithGroupCode("İçecekler")
                           .Build();

            Assert.AreEqual("İçecekler", menuItem.GroupCode);
        }
        public void MenuBuilder_AddMultiplePortions_PortionCountCorrect()
        {
            var menuItem = MenuItemBuilder.Create("Hamburger")
                           .AddPortion("Küçük", 5)
                           .AddPortion("Büyük", 8)
                           .Build();

            Assert.AreEqual(2, menuItem.Portions.Count);
        }
Exemplo n.º 12
0
        public void TicketBuilder_CreatesOrder_OrderAdded()
        {
            var context = TicketBuilderTestContext.GetDefaultContext();
            var ticket  = TicketBuilder.Create(context.TicketType, context.Department)
                          .AddOrder().ForMenuItem(MenuItemBuilder.Create("Hamburger").AddPortion("Adet", 10).Build()).Do()
                          .Build();

            Assert.AreEqual(10, ticket.GetSum());
        }
        public void MergeOrders_DifferentOrderStates_ShouldSkipMerge()
        {
            var kola   = MenuItemBuilder.Create("Kola").AddPortion("Adet", 5).Build();
            var ticket = TicketBuilder.Create(TicketType.Default, Department.Default)
                         .AddOrder().ForMenuItem(kola).Do(2)
                         .Build();

            ticket.Orders[0].SetStateValue("Status", 1, "New", 1, "", 0);
            ticket.MergeOrdersAndUpdateOrderNumbers(1);
            Assert.AreEqual(2, ticket.Orders.Count);
        }
        public void CanUpdateQuantityOfMergedOrders()
        {
            var kola   = MenuItemBuilder.Create("Kola").AddPortion("Adet", 5).Build();
            var ticket = TicketBuilder.Create(TicketType.Default, Department.Default)
                         .AddOrder().ForMenuItem(kola).Do(2)
                         .Build();

            ticket.MergeOrdersAndUpdateOrderNumbers(1);

            Assert.AreEqual(2, ticket.Orders[0].Quantity);
        }
Exemplo n.º 15
0
        public static MenuItem CreateTemplateItems(MaterialExplorer explorer)
        {
            MenuItemBuilder builder = new MenuItemBuilder();
            MenuItem        tmp     = builder.New("Create Template").MenuItem;

            tmp.Items.Add(builder.New("_Site").Handler(() => { explorer.AddSiteTemplate(); }).MenuItem);
            tmp.Items.Add(builder.New("Site _Visit").Handler(() => { explorer.AddSiteVisitTemplate(); }).MenuItem);
            tmp.Items.Add(builder.New("_Material").Handler(() => { explorer.AddMaterialTemplate(); }).MenuItem);

            return(tmp);
        }
        public void MergeOrders_DifferentOrderQuantites_ShouldSkipMerge()
        {
            var kola   = MenuItemBuilder.Create("Kola").AddPortion("Adet", 5).Build();
            var ticket = TicketBuilder.Create(TicketType.Default, Department.Default)
                         .AddOrder().ForMenuItem(kola).WithQuantity(2).Do()
                         .AddOrder().ForMenuItem(kola).WithQuantity(1).Do()
                         .Build();

            ticket.MergeOrdersAndUpdateOrderNumbers(1);
            Assert.AreEqual(2, ticket.Orders.Count);
        }
        public void MergeOrders_OneOrderIsGift_ShouldSkipMerge()
        {
            var kola   = MenuItemBuilder.Create("Kola").AddPortion("Adet", 5).Build();
            var ticket = TicketBuilder.Create(TicketType.Default, Department.Default)
                         .AddOrder().ForMenuItem(kola).Do(2)
                         .Build();

            ticket.Orders[0].CalculatePrice = false;
            ticket.MergeOrdersAndUpdateOrderNumbers(1);
            Assert.AreEqual(2, ticket.Orders.Count);
        }
Exemplo n.º 18
0
        public void HtmlAttribute_SetsItemInnertext()
        {
            actual     = string.Empty;
            returnHtml = string.Empty;
            MenuItemBuilder target   = new MenuItemBuilder();
            string          expected = target.Text = "Level1";

            returnHtml = Utility.ControlHtmlBuilder <MenuItem, MenuItemBuilder>(target);
            actual     = Utility.GetSection(returnHtml, "li/a");
            Assert.AreEqual(expected, actual);
        }
        public void MergeOrders_OneOrderPortionDifferent_ShouldSkipMerge()
        {
            var kola   = MenuItemBuilder.Create("Kola").AddPortion("Adet", 5).AddPortion("Büyük", 6).Build();
            var ticket = TicketBuilder.Create(TicketType.Default, Department.Default)
                         .AddOrder().ForMenuItem(kola).Do(2)
                         .Build();

            ticket.Orders[0].UpdatePortion(kola.Portions[1], "", null);
            ticket.MergeOrdersAndUpdateOrderNumbers(1);
            Assert.AreEqual(2, ticket.Orders.Count);
            Assert.AreEqual(11, ticket.GetSum());
        }
        public void OrderMerge_CanCompareOrdersWithDifferentPrice_ReturnsFalse()
        {
            var kola   = MenuItemBuilder.Create("Kola").WithId(1).AddPortion("Adet", 5).Build();
            var ticket = TicketBuilder.Create(TicketType.Default, Department.Default)
                         .AddOrder().ForMenuItem(kola).WithPrice(3).Do()
                         .AddOrder().ForMenuItem(kola).Do()
                         .Build();

            var equals = OrderMerger.CanMergeOrders(ticket.Orders[0], ticket.Orders[1]);

            Assert.False(equals);
        }
        public void CanMergeMultipleOrders()
        {
            var kola   = MenuItemBuilder.Create("Kola").AddPortion("Adet", 5).Build();
            var pizza  = MenuItemBuilder.Create("Pizza").AddPortion("Adet", 10).Build();
            var ticket = TicketBuilder.Create(TicketType.Default, Department.Default)
                         .AddOrder().ForMenuItem(kola).Do(2)
                         .AddOrder().ForMenuItem(pizza).Do(2)
                         .Build();

            ticket.MergeOrdersAndUpdateOrderNumbers(1);

            Assert.AreEqual(2, ticket.Orders.Count);
        }
Exemplo n.º 22
0
        public void HtmlAttribute_SetsCompleteItem()
        {
            actual = string.Empty;
            MenuItemBuilder target = new MenuItemBuilder();

            target.Text = "Level1";
            target.ChildItems(child => child.Add(childItem => childItem.Text = "Level1-1"));
            string expected = "<li><a href=\"#\">Level1</a><ul><li><a href=\"#\">Level1-1</a></li></ul></li>";

            returnHtml = Utility.ControlHtmlBuilder <MenuItem, MenuItemBuilder>(target);
            actual     = returnHtml.ToString().StringReplace();
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 23
0
        public void HtmlAttribute_SetsMenuItemHref()
        {
            actual     = string.Empty;
            returnHtml = string.Empty;
            MenuItemBuilder target = new MenuItemBuilder();

            target.Text = "Level1";
            string expected = "#";

            returnHtml = Utility.ControlHtmlBuilder <MenuItem, MenuItemBuilder>(target);
            actual     = Utility.GetAttribute(returnHtml, "href", "li/a");
            Assert.AreEqual(expected, actual);
        }
        public void OrderMerge_CanCompareOrdersWithOneOfThemGift_ReturnsFalse()
        {
            var kola   = MenuItemBuilder.Create("Kola").WithId(1).AddPortion("Adet", 5).AddPortion("Büyük", 5).Build();
            var ticket = TicketBuilder.Create(TicketType.Default, Department.Default)
                         .AddOrder().ForMenuItem(kola).Do()
                         .AddOrder().ForMenuItem(kola).Do()
                         .Build();

            ticket.Orders[0].CalculatePrice = false;
            var equals = OrderMerger.CanMergeOrders(ticket.Orders[0], ticket.Orders[1]);

            Assert.False(equals);
        }
        public void OrderBuilder_CreateMenuItemWithDoublePortions_PriceCorrect()
        {
            var testContext = OrderBuilderTestContext.CreateDefault();
            var tost        = MenuItemBuilder.Create("Tost").AddPortion("Küçük", 4.5m).AddPortion("Büyük", 8).Build();
            var order       = OrderBuilder.Create()
                              .ForMenuItem(tost)
                              .WithPortion(tost.Portions[1])
                              .WithDepartment(testContext.Department)
                              .WithAccountTransactionType(testContext.AccountTransactionType)
                              .Build();

            Assert.AreEqual(8m, order.Price);
        }
        public void MergeMultipleOrders_OneOrderLocked_ShouldSkipMerge()
        {
            var kola   = MenuItemBuilder.Create("Kola").AddPortion("Adet", 5).Build();
            var pizza  = MenuItemBuilder.Create("Pizza").AddPortion("Adet", 10).Build();
            var ticket = TicketBuilder.Create(TicketType.Default, Department.Default)
                         .AddOrder().ForMenuItem(kola).Do(2)
                         .AddOrder().ForMenuItem(pizza).Do(2)
                         .Build();

            ticket.Orders[0].Locked = true;
            ticket.MergeOrdersAndUpdateOrderNumbers(1);
            Assert.AreEqual(3, ticket.Orders.Count);
            Assert.AreEqual(30, ticket.GetSum());
        }
Exemplo n.º 27
0
        public void TicketBuilder_AddsOrderWithMultipleMenuItems_OrdersAdded2()
        {
            var context = TicketBuilderTestContext.GetDefaultContext();

            var hamburger = MenuItemBuilder.Create("Hamburger").AddPortion("Adet", 10).Build();
            var tost      = MenuItemBuilder.Create("Tost").AddPortion("Adet", 4).Build();

            var ticket = TicketBuilder.Create(context.TicketType, context.Department)
                         .AddOrderFor(hamburger).Do()
                         .AddOrderFor(tost).WithQuantity(2).Do()
                         .Build();

            Assert.AreEqual(10 + (4 * 2), ticket.GetSum());
        }
        public void OrderMerge_CanCompareOrdersWithDifferentOrderStates_ReturnsFalse()
        {
            var kola   = MenuItemBuilder.Create("Kola").WithId(1).AddPortion("Adet", 5).Build();
            var ticket = TicketBuilder.Create(TicketType.Default, Department.Default)
                         .AddOrder().ForMenuItem(kola).Do()
                         .AddOrder().ForMenuItem(kola).Do()
                         .Build();

            ticket.Orders[0].SetStateValue("Status", 1, "New", 1, "", 0);
            ticket.Orders[1].SetStateValue("Status", 1, "Submitted", 1, "", 0);
            var equals = OrderMerger.CanMergeOrders(ticket.Orders[0], ticket.Orders[1]);

            Assert.False(equals);
        }
Exemplo n.º 29
0
        public void HtmlAttribute_SetsItemChildrenInnertext()
        {
            actual     = string.Empty;
            returnHtml = string.Empty;
            MenuItemBuilder target = new MenuItemBuilder();

            target.Text = "Level1";
            string expected = "Level1-1";

            target.ChildItems(child => child.Add(childItem => childItem.Text = "Level1-1"));
            returnHtml = Utility.ControlHtmlBuilder <MenuItem, MenuItemBuilder>(target);
            actual     = Utility.GetSection(returnHtml, "li/ul/li/a");
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 30
0
        private static MenuItem CreateReportMenuItems(SiteExplorerNodeViewModel node, MaterialExplorer explorer)
        {
            var builder = new MenuItemBuilder();

            MenuItem reports = builder.New("Reports").MenuItem;
            var      list    = explorer.Owner.GetReportsForNode(node);

            foreach (IBioLinkReport report in list)
            {
                IBioLinkReport reportToExecute = report;
                reports.Items.Add(builder.New(report.Name).Handler(() => { PluginManager.Instance.RunReport(explorer.Owner, reportToExecute); }).MenuItem);
            }

            return(reports);
        }
        public void MergeOrders_OrdersTagged_ShouldSkipMerge()
        {
            var kola   = MenuItemBuilder.Create("Kola").AddPortion("Adet", 5).Build();
            var ticket = TicketBuilder.Create(TicketType.Default, Department.Default)
                         .AddOrder().ForMenuItem(kola).Do(2)
                         .Build();

            ticket.Orders[0].ToggleOrderTag(new OrderTagGroup {
                Name = "Service"
            }, new OrderTag {
                Name = "Pause"
            }, 0, "");
            ticket.MergeOrdersAndUpdateOrderNumbers(1);
            Assert.AreEqual(2, ticket.Orders.Count);
        }
Exemplo n.º 32
0
        public static MenuItem CreateTemplateItems(MaterialExplorer explorer)
        {
            MenuItemBuilder builder = new MenuItemBuilder();
            MenuItem tmp = builder.New("Create Template").MenuItem;
            tmp.Items.Add(builder.New("_Site").Handler(() => { explorer.AddSiteTemplate(); }).MenuItem);
            tmp.Items.Add(builder.New("Site _Visit").Handler(() => { explorer.AddSiteVisitTemplate(); }).MenuItem);
            tmp.Items.Add(builder.New("_Material").Handler(() => { explorer.AddMaterialTemplate(); }).MenuItem);

            return tmp;
        }
Exemplo n.º 33
0
        private void addSetOperations(ContextMenuBuilder builder, LookupType type, params string[] idColAliases)
        {
            int index = -1;
            foreach (string alias in idColAliases) {
                var field = alias;
                for (int i = 0; i < Data.Columns.Count; ++i) {
                    var col = Data.Columns[i];
                    if (col.Name.Contains(alias)) {
                        index = i;
                        break;
                    }
                }

                if (index >= 0) {
                    break;
                }
            }

            if (index > -1) {

                List<int> idSet = new List<int>();

                if (lvw.SelectedItems.Count > 1) {
                    foreach (object selected in lvw.SelectedItems) {
                        var row = selected as MatrixRow;
                        var selectedRow = Data.Rows.IndexOf(row);
                        idSet.Add((int)row[selectedRow]);
                    }
                } else {
                    Data.Rows.ForEach(row => {
                        var objectIndex = row[index];
                        if (objectIndex is int) {
                            idSet.Add((int)row[index]);
                        }
                    });
                }

                if (idSet.Count > 0) {
                    var commands = PluginManager.Instance.SolicitCommandsForObjectSet(idSet, type);
                    if (commands != null && commands.Count > 0) {
                        MenuItemBuilder b = new MenuItemBuilder();

                        var typeItem = b.New(type.ToString() + String.Format(" Set ({0} items)", idSet.Count)).MenuItem;

                        commands.ForEach((cmd) => {
                            if (cmd is CommandSeparator) {
                                typeItem.Items.Add(new Separator());
                            } else {
                                typeItem.Items.Add(b.New(cmd.Caption).Handler(() => {
                                    cmd.CommandAction(idSet);
                                }).MenuItem);
                            }
                        });
                        builder.AddMenuItem(typeItem);
                    }
                }
            }
        }
Exemplo n.º 34
0
        private void AddLookupItem(ContextMenuBuilder builder, LookupType lookupType, params String[] aliases)
        {
            int index = -1;
            foreach (string alias in aliases) {
                var field = alias;

                for (int i = 0; i < Data.Columns.Count; ++i) {
                    var col = Data.Columns[i];
                    if (col.Name.Contains(alias)) {
                        index = i;
                        break;
                    }
                }

                if (index >= 0) {
                    break;
                }
            }

            if (index > -1) {
                var row = lvw.SelectedItem as MatrixRow;

                int objectId = 0;
                var enabled = false;
                if (row[index] != null) {
                    if (Int32.TryParse(row[index].ToString(), out objectId) && objectId > 0) {
                        enabled = true;
                    }
                }

                var pinnable = PluginManager.Instance.GetPinnableForLookupType(lookupType, objectId);

                var commands = new List<Command>();

                if (pinnable != null) {
                    var vm = PluginManager.Instance.GetViewModel(pinnable);
                    if (vm != null) {
                        var selected = new List<ViewModelBase>();
                        selected.Add(vm);
                        commands.AddRange(PluginManager.Instance.SolicitCommandsForObjects(selected));
                    }
                }

                if (commands.Count > 0) {

                    MenuItemBuilder b = new MenuItemBuilder();

                    var typeItem = b.New(lookupType.ToString()).MenuItem;

                    typeItem.Items.Add(b.New("Pin {0} to pinboard", lookupType).Handler(() => {
                        PluginManager.Instance.PinObject(pinnable);
                    }).Enabled(enabled).MenuItem);
                    typeItem.Items.Add(new Separator());

                    commands.ForEach((cmd) => {
                        if (cmd is CommandSeparator) {
                            typeItem.Items.Add(new Separator());
                        } else {
                            typeItem.Items.Add(b.New(cmd.Caption).Handler(() => {
                                cmd.CommandAction(pinnable);
                            }).Enabled(enabled).MenuItem);
                        }
                    });

                    builder.AddMenuItem(typeItem);
                } else {
                    builder.New("Edit " + lookupType.ToString()).Handler(() => {
                        PluginManager.Instance.EditLookupObject(lookupType, objectId);
                    }).Enabled(enabled).End();
                }
            }

            addSetOperations(builder, lookupType, aliases);
        }
Exemplo n.º 35
0
 private static MenuItem CreateFavoriteMenuItems(MaterialExplorer explorer, SiteExplorerNodeViewModel node)
 {
     MenuItemBuilder builder = new MenuItemBuilder();
     MenuItem add = builder.New("Add to favorites").MenuItem;
     add.Items.Add(builder.New("User specific").Handler(() => { explorer.Favorites.AddToFavorites(node, false); }).MenuItem);
     add.Items.Add(builder.New("Global").Handler(() => { explorer.Favorites.AddToFavorites(node, true); }).MenuItem);
     return add;
 }
Exemplo n.º 36
0
        private static MenuItem CreateReportMenuItems(SiteExplorerNodeViewModel node, MaterialExplorer explorer)
        {
            var builder = new MenuItemBuilder();

            MenuItem reports = builder.New("Reports").MenuItem;
            var list = explorer.Owner.GetReportsForNode(node);
            foreach (IBioLinkReport report in list) {
                IBioLinkReport reportToExecute = report;
                reports.Items.Add(builder.New(report.Name).Handler(() => { PluginManager.Instance.RunReport(explorer.Owner, reportToExecute); }).MenuItem);
            }

            return reports;
        }
Exemplo n.º 37
0
        public void ShowContextMenu()
        {
            var item = thumbList.SelectedItem as MultimediaLinkViewModel;
            if (item != null) {
                ContextMenu menu = new ContextMenu();
                MenuItemBuilder builder = new MenuItemBuilder();

                string filename = _tempFileManager.GetContentFileName(item.MultimediaID, item.Extension);

                thumbList.ContextMenu = menu;

                var verbMenuItems = SystemUtils.GetVerbsAsMenuItems(filename);
                foreach (MenuItem verbItem in verbMenuItems) {
                    menu.Items.Add(verbItem);
                }

                menu.Items.Add(new Separator());
                menu.Items.Add(builder.New("Add multimedia").Handler(() => { AddMultimedia(); }).Enabled(!IsReadOnly).MenuItem);
                menu.Items.Add(new Separator());
                menu.Items.Add(builder.New("Delete").Handler(() => { DeleteSelectedMultimedia(); }).Enabled(!IsReadOnly).MenuItem);
                menu.Items.Add(new Separator());
                menu.Items.Add(builder.New("Show items linked to this multimedia...").Handler(() => { ShowLinkedItems(); }).MenuItem);
                menu.Items.Add(new Separator());
                menu.Items.Add(builder.New("Edit Details...").Handler(() => { ShowProperties(); }).Enabled(!IsReadOnly).MenuItem);
            }
        }
Exemplo n.º 38
0
        private void ShowContextMenu(TreeView tvw)
        {
            var selected = tvw.SelectedItem as SiteExplorerNodeViewModel;
            var builder = new ContextMenuBuilder(null);
            if (selected != null) {
                tvw.ContextMenu = SiteExplorerMenuBuilder.Build(selected, this);
            } else if (tvw.SelectedItem == this.regionsNode) {
                builder.New("Add _Region").Handler(() => {
                    var newNode = AddRegion(null);
                    RegionsModel.Insert(0, newNode);
                }).End();
                builder.Separator();
                builder.AddMenuItem(SiteExplorerMenuBuilder.CreateTemplateItems(this));
                builder.Separator();
                builder.New("Refresh").Handler(() => { Refresh(); }).End();
                tvw.ContextMenu = builder.ContextMenu;
            } else if (tvw.SelectedItem == unplacedNode) {
                builder.New("Add Site _Group").Handler(() => {
                    var newNode = AddSiteGroup(null);
                    UnplacedModel.Insert(0, newNode);
                }).End();

                MenuItemBuilder b = new MenuItemBuilder();
                MenuItem addSite = b.New("Add Site").MenuItem;
                addSite.Items.Add(b.New("Blank").Handler(() => {
                    var newNode = AddSite(null);
                    UnplacedModel.Insert(0, newNode);
                }).MenuItem);

                addSite.Items.Add(b.New("From _Template").Handler(() => {
                    int? templateId = ChooseTemplate(SiteExplorerNodeType.Site);
                    if (templateId != null && templateId.HasValue) {
                        var newNode = AddSite(null, templateId.Value);
                        UnplacedModel.Insert(0, newNode);
                    }
                }).MenuItem);

                builder.AddMenuItem(addSite);

                builder.Separator();
                builder.AddMenuItem(SiteExplorerMenuBuilder.CreateTemplateItems(this));
                builder.Separator();
                builder.New("Refresh").Handler(() => { Refresh(); }).End();
                tvw.ContextMenu = builder.ContextMenu;
            } else if (tvw.SelectedItem is ViewModelPlaceholder) {
                var ph = tvw.SelectedItem as ViewModelPlaceholder;
                switch (ph.DisplayLabel.ToLower()) {
                    case "site templates":
                        builder.New("Add new _Site Template").Handler(() => { AddSiteTemplate(); }).End();
                        break;
                    case "site visit templates":
                        builder.New("Add new Site _Visit Template").Handler(() => { AddSiteVisitTemplate(); }).End();
                        break;
                    case "material templates":
                        builder.New("Add new _Material Template").Handler(() => { AddMaterialTemplate(); }).End();
                        break;
                }

                tvw.ContextMenu = builder.ContextMenu;
            } else if (tvw.SelectedItem == templatesNode) {
                builder.AddMenuItem(SiteExplorerMenuBuilder.CreateTemplateItems(this));
                tvw.ContextMenu = builder.ContextMenu;
            } else {
                tvw.ContextMenu = null;
            }
        }
Exemplo n.º 39
0
        private static MenuItem CreateAddMenu(SiteExplorerNodeViewModel viewModel, MaterialExplorer explorer)
        {
            var addMenu = new MenuItem();
            addMenu.Header = "Add";

            var user = PluginManager.Instance.User;
            var service = new MaterialService(user);

            var builder = new MenuItemBuilder();

            switch (NodeType(viewModel)) {
                case SiteExplorerNodeType.Region:
                    addMenu.Items.Add(builder.New("New Region").Handler(() => { explorer.AddRegion(viewModel); }).MenuItem);
                    addMenu.Items.Add(builder.New("New Site Group").Handler(() => { explorer.AddSiteGroup(viewModel); }).MenuItem);
                    var addSite = builder.New("_Site").MenuItem;
                    addSite.Items.Add(builder.New("_Blank").Handler(() => { explorer.AddSite(viewModel); }).MenuItem);
                    var lastSiteTemplateId = Config.GetUser(user, "SiteExplorer.LastSiteTemplate", -1);
                    if (lastSiteTemplateId > 0) {
                        var siteTemplate = service.GetSite(lastSiteTemplateId);
                        if (siteTemplate != null) {
                            addSite.Items.Add(builder.New("As '" + siteTemplate.SiteName + "'").Handler(() => {
                                explorer.AddSite(viewModel, lastSiteTemplateId);
                            }).MenuItem);
                        }
                    }

                    addSite.Items.Add(builder.New("From _Template").Handler(() => {
                        int? templateId = explorer.ChooseTemplate(SiteExplorerNodeType.Site);
                        if (templateId.HasValue) {
                            explorer.AddSite(viewModel, templateId.Value);
                            Config.SetUser(PluginManager.Instance.User, "SiteExplorer.LastSiteTemplate", templateId.Value);
                        }
                    }).MenuItem);
                    addMenu.Items.Add(addSite);
                    break;
                case SiteExplorerNodeType.SiteGroup:
                    addMenu.Items.Add(builder.New("New Site Group").Handler(() => { explorer.AddSiteGroup(viewModel); }).MenuItem);
                    addSite = builder.New("_Site").MenuItem;
                    addSite.Items.Add(builder.New("_Blank").Handler(() => { explorer.AddSite(viewModel); }).MenuItem);

                    lastSiteTemplateId = Config.GetUser(user, "SiteExplorer.LastSiteTemplate", -1);
                    if (lastSiteTemplateId > 0) {
                        var siteTemplate = service.GetSite(lastSiteTemplateId);
                        if (siteTemplate != null) {
                            addSite.Items.Add(builder.New("As '" + siteTemplate.SiteName + "'").Handler(() => {
                                explorer.AddSite(viewModel, lastSiteTemplateId);
                            }).MenuItem);
                        }
                    }

                    addSite.Items.Add(builder.New("From _Template").Handler(() => {
                        int? templateId = explorer.ChooseTemplate(SiteExplorerNodeType.Site);
                        if (templateId.HasValue) {
                            explorer.AddSite(viewModel, templateId.Value);
                            Config.SetUser(PluginManager.Instance.User, "SiteExplorer.LastSiteTemplate", templateId.Value);
                        }
                    }).MenuItem);
                    addMenu.Items.Add(addSite);
                    break;
                case SiteExplorerNodeType.Site:
                    addMenu.Items.Add(builder.New("New Trap").Handler(() => { explorer.AddTrap(viewModel); }).MenuItem);

                    var addVisit = builder.New("Site _Visit").MenuItem;
                    addVisit.Items.Add(builder.New("_Blank").Handler(() => { explorer.AddSiteVisit(viewModel); }).MenuItem);

                    var lastSiteVisitTemplateId = Config.GetUser(user, "SiteExplorer.LastSiteVisitTemplate", -1);
                    if (lastSiteVisitTemplateId > 0) {
                        var siteVisitTemplate = service.GetSiteVisit(lastSiteVisitTemplateId);
                        if (siteVisitTemplate != null) {
                            addVisit.Items.Add(builder.New("As '" + siteVisitTemplate.SiteVisitName + "'").Handler(() => {
                                explorer.AddSiteVisit(viewModel, lastSiteVisitTemplateId);
                            }).MenuItem);
                        }
                    }

                    addVisit.Items.Add(builder.New("From _Template").Handler(() => {
                        int? templateId = explorer.ChooseTemplate(SiteExplorerNodeType.SiteVisit);
                        if (templateId.HasValue) {
                            explorer.AddSiteVisit(viewModel, templateId.Value);
                            Config.SetUser(user, "SiteExplorer.LastSiteVisitTemplate", templateId.Value);
                        }
                    }).MenuItem);
                    addMenu.Items.Add(addVisit);

                    break;
                case SiteExplorerNodeType.SiteVisit:
                    var addMaterial = builder.New("_Material").MenuItem;
                    addMaterial.Items.Add(builder.New("_Blank").Handler(() => { explorer.AddMaterial(viewModel); }).MenuItem);

                    var lastMaterialTemplateId = Config.GetUser(user, "SiteExplorer.LastMaterialTemplate", -1);
                    if (lastMaterialTemplateId > 0) {
                        var materialTemplate = service.GetMaterial(lastMaterialTemplateId);
                        if (materialTemplate != null) {
                            addMaterial.Items.Add(builder.New("As '" + materialTemplate.MaterialName + "'").Handler(() => {
                                explorer.AddMaterial(viewModel, lastMaterialTemplateId);
                            }).MenuItem);
                        }
                    }

                    addMaterial.Items.Add(builder.New("From _Template").Handler(() => {
                        int? templateId = explorer.ChooseTemplate(SiteExplorerNodeType.Material);
                        if (templateId.HasValue) {
                            explorer.AddMaterial(viewModel, templateId.Value);
                            Config.SetUser(user, "SiteExplorer.LastMaterialTemplate", templateId);
                        }
                    }).MenuItem);
                    addMenu.Items.Add(addMaterial);
                    break;
                default:
                    break;
            }

            return addMenu;
        }
Exemplo n.º 40
0
        private void ShowCategoryContextMenu()
        {
            PhraseCategoryViewModel category = CurrentCategory;
            if (category == null) {
                return;
            }

            ContextMenu menu = new ContextMenu();

            MenuItemBuilder builder = new MenuItemBuilder();
            menu.Items.Add(builder.New("Delete Category").Handler(() => { DeleteCategory(category); }).MenuItem);
            menu.Items.Add(builder.New("Add New Category").Handler(() => { AddPhraseCategory(); }).MenuItem);
            lvwCategories.ContextMenu = menu;
        }
Exemplo n.º 41
0
        private void ShowPhraseContextMenu()
        {
            PhraseViewModel phrase = lvwPhrases.SelectedItem as PhraseViewModel;

            if (phrase == null) {
                return;
            }

            ContextMenu menu = new ContextMenu();

            MenuItemBuilder builder = new MenuItemBuilder();
            menu.Items.Add(builder.New("Delete").Handler(() => {
                DeletePhrase(phrase);
            }).MenuItem);

            menu.Items.Add(builder.New("Rename").Handler(() => {
                RenamePhrase(phrase);
            }).MenuItem);

            menu.Items.Add(new Separator());

            menu.Items.Add(builder.New("Add new phrase value").Handler(() => {
                AddNewPhraseValue();
            }).MenuItem);

            lvwPhrases.ContextMenu = menu;
        }