public override void ResetValue(object component) { object invokee = MemberDescriptor.GetInvokee(this._componentType, component); DefaultValueAttribute defaultValueAttribute = (DefaultValueAttribute)this.Attributes[typeof(DefaultValueAttribute)]; if (defaultValueAttribute != null) { this.SetValue(invokee, defaultValueAttribute.Value); } System.ComponentModel.Design.DesignerTransaction tran = this.CreateTransaction(component, "Reset Property '" + this.Name + "'"); object value = this.GetValue(invokee); try { MethodInfo methodInfo = this.FindPropertyMethod(invokee, "Reset"); if (methodInfo != null) { methodInfo.Invoke(invokee, null); } this.EndTransaction(component, tran, value, this.GetValue(invokee), true); } catch { this.EndTransaction(component, tran, value, this.GetValue(invokee), false); throw; } }
public SmartTagTransactions(string transactionname,DesignerActionList list,Control ctrl) { this.actionList = list; this.ctrl = ctrl; host = (IDesignerHost)this.actionList.GetService(typeof(IDesignerHost)); this.transaction = host.CreateTransaction(transactionname); changeService = (IComponentChangeService)this.actionList.GetService(typeof(IComponentChangeService)); changeService.OnComponentChanging(ctrl,null); }
public UISelectionService (IServiceProvider serviceProvider) { if (serviceProvider == null) throw new ArgumentNullException ("serviceProvider"); _serviceProvider = serviceProvider; _transaction = null; _selectionService = serviceProvider.GetService (typeof (ISelectionService)) as ISelectionService; if (_selectionService == null) { IServiceContainer serviceContainer = serviceProvider.GetService (typeof (IServiceContainer)) as IServiceContainer; _selectionService = new SelectionService (serviceContainer); serviceContainer.AddService (typeof (ISelectionService), (ISelectionService) _selectionService); } _selectionService.SelectionChanged += new EventHandler (OnSelectionChanged); }
public override void SetValue(object component, object value) { System.ComponentModel.Design.DesignerTransaction tran = this.CreateTransaction(component, "Set Property '" + this.Name + "'"); object invokee = MemberDescriptor.GetInvokee(this._componentType, component); object value2 = this.GetValue(invokee); try { this.InitAccessors(); this.setter.SetValue(invokee, value, null); this.EndTransaction(component, tran, value2, value, true); } catch { this.EndTransaction(component, tran, value2, value, false); throw; } }
private System.ComponentModel.Design.DesignerTransaction CreateTransaction(object obj, string description) { IComponent component = obj as IComponent; if (component == null || component.Site == null) { return(null); } System.ComponentModel.Design.IDesignerHost designerHost = (System.ComponentModel.Design.IDesignerHost)component.Site.GetService(typeof(System.ComponentModel.Design.IDesignerHost)); if (designerHost == null) { return(null); } System.ComponentModel.Design.DesignerTransaction result = designerHost.CreateTransaction(description); System.ComponentModel.Design.IComponentChangeService componentChangeService = (System.ComponentModel.Design.IComponentChangeService)component.Site.GetService(typeof(System.ComponentModel.Design.IComponentChangeService)); if (componentChangeService != null) { componentChangeService.OnComponentChanging(component, this); } return(result); }
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(); } }
private void ComponentChangeSvc_ComponentRemoved(object sender, ComponentEventArgs e) { if ((e.Component is ToolStripItem) && (((ToolStripItem) e.Component).Owner == base.Component)) { ToolStripItem item = (ToolStripItem) e.Component; int index = this.ToolStrip.Items.IndexOf(item); try { if (index != -1) { this.ToolStrip.Items.Remove(item); base.RaiseComponentChanged(TypeDescriptor.GetProperties(base.Component)["Items"], null, null); } } finally { if (this._pendingTransaction != null) { this._pendingTransaction.Commit(); this._pendingTransaction = null; } } if (this.ToolStrip.Items.Count > 1) { index = Math.Min(this.ToolStrip.Items.Count - 1, index); index = Math.Max(0, index); } else { index = -1; } this.LayoutToolStrip(); if (item.Placement == ToolStripItemPlacement.Overflow) { this.RemoveBodyGlyphsForOverflow(); this.AddBodyGlyphsForOverflow(); } if ((this.toolStripAdornerWindowService != null) && (this.boundsToInvalidate != Rectangle.Empty)) { this.toolStripAdornerWindowService.Invalidate(this.boundsToInvalidate); base.BehaviorService.Invalidate(this.boundsToInvalidate); } if (this.KeyboardHandlingService.CutOrDeleteInProgress) { IComponent component = (index == -1) ? ((IComponent) this.ToolStrip) : ((IComponent) this.ToolStrip.Items[index]); if (component != null) { if (component is DesignerToolStripControlHost) { if (this.KeyboardHandlingService != null) { this.KeyboardHandlingService.SelectedDesignerControl = component; } this.SelectionService.SetSelectedComponents(null, SelectionTypes.Replace); } else { this.SelectionService.SetSelectedComponents(new IComponent[] { component }, SelectionTypes.Replace); } } } } }
private void ComponentChangeSvc_ComponentAdded(object sender, ComponentEventArgs e) { if (this.toolStripSelected && (e.Component is System.Windows.Forms.ToolStrip)) { this.toolStripSelected = false; } ToolStripItem component = e.Component as ToolStripItem; try { if (((component != null) && this._addingItem) && !component.IsOnDropDown) { this._addingItem = false; if (this.CacheItems) { this.items.Add(component); } else { int count = this.ToolStrip.Items.Count; try { base.RaiseComponentChanging(TypeDescriptor.GetProperties(base.Component)["Items"]); ToolStripItem primarySelection = this.SelectionService.PrimarySelection as ToolStripItem; if (primarySelection != null) { if (primarySelection.Owner == this.ToolStrip) { int index = this.ToolStrip.Items.IndexOf(primarySelection); this.ToolStrip.Items.Insert(index, component); } } else if (count > 0) { this.ToolStrip.Items.Insert(count - 1, component); } else { this.ToolStrip.Items.Add(component); } } finally { base.RaiseComponentChanged(TypeDescriptor.GetProperties(base.Component)["Items"], null, null); } } } } catch { if (this._pendingTransaction != null) { this._pendingTransaction.Cancel(); this._pendingTransaction = null; this._insertMenuItemTransaction = null; } } finally { if (this._pendingTransaction != null) { this._pendingTransaction.Commit(); this._pendingTransaction = null; this._insertMenuItemTransaction = null; } } }
// 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); } } }
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 (); }
protected virtual void ComponentChangeComponentAdded(object sender, ComponentEventArgs e) { if (m_AddingItem) { m_AddingItem = false; IComponentChangeService cc = this.GetService(typeof(IComponentChangeService)) as IComponentChangeService; if (cc != null) cc.OnComponentChanging(this.Control, null); this.GetDefaultNewItemContainer().SubItems.Add(e.Component as BaseItem); if (cc != null) cc.OnComponentChanged(this.Control, null, null, null); m_InsertItemTransaction.Commit(); m_InsertItemTransaction = null; this.RecalcLayout(); } }
private void InitiateResize() { bool useSnapLines = this.BehaviorService.UseSnapLines; ArrayList dragComponents = new ArrayList(); IDesignerHost service = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost; for (int i = 0; i < this.resizeComponents.Length; i++) { this.resizeComponents[i].resizeBounds = ((Control) this.resizeComponents[i].resizeControl).Bounds; if (useSnapLines) { dragComponents.Add(this.resizeComponents[i].resizeControl); } if (service != null) { ControlDesigner designer = service.GetDesigner(this.resizeComponents[i].resizeControl as Component) as ControlDesigner; if (designer != null) { this.resizeComponents[i].resizeRules = designer.SelectionRules; } else { this.resizeComponents[i].resizeRules = SelectionRules.None; } } } this.BehaviorService.EnableAllAdorners(false); IDesignerHost host2 = (IDesignerHost) this.serviceProvider.GetService(typeof(IDesignerHost)); if (host2 != null) { string str; if (this.resizeComponents.Length == 1) { string componentName = TypeDescriptor.GetComponentName(this.resizeComponents[0].resizeControl); if ((componentName == null) || (componentName.Length == 0)) { componentName = this.resizeComponents[0].resizeControl.GetType().Name; } str = System.Design.SR.GetString("BehaviorServiceResizeControl", new object[] { componentName }); } else { str = System.Design.SR.GetString("BehaviorServiceResizeControls", new object[] { this.resizeComponents.Length }); } this.resizeTransaction = host2.CreateTransaction(str); } this.initialResize = true; if (useSnapLines) { this.dragManager = new DragAssistanceManager(this.serviceProvider, dragComponents, true); } else if (this.resizeComponents.Length > 0) { Control resizeControl = this.resizeComponents[0].resizeControl as Control; if ((resizeControl != null) && (resizeControl.Parent != null)) { PropertyDescriptor descriptor = TypeDescriptor.GetProperties(resizeControl.Parent)["SnapToGrid"]; if ((descriptor != null) && ((bool) descriptor.GetValue(resizeControl.Parent))) { PropertyDescriptor descriptor2 = TypeDescriptor.GetProperties(resizeControl.Parent)["GridSize"]; if (descriptor2 != null) { this.parentGridSize = (Size) descriptor2.GetValue(resizeControl.Parent); this.parentLocation = this.behaviorService.ControlToAdornerWindow(resizeControl); this.parentLocation.X -= resizeControl.Location.X; this.parentLocation.Y -= resizeControl.Location.Y; } } } } this.captureLost = false; }
internal static void SaveGridState(DesignerTransaction dt, Grid grid, IComponentChangeService service) { service.OnComponentChanging(grid, null); service.OnComponentChanged(grid, null, null, null); dt.Commit(); }
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); } } } }
internal static void ConfigureGrid(ref Grid grid, ref IDesignerHost designerhost, ref IComponentChangeService componentChangeService, ref DesignerTransaction dt, GridTemplate template) { if (template == GridTemplate.None) return; switch (template) { case GridTemplate.ProductCatalog: { dt = designerhost.CreateTransaction(string.Format("Configure WebGrid as {0}", template)); grid.RecordsPerRow = 3; grid.Width = Unit.Percentage(100); grid.Title = "Product catalog"; grid.DefaultVisibility = Visibility.None; grid.DisplayView = DisplayView.Grid; grid.Columns.Clear(); Text producttitle = (Text) designerhost.CreateComponent(typeof (Text)); producttitle.ColumnId = "productTitle"; producttitle.Grid = grid; producttitle.Title = "Title"; producttitle.Visibility = Visibility.Both; producttitle.DisplayIndex = 10; grid.Columns.Add(producttitle); File productImageGrid = (File) designerhost.CreateComponent(typeof (File)); productImageGrid.ColumnId = "productImageGrid"; productImageGrid.Grid = grid; productImageGrid.Title = "Grid image"; productImageGrid.HideDetailTitle = true; productImageGrid.NewRowInGrid = true; productImageGrid.Visibility = Visibility.Grid; productImageGrid.DisplayIndex = 20; grid.Columns.Add(productImageGrid); File productImageEdit = (File) designerhost.CreateComponent(typeof (File)); productImageEdit.ColumnId = "productImageEdit"; productImageEdit.Title = "Edit image"; productImageEdit.Grid = grid; productImageEdit.HideDetailTitle = true; productImageEdit.NewRowInGrid = true; productImageEdit.Visibility = Visibility.Detail; productImageEdit.DisplayIndex = 20; grid.Columns.Add(productImageEdit); Text productGridDescription = (Text) designerhost.CreateComponent(typeof (Text)); productGridDescription.ColumnId = "productGridDescription"; productGridDescription.Title = "Grid description"; productGridDescription.Grid = grid; productGridDescription.HideDetailTitle = true; productGridDescription.Visibility = Visibility.Grid; productGridDescription.IsHtml = true; productGridDescription.DisplayIndex = 30; grid.Columns.Add(productGridDescription); Text productEditDescription = (Text) designerhost.CreateComponent(typeof (Text)); productEditDescription.ColumnId = "productGridDescription"; productEditDescription.Grid = grid; productEditDescription.Title = "Edit description"; productEditDescription.HideDetailTitle = true; productEditDescription.IsHtml = true; productEditDescription.Visibility = Visibility.Detail; productEditDescription.DisplayIndex = 30; grid.Columns.Add(productEditDescription); WebGridDesignTime.SaveGridState(dt, grid, componentChangeService); return; } case GridTemplate.UserRegistration: { grid.Width = Unit.Pixel(500); grid.Title = "User login"; grid.DefaultVisibility = Visibility.None; grid.DisplayView = DisplayView.Detail; grid.AllowCancel = false; grid.AllowUpdate = true; grid.RecordsPerRow = 1; grid.Columns.Clear(); Text userloginID = (Text) designerhost.CreateComponent(typeof (Text)); userloginID.ColumnId = "LoginID"; userloginID.Title = "Login ID"; userloginID.Grid = grid; userloginID.HideDetailTitle = true; userloginID.Visibility = Visibility.Detail; userloginID.DisplayIndex = 10; userloginID.Required = true; grid.Columns.Add(userloginID); Text userpassword = (Text) designerhost.CreateComponent(typeof (Text)); userpassword.ColumnId = "LoginPassword"; userpassword.Title = "Login password"; userpassword.Grid = grid; userpassword.IsPassword = true; userpassword.Visibility = Visibility.Detail; userpassword.DisplayIndex = 20; userpassword.ValidExpression = "[RepeatPassword] != [LoginPassword]"; userpassword.Required = true; userpassword.MinSize = 5; userpassword.MaxSize = 15; userpassword.SystemMessage = "Your passwords did not match."; grid.Columns.Add(userpassword); Text repeatuserpassword = (Text) designerhost.CreateComponent(typeof (Text)); repeatuserpassword.ColumnId = "RepeatPassword"; repeatuserpassword.Title = "Repeat password"; repeatuserpassword.NewRowInDetail = false; repeatuserpassword.Grid = grid; repeatuserpassword.IsPassword = true; repeatuserpassword.Visibility = Visibility.Detail; repeatuserpassword.DisplayIndex = 30; repeatuserpassword.MinSize = 5; repeatuserpassword.MaxSize = 15; repeatuserpassword.Required = true; grid.Columns.Add(repeatuserpassword); WebGridDesignTime.SaveGridState(dt, grid, componentChangeService); return; } case GridTemplate.RowSummary: { grid.Width = Unit.Percentage(100); grid.Title = "Row summary"; grid.DefaultVisibility = Visibility.None; grid.RecordsPerRow = 1; grid.DisplayView = DisplayView.Grid; grid.Columns.Clear(); Decimal productprice = (Decimal) designerhost.CreateComponent(typeof (Decimal)); productprice.ColumnId = "Price"; productprice.Title = "Price"; productprice.Grid = grid; productprice.Visibility = Visibility.Both; productprice.DisplayIndex = 10; grid.Columns.Add(productprice); Number productQuantity = (Number) designerhost.CreateComponent(typeof (Number)); productQuantity.ColumnId = "Quantity"; productQuantity.Title = "Quantity"; productQuantity.Grid = grid; productQuantity.Visibility = Visibility.Both; productQuantity.DisplayIndex = 20; grid.Columns.Add(productQuantity); Decimal productSubSum = (Decimal) designerhost.CreateComponent(typeof (Decimal)); productSubSum.ColumnId = "Total"; productSubSum.Title = "Sub total"; productSubSum.Grid = grid; productSubSum.Visibility = Visibility.Grid; productSubSum.DisplayIndex = 30; productSubSum.DisplayTotalSummary = true; productSubSum.Sum = "[Quantity]*[Price]"; grid.Columns.Add(productSubSum); WebGridDesignTime.SaveGridState(dt, grid, componentChangeService); return; } case GridTemplate.DocumentDatabase: { grid.Width = Unit.Percentage(100); grid.Title = "Document database"; grid.DefaultVisibility = Visibility.None; grid.RecordsPerRow = 1; grid.DisplayView = DisplayView.Grid; grid.Columns.Clear(); Text documenttitle = (Text) designerhost.CreateComponent(typeof (Text)); documenttitle.ColumnId = "TitleDocument"; documenttitle.Title = "Title"; documenttitle.Grid = grid; documenttitle.Visibility = Visibility.Both; documenttitle.DisplayIndex = 10; documenttitle.Required = true; grid.Columns.Add(documenttitle); Text htmldocument = (Text) designerhost.CreateComponent(typeof (Text)); htmldocument.ColumnId = "htmlDocument"; htmldocument.Title = "Document"; htmldocument.Grid = grid; htmldocument.IsHtml = true; htmldocument.WidthEditableColumn = Unit.Percentage(90); htmldocument.HeightEditableColumn = Unit.Pixel(300); htmldocument.Visibility = Visibility.Detail; htmldocument.DisplayIndex = 20; htmldocument.Required = true; grid.Columns.Add(htmldocument); File fileattachment = (File) designerhost.CreateComponent(typeof (File)); fileattachment.ColumnId = "FileAttachment"; fileattachment.Title = "File Attachment"; fileattachment.Grid = grid; fileattachment.Visibility = Visibility.Both; fileattachment.DisplayIndex = 30; fileattachment.Required = false; grid.Columns.Add(fileattachment); WebGridDesignTime.SaveGridState(dt, grid, componentChangeService); return; } } }
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 (); }
private void TryCancelTransaction(ref DesignerTransaction transaction) { if (transaction != null) { try { transaction.Cancel(); transaction = null; } catch { } } }
/// <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) { Exception ex = new InvalidOperationException(string.Format(SR.EventBindingServiceEventReadOnly, Name)); ex.HelpLink = SR.EventBindingServiceEventReadOnly; throw ex; } if (value != null && !(value is string)) { Exception ex = new ArgumentException(string.Format(SR.EventBindingServiceBadArgType, Name, typeof(string).Name)); ex.HelpLink = SR.EventBindingServiceBadArgType; throw ex; } string name = (string)value; if (name != 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) { site = ((IComponent)component).Site; } if (site is null && (_eventSvc._provider.GetService(typeof(IReferenceService)) is IReferenceService rs)) { IComponent baseComponent = rs.GetComponent(component); if (baseComponent != null) { site = baseComponent.Site; } } if (site is null) { Exception ex = new InvalidOperationException(SR.EventBindingServiceNoSite); ex.HelpLink = SR.EventBindingServiceNoSite; throw ex; } // The dictionary service is where we store the actual event method name. if (!(site.GetService(typeof(IDictionaryService)) is IDictionaryService ds)) { Exception ex = new InvalidOperationException(string.Format(SR.EventBindingServiceMissingService, typeof(IDictionaryService).Name)); ex.HelpLink = SR.EventBindingServiceMissingService; throw ex; } // Get the old method name, ensure that they are different, and then continue. ReferenceEventClosure key = new ReferenceEventClosure(component, this); string oldName = (string)ds.GetValue(key); if (object.ReferenceEquals(oldName, name)) { return; } if (oldName != null && name != null && oldName.Equals(name)) { return; } // Before we continue our work, ensure that the name is actually valid. if (name != null) { _eventSvc.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 trans = null; if (site.GetService(typeof(IDesignerHost)) is IDesignerHost host) { trans = host.CreateTransaction(string.Format(SR.EventBindingServiceSetValue, site.Name, name)); } try { // Ok, the names are different. Fire a changing event to make // sure it's OK to perform the change. IComponentChangeService change = site.GetService(typeof(IComponentChangeService)) as IComponentChangeService; if (change != null) { try { change.OnComponentChanging(component, this); change.OnComponentChanging(component, Event); } catch (CheckoutException coEx) { if (coEx == CheckoutException.Canceled) { return; } throw; } } // 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 != null) { _eventSvc.UseMethod((IComponent)component, Event, name); } if (oldName != null) { _eventSvc.FreeMethod((IComponent)component, Event, oldName); } ds.SetValue(key, name); if (change != null) { change.OnComponentChanged(component, Event, null, null); change.OnComponentChanged(component, this, oldName, name); } OnValueChanged(component, EventArgs.Empty); if (trans != null) { trans.Commit(); } } finally { if (trans != null) { ((IDisposable)trans).Dispose(); } } }
private void SetResizableDesigner(ActivityDesigner designer, DesignerEdges sizingEdge) { if ((this.designerToResize != designer) && ((designer == null) || this.CanResizeDesigner(designer))) { WorkflowView parentView = base.ParentView; if (parentView == null) { throw new InvalidOperationException(DR.GetString("WorkflowViewNull", new object[0])); } if (designer != null) { if (this.designerTransaction != null) { this.designerTransaction.Cancel(); } IDesignerHost service = base.GetService(typeof(IDesignerHost)) as IDesignerHost; if (service != null) { this.designerTransaction = service.CreateTransaction(DR.GetString("ResizeUndoDescription", new object[] { designer.Text })); } ((IWorkflowDesignerMessageSink) designer).OnBeginResizing(sizingEdge); } else { if (this.designerTransaction != null) { this.designerTransaction.Commit(); this.designerTransaction = null; } ((IWorkflowDesignerMessageSink) this.designerToResize).OnEndResizing(); } this.designerToResize = designer; this.designerSizingEdge = sizingEdge; parentView.Capture = this.designerToResize != null; this.UpdateCursor(this.designerSizingEdge); } }
/// <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 OnLoseCapture(Glyph g, EventArgs e) { if (this.pushedBehavior) { this.FinishResize(); if (this.resizeTransaction != null) { DesignerTransaction resizeTransaction = this.resizeTransaction; this.resizeTransaction = null; using (resizeTransaction) { resizeTransaction.Cancel(); } } } }
internal void OnTransactionClosed (bool commit, DesignerTransaction trans) { DesignerTransaction t = (DesignerTransaction) transactionStack.Pop(); if (t != trans) throw new Exception ("Transactions cannot be closed out of order"); if (TransactionClosed != null) TransactionClosed (this, new DesignerTransactionCloseEventArgs(commit)); }
public override bool OnMouseDown(Glyph g, MouseButtons button, Point mouseLoc) { if ((button != MouseButtons.Left) || !(g is TableLayoutPanelResizeGlyph)) { goto Label_02E0; } this.tableGlyph = g as TableLayoutPanelResizeGlyph; ISelectionService service = this.serviceProvider.GetService(typeof(ISelectionService)) as ISelectionService; if (service != null) { service.SetSelectedComponents(new object[] { this.designer.Component }, SelectionTypes.Click); } bool isColumn = this.tableGlyph.Type == TableLayoutPanelResizeGlyph.TableLayoutResizeType.Column; this.lastMouseLoc = mouseLoc; this.resizeProp = TypeDescriptor.GetProperties(this.tableGlyph.Style)[isColumn ? "Width" : "Height"]; IComponentChangeService service2 = this.serviceProvider.GetService(typeof(IComponentChangeService)) as IComponentChangeService; if (service2 != null) { this.changedProp = TypeDescriptor.GetProperties(this.table)[isColumn ? "ColumnStyles" : "RowStyles"]; int[] widths = isColumn ? this.table.GetColumnWidths() : this.table.GetRowHeights(); if (this.changedProp != null) { this.GetActiveStyleCollection(isColumn); if ((this.styles != null) && this.CanResizeStyle(widths)) { IDesignerHost host = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost; if (host != null) { this.resizeTransaction = host.CreateTransaction(System.Design.SR.GetString("TableLayoutPanelRowColResize", new object[] { isColumn ? "Column" : "Row", this.designer.Control.Site.Name })); } try { int index = this.styles.IndexOf(this.tableGlyph.Style); this.rightStyle.index = this.IndexOfNextStealableStyle(true, index, widths); this.rightStyle.style = (TableLayoutStyle) this.styles[this.rightStyle.index]; this.rightStyle.styleProp = TypeDescriptor.GetProperties(this.rightStyle.style)[isColumn ? "Width" : "Height"]; this.leftStyle.index = this.IndexOfNextStealableStyle(false, index, widths); this.leftStyle.style = (TableLayoutStyle) this.styles[this.leftStyle.index]; this.leftStyle.styleProp = TypeDescriptor.GetProperties(this.leftStyle.style)[isColumn ? "Width" : "Height"]; service2.OnComponentChanging(this.table, this.changedProp); goto Label_02CD; } catch (CheckoutException exception) { if ((CheckoutException.Canceled.Equals(exception) && (this.resizeTransaction != null)) && !this.resizeTransaction.Canceled) { this.resizeTransaction.Cancel(); } throw; } } return false; } } Label_02CD: this.behaviorService.PushCaptureBehavior(this); this.pushedBehavior = true; Label_02E0: return false; }
/// <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); } }
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; }
internal ToolStripItem AddNewItem(System.Type t, string text, bool enterKeyPressed, bool tabKeyPressed) { DesignerTransaction transaction = this.host.CreateTransaction(System.Design.SR.GetString("ToolStripAddingItem", new object[] { t.Name })); ToolStripItem item = null; try { this._addingItem = true; this.ToolStrip.SuspendLayout(); IComponent component = this.host.CreateComponent(t, NameFromText(text, t, base.Component.Site)); ToolStripItemDesigner itemDesigner = this.host.GetDesigner(component) as ToolStripItemDesigner; try { if (!string.IsNullOrEmpty(text)) { itemDesigner.InternalCreate = true; } if (itemDesigner != null) { itemDesigner.InitializeNewComponent(null); } } finally { itemDesigner.InternalCreate = false; } item = component as ToolStripItem; if (item != null) { PropertyDescriptor descriptor = TypeDescriptor.GetProperties(item)["Text"]; if ((descriptor != null) && !string.IsNullOrEmpty(text)) { descriptor.SetValue(item, text); } if (((item is ToolStripButton) || (item is ToolStripSplitButton)) || (item is ToolStripDropDownButton)) { Image image = null; try { image = new Bitmap(typeof(ToolStripButton), "blank.bmp"); } catch (Exception exception) { if (System.Windows.Forms.ClientUtils.IsCriticalException(exception)) { throw; } } PropertyDescriptor descriptor2 = TypeDescriptor.GetProperties(item)["Image"]; if ((descriptor2 != null) && (image != null)) { descriptor2.SetValue(item, image); } PropertyDescriptor descriptor3 = TypeDescriptor.GetProperties(item)["DisplayStyle"]; if (descriptor3 != null) { descriptor3.SetValue(item, ToolStripItemDisplayStyle.Image); } PropertyDescriptor descriptor4 = TypeDescriptor.GetProperties(item)["ImageTransparentColor"]; if (descriptor4 != null) { descriptor4.SetValue(item, Color.Magenta); } } } this.ToolStrip.ResumeLayout(); if (!tabKeyPressed) { if (enterKeyPressed) { if (!itemDesigner.SetSelection(enterKeyPressed) && (this.KeyboardHandlingService != null)) { this.KeyboardHandlingService.SelectedDesignerControl = this.editorNode; this.SelectionService.SetSelectedComponents(null, SelectionTypes.Replace); } } else { this.KeyboardHandlingService.SelectedDesignerControl = null; this.SelectionService.SetSelectedComponents(new IComponent[] { item }, SelectionTypes.Replace); this.editorNode.RefreshSelectionGlyph(); } } else if (this.keyboardHandlingService != null) { this.KeyboardHandlingService.SelectedDesignerControl = this.editorNode; this.SelectionService.SetSelectedComponents(null, SelectionTypes.Replace); } if ((itemDesigner != null) && (item.Placement != ToolStripItemPlacement.Overflow)) { Rectangle glyphBounds = itemDesigner.GetGlyphBounds(); SelectionManager service = (SelectionManager) this.GetService(typeof(SelectionManager)); System.Windows.Forms.Design.Behavior.Behavior b = new ToolStripItemBehavior(); ToolStripItemGlyph glyph = new ToolStripItemGlyph(item, itemDesigner, glyphBounds, b); service.BodyGlyphAdorner.Glyphs.Insert(0, glyph); return item; } if ((itemDesigner != null) && (item.Placement == ToolStripItemPlacement.Overflow)) { this.RemoveBodyGlyphsForOverflow(); this.AddBodyGlyphsForOverflow(); } return item; } catch (Exception exception2) { this.ToolStrip.ResumeLayout(); if (this._pendingTransaction != null) { this._pendingTransaction.Cancel(); this._pendingTransaction = null; } if (transaction != null) { transaction.Cancel(); transaction = null; } CheckoutException exception3 = exception2 as CheckoutException; if ((exception3 != null) && (exception3 != CheckoutException.Canceled)) { throw; } } finally { if (this._pendingTransaction != null) { this._pendingTransaction.Cancel(); this._pendingTransaction = null; if (transaction != null) { transaction.Cancel(); } } else if (transaction != null) { transaction.Commit(); transaction = null; } this._addingItem = false; } return item; }
internal void EditTemplateNode(bool clicked) { this.typeHereNode.RefreshSelectionGlyph(); if ((this.KeyboardHandlingService != null) && this.KeyboardHandlingService.TemplateNodeActive) { this.KeyboardHandlingService.ActiveTemplateNode.CommitAndSelect(); } if (!clicked || (this.MenuItem != null)) { try { ToolStripDesigner.editTemplateNode = true; this.selSvc.SetSelectedComponents(new object[] { this.MenuItem }, SelectionTypes.Replace); } finally { ToolStripDesigner.editTemplateNode = false; } ToolStripDropDownItem ownerItem = null; if ((this.selSvc.PrimarySelection == null) && (this.KeyboardHandlingService != null)) { ToolStripItem selectedDesignerControl = this.KeyboardHandlingService.SelectedDesignerControl as ToolStripItem; if (selectedDesignerControl != null) { ownerItem = ((ToolStripDropDown) selectedDesignerControl.Owner).OwnerItem as ToolStripDropDownItem; } } else { ownerItem = this.selSvc.PrimarySelection as ToolStripDropDownItem; } if ((ownerItem != null) && (ownerItem != this.MenuItem)) { this.HideSiblingDropDowns(ownerItem); } this.MenuItem.DropDown.SuspendLayout(); base.dummyItemAdded = true; int index = this.MenuItem.DropDownItems.IndexOf(this.typeHereNode); ToolStripItem component = null; try { this.addingDummyItem = true; component = this.CreateDummyItem(typeof(ToolStripMenuItem), index); } catch (CheckoutException exception) { if (!exception.Equals(CheckoutException.Canceled)) { throw; } this.CommitInsertTransaction(false); if (this.newMenuItemTransaction != null) { this.newMenuItemTransaction.Cancel(); this.newMenuItemTransaction = null; } } finally { base.dummyItemAdded = component != null; this.addingDummyItem = false; } this.MenuItem.DropDown.ResumeLayout(); if (component != null) { ToolStripMenuItemDesigner designer = this.designerHost.GetDesigner(component) as ToolStripMenuItemDesigner; if (designer != null) { designer.InitializeDropDown(); designer.ShowEditNode(clicked); } } } }
private void ComponentChangeSvc_ComponentAdding(object sender, ComponentEventArgs e) { if ((this.KeyboardHandlingService == null) || !this.KeyboardHandlingService.CopyInProgress) { object primarySelection = this.SelectionService.PrimarySelection; if ((primarySelection == null) && (this.keyboardHandlingService != null)) { primarySelection = this.KeyboardHandlingService.SelectedDesignerControl; } ToolStripItem item = primarySelection as ToolStripItem; if ((item == null) || (item.Owner == this.ToolStrip)) { ToolStripItem component = e.Component as ToolStripItem; if ((((component == null) || (component.Owner == null)) || (component.Owner.Site != null)) && ((((this._insertMenuItemTransaction == null) && _autoAddNewItems) && ((component != null) && !this._addingItem)) && (this.IsToolStripOrItemSelected && !this.EditingCollection))) { this._addingItem = true; if (this._pendingTransaction == null) { this._insertMenuItemTransaction = this._pendingTransaction = this.host.CreateTransaction(System.Design.SR.GetString("ToolStripDesignerTransactionAddingItem")); } } } } }
internal override void CommitEdit(System.Type type, string text, bool commit, bool enterKeyPressed, bool tabKeyPressed) { base.IsEditorActive = false; if (!(this.MenuItem.Owner is ToolStripDropDown) && (base.Editor != null)) { base.CommitEdit(type, text, commit, enterKeyPressed, tabKeyPressed); return; } if (!commit) { if (this.commitedEditorNode != null) { this.MenuItem.DropDown.SuspendLayout(); bool flag2 = base.dummyItemAdded; base.dummyItemAdded = false; int index = this.MenuItem.DropDownItems.IndexOf(this.commitedEditorNode); ToolStripItem item4 = this.MenuItem.DropDownItems[index + 1]; this.MenuItem.DropDown.Items.Remove(this.commitedEditorNode); item4.Visible = true; if (this.commitedTemplateNode != null) { this.commitedTemplateNode.CloseEditor(); this.commitedTemplateNode = null; } if (this.commitedEditorNode != null) { this.commitedEditorNode.Dispose(); this.commitedEditorNode = null; } if (flag2) { this.MenuItem.DropDownItems.Remove(item4); try { this.designerHost.DestroyComponent(item4); } catch { if (this.newMenuItemTransaction != null) { try { this.newMenuItemTransaction.Cancel(); } catch { } this.newMenuItemTransaction = null; } } item4 = null; } this.MenuItem.DropDown.ResumeLayout(); if (item4 != null) { this.AddItemBodyGlyph(item4); } if (flag2) { SelectionManager service = (SelectionManager) this.GetService(typeof(SelectionManager)); service.NeedRefresh = false; if (this.newMenuItemTransaction != null) { try { base.dummyItemAdded = true; this.newMenuItemTransaction.Cancel(); this.newMenuItemTransaction = null; if (this.MenuItem.DropDownItems.Count == 0) { this.CreatetypeHereNode(); } } finally { base.dummyItemAdded = false; } } flag2 = false; } this.MenuItem.DropDown.PerformLayout(); } return; } int dummyIndex = -1; bool dummyItemAdded = base.dummyItemAdded; base.dummyItemAdded = false; this.MenuItem.DropDown.SuspendLayout(); if (this.commitedEditorNode != null) { dummyIndex = this.MenuItem.DropDownItems.IndexOf(this.commitedEditorNode); ToolStripItem component = this.MenuItem.DropDownItems[dummyIndex + 1]; this.MenuItem.DropDown.Items.Remove(this.commitedEditorNode); if (this.commitedTemplateNode != null) { this.commitedTemplateNode.CloseEditor(); this.commitedTemplateNode = null; } if (this.commitedEditorNode != null) { this.commitedEditorNode.Dispose(); this.commitedEditorNode = null; } if (text == "-") { ToolStripItemDesigner designer = this.designerHost.GetDesigner(component) as ToolStripItemDesigner; if (designer == null) { goto Label_028C; } try { try { component = designer.MorphCurrentItem(typeof(ToolStripSeparator)); this.RemoveItemBodyGlyph(component); } catch { if (this.newMenuItemTransaction != null) { try { this.newMenuItemTransaction.Cancel(); } catch { } this.newMenuItemTransaction = null; } } goto Label_028C; } finally { if (this.newMenuItemTransaction != null) { this.newMenuItemTransaction.Commit(); this.newMenuItemTransaction = null; } } } if (dummyItemAdded) { try { try { base.dummyItemAdded = true; this.CreateNewItem(type, dummyIndex, text); this.designerHost.DestroyComponent(component); if (enterKeyPressed) { this.typeHereNode.SelectControl(); } } catch { if (this.newMenuItemTransaction != null) { try { this.newMenuItemTransaction.Cancel(); } catch { } this.newMenuItemTransaction = null; } } goto Label_028C; } finally { if (this.newMenuItemTransaction != null) { this.newMenuItemTransaction.Commit(); this.newMenuItemTransaction = null; } base.dummyItemAdded = false; } } component.Visible = true; DesignerTransaction transaction = this.designerHost.CreateTransaction(System.Design.SR.GetString("ToolStripItemPropertyChangeTransaction")); try { PropertyDescriptor descriptor = TypeDescriptor.GetProperties(component)["Text"]; string str = (string) descriptor.GetValue(component); if ((descriptor != null) && (text != str)) { descriptor.SetValue(component, text); } } catch { if (transaction != null) { transaction.Cancel(); transaction = null; } } finally { if (transaction != null) { transaction.Commit(); transaction = null; } } } else { dummyIndex = this.MenuItem.DropDownItems.IndexOf(this.typeHereNode); try { base.dummyItemAdded = true; this.CreateNewItem(type, dummyIndex, text); } finally { base.dummyItemAdded = false; } this.typeHereNode.SelectControl(); } Label_028C: this.MenuItem.DropDown.ResumeLayout(true); this.MenuItem.DropDown.PerformLayout(); this.ResetGlyphs(this.MenuItem); if (this.selSvc != null) { if (enterKeyPressed) { ToolStripItem item2 = null; if (((this.MenuItem.DropDownDirection == ToolStripDropDownDirection.AboveLeft) || (this.MenuItem.DropDownDirection == ToolStripDropDownDirection.AboveRight)) && (dummyIndex >= 1)) { item2 = this.MenuItem.DropDownItems[dummyIndex - 1]; } else { item2 = this.MenuItem.DropDownItems[dummyIndex + 1]; } if (this.KeyboardHandlingService != null) { if (item2 != null) { ToolStripDropDownItem item3 = this.MenuItem.DropDownItems[dummyIndex] as ToolStripDropDownItem; if (item3 != null) { item3.HideDropDown(); } } if (item2 == this.typeHereNode) { this.KeyboardHandlingService.SelectedDesignerControl = item2; this.selSvc.SetSelectedComponents(null, SelectionTypes.Replace); } else { this.KeyboardHandlingService.SelectedDesignerControl = null; this.selSvc.SetSelectedComponents(new object[] { item2 }); } } } else if (tabKeyPressed) { this.selSvc.SetSelectedComponents(new object[] { this.MenuItem.DropDownItems[dummyIndex] }, SelectionTypes.Replace); } } }
private void ComponentChangeSvc_ComponentRemoving(object sender, ComponentEventArgs e) { if ((e.Component is ToolStripItem) && (((ToolStripItem) e.Component).Owner == base.Component)) { try { this._pendingTransaction = this.host.CreateTransaction(System.Design.SR.GetString("ToolStripDesignerTransactionRemovingItem")); base.RaiseComponentChanging(TypeDescriptor.GetProperties(base.Component)["Items"]); ToolStripDropDownItem component = e.Component as ToolStripDropDownItem; if (component != null) { component.HideDropDown(); this.boundsToInvalidate = component.DropDown.Bounds; } } catch { if (this._pendingTransaction != null) { this._pendingTransaction.Cancel(); this._pendingTransaction = null; } } } }
private void CommitInsertTransaction(bool commit) { if (!this.IsOnContextMenu) { ToolStrip mainToolStrip = this.GetMainToolStrip(); ToolStripDesigner designer = this.designerHost.GetDesigner(mainToolStrip) as ToolStripDesigner; if ((designer != null) && (designer.InsertTansaction != null)) { if (commit) { designer.InsertTansaction.Commit(); } else { designer.InsertTansaction.Cancel(); } designer.InsertTansaction = null; } } else if (this.insertMenuItemTransaction != null) { if (commit) { this.insertMenuItemTransaction.Commit(); } else { this.insertMenuItemTransaction.Cancel(); } this.insertMenuItemTransaction = null; } }
internal static void AddGridColumn(ref Grid grid, ref IDesignerHost designerhost, ref IComponentChangeService componentChangeService, ref DesignerTransaction dt, ColumnTemplates template) { if (template == ColumnTemplates.None) return; dt = designerhost.CreateTransaction(string.Format("Configure WebGrid as {0}", template)); switch (template) { case ColumnTemplates.SelectRowColumn: { SystemColumn systemcolumn = (SystemColumn) designerhost.CreateComponent(typeof (SystemColumn)); systemcolumn.ColumnId = "SelectColumn"; systemcolumn.Grid = grid; systemcolumn.Title = string.Empty; systemcolumn.Visibility = Visibility.Grid; systemcolumn.SystemColumnType = Enums.SystemColumn.SelectColumn; systemcolumn.DisplayIndex = 5; grid.Columns.Add(systemcolumn); } break; case ColumnTemplates.EditRowColumn: { SystemColumn systemcolumn = (SystemColumn) designerhost.CreateComponent(typeof (SystemColumn)); systemcolumn.ColumnId = "EditColumn"; systemcolumn.Grid = grid; systemcolumn.Html = "Edit row"; systemcolumn.Title = string.Empty; systemcolumn.Visibility = Visibility.Grid; systemcolumn.SystemColumnType = Enums.SystemColumn.EditColumn; systemcolumn.DisplayIndex = 7; grid.Columns.Add(systemcolumn); } break; case ColumnTemplates.CopyRowColumnn: { SystemColumn systemcolumn = (SystemColumn) designerhost.CreateComponent(typeof (SystemColumn)); systemcolumn.ColumnId = "CopyColumn"; systemcolumn.Grid = grid; systemcolumn.Html = "Copy row"; systemcolumn.Title = string.Empty; systemcolumn.Visibility = Visibility.Grid; systemcolumn.SystemColumnType = Enums.SystemColumn.CopyColumn; systemcolumn.DisplayIndex = 2; grid.Columns.Add(systemcolumn); } break; case ColumnTemplates.UpdateGridRecordColumn: { SystemColumn systemcolumn = (SystemColumn) designerhost.CreateComponent(typeof (SystemColumn)); systemcolumn.ColumnId = "UpdateRecord"; systemcolumn.Grid = grid; systemcolumn.Html = "Update record"; systemcolumn.Title = string.Empty; systemcolumn.Visibility = Visibility.Grid; systemcolumn.SystemColumnType = Enums.SystemColumn.UpdateGridRecordColumn; systemcolumn.DisplayIndex = 9; grid.Columns.Add(systemcolumn); } break; case ColumnTemplates.UpdateGridRecordsColumn: { SystemColumn systemcolumn = (SystemColumn) designerhost.CreateComponent(typeof (SystemColumn)); systemcolumn.ColumnId = "UpdateRecords"; systemcolumn.Grid = grid; systemcolumn.Html = "Update all"; systemcolumn.Title = string.Empty; systemcolumn.Visibility = Visibility.Grid; systemcolumn.SystemColumnType = Enums.SystemColumn.UpdateGridRecordsColumn; systemcolumn.DisplayIndex = 9; grid.Columns.Add(systemcolumn); } break; case ColumnTemplates.DeleteRowColumn: { SystemColumn systemcolumn = (SystemColumn) designerhost.CreateComponent(typeof (SystemColumn)); systemcolumn.ColumnId = "DeleteRow"; systemcolumn.Html = "Delete row"; systemcolumn.Grid = grid; systemcolumn.Title = string.Empty; systemcolumn.Visibility = Visibility.Grid; systemcolumn.SystemColumnType = Enums.SystemColumn.DeleteColumn; grid.Columns.Add(systemcolumn); } break; case ColumnTemplates.HtmlEditorColumn: { Text htmlColumn = (Text) designerhost.CreateComponent(typeof (Text)); htmlColumn.ColumnId = "HtmlColumn"; htmlColumn.Title = "Html column"; htmlColumn.Grid = grid; htmlColumn.IsHtml = true; htmlColumn.WidthEditableColumn = Unit.Percentage(90); htmlColumn.HeightEditableColumn = Unit.Pixel(300); htmlColumn.Visibility = Visibility.Detail; htmlColumn.Required = true; grid.Columns.Add(htmlColumn); } break; case ColumnTemplates.EmailValidColumn: { Text emailcolumn = (Text) designerhost.CreateComponent(typeof (Text)); emailcolumn.ColumnId = "Emailcolumn"; emailcolumn.Title = "E-mail address"; emailcolumn.Grid = grid; emailcolumn.Visibility = Visibility.Both; emailcolumn.DisplayIndex = grid.Columns.Count*10; emailcolumn.Required = true; grid.Columns.Add(emailcolumn); } break; } WebGridDesignTime.SaveGridState(dt, grid, componentChangeService); }
private void ComponentChangeSvc_ComponentAdding(object sender, ComponentEventArgs e) { if (((this.KeyboardHandlingService == null) || !this.KeyboardHandlingService.CopyInProgress) && ((e.Component is ToolStripItem) && (this.MenuItemSelected || this.fireComponentChanged))) { if (!this.IsOnContextMenu) { ToolStrip mainToolStrip = this.GetMainToolStrip(); ToolStripDesigner designer = this.designerHost.GetDesigner(mainToolStrip) as ToolStripDesigner; if (((designer != null) && !designer.EditingCollection) && (designer.InsertTansaction == null)) { this.componentAddingFired = true; designer.InsertTansaction = this.designerHost.CreateTransaction(System.Design.SR.GetString("ToolStripInsertingIntoDropDownTransaction")); } } else { ToolStripItem component = e.Component as ToolStripItem; if ((component != null) && (component.Owner == null)) { this.componentAddingFired = true; this.insertMenuItemTransaction = this.designerHost.CreateTransaction(System.Design.SR.GetString("ToolStripInsertingIntoDropDownTransaction")); } } } }
private void ComponentChangeSvc_ComponentRemoved(object sender, ComponentEventArgs e) { ToolStripItem item = e.Component as ToolStripItem; if ((item != null) && item.IsOnDropDown) { ToolStripDropDownItem ownerItem = (ToolStripDropDownItem) ((ToolStripDropDown) item.Owner).OwnerItem; if ((ownerItem != null) && (ownerItem == this.MenuItem)) { int index = ownerItem.DropDownItems.IndexOf(item); try { if (index != -1) { ownerItem.DropDownItems.Remove(item); base.RaiseComponentChanged(TypeDescriptor.GetProperties(ownerItem)["DropDownItems"], null, null); } } finally { if (this._pendingTransaction != null) { this._pendingTransaction.Commit(); this._pendingTransaction = null; } } this.ResetGlyphs(ownerItem); if (ownerItem.DropDownItems.Count > 1) { index = Math.Min(ownerItem.DropDownItems.Count - 1, index); index = Math.Max(0, index); } else { index = -1; } if ((this.toolStripAdornerWindowService != null) && (this.boundsToInvalidateOnRemove != Rectangle.Empty)) { using (Region region = new Region(this.boundsToInvalidateOnRemove)) { region.Exclude(this.MenuItem.DropDown.Bounds); this.toolStripAdornerWindowService.Invalidate(region); this.boundsToInvalidateOnRemove = Rectangle.Empty; } } if (((this.KeyboardHandlingService != null) && this.KeyboardHandlingService.CutOrDeleteInProgress) && ((this.selSvc != null) && !base.dummyItemAdded)) { IComponent component = (index == -1) ? ownerItem : ownerItem.DropDownItems[index]; if (component is DesignerToolStripControlHost) { this.KeyboardHandlingService.SelectedDesignerControl = component; this.KeyboardHandlingService.OwnerItemAfterCut = this.MenuItem; this.selSvc.SetSelectedComponents(null, SelectionTypes.Replace); } else { this.selSvc.SetSelectedComponents(new IComponent[] { component }, SelectionTypes.Replace); } } } } }
private void ComponentChangeSvc_ComponentRemoving(object sender, ComponentEventArgs e) { if (!base.dummyItemAdded) { ToolStripItem component = e.Component as ToolStripItem; if (((component != null) && component.IsOnDropDown) && (component.Placement == ToolStripItemPlacement.Main)) { ToolStripDropDownItem ownerItem = (ToolStripDropDownItem) ((ToolStripDropDown) component.Owner).OwnerItem; if ((ownerItem != null) && (ownerItem == this.MenuItem)) { this.RemoveItemBodyGlyph(component); this.InitializeBodyGlyphsForItems(false, ownerItem); this.boundsToInvalidateOnRemove = ownerItem.DropDown.Bounds; ToolStripDropDownItem item3 = component as ToolStripDropDownItem; if (item3 != null) { this.boundsToInvalidateOnRemove = Rectangle.Union(this.boundsToInvalidateOnRemove, item3.DropDown.Bounds); } try { this._pendingTransaction = this.designerHost.CreateTransaction(System.Design.SR.GetString("ToolStripDesignerTransactionRemovingItem")); base.RaiseComponentChanging(TypeDescriptor.GetProperties(ownerItem)["DropDownItems"]); } catch { if (this._pendingTransaction != null) { this._pendingTransaction.Cancel(); this._pendingTransaction = null; } } } } } }
/// <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) { 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); } }
private ToolStripItem CreateDummyItem(System.Type t, int dummyIndex) { if (this.designerHost == null) { return null; } ToolStripItem component = null; if ((this.MenuItem.DropDownDirection == ToolStripDropDownDirection.AboveLeft) || (this.MenuItem.DropDownDirection == ToolStripDropDownDirection.AboveRight)) { dummyIndex++; } try { ToolStripDesigner._autoAddNewItems = false; this.indexToInsertNewItem = dummyIndex; try { if (this.newMenuItemTransaction == null) { this.newMenuItemTransaction = this.designerHost.CreateTransaction(System.Design.SR.GetString("ToolStripCreatingNewItemTransaction")); } this.fireComponentChanged = true; component = (ToolStripItem) this.designerHost.CreateComponent(t); } finally { this.fireComponentChanged = false; } ToolStripItemDesigner designer = this.designerHost.GetDesigner(component) as ToolStripItemDesigner; try { designer.InternalCreate = true; if (designer != null) { designer.InitializeNewComponent(null); } } finally { designer.InternalCreate = false; } return component; } catch (InvalidOperationException exception) { this.CommitInsertTransaction(false); if (this.newMenuItemTransaction != null) { this.newMenuItemTransaction.Cancel(); this.newMenuItemTransaction = null; } ((IUIService) this.GetService(typeof(IUIService))).ShowError(exception.Message); } finally { ToolStripDesigner._autoAddNewItems = true; this.indexToInsertNewItem = -1; } return component; }
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; }
private void ComponentChangeComponentAdding(object sender, ComponentEventArgs e) { if (m_InsertItemTransaction == null && !m_AddingItem && !m_CreatingItem && e.Component is BaseItem) { ISelectionService ss = this.GetService(typeof(ISelectionService)) as ISelectionService; if (ss != null && ss.PrimarySelection == this.Control) { IDesignerHost dh = this.GetService(typeof(IDesignerHost)) as IDesignerHost; if (dh.InTransaction && dh.TransactionDescription == CreatingItemTransactionDescription) return; m_AddingItem = true; m_InsertItemTransaction = dh.CreateTransaction("Adding Item Clip"); } } }
public override void OnLoseCapture(Glyph g, EventArgs e) { this.captureLost = true; if (this.pushedBehavior) { this.pushedBehavior = false; if (this.BehaviorService != null) { if (this.dragging) { this.dragging = false; for (int i = 0; !this.captureLost && (i < this.resizeComponents.Length); i++) { Control resizeControl = this.resizeComponents[i].resizeControl as Control; Rectangle rect = this.BehaviorService.ControlRectInAdornerWindow(resizeControl); if (!rect.IsEmpty) { using (Graphics graphics = this.BehaviorService.AdornerWindowGraphics) { graphics.SetClip(rect); using (Region region = new Region(rect)) { region.Exclude(Rectangle.Inflate(rect, -2, -2)); this.BehaviorService.Invalidate(region); } graphics.ResetClip(); } } } this.BehaviorService.EnableAllAdorners(true); } this.BehaviorService.PopBehavior(this); if (this.lastResizeRegion != null) { this.BehaviorService.Invalidate(this.lastResizeRegion); this.lastResizeRegion.Dispose(); this.lastResizeRegion = null; } } } if (this.resizeTransaction != null) { DesignerTransaction resizeTransaction = this.resizeTransaction; this.resizeTransaction = null; using (resizeTransaction) { resizeTransaction.Cancel(); } } }
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(); } } } }