Ejemplo n.º 1
0
        protected virtual void OnPopToRoot(IPageViewModel viewModel, bool animated)
        {
            var except = PageReferences.FirstOrDefault();

            PageReferences.RemoveAll(p => p != except);
            PopToRootAsync(animated);
        }
        /// <summary>
        /// Add an imported page to our output
        /// @throws IOException, BadPdfFormatException
        /// </summary>
        /// <param name="iPage">an imported page</param>
        public void AddPage(PdfImportedPage iPage)
        {
            var pageNum = SetFromIPage(iPage);

            var thePage = Reader.GetPageN(pageNum);
            var origRef = Reader.GetPageOrigRef(pageNum);

            Reader.ReleasePage(pageNum);
            var key = new RefKey(origRef);
            PdfIndirectReference pageRef;
            var iRef = (IndirectReferences)Indirects[key];

            if (iRef != null && !iRef.Copied)
            {
                PageReferences.Add(iRef.Ref);
                iRef.SetCopied();
            }
            pageRef = CurrentPage;
            if (iRef == null)
            {
                iRef           = new IndirectReferences(pageRef);
                Indirects[key] = iRef;
            }
            iRef.SetCopied();
            var newPage = CopyDictionary(thePage);

            Root.AddPage(newPage);
            ++currentPageNumber;
        }
Ejemplo n.º 3
0
        protected void OnPopToNewRoot(IPageViewModel viewModel, bool animated)
        {
            var pref = createPageFor(viewModel);

            PageReferences.Clear();
            PageReferences.Add(pref);
            popToNewRootAsync(pref.View, animated);
        }
Ejemplo n.º 4
0
 protected void RemoveReferenceFromStack(ViewLinkHelper reference)
 {
     if (reference != null)
     {
         PageReferences.Remove(reference);
         ViewModel.EnforcePageDisappearsNotification(reference.Model, true);
     }
 }
Ejemplo n.º 5
0
        protected void PageDisappears(ViewLinkHelper viewLinkHelper)
        {
            var removingFromStack = ViewModel.Pages.LastOrDefault() == viewLinkHelper.Model;

            if (removingFromStack)
            {
                PageReferences.Remove(viewLinkHelper);
            }

            ViewModel.EnforcePageDisappearsNotification(viewLinkHelper.Model, removingFromStack);
        }
Ejemplo n.º 6
0
        protected virtual void OnPushViewModel(IPageViewModel viewModel, bool animated)
        {
            if (PageReferences.Any(p => p.Model == viewModel))
            {
                throw new Exception(String.Format("The navigation stack already contains the viewModel: {0}", viewModel));
            }

            var pref = createPageFor(viewModel);

            PageReferences.Add(pref);
            PushAsync(pref.View, animated);
        }
Ejemplo n.º 7
0
        protected virtual void OnPopViewModel(IPageViewModel viewModel, bool animated)
        {
            if (PageReferences.LastOrDefault()?.Model != viewModel)
            {
                throw new Exception(String.Format("The viewModel is not the last in the stack: {0}", viewModel));
            }

            var pageReference = PageReferences.LastOrDefault();

            PageReferences.RemoveAt(PageReferences.Count - 1);
            if (this.Navigation.NavigationStack.LastOrDefault() == pageReference.View)
            {
                PopAsync();
            }
        }
Ejemplo n.º 8
0
        async void updatePages()
        {
            if (_pages != null && _pages.Count > 0)
            {
                foreach (var pref in PageReferences.Where(p => !_pages.Contains(p.Model)).ToList())
                {
                    PageReferences.Remove(pref);
                }

                if (new[] { this.Navigation.NavigationStack.FirstOrDefault(), this.Navigation.NavigationStack.LastOrDefault(), PageReferences.LastOrDefault()?.View }
                    .All(v => v == PageReferences.FirstOrDefault()?.View))
                {
                    OnPopToRoot(Pages.LastOrDefault(), TransitionAnimationEnabled);
                }
                else
                {
                    if (Navigation.NavigationStack.Count > 0)
                    {
                        var pref = createPageFor(Pages.LastOrDefault());

                        PageReferences.Clear();
                        PageReferences.Add(pref);
                        await popToNewRootAsync(pref.View, TransitionAnimationEnabled);
                    }
                    else
                    {
                        OnPushViewModel(Pages.LastOrDefault(), TransitionAnimationEnabled);
                    }
                }
            }
            else
            {
                //At least on page should be displayed
                PageReferences.Clear();
                var blankPage = new ContentPage {
                    BackgroundColor = Color.Transparent
                };

                if (Navigation.NavigationStack.Count > 0)
                {
                    await popToNewRootAsync(blankPage, TransitionAnimationEnabled);
                }
                else
                {
                    await PushAsync(blankPage, TransitionAnimationEnabled);
                }
            }
        }
Ejemplo n.º 9
0
        void _pages_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            bool wasResetting = resetting;

            resetting = false;

            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                if (wasResetting && e.NewItems.OfType <IPageViewModel> ().FirstOrDefault() == PageReferences.FirstOrDefault()?.Model)
                {
                    OnPopToRoot(Pages.LastOrDefault(), TransitionAnimationEnabled);
                }
                else if (wasResetting)
                {
                    OnPopToNewRoot(e.NewItems.OfType <IPageViewModel> ().LastOrDefault(), TransitionAnimationEnabled);
                }
                else
                {
                    OnPushViewModel(e.NewItems.OfType <IPageViewModel> ().LastOrDefault(), TransitionAnimationEnabled);
                }
            }
            else if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                if (PageReferences.LastOrDefault()?.Model == e.OldItems.OfType <IPageViewModel> ().LastOrDefault() && e.OldItems.Count == 1)
                {
                    OnPopViewModel(e.OldItems.OfType <IPageViewModel> ().LastOrDefault(), TransitionAnimationEnabled);
                }
                else
                {
                    PageReferences.RemoveAll(r => e.OldItems.Contains(r.Model));
                }
            }
            else if (e.Action == NotifyCollectionChangedAction.Reset)
            {
                resetting = true;
            }
        }