private void EndTransaction(object obj, System.ComponentModel.Design.DesignerTransaction tran, object oldValue, object newValue, bool commit) { if (tran == null) { this.OnValueChanged(obj, new PropertyChangedEventArgs(this.Name)); return; } if (commit) { IComponent component = obj as IComponent; System.ComponentModel.Design.IComponentChangeService componentChangeService = (System.ComponentModel.Design.IComponentChangeService)component.Site.GetService(typeof(System.ComponentModel.Design.IComponentChangeService)); if (componentChangeService != null) { componentChangeService.OnComponentChanged(component, this, oldValue, newValue); } tran.Commit(); this.OnValueChanged(obj, new PropertyChangedEventArgs(this.Name)); } else { tran.Cancel(); } }
public override bool OnMouseUp(Glyph g, MouseButtons button) { try { if (this.dragging) { if (this.dragManager != null) { this.dragManager.OnMouseUp(); this.dragManager = null; this.lastSnapOffset = Point.Empty; this.didSnap = false; } if ((this.resizeComponents != null) && (this.resizeComponents.Length > 0)) { PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Width"]; PropertyDescriptor descriptor2 = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Height"]; PropertyDescriptor descriptor3 = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Top"]; PropertyDescriptor descriptor4 = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Left"]; for (int i = 0; i < this.resizeComponents.Length; i++) { if ((descriptor != null) && (((Control) this.resizeComponents[i].resizeControl).Width != this.resizeComponents[i].resizeBounds.Width)) { descriptor.SetValue(this.resizeComponents[i].resizeControl, ((Control) this.resizeComponents[i].resizeControl).Width); } if ((descriptor2 != null) && (((Control) this.resizeComponents[i].resizeControl).Height != this.resizeComponents[i].resizeBounds.Height)) { descriptor2.SetValue(this.resizeComponents[i].resizeControl, ((Control) this.resizeComponents[i].resizeControl).Height); } if ((descriptor3 != null) && (((Control) this.resizeComponents[i].resizeControl).Top != this.resizeComponents[i].resizeBounds.Y)) { descriptor3.SetValue(this.resizeComponents[i].resizeControl, ((Control) this.resizeComponents[i].resizeControl).Top); } if ((descriptor4 != null) && (((Control) this.resizeComponents[i].resizeControl).Left != this.resizeComponents[i].resizeBounds.X)) { descriptor4.SetValue(this.resizeComponents[i].resizeControl, ((Control) this.resizeComponents[i].resizeControl).Left); } if ((this.resizeComponents[i].resizeControl == this.primaryControl) && (this.statusCommandUI != null)) { this.statusCommandUI.SetStatusInformation(this.primaryControl); } } } } if (this.resizeTransaction != null) { DesignerTransaction resizeTransaction = this.resizeTransaction; this.resizeTransaction = null; using (resizeTransaction) { resizeTransaction.Commit(); } } } finally { this.OnLoseCapture(g, EventArgs.Empty); } return false; }
internal static void SaveGridState(DesignerTransaction dt, Grid grid, IComponentChangeService service) { service.OnComponentChanging(grid, null); service.OnComponentChanged(grid, null, null, null); dt.Commit(); }
void EndTransaction (object obj, DesignerTransaction tran, object oldValue, object newValue, bool commit) { if (tran == null) return; if (commit) { IComponent com = obj as IComponent; IComponentChangeService ccs = (IComponentChangeService) com.Site.GetService (typeof(IComponentChangeService)); if (ccs != null) ccs.OnComponentChanged (com, Property, oldValue, newValue); tran.Commit (); } else tran.Cancel (); }
/// <summary> /// Creates a method signature in the source code file for the default event on the component and navigates /// the user's cursor to that location in preparation to assign the default action. /// </summary> public virtual void DoDefaultAction() { // If the event binding service is not available, there is nothing much we can do, so just return. if (!TryGetService(out IEventBindingService ebs) || !TryGetService(out ISelectionService selectionService)) { return; } ICollection components = selectionService.GetSelectedComponents(); EventDescriptor thisDefaultEvent = null; string thisHandler = null; IDesignerHost host = GetService <IDesignerHost>(); DesignerTransaction t = null; if (components is null) { return; } try { foreach (IComponent comp in components.OfType <IComponent>()) { EventDescriptor defaultEvent = TypeDescriptor.GetDefaultEvent(comp); PropertyDescriptor defaultPropEvent = null; bool eventChanged = false; if (defaultEvent is not null) { defaultPropEvent = ebs.GetEventProperty(defaultEvent); } // If we couldn't find a property for this event, or of the property is read only, then abort. if (defaultPropEvent is null || defaultPropEvent.IsReadOnly) { continue; } try { if (host is not null && t is null) { t = host.CreateTransaction(string.Format(SR.ComponentDesignerAddEvent, defaultEvent.Name)); } } catch (CheckoutException cxe) when(cxe == CheckoutException.Canceled) { return; } // handler will be null if there is no explicit event hookup in the parsed init method object result = defaultPropEvent.GetValue(comp); string handler = result as string; if (handler is null) { // Skip invalid properties. if (result is not null) { continue; } eventChanged = true; handler = ebs.CreateUniqueMethodName(comp, defaultEvent); } else { // ensure the handler is still there eventChanged = true; ICollection methods = ebs.GetCompatibleMethods(defaultEvent); if (methods is not null) { foreach (string compatibleMethod in methods.OfType <string>()) { if (handler == compatibleMethod) { eventChanged = false; break; } } } } // Save the new value... BEFORE navigating to it! // s_codemarkers.CodeMarker(CodeMarkerEvent.perfFXBindEventDesignToCode); if (eventChanged) { defaultPropEvent.SetValue(comp, handler); } if (Component == comp) { thisDefaultEvent = defaultEvent; thisHandler = handler; } } } catch (InvalidOperationException) { t?.Cancel(); t = null; } finally { t?.Commit(); } // Now show the event code. if (thisHandler is not null && thisDefaultEvent is not null) { ebs.ShowCode(Component, thisDefaultEvent); } }
void EndTransaction (object obj, DesignerTransaction tran, object oldValue, object newValue, bool commit) { if (tran == null) { // FIXME: EventArgs might be differen type. OnValueChanged (obj, new PropertyChangedEventArgs (Name)); return; } if (commit) { IComponent com = obj as IComponent; IComponentChangeService ccs = (IComponentChangeService) com.Site.GetService (typeof(IComponentChangeService)); if (ccs != null) ccs.OnComponentChanged (com, this, oldValue, newValue); tran.Commit (); // FIXME: EventArgs might be differen type. OnValueChanged (obj, new PropertyChangedEventArgs (Name)); } else tran.Cancel (); }
public override bool OnMouseUp(Glyph g, MouseButtons button) { if (this.pushedBehavior) { this.FinishResize(); if (this.resizeTransaction != null) { DesignerTransaction resizeTransaction = this.resizeTransaction; this.resizeTransaction = null; using (resizeTransaction) { resizeTransaction.Commit(); } this.resizeProp = null; } } return false; }
/// <summary> /// This will set value to be the new value of this property on the /// component by invoking the setXXX method on the component. If the /// value specified is invalid, the component should throw an exception /// which will be passed up. The component designer should design the /// property so that getXXX following a setXXX should return the value /// passed in if no exception was thrown in the setXXX call. /// </summary> public override void SetValue(object component, object value) { // Argument, state checking. Is it ok to set this event? if (IsReadOnly) { throw new InvalidOperationException(string.Format(SR.EventBindingServiceEventReadOnly, Name)) { HelpLink = SR.EventBindingServiceEventReadOnly }; } if (value is not null and not string) { throw new ArgumentException(string.Format(SR.EventBindingServiceBadArgType, Name, typeof(string).Name)) { HelpLink = SR.EventBindingServiceBadArgType }; } string name = (string)value; if (name is not null && name.Length == 0) { name = null; } // Obtain the site for the component. Note that this can be a site // to a parent component if we can get to the reference service. ISite site = null; if (component is IComponent component1) { site = component1.Site; } if (site is null && _eventService._provider.TryGetService(out IReferenceService referenceService)) { IComponent baseComponent = referenceService.GetComponent(component); if (baseComponent is not null) { site = baseComponent.Site; } } if (site is null) { throw new InvalidOperationException(SR.EventBindingServiceNoSite) { HelpLink = SR.EventBindingServiceNoSite }; } // The dictionary service is where we store the actual event method name. if (!site.TryGetService(out IDictionaryService dictionaryService)) { throw new InvalidOperationException(string.Format(SR.EventBindingServiceMissingService, typeof(IDictionaryService).Name)) { HelpLink = SR.EventBindingServiceMissingService }; } // Get the old method name, ensure that they are different, and then continue. ReferenceEventClosure key = new(component, this); string oldName = (string)dictionaryService.GetValue(key); if (ReferenceEquals(oldName, name)) { return; } if (oldName is not null && name is not null && oldName.Equals(name)) { return; } // Before we continue our work, ensure that the name is actually valid. if (name is not null) { _eventService.ValidateMethodName(name); } // If there is a designer host, create a transaction so there is a // nice name for this change. We don't want a name like // "Change property 'Click', because to users, this isn't a property. DesignerTransaction transaction = null; if (site.TryGetService(out IDesignerHost host)) { transaction = host.CreateTransaction(string.Format(SR.EventBindingServiceSetValue, site.Name, name)); } try { // The names are different. Fire a changing event to make // sure it's OK to perform the change. if (site.TryGetService(out IComponentChangeService changeService)) { try { changeService.OnComponentChanging(component, this); changeService.OnComponentChanging(component, Event); } catch (CheckoutException coEx) when(coEx == CheckoutException.Canceled) { return; } } // Less chance of success of adding a new method name, so // don't release the old name until we verify that adding // the new one actually succeeded. if (name is not null) { _eventService.UseMethod((IComponent)component, Event, name); } if (oldName is not null) { _eventService.FreeMethod((IComponent)component, Event, oldName); } dictionaryService.SetValue(key, name); if (changeService is not null) { changeService.OnComponentChanged(component, Event); changeService.OnComponentChanged(component, this, oldName, name); } OnValueChanged(component, EventArgs.Empty); transaction?.Commit(); } finally { if (transaction is not null) { ((IDisposable)transaction).Dispose(); } } }
// This method is called when a user double-clicks (the representation of) a component. // Tries to bind the default event to a method or creates a new one. // public virtual void DoDefaultAction() { IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost)); DesignerTransaction transaction = null; if (host != null) { transaction = host.CreateTransaction("ComponentDesigner_AddEvent"); } IEventBindingService eventBindingService = GetService(typeof(IEventBindingService)) as IEventBindingService; EventDescriptor defaultEventDescriptor = null; if (eventBindingService != null) { ISelectionService selectionService = this.GetService(typeof(ISelectionService)) as ISelectionService; try { if (selectionService != null) { ICollection selectedComponents = selectionService.GetSelectedComponents(); foreach (IComponent component in selectedComponents) { EventDescriptor eventDescriptor = TypeDescriptor.GetDefaultEvent(component); if (eventDescriptor != null) { PropertyDescriptor eventProperty = eventBindingService.GetEventProperty(eventDescriptor); if (eventProperty != null && !eventProperty.IsReadOnly) { string methodName = eventProperty.GetValue(component) as string; bool newMethod = true; if (methodName != null || methodName != String.Empty) { ICollection compatibleMethods = eventBindingService.GetCompatibleMethods(eventDescriptor); foreach (string signature in compatibleMethods) { if (signature == methodName) { newMethod = false; break; } } } if (newMethod) { if (methodName == null) { methodName = eventBindingService.CreateUniqueMethodName(component, eventDescriptor); } eventProperty.SetValue(component, methodName); } if (component == _component) { defaultEventDescriptor = eventDescriptor; } } } } } } catch { if (transaction != null) { transaction.Cancel(); transaction = null; } } finally { if (transaction != null) { transaction.Commit(); } } if (defaultEventDescriptor != null) { eventBindingService.ShowCode(_component, defaultEventDescriptor); } } }
public virtual void DoDefaultAction() { IEventBindingService service = (IEventBindingService)this.GetService(typeof(IEventBindingService)); if (service != null) { ISelectionService service2 = (ISelectionService)this.GetService(typeof(ISelectionService)); if (service2 != null) { ICollection selectedComponents = service2.GetSelectedComponents(); EventDescriptor e = null; string str = null; IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost)); DesignerTransaction transaction = null; try { foreach (object obj2 in selectedComponents) { if (!(obj2 is IComponent)) { continue; } EventDescriptor defaultEvent = TypeDescriptor.GetDefaultEvent(obj2); PropertyDescriptor eventProperty = null; string str2 = null; bool flag = false; if (defaultEvent != null) { eventProperty = service.GetEventProperty(defaultEvent); } if ((eventProperty != null) && !eventProperty.IsReadOnly) { try { if ((host != null) && (transaction == null)) { transaction = host.CreateTransaction(System.Design.SR.GetString("ComponentDesignerAddEvent", new object[] { defaultEvent.Name })); } } catch (CheckoutException exception) { if (exception != CheckoutException.Canceled) { throw exception; } return; } str2 = (string)eventProperty.GetValue(obj2); if (str2 == null) { flag = true; str2 = service.CreateUniqueMethodName((IComponent)obj2, defaultEvent); } else { flag = true; foreach (string str3 in service.GetCompatibleMethods(defaultEvent)) { if (str2 == str3) { flag = false; break; } } } codemarkers.CodeMarker(CodeMarkerEvent.perfFXBindEventDesignToCode); if (flag && (eventProperty != null)) { eventProperty.SetValue(obj2, str2); } if (this.component == obj2) { e = defaultEvent; str = str2; } } } } catch (InvalidOperationException) { if (transaction != null) { transaction.Cancel(); transaction = null; } } finally { if (transaction != null) { transaction.Commit(); } } if ((str != null) && (e != null)) { service.ShowCode(this.component, e); } } } }
/// <include file='doc\ComponentDesigner.uex' path='docs/doc[@for="ComponentDesigner.DoDefaultAction"]/*' /> /// <devdoc> /// <para>Creates a method signature in the source code file for the default event on the component and navigates /// the user's cursor to that location in preparation to assign /// the default action.</para> /// </devdoc> public virtual void DoDefaultAction() { ISelectionService selectionService = (ISelectionService)GetService(typeof(ISelectionService)); ICollection components = selectionService.GetSelectedComponents(); // hmmmm, I sure could use some services. // IEventBindingService eps = (IEventBindingService)GetService(typeof(IEventBindingService)); EventDescriptor thisDefaultEvent = null; string thisHandler = null; IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); DesignerTransaction t = null; try { foreach (object comp in components) { if (!(comp is IComponent)) { continue; } EventDescriptor defaultEvent = TypeDescriptor.GetDefaultEvent(comp); PropertyDescriptor defaultPropEvent = null; string handler = null; bool eventChanged = false; if (defaultEvent != null) { if (CompModSwitches.CommonDesignerServices.Enabled) { Debug.Assert(eps != null, "IEventBindingService not found"); } if (eps != null) { defaultPropEvent = eps.GetEventProperty(defaultEvent); } } // If we couldn't find a property for this event, or of the property is read only, then // abort. // if (defaultPropEvent == null || defaultPropEvent.IsReadOnly) { continue; } try { if (host != null && t == null) { t = host.CreateTransaction(SR.GetString(SR.ComponentDesignerAddEvent, defaultEvent.Name)); } } catch (CheckoutException cxe) { if (cxe == CheckoutException.Canceled) { return; } throw cxe; } // handler will be null if there is no explicit event hookup in the parsed init method handler = (string)defaultPropEvent.GetValue(comp); if (handler == null) { eventChanged = true; handler = eps.CreateUniqueMethodName((IComponent)comp, defaultEvent); } else { // ensure the handler is still there eventChanged = true; foreach (string compatibleMethod in eps.GetCompatibleMethods(defaultEvent)) { if (handler == compatibleMethod) { eventChanged = false; break; } } } // Save the new value... BEFORE navigating to it! // if (eventChanged && defaultPropEvent != null) { defaultPropEvent.SetValue(comp, handler); } if (component == comp) { thisDefaultEvent = defaultEvent; thisHandler = handler; } } } finally { if (t != null) { t.Commit(); } } // Now show the event code. // if (thisHandler != null && thisDefaultEvent != null) { eps.ShowCode(component, thisDefaultEvent); } }
public override void SetValue(object component, object value) { if (this.IsReadOnly) { Exception exception = new InvalidOperationException(System.Design.SR.GetString("EventBindingServiceEventReadOnly", new object[] { this.Name })) { HelpLink = "EventBindingServiceEventReadOnly" }; throw exception; } if ((value != null) && !(value is string)) { Exception exception2 = new ArgumentException(System.Design.SR.GetString("EventBindingServiceBadArgType", new object[] { this.Name, typeof(string).Name })) { HelpLink = "EventBindingServiceBadArgType" }; throw exception2; } string objB = (string)value; if ((objB != null) && (objB.Length == 0)) { objB = null; } ISite site = null; if (component is IComponent) { site = ((IComponent)component).Site; } if (site == null) { IReferenceService service = this._eventSvc._provider.GetService(typeof(IReferenceService)) as IReferenceService; if (service != null) { IComponent component2 = service.GetComponent(component); if (component2 != null) { site = component2.Site; } } } if (site == null) { Exception exception3 = new InvalidOperationException(System.Design.SR.GetString("EventBindingServiceNoSite")) { HelpLink = "EventBindingServiceNoSite" }; throw exception3; } IDictionaryService service2 = site.GetService(typeof(IDictionaryService)) as IDictionaryService; if (service2 == null) { Exception exception4 = new InvalidOperationException(System.Design.SR.GetString("EventBindingServiceMissingService", new object[] { typeof(IDictionaryService).Name })) { HelpLink = "EventBindingServiceMissingService" }; throw exception4; } ReferenceEventClosure key = new ReferenceEventClosure(component, this); string objA = (string)service2.GetValue(key); if (!object.ReferenceEquals(objA, objB) && (((objA == null) || (objB == null)) || !objA.Equals(objB))) { if (objB != null) { this._eventSvc.ValidateMethodName(objB); } IDesignerHost host = site.GetService(typeof(IDesignerHost)) as IDesignerHost; DesignerTransaction transaction = null; if (host != null) { transaction = host.CreateTransaction(System.Design.SR.GetString("EventBindingServiceSetValue", new object[] { site.Name, objB })); } try { IComponentChangeService service3 = site.GetService(typeof(IComponentChangeService)) as IComponentChangeService; if (service3 != null) { try { service3.OnComponentChanging(component, this); service3.OnComponentChanging(component, this.Event); } catch (CheckoutException exception5) { if (exception5 != CheckoutException.Canceled) { throw; } return; } } if (objB != null) { this._eventSvc.UseMethod((IComponent)component, this._eventDesc, objB); } if (objA != null) { this._eventSvc.FreeMethod((IComponent)component, this._eventDesc, objA); } service2.SetValue(key, objB); if (service3 != null) { service3.OnComponentChanged(component, this.Event, null, null); service3.OnComponentChanged(component, this, objA, objB); } this.OnValueChanged(component, EventArgs.Empty); if (transaction != null) { transaction.Commit(); } } finally { if (transaction != null) { ((IDisposable)transaction).Dispose(); } } } }
/// <summary> /// Creates a method signature in the source code file for the default event on the component and navigates the user's cursor to that location in preparation to assign the default action. /// </summary> public virtual void DoDefaultAction() { IEventBindingService eps = (IEventBindingService)GetService(typeof(IEventBindingService)); //If the event binding service is not available, there is nothing much we can do, so just return. if (eps == null) { return; } ISelectionService selectionService = (ISelectionService)GetService(typeof(ISelectionService)); if (selectionService == null) { return; } ICollection components = selectionService.GetSelectedComponents(); EventDescriptor thisDefaultEvent = null; string thisHandler = null; IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); DesignerTransaction t = null; try { foreach (object comp in components) { if (!(comp is IComponent)) { continue; } EventDescriptor defaultEvent = TypeDescriptor.GetDefaultEvent(comp); PropertyDescriptor defaultPropEvent = null; string handler = null; bool eventChanged = false; if (defaultEvent != null) { defaultPropEvent = eps.GetEventProperty(defaultEvent); } // If we couldn't find a property for this event, or of the property is read only, then abort. if (defaultPropEvent == null || defaultPropEvent.IsReadOnly) { continue; } try { if (host != null && t == null) { t = host.CreateTransaction(string.Format(SR.ComponentDesignerAddEvent, defaultEvent.Name)); } } catch (CheckoutException cxe) { if (cxe == CheckoutException.Canceled) { return; } throw cxe; } // handler will be null if there is no explicit event hookup in the parsed init method handler = (string)defaultPropEvent.GetValue(comp); if (handler == null) { eventChanged = true; handler = eps.CreateUniqueMethodName((IComponent)comp, defaultEvent); } else { // ensure the handler is still there eventChanged = true; foreach (string compatibleMethod in eps.GetCompatibleMethods(defaultEvent)) { if (handler == compatibleMethod) { eventChanged = false; break; } } } // Save the new value... BEFORE navigating to it! //s_codemarkers.CodeMarker(CodeMarkerEvent.perfFXBindEventDesignToCode); if (eventChanged && defaultPropEvent != null) { defaultPropEvent.SetValue(comp, handler); } if (_component == comp) { thisDefaultEvent = defaultEvent; thisHandler = handler; } } } catch (InvalidOperationException) { // VSWhidbey 434433 - If the doc data for this designer is currently locked, we will get an exception here. // In this case, just eat the exception. if (t != null) { t.Cancel(); t = null; } } finally { if (t != null) { t.Commit(); } } // Now show the event code. if (thisHandler != null && thisDefaultEvent != null) { eps.ShowCode(_component, thisDefaultEvent); } }