Ejemplo n.º 1
0
        /// <summary>
        /// Deactivates the specified item.
        /// </summary>
        /// <param name="item">The item to close.</param>
        /// <param name="close">Indicates whether or not to close the item after deactivating it.</param>
        /// <param name="cancellationToken">The cancellation token to cancel operation.</param>
        /// <returns>A task that represents the asynchronous operation.</returns>
        public override async Task DeactivateItemAsync(T item, bool close, CancellationToken cancellationToken)
        {
            if (item == null || !item.Equals(ActiveItem))
            {
                return;
            }

            ICloseResult <T> closeResult = await CloseStrategy.ExecuteAsync(new[] { ActiveItem }, CancellationToken.None);

            if (closeResult.CloseCanOccur)
            {
                await ChangeActiveItemAsync(default, close, cancellationToken);
Ejemplo n.º 2
0
                /// <summary>
                /// Called to check whether or not this instance can close.
                /// </summary>
                /// <param name="cancellationToken">The cancellation token to cancel operation.</param>
                /// <returns>A task that represents the asynchronous operation.</returns>
                public override async Task <bool> CanCloseAsync(CancellationToken cancellationToken)
                {
                    ICloseResult <T> closeResult = await CloseStrategy.ExecuteAsync(_items.ToList(), cancellationToken);

                    if (!closeResult.CloseCanOccur && closeResult.Children.Any())
                    {
                        foreach (IDeactivate deactivate in closeResult.Children.OfType <IDeactivate>())
                        {
                            await deactivate.DeactivateAsync(true, cancellationToken);
                        }

                        _items.RemoveRange(closeResult.Children);
                    }

                    return(closeResult.CloseCanOccur);
                }
Ejemplo n.º 3
0
                /// <summary>
                /// Deactivates the specified item.
                /// </summary>
                /// <param name="item">The item to close.</param>
                /// <param name="close">Indicates whether or not to close the item after deactivating it.</param>
                /// <param name="cancellationToken">The cancellation token to cancel operation.</param>
                /// <returns>A task that represents the asynchronous operation.</returns>
                public override async Task DeactivateItemAsync(T item, bool close, CancellationToken cancellationToken)
                {
                    if (item == null)
                    {
                        return;
                    }

                    if (close)
                    {
                        ICloseResult <T> closeResult = await CloseStrategy.ExecuteAsync(new[] { item }, CancellationToken.None);

                        if (closeResult.CloseCanOccur)
                        {
                            await CloseItemCoreAsync(item, cancellationToken);
                        }
                    }
                    else
                    {
                        await ScreenExtensions.TryDeactivateAsync(item, false, cancellationToken);
                    }
                }
Ejemplo n.º 4
0
                /// <summary>
                /// Called to check whether or not this instance can close.
                /// </summary>
                /// <param name="cancellationToken">The cancellation token to cancel operation.</param>
                /// <returns>A task that represents the asynchronous operation.</returns>
                public override async Task <bool> CanCloseAsync(CancellationToken cancellationToken)
                {
                    ICloseResult <T> closeResult = await CloseStrategy.ExecuteAsync(_items.ToList(), cancellationToken);

                    if (!closeResult.CloseCanOccur && closeResult.Children.Any())
                    {
                        IEnumerable <T> closable = closeResult.Children;

                        if (closable.Contains(ActiveItem))
                        {
                            List <T> list = _items.ToList();
                            T        next = ActiveItem;
                            do
                            {
                                T previous = next;
                                next = DetermineNextItemToActivate(list, list.IndexOf(previous));
                                list.Remove(previous);
                            } while (closable.Contains(next));

                            T previousActive = ActiveItem;
                            await ChangeActiveItemAsync(next, true, cancellationToken);

                            _items.Remove(previousActive);

                            List <T> stillToClose = closable.ToList();
                            stillToClose.Remove(previousActive);
                            closable = stillToClose;
                        }

                        foreach (IDeactivate deactivate in closable.OfType <IDeactivate>())
                        {
                            await deactivate.DeactivateAsync(true, cancellationToken);
                        }

                        _items.RemoveRange(closable);
                    }

                    return(closeResult.CloseCanOccur);
                }
Ejemplo n.º 5
0
        /// <inheritdoc />
        public override async Task ActivateItemAsync(T item, CancellationToken cancellationToken)
        {
            if (item != null && item.Equals(ActiveItem))
            {
                if (IsActive)
                {
                    await ScreenExtensions.TryActivateAsync(item, cancellationToken);

                    OnActivationProcessed(item, true);
                }
                return;
            }

            ICloseResult <T> closeResult = await CloseStrategy.ExecuteAsync(new[] { ActiveItem }, cancellationToken);

            if (closeResult.CloseCanOccur)
            {
                await ChangeActiveItemAsync(item, true, cancellationToken);
            }
            else
            {
                OnActivationProcessed(item, false);
            }
        }