/// <override></override> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (provider != null) { #if DEBUG if (!(context.PropertyDescriptor is PropertyDescriptorDg)) { System.Diagnostics.Debug.Print("### The given PropertyDescriptor for {0} is not of type {1}.", value, typeof(PropertyDescriptorDg).Name); } else { System.Diagnostics.Debug.Print("### PropertyDescriptor is of type {1}.", value, typeof(PropertyDescriptorDg).Name); } #endif IWindowsFormsEditorService editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (editorService != null) { // fetch current Design (if changed) if (designBuffer != null && designBuffer != design) { design = designBuffer; } // Examine edited instances and determine whether the list item "Default Style" should be displayed. bool showItemDefaultStyle = false; bool showItemOpenEditor = false; if (context.Instance is Shape) { showItemDefaultStyle = ((Shape)context.Instance).Template != null; showItemOpenEditor = project.SecurityManager.IsGranted(Permission.Designs); } else if (context.Instance is ICapStyle) { showItemDefaultStyle = true; } else if (context.Instance is object[]) { object[] objArr = (object[])context.Instance; int cnt = objArr.Length; showItemDefaultStyle = true; showItemOpenEditor = project.SecurityManager.IsGranted(Permission.Designs); foreach (object obj in objArr) { Shape shape = obj as Shape; if (shape == null || shape.Template == null) { showItemDefaultStyle = false; showItemOpenEditor = false; break; } } } StyleListBox styleListBox = null; try { Type styleType = null; if (value == null) { if (context.PropertyDescriptor.PropertyType == typeof(ICapStyle)) { styleType = typeof(CapStyle); } else if (context.PropertyDescriptor.PropertyType == typeof(IColorStyle)) { styleType = typeof(ColorStyle); } else if (context.PropertyDescriptor.PropertyType == typeof(IFillStyle)) { styleType = typeof(FillStyle); } else if (context.PropertyDescriptor.PropertyType == typeof(ICharacterStyle)) { styleType = typeof(CharacterStyle); } else if (context.PropertyDescriptor.PropertyType == typeof(ILineStyle)) { styleType = typeof(LineStyle); } else if (context.PropertyDescriptor.PropertyType == typeof(IParagraphStyle)) { styleType = typeof(ParagraphStyle); } else { throw new NShapeUnsupportedValueException(context.PropertyDescriptor.PropertyType); } if (project != null) { styleListBox = new StyleListBox(editorService, project, design, styleType, showItemDefaultStyle, showItemOpenEditor); } else { styleListBox = new StyleListBox(editorService, design, styleType, showItemDefaultStyle, showItemOpenEditor); } } else { if (project != null) { styleListBox = new StyleListBox(editorService, project, design, value as Style, showItemDefaultStyle, showItemOpenEditor); } else { styleListBox = new StyleListBox(editorService, design, value as Style, showItemDefaultStyle, showItemOpenEditor); } } editorService.DropDownControl(styleListBox); if (styleListBox.SelectedItem is IStyle) { value = styleListBox.SelectedItem; } else { value = null; } } finally { if (styleListBox != null) { styleListBox.Dispose(); } styleListBox = null; } } } return(value); }
/// <override></override> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (provider != null) { #if DEBUG if (!(context.PropertyDescriptor is PropertyDescriptorDg)) System.Diagnostics.Debug.Print("### The given PropertyDescriptor for {0} is not of type {1}.", value, typeof(PropertyDescriptorDg).Name); else System.Diagnostics.Debug.Print("### PropertyDescriptor is of type {1}.", value, typeof(PropertyDescriptorDg).Name); #endif IWindowsFormsEditorService editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (editorService != null) { // fetch current Design (if changed) if (designBuffer != null && designBuffer != design) design = designBuffer; // Examine edited instances and determine whether the list item "Default Style" should be displayed. bool showItemDefaultStyle = false; bool showItemOpenEditor = false; if (context.Instance is Shape) { showItemDefaultStyle = ((Shape)context.Instance).Template != null; showItemOpenEditor = project.SecurityManager.IsGranted(Permission.Designs); } else if (context.Instance is object[]) { object[] objArr = (object[])context.Instance; int cnt = objArr.Length; showItemDefaultStyle = true; showItemOpenEditor = project.SecurityManager.IsGranted(Permission.Designs); for (int i = 0; i < cnt; ++i) { Shape shape = objArr[i] as Shape; if (shape == null || shape.Template == null) { showItemDefaultStyle = false; showItemOpenEditor = false; break; } } } StyleListBox styleListBox = null; try { Type styleType = null; if (value == null) { if (context.PropertyDescriptor.PropertyType == typeof(ICapStyle)) styleType = typeof(CapStyle); else if (context.PropertyDescriptor.PropertyType == typeof(IColorStyle)) styleType = typeof(ColorStyle); else if (context.PropertyDescriptor.PropertyType == typeof(IFillStyle)) styleType = typeof(FillStyle); else if (context.PropertyDescriptor.PropertyType == typeof(ICharacterStyle)) styleType = typeof(CharacterStyle); else if (context.PropertyDescriptor.PropertyType == typeof(ILineStyle)) styleType = typeof(LineStyle); else if (context.PropertyDescriptor.PropertyType == typeof(IParagraphStyle)) styleType = typeof(ParagraphStyle); else throw new NShapeUnsupportedValueException(context.PropertyDescriptor.PropertyType); if (project != null) styleListBox = new StyleListBox(editorService, project, design, styleType, showItemDefaultStyle, showItemOpenEditor); else styleListBox = new StyleListBox(editorService, design, styleType, showItemDefaultStyle, showItemOpenEditor); } else { if (project != null) styleListBox = new StyleListBox(editorService, project, design, value as Style, showItemDefaultStyle, showItemOpenEditor); else styleListBox = new StyleListBox(editorService, design, value as Style, showItemDefaultStyle, showItemOpenEditor); } editorService.DropDownControl(styleListBox); if (styleListBox.SelectedItem is IStyle) value = styleListBox.SelectedItem; else value = null; } finally { if (styleListBox != null) styleListBox.Dispose(); styleListBox = null; } } } return value; }