public async Task ActiveViewInHierarchy()
        {
            var controller = new TestController();
            await controller.Initialize(null, null);

            var view = await controller.GetDocumentView();

            Assert.AreEqual(view, view.ActiveViewInHierarchy);

            var attached1 = new DocumentViewContent(c => Task.FromResult <Control> (null));
            var attached2 = new DocumentViewContent(c => Task.FromResult <Control> (null));

            view.AttachedViews.Add(attached1);
            view.AttachedViews.Add(attached2);

            Assert.AreEqual(view, view.ActiveViewInHierarchy);

            attached1.SetActive();
            Assert.AreEqual(attached1, view.ActiveViewInHierarchy);
            Assert.AreEqual(attached1, attached1.ActiveViewInHierarchy);
            Assert.AreEqual(attached2, attached2.ActiveViewInHierarchy);

            attached2.SetActive();
            Assert.AreEqual(attached2, view.ActiveViewInHierarchy);
            Assert.AreEqual(attached1, attached1.ActiveViewInHierarchy);
            Assert.AreEqual(attached2, attached2.ActiveViewInHierarchy);
        }
        public async Task SplitContainerCollectionOperations(DocumentViewContainerMode mode)
        {
            var controller = new ContentVisibleEventWithContainerTestController();

            controller.Mode = mode;

            await controller.Initialize(new ModelDescriptor());

            var doc = await documentManager.OpenDocument(controller);

            var view = await controller.GetDocumentView();

            Assert.IsTrue(controller.View1.ContentVisible);
            Assert.IsTrue(controller.View2.ContentVisible);
            Assert.IsTrue(controller.View3.ContentVisible);

            var newView = new DocumentViewContent(() => new DummyControl());

            Assert.IsFalse(newView.ContentVisible);

            controller.Container.Views [1] = newView;
            Assert.IsTrue(newView.ContentVisible);
            Assert.IsFalse(controller.View2.ContentVisible);

            controller.Container.Views.RemoveAt(1);
            Assert.IsFalse(newView.ContentVisible);
            Assert.IsTrue(controller.View1.ContentVisible);
            Assert.IsTrue(controller.View3.ContentVisible);

            controller.Container.Views.Clear();
            Assert.IsFalse(controller.View1.ContentVisible);
            Assert.IsFalse(controller.View3.ContentVisible);
        }
 /// <summary>
 /// Called to get the control that the main view is going to show.
 /// </summary>
 /// <returns>The control</returns>
 /// <param name="view">View to which the control will be added.</param>
 protected virtual Control OnGetViewControl(DocumentViewContent view)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Called to (asynchronously) get the control that the main view is going to show.
 /// </summary>
 /// <returns>The control</returns>
 /// <param name="token">Cancellation token for the async operation</param>
 /// <param name="view">View to which the control will be added.</param>
 protected virtual Task <Control> OnGetViewControlAsync(CancellationToken token, DocumentViewContent view)
 {
     return(Task.FromResult(OnGetViewControl(view)));
 }
        public void ActiveViewInHierarchy2()
        {
            var root = new DocumentViewContainer()
            {
                Title = "root"
            };

            root.IsRoot = true;
            Assert.IsNull(root.ActiveViewInHierarchy);
            Assert.IsNull(root.ActiveView);

            var attached1 = new DocumentViewContent(c => Task.FromResult <Control> (null))
            {
                Title = "attached1"
            };

            root.AttachedViews.Add(attached1);
            Assert.IsNull(root.ActiveView);
            Assert.IsNull(root.ActiveViewInHierarchy);

            var view1 = new DocumentViewContent(c => Task.FromResult <Control> (null))
            {
                Title = "view1"
            };

            root.Views.Add(view1);
            Assert.AreEqual(view1, root.ActiveView);
            Assert.AreEqual(view1, root.ActiveViewInHierarchy);
            Assert.AreEqual(view1, view1.ActiveViewInHierarchy);

            attached1.SetActive();
            Assert.AreEqual(view1, root.ActiveView);
            Assert.AreEqual(attached1, root.ActiveViewInHierarchy);

            root.SetActive();
            Assert.AreEqual(view1, root.ActiveView);
            Assert.AreEqual(view1, root.ActiveViewInHierarchy);

            var view2 = new DocumentViewContent(c => Task.FromResult <Control> (null))
            {
                Title = "view2"
            };

            root.Views.Add(view2);
            Assert.AreEqual(view1, root.ActiveView);
            Assert.AreEqual(view1, root.ActiveViewInHierarchy);
            Assert.AreEqual(view2, view2.ActiveViewInHierarchy);

            var container = new DocumentViewContainer();

            root.Views.Add(container);
            Assert.AreEqual(view1, root.ActiveView);
            Assert.AreEqual(view1, root.ActiveViewInHierarchy);
            Assert.IsNull(container.ActiveViewInHierarchy);

            var subView1 = new DocumentViewContent(c => Task.FromResult <Control> (null))
            {
                Title = "subView1"
            };

            container.Views.Add(subView1);
            Assert.AreEqual(view1, root.ActiveView);
            Assert.AreEqual(view1, root.ActiveViewInHierarchy);
            Assert.AreEqual(subView1, container.ActiveView);
            Assert.AreEqual(subView1, container.ActiveViewInHierarchy);
            Assert.AreEqual(subView1, subView1.ActiveViewInHierarchy);

            var subView2 = new DocumentViewContent(c => Task.FromResult <Control> (null))
            {
                Title = "subView2"
            };

            container.Views.Add(subView2);
            Assert.AreEqual(view1, root.ActiveView);
            Assert.AreEqual(view1, root.ActiveViewInHierarchy);
            Assert.AreEqual(subView1, container.ActiveView);
            Assert.AreEqual(subView1, container.ActiveViewInHierarchy);
            Assert.AreEqual(subView2, subView2.ActiveViewInHierarchy);

            container.SetActive();
            Assert.AreEqual(container, root.ActiveView);
            Assert.AreEqual(subView1, root.ActiveViewInHierarchy);
            Assert.AreEqual(subView1, container.ActiveViewInHierarchy);

            subView2.SetActive();
            Assert.AreEqual(subView2, root.ActiveViewInHierarchy);
            Assert.AreEqual(subView2, container.ActiveViewInHierarchy);

            view2.SetActive();
            Assert.AreEqual(view2, root.ActiveViewInHierarchy);
            Assert.AreEqual(subView2, container.ActiveViewInHierarchy);

            subView1.SetActive();
            Assert.AreEqual(view2, root.ActiveViewInHierarchy);
            Assert.AreEqual(subView1, container.ActiveViewInHierarchy);

            container.SetActive();
            Assert.AreEqual(subView1, root.ActiveViewInHierarchy);
            Assert.AreEqual(subView1, container.ActiveViewInHierarchy);
        }
Beispiel #6
0
 protected override Control OnGetViewControl(DocumentViewContent view)
 {
     return(new DummyControl());
 }
        public async Task WithTabs()
        {
            var controller = new ContentVisibleEventWithContainerTestController();

            controller.Mode = DocumentViewContainerMode.Tabs;

            await controller.Initialize(new ModelDescriptor());

            var doc = await documentManager.OpenDocument(controller);

            var view = await controller.GetDocumentView();

            Assert.IsFalse(controller.View1.ContentVisible);
            Assert.IsTrue(controller.View2.ContentVisible);
            Assert.IsFalse(controller.View3.ContentVisible);

            Assert.AreEqual(0, controller.View1_VisibleChangeEvents);
            Assert.AreEqual(1, controller.View2_VisibleChangeEvents);
            Assert.AreEqual(0, controller.View3_VisibleChangeEvents);

            controller.View3.SetActive();

            Assert.IsFalse(controller.View1.ContentVisible);
            Assert.IsFalse(controller.View2.ContentVisible);
            Assert.IsTrue(controller.View3.ContentVisible);

            Assert.AreEqual(0, controller.View1_VisibleChangeEvents);
            Assert.AreEqual(2, controller.View2_VisibleChangeEvents);
            Assert.AreEqual(1, controller.View3_VisibleChangeEvents);

            controller.View1.SetActive();

            Assert.IsTrue(controller.View1.ContentVisible);
            Assert.IsFalse(controller.View2.ContentVisible);
            Assert.IsFalse(controller.View3.ContentVisible);

            Assert.AreEqual(1, controller.View1_VisibleChangeEvents);
            Assert.AreEqual(2, controller.View2_VisibleChangeEvents);
            Assert.AreEqual(2, controller.View3_VisibleChangeEvents);

            var extraView = new DocumentViewContent(() => new DummyControl());

            controller.Container.Views.Add(extraView);
            Assert.IsFalse(extraView.ContentVisible);

            var doc2 = await documentManager.OpenDocument(new ContentVisibleEventWithContainerTestController());

            doc2.Select();

            Assert.IsFalse(controller.View1.ContentVisible);
            Assert.IsFalse(controller.View2.ContentVisible);
            Assert.IsFalse(controller.View3.ContentVisible);

            Assert.AreEqual(2, controller.View1_VisibleChangeEvents);
            Assert.AreEqual(2, controller.View2_VisibleChangeEvents);
            Assert.AreEqual(2, controller.View3_VisibleChangeEvents);

            await doc.Close(true);

            await doc2.Close(true);
        }