Пример #1
0
 //
 // Internal API that calls OnItemChanged.  This is invoked from the
 // abstract ContextItemManager class so deriving classes can still
 // invoke it.
 //
 internal void InvokeOnItemChanged(EditingContext context, ContextItem previousItem) 
 {
     OnItemChanged(context, previousItem);
 }
Пример #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) 
 {
 }
            // <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>
            // <param name="item"></param>
            private void OnItemChanged(ContextItem item) 
            {
                SubscribeContextCallback callback;

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

                if (_subscriptions != null && _subscriptions.TryGetValue(item.ItemType, out callback)) 
                {
                    callback(item);
                }
            }
Пример #4
0
        private void OnSelectionChanged(ContextItem item)
        {
            var selection = item as Selection;

            if (selection?.PrimarySelection == null)
                return;

            var addedItems = selection.SelectedObjects.ToList();
            var args = new SelectionChangedEventArgs(SelectionChangedEvent, _currentSelectedItems, addedItems);
            RaiseEvent(args);

            // keep the current selected items
            _currentSelectedItems.Clear();
            _currentSelectedItems.AddRange(addedItems);
        }
            // <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>
            public override void SetValue(ContextItem value) 
            {
                if (value == null) 
                {
                    throw FxTrace.Exception.ArgumentNull("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);
                }

                bool 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);
                        }
                    }
                }
            }