protected override void OnDragDrop(DragEventArgs de) { base.OnDragDrop(de); var insertionIndex = (_insertionBeforeControl == null) ? Panel.Controls.Count : Panel.Controls.IndexOf(_insertionBeforeControl); var transaction = DesignerHost.CreateTransaction($"Move {GetSelectedControlsString()} to position {insertionIndex} in {Panel.Name}"); using (transaction) using (Panel.ChangingComponentProperty(nameof(Panel.Controls))) { SelectionService.GetSelectedComponents() .OfType <Control>() .ToList() .ForEach(control => { var currentIndex = Panel.Controls.GetChildIndex(control); if (currentIndex >= 0 && currentIndex < insertionIndex) { insertionIndex--; } Panel.Controls.SetChildIndex(control, insertionIndex++); }); transaction.Commit(); } ClearInsertionDisplay(); }
internal override bool SendNotification(GridEntry entry, Notify notification) { DesignerTransaction transaction = DesignerHost?.CreateTransaction(); try { return(base.SendNotification(entry, notification)); } finally { transaction?.Commit(); } }
protected internal override bool NotifyChildValue(GridEntry entry, Notify type) { DesignerTransaction transaction = DesignerHost?.CreateTransaction(); try { return(base.NotifyChildValue(entry, type)); } finally { transaction?.Commit(); } }
private DesignerTransaction CreateDesignerTransaction(String description) { try { return(DesignerHost.CreateTransaction(description)); } catch (CheckoutException exc) { if (exc != CheckoutException.Canceled) { throw; } } return(null); }
/// <summary> /// Navigates code to the given event. /// </summary> protected bool ViewEvent(object obj, string newHandler, EventDescriptor eventdesc, bool alwaysNavigate) { object value = GetPropertyValueCore(obj); string handler = value as string; if (handler == null && value != null && TypeConverter != null && TypeConverter.CanConvertTo(typeof(string))) { handler = TypeConverter.ConvertToString(value); } if (newHandler == null && !string.IsNullOrEmpty(handler)) { newHandler = handler; } else if (handler == newHandler && !string.IsNullOrEmpty(newHandler)) { return(true); } IComponent component = obj as IComponent; if (component == null && propertyInfo is MergePropertyDescriptor) { // It's possible that multiple objects are selected, and we're trying to create an event for each of them // Array objArray = obj as Array; if (objArray != null && objArray.Length > 0) { component = objArray.GetValue(0) as IComponent; } } if (component == null) { return(false); } if (propertyInfo.IsReadOnly) { return(false); } if (eventdesc == null) { if (eventBindings == null) { eventBindings = (IEventBindingService)GetService(typeof(IEventBindingService)); } if (eventBindings != null) { eventdesc = eventBindings.GetEvent(propertyInfo); } } IDesignerHost host = this.DesignerHost; DesignerTransaction trans = null; try { // This check can cause exceptions if the event has unreferenced dependencies, which we want to cath. // This must be done before the transaction is started or the commit/cancel will also throw. if (eventdesc.EventType == null) { return(false); } if (host != null) { string compName = component.Site != null ? component.Site.Name : component.GetType().Name; trans = DesignerHost.CreateTransaction(string.Format(SR.WindowsFormsSetEvent, compName + "." + this.PropertyName)); } if (eventBindings == null) { ISite site = component.Site; if (site != null) { eventBindings = (IEventBindingService)site.GetService(typeof(IEventBindingService)); } } if (newHandler == null && eventBindings != null) { newHandler = eventBindings.CreateUniqueMethodName(component, eventdesc); } if (newHandler != null) { // now walk through all the matching methods to see if this one exists. // if it doesn't we'll wanna show code. // if (eventBindings != null) { bool methodExists = false; foreach (string methodName in eventBindings.GetCompatibleMethods(eventdesc)) { if (newHandler == methodName) { methodExists = true; break; } } if (!methodExists) { alwaysNavigate = true; } } try { propertyInfo.SetValue(obj, newHandler); } catch (InvalidOperationException ex) { if (trans != null) { trans.Cancel(); trans = null; } if (this.GridEntryHost != null && this.GridEntryHost is PropertyGridView) { PropertyGridView pgv = this.GridEntryHost as PropertyGridView; pgv.ShowInvalidMessage(newHandler, obj, ex); } return(false); } } if (alwaysNavigate && eventBindings != null) { targetBindingService = eventBindings; targetComponent = component; targetEventdesc = eventdesc; Application.Idle += new EventHandler(PropertyDescriptorGridEntry.ShowCodeIdle); } } catch { if (trans != null) { trans.Cancel(); trans = null; } throw; } finally { if (trans != null) { trans.Commit(); } } return(true); }