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>
        /// 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>
        public override async void DeactivateItem(T item, bool close)
        {
            if (item == null || !ReferenceEquals(item, ActiveItem))
            {
                return;
            }

            var result = await CloseStrategy.ExecuteAsync(new[] { ActiveItem });

            if (result.Item1)
            {
                ChangeActiveItem(default(T), close);
            }
        }
Ejemplo n.º 3
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)
                {
                    var closeResult = await CloseStrategy.ExecuteAsync(_items.ToArray(), cancellationToken);

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

                        _items.RemoveRange(closeResult.Children);
                    }

                    return(closeResult.CloseCanOccur);
                }
Ejemplo n.º 4
0
                /// <summary>
                /// Called to check whether or not this instance can close.
                /// </summary>
                /// <returns>A task containing the result of the close check.</returns>
                public override async Task <bool> CanCloseAsync()
                {
                    var result = await CloseStrategy.ExecuteAsync(_items.ToArray());

                    var canClose   = result.CanClose;
                    var closeables = result.Closeables;

                    if (!canClose && closeables.Any())
                    {
                        foreach (var x in closeables.OfType <IDeactivate>())
                        {
                            x.Deactivate(true);
                        }
                        _items.RemoveRange(closeables);
                    }

                    return(canClose);
                }
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);
                }
                return;
            }

            var closeResult = await CloseStrategy.ExecuteAsync(new[] { ActiveItem }, cancellationToken);

            if (closeResult.CloseCanOccur)
            {
                await ChangeActiveItemAsync(item, true, cancellationToken);
            }
        }
Ejemplo n.º 6
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)
                    {
                        var closeResult = await CloseStrategy.ExecuteAsync(new[] { item }, CancellationToken.None);

                        if (closeResult.CloseCanOccur)
                        {
                            await CloseItemCoreAsync(item, cancellationToken);
                        }
                    }
                    else
                    {
                        await ScreenExtensions.TryDeactivateAsync(item, false, cancellationToken);
                    }
                }
Ejemplo n.º 7
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>
                public override async void DeactivateItem(T item, bool close)
                {
                    if (item == null)
                    {
                        return;
                    }

                    if (!close)
                    {
                        ScreenHelper.TryDeactivate(item, false);
                    }
                    else
                    {
                        var result = await CloseStrategy.ExecuteAsync(new[] { item });

                        if (result.CanClose)
                        {
                            CloseItemCore(item);
                        }
                    }
                }
Ejemplo n.º 8
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 = default)
                {
                    var closeResult = await CloseStrategy.ExecuteAsync(_items.ToList(), cancellationToken);

                    if (!closeResult.CloseCanOccur && closeResult.Children.Any())
                    {
                        var closable = closeResult.Children;

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

                            var previousActive = ActiveItem;
                            await ChangeActiveItemAsync(next, true);

                            _items.Remove(previousActive);

                            var stillToClose = closable.ToList();
                            stillToClose.Remove(previousActive);
                            closable = stillToClose;
                        }

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

                        _items.RemoveRange(closable);
                    }

                    return(closeResult.CloseCanOccur);
                }
                /// <summary>
                /// Called to check whether or not this instance can close.
                /// </summary>
                /// <returns>A task containing the result of the close check.</returns>
                public override async Task <bool> CanCloseAsync()
                {
                    var result = await CloseStrategy.ExecuteAsync(_items.ToArray());

                    var canClose  = result.CanClose;
                    var closables = result.Closeables;

                    if (!canClose && closables.Any())
                    {
                        if (closables.Contains(ActiveItem))
                        {
                            var list = _items.ToList();
                            var next = ActiveItem;
                            do
                            {
                                var previous = next;
                                next = DetermineNextItemToActivate(list, list.IndexOf(previous));
                                list.Remove(previous);
                            } while (closables.Contains(next));

                            var previousActive = ActiveItem;
                            ChangeActiveItem(next, true);
                            _items.Remove(previousActive);

                            var stillToClose = closables.ToList();
                            stillToClose.Remove(previousActive);
                            closables = stillToClose;
                        }

                        foreach (var x in closables.OfType <IDeactivate>())
                        {
                            x.Deactivate(true);
                        }
                        _items.RemoveRange(closables);
                    }

                    return(canClose);
                }
Ejemplo n.º 10
0
        /// <summary>
        /// Activates the specified item.
        /// </summary>
        /// <param name="item">The item to activate.</param>
        public override async void ActivateItem(T item)
        {
            if (item != null && ReferenceEquals(item, ActiveItem))
            {
                if (IsActive)
                {
                    ScreenHelper.TryActivate(item);
                    OnActivationProcessed(item, true);
                }
                return;
            }

            var result = await CloseStrategy.ExecuteAsync(new[] { ActiveItem });

            if (result.Item1)
            {
                ChangeActiveItem(item, true);
            }
            else
            {
                OnActivationProcessed(item, false);
            }
        }
Ejemplo n.º 11
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)
        {
            var closeResult = await CloseStrategy.ExecuteAsync(new[] { ActiveItem }, cancellationToken);

            return(closeResult.CloseCanOccur);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Called to check whether or not this instance can close.
        /// </summary>
        /// <returns>A task containing the result of the close check.</returns>
        public override async Task <bool> CanCloseAsync()
        {
            var result = await CloseStrategy.ExecuteAsync(new[] { ActiveItem });

            return(result.Item1);
        }