private void thumbList_MouseRightButtonUp(object sender, MouseButtonEventArgs e) { var selected = thumbList.SelectedItem as MultimediaLinkViewModel; if (selected != null) { var builder = new ContextMenuBuilder(null); string filename = _tempFileManager.GetContentFileName(selected.MultimediaID, selected.Extension); var verbMenuItems = SystemUtils.GetVerbsAsMenuItems(filename); foreach (MenuItem verbItem in verbMenuItems) { builder.AddMenuItem(verbItem); } builder.Separator(); builder.New("Show linked items...").Handler(() => ShowLinkedItems(selected)).End(); builder.Separator(); builder.New("Save as...").Handler(() => SaveAs(selected)).End(); builder.Separator(); builder.New("Open in system editor...").Handler(() => OpenSelected()).End(); builder.Separator(); builder.New("Properties...").Handler(() => ShowMultimediaProperties(selected)).End(); thumbList.ContextMenu = builder.ContextMenu; } }
void lvw_MouseRightButtonUp(object sender, MouseButtonEventArgs e) { var selected = lvw.SelectedItem as ViewModelBase; if (selected != null) { var list = new List <ViewModelBase>(); list.Add(selected); var commands = PluginManager.Instance.SolicitCommandsForObjects(list); if (commands.Count > 0) { var builder = new ContextMenuBuilder(null); foreach (Command loopvar in commands) { Command cmd = loopvar; // include this in the closure scope, loopvar is outside, hence will always point to the last item... if (cmd is CommandSeparator) { builder.Separator(); } else { builder.New(cmd.Caption).Handler(() => { cmd.CommandAction(selected); }).End(); } } lvw.ContextMenu = builder.ContextMenu; } } }
void lvw_MouseRightButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { var row = lvw.SelectedItem as MatrixRow; if (row != null) { var builder = new ContextMenuBuilder(null); AddLookupItem(builder, LookupType.Site, "SiteID", "intSiteID", "Site Identifier"); AddLookupItem(builder, LookupType.SiteVisit, "SiteVisitID", "intSiteVisitID", "Visit Identifier"); AddLookupItem(builder, LookupType.Material, "MaterialID", "intMaterialID", "Material Identifier"); AddLookupItem(builder, LookupType.Taxon, "BiotaID", "intBiotaID", "Taxon Identifier", "TaxonID"); AddLookupItem(builder, LookupType.Reference, "RefID", "intRefID", "ReferenceID", "Reference Identifier"); AddLookupItem(builder, LookupType.Journal, "JournalID", "intJournalID", "Journal Identifier"); string latColName = null; string longColName = null; foreach (MatrixColumn col in Data.Columns) { if (latColName == null && col.Name.Contains("Lat")) { latColName = col.Name; } if (longColName == null && col.Name.Contains("Long")) { longColName = col.Name; } } AddMapItems(builder, "Lat,Long", "Latitude,Longitude", "Y,X", "Y1,X1", "decimalLatitude,decimalLongitude"); AddMaterialItems(builder, "materialID", "intMaterialID"); if (builder.ContextMenu.HasItems) { builder.Separator(); } if (ContextMenuHandler != null) { ContextMenuHandler(builder, row); if (builder.ContextMenu.HasItems) { builder.Separator(); } } builder.New("Export data...").Handler(() => { Export(); }).End(); builder.Separator(); builder.New("Copy All (including column names)").Handler(() => CopyAll(true)).End(); builder.New("Copy All (excluding column names)").Handler(() => CopyAll(false)).End(); builder.Separator(); builder.New("Copy Selected (including column names)").Handler(() => CopySelected(true)).End(); builder.New("Copy Selected (excluding column names)").Handler(() => CopySelected(false)).End(); lvw.ContextMenu = builder.ContextMenu; } }
private void AddMapItems(ContextMenuBuilder builder, params string[] colAliases) { foreach (string colpair in colAliases) { var bits = colpair.Split(','); if (bits.Length == 2) { if (Data.ContainsColumn(bits[0]) && Data.ContainsColumn(bits[1])) { var latColName = bits[0]; var longColName = bits[1]; if (!string.IsNullOrEmpty(longColName) && !string.IsNullOrEmpty(latColName)) { if (builder.ContextMenu.HasItems) { builder.Separator(); } builder.New("Plot selected rows on Map").Handler(() => { PlotSelected(longColName, latColName); }).End(); builder.New("Plot all rows on Map").Handler(() => { PlotAll(longColName, latColName); }).End(); } break; } } } }
private void ShowContextMenu(HierarchicalViewModelBase selected, FrameworkElement control) { ContextMenuBuilder builder = new ContextMenuBuilder(null); if (_content.CanAddNewItem) { builder.New("Add new").Handler(() => { AddNewItem(selected); }).End(); } if (_content.CanRenameItem) { builder.Separator(); builder.New("Rename").Handler(() => { RenameItem(selected); }).End(); } if (_content.CanDeleteItem) { builder.Separator(); builder.New("Delete").Handler(() => { DeleteItem(selected); }).End(); } if (builder.HasItems) { control.ContextMenu = builder.ContextMenu; } }
private void AddMaterialItems(ContextMenuBuilder builder, params string[] colAliases) { foreach (string col in colAliases) { if (Data.ContainsColumn(col)) { if (builder.ContextMenu.HasItems) { builder.Separator(); } } } }
void tvw_MouseRightButtonUp(object sender, MouseButtonEventArgs e) { var selected = (sender as TreeView).SelectedItem as HierarchicalViewModelBase; if (selected != null) { ContextMenu menu = Provider.GetContextMenu(selected); if (menu == null) { menu = new ContextMenu(); } var builder = new ContextMenuBuilder(null, menu); if (selected is FavoriteViewModel <T> ) { var favViewModel = selected as FavoriteViewModel <T>; if (menu.HasItems) { menu.Items.Add(new Separator()); } if (favViewModel.IsGroup) { builder.New("Rename group").Handler(() => { RenameFavoriteGroup(favViewModel); }).End(); builder.New("Remove favorite group").Handler(() => { DeleteFavoriteGroup(favViewModel); }).End(); } else { builder.New("Remove from favorites").Handler(() => { DeleteFavorite(favViewModel.FavoriteID); }).End(); } } else if (selected is ViewModelPlaceholder) { builder.New("Add favorite group").Handler(() => { AddFavoriteGroup(selected); }).End(); } if (menu.HasItems) { Provider.FavoritesTree.ContextMenu = menu; } else { Provider.FavoritesTree.ContextMenu = null; } } }
private void Border_MouseRightButtonUp(object sender, MouseButtonEventArgs e) { lst.ContextMenu = null; var selected = lst.SelectedItem as AssociateReportViewModel; if (selected != null) { var builder = new ContextMenuBuilder(null); builder.New("Edit " + selected.FromViewModel.DisplayLabel + " (" + selected.RelationFromTo + ")").Handler(() => { EditAssociatedItem(selected.Model.FromCatID, selected.Model.FromIntraCatID); }).End(); builder.Separator(); builder.New("Pin " + selected.FromViewModel.DisplayLabel + " (" + selected.RelationFromTo + ") to pin board").Handler(() => PinAssociatedItem(selected.Model.FromCatID, selected.Model.FromIntraCatID)).End(); lst.ContextMenu = builder.ContextMenu; } }
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); }
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); } } } }