/// <summary> /// Populate the <see cref="ContextMenu"/> /// </summary> public virtual void PopulateContextMenu() { this.ContextMenu.Clear(); if (this.SelectedThing == null) { return; } if (!(this.SelectedThing is FolderRowViewModel)) { this.ContextMenu.Add(new ContextMenuItemViewModel("Edit", "CTRL+E", this.UpdateCommand, MenuItemKind.Edit)); this.ContextMenu.Add(new ContextMenuItemViewModel("Inspect", "CTRL+I", this.InspectCommand, MenuItemKind.Inspect)); var deprecableThing = this.SelectedThing.Thing as IDeprecatableThing; if (deprecableThing == null) { this.ContextMenu.Add(new ContextMenuItemViewModel(string.Format("Delete this {0}", this.camelCaseToSpaceConverter.Convert(this.SelectedThing.Thing.ClassKind, null, null, null)), "", this.DeleteCommand, MenuItemKind.Delete)); } else { this.ContextMenu.Add(new ContextMenuItemViewModel(deprecableThing.IsDeprecated ? "Un-Deprecate" : "Deprecate", "", this.DeprecateCommand, MenuItemKind.Deprecate)); } var categorizableThing = this.SelectedThing.Thing as ICategorizableThing; if (categorizableThing != null && categorizableThing.Category.Any()) { var categoriesMenu = new ContextMenuItemViewModel("Categories", "", null, MenuItemKind.None); foreach (var category in categorizableThing.Category) { var removeCategory = new ContextMenuItemViewModel($" Remove {category.Name} [{category.ShortName}]", "", this.RemoveCategoryFromSelectedThing, category, this.PermissionService.CanWrite(this.SelectedThing.Thing), MenuItemKind.Edit); categoriesMenu.SubMenu.Add(removeCategory); } this.ContextMenu.Add(categoriesMenu); } } if (this.SelectedThing != null && this.SelectedThing.ContainedRows.Count > 0) { this.ContextMenu.Add(this.SelectedThing.IsExpanded ? new ContextMenuItemViewModel("Collapse Rows", "", this.CollpaseRowsCommand, MenuItemKind.None, ClassKind.NotThing) : new ContextMenuItemViewModel("Expand Rows", "", this.ExpandRowsCommand, MenuItemKind.None, ClassKind.NotThing)); } }
/// <summary> /// Populate the <see cref="AnnotationMenuGroup"/> property /// </summary> protected virtual void PopulateAnnotationMenuItemGroup() { this.AnnotationMenuGroup.SubMenu.Clear(); if (this.SelectedThing == null) { return; } var model = (EngineeringModel)this.Thing.Container; var annotations = model.ModellingAnnotation.Where(x => x.RelatedThing.Any(rt => rt.ReferencedThing == this.SelectedThing.Thing)); var menugroup = new ReactiveList <ContextMenuItemViewModel>(); foreach (var modellingAnnotationItem in annotations) { var menuitem = new ContextMenuItemViewModel(modellingAnnotationItem.ShortName, "", x => this.ExecuteOpenAnnotationWindow((ModellingAnnotationItem)x), modellingAnnotationItem, true, MenuItemKind.Navigate); menugroup.Add(menuitem); } this.AnnotationMenuGroup.SubMenu.AddRange(menugroup.OrderBy(x => x.Header)); }