Exemplo n.º 1
0
 //
 // Internal API that calls OnItemChanged.  This is invoked from the
 // abstract ContextItemCollection class so deriving classes can still
 // invoke it.
 //
 internal void InvokeOnItemChanged(EditingContext context, ContextItem previousItem)
 {
     OnItemChanged(context, previousItem);
 }
Exemplo n.º 2
0
 /// <summary>
 ///     This method is called on a context item before it is stored in the context item
 ///     manager.  The previous item in the context item manager is passed.
 /// </summary>
 /// <param name="context">The editing context that is making this change.</param>
 /// <param name="previousItem">The previously active item in the context.  Because items must have default constructors a default item will be fabricated if an item is first passed into the context.</param>
 /// <returns></returns>
 protected virtual void OnItemChanged(EditingContext context, ContextItem previousItem)
 {
 }
Exemplo n.º 3
0
            /// <summary>
            ///     Called when an item changes value.  This happens in one of two ways:
            ///     either the user has called Change, or the user has removed a layer.
            /// </summary>
            private void OnItemChanged(ContextItem item)
            {
                SubscribeContextCallback callback;

                Debug.Assert(item != null, "You cannot pass a null item here.");

                if (_subscriptions != null
                    && _subscriptions.TryGetValue(item.ItemType, out callback))
                {
                    callback(item);
                }
            }
Exemplo n.º 4
0
            /// <summary>
            ///     This changes a context item to the given value.  It is illegal to pass
            ///     null here.  If you want to set a context item to its empty value create
            ///     an instance of the item using a default constructor.
            /// </summary>
            /// <param name="value"></param>
            internal override void SetValue(ContextItem value)
            {
                if (value == null)
                {
                    throw new ArgumentNullException("value");
                }

                // The rule for change is that we store the new value,
                // raise a change on the item, and then raise a change
                // to everyone else.  If changing the item fails, we recover
                // the previous item.
                ContextItem existing, existingRawValue;
                existing = existingRawValue = GetValueNull(value.ItemType);

                if (existing == null)
                {
                    existing = GetValue(value.ItemType);
                }

                var success = false;

                try
                {
                    _currentLayer.Items[value.ItemType] = value;
                    NotifyItemChanged(_context, value, existing);
                    success = true;
                }
                finally
                {
                    if (success)
                    {
                        OnItemChanged(value);
                    }
                    else
                    {
                        // The item threw during its transition to 
                        // becoming active.  Put the old one back.
                        // We must put the old one back by re-activating
                        // it.  This could throw a second time, so we
                        // cover this case by removing the value first.
                        // Should it throw again, we won't recurse because
                        // the existing raw value would be null.

                        _currentLayer.Items.Remove(value.ItemType);
                        if (existingRawValue != null)
                        {
                            SetValue(existingRawValue);
                        }
                    }
                }
            }
Exemplo n.º 5
0
 //
 // Internal API that calls OnItemChanged.  This is invoked from the
 // abstract ContextItemCollection class so deriving classes can still
 // invoke it.
 //
 internal void InvokeOnItemChanged(EditingContext context, ContextItem previousItem)
 {
     OnItemChanged(context, previousItem);
 }
Exemplo n.º 6
0
 /// <summary>
 ///     This method is called on a context item before it is stored in the context item
 ///     manager.  The previous item in the context item manager is passed.
 /// </summary>
 /// <param name="context">The editing context that is making this change.</param>
 /// <param name="previousItem">The previously active item in the context.  Because items must have default constructors a default item will be fabricated if an item is first passed into the context.</param>
 /// <returns></returns>
 protected virtual void OnItemChanged(EditingContext context, ContextItem previousItem)
 {
 }