コード例 #1
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;
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
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;
        }
コード例 #6
0
        void lvwResults_PreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            ContextMenuBuilder builder = new ContextMenuBuilder(null);

            builder.New("Add New").Handler(() => AddNew()).End();
            builder.Separator();
            builder.New("Delete").Handler(() => DeleteSelected()).End();
            builder.Separator();
            MenuItemBuilder b        = new MenuItemBuilder();
            var             selected = lvwResults.SelectedItem as ReferenceSearchResultViewModel;
            var             mnuFav   = b.New("Add to Favorites").MenuItem;

            mnuFav.Items.Add(b.New("User specific").Handler(() => { _favorites.AddToFavorites(selected, false); }).MenuItem);
            mnuFav.Items.Add(b.New("Global").Handler(() => { _favorites.AddToFavorites(selected, true); }).MenuItem);
            builder.AddMenuItem(mnuFav);
            builder.Separator();
            builder.New("Pin to pinboard").Handler(() => { PinSelected(); }).End();
            builder.New("Edit").Handler(() => EditSelected()).End();

            lvwResults.ContextMenu = builder.ContextMenu;
        }
コード例 #7
0
ファイル: MaterialExplorer.xaml.cs プロジェクト: kehh/biolink
        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;
            }
        }
コード例 #8
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);
        }
コード例 #9
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;
        }
コード例 #10
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);
        }
コード例 #11
0
        private MenuItem CreateFavoriteMenuItems()
        {
            MenuItem add = _builder.New("Add to favorites").MenuItem;

            add.Items.Add(_builder.New("User specific").Handler(() => { Explorer.AddToFavorites(Taxon, false); }).MenuItem);
            add.Items.Add(_builder.New("Global").Handler(() => { Explorer.AddToFavorites(Taxon, true); }).MenuItem);
            return(add);
        }
コード例 #12
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;
        }
コード例 #13
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;
 }
コード例 #14
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;
        }
コード例 #15
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);
            }
        }
コード例 #16
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;
            }
        }
コード例 #17
0
ファイル: PhraseManager.xaml.cs プロジェクト: kehh/biolink
        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;
        }
コード例 #18
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);
                    }
                }
            }
        }
コード例 #19
0
ファイル: PhraseManager.xaml.cs プロジェクト: kehh/biolink
        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;
        }