Cancel() public method

public Cancel ( ) : void
return void
 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 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();
         }
     }
 }
Esempio n. 3
0
        /// <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);
            }
        }
		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 ();
		}
Esempio n. 5
0
        // 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);
                }
            }
        }
Esempio n. 6
0
        /// <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 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();
             }
         }
     }
 }
 private void TryCancelTransaction(ref DesignerTransaction transaction)
 {
     if (transaction != null)
     {
         try
         {
             transaction.Cancel();
             transaction = null;
         }
         catch
         {
         }
     }
 }
Esempio n. 10
0
        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);
                    }
                }
            }
        }