示例#1
0
        private DialogScreenResult ShowModal(IScreenFactory <IScreenBase> screenFactory)
        {
            _modal = true;

            DialogLifecycle dialogLifecycle = null;

            try {
                _screen = screenFactory.Create(
                    _aggregator,
                    s => {
                    dialogLifecycle = new DialogLifecycle(s);
                    s.Children.Add(dialogLifecycle);
                }
                    );

                Initialize();

                try {
                    _windowService.ShowWindow(_window, modal: true);
                } catch (Exception ex) {
                    // If an exception is thrown in the UI code of the dialog window (e.g. in
                    // a command handler or on a Dispatcher action), ShowDialog rethrows this
                    // exception but leaves the Window open and visible.
                    if (!ex.IsCritical() && _window.IsVisible)
                    {
                        CloseWindowImmediatately();
                    }

                    // It's possible that 'HandleClose' or 'HandleWindowClosed' was already executed
                    // but 'ShowDialog' still threw an exception. In that case we have to check the
                    // current state of the screen to prevent invalid state transitions.
                    // TODO: Write a Unit Test when it's known how to reproduce it!
                    CloseScreen(checkState: true);

                    throw;
                }

                if (_lastWindowHandlerException != null)
                {
                    throw _lastWindowHandlerException;
                }

                return(dialogLifecycle.ScreenResult ?? new DialogScreenResult(false));
            } finally {
                Disconnect();

                if (_screen != null)
                {
                    _screen
                    .Children
                    .Remove(dialogLifecycle);
                }

                if (_window.Owner != null)
                {
                    // Fix for http://stackoverflow.com/questions/3144004/wpf-app-loses-completely-focus-on-window-close
                    _window.Owner.Activate();
                }
            }
        }
示例#2
0
        public ShellViewModel(
            ISolutionManager solutionManager,
            IScreenFactory <DragViewModel> dragScreenFactory,
            IScreenFactory <ErrorViewModel> errorScreenFactory,
            IScreenFactory <SolutionViewModel> solutionScreenFactory)
        {
            _solutionManager       = solutionManager;
            _dragScreenFactory     = dragScreenFactory;
            _errorScreenFactory    = errorScreenFactory;
            _solutionScreenFactory = solutionScreenFactory;

            _solutionManager.PropertyChanged +=
                (_, args) =>
            {
                // TODO: WRITE SOMETHING THAT BINDS THE PROPERTYNAME TO AN EXPRESSION<T> OF SENDER, this kind of code with the switch(**MAGIC STRING**) is a piece of crap.
                switch (args.PropertyName)
                {
                case "HasError":
                    if (_solutionManager.HasError)
                    {
                        ActivateItem(_errorScreenFactory.Create());
                    }
                    break;

                case "CurrentSolution":
                    ActivateItem(_solutionScreenFactory.Create());
                    break;
                }
            };

            SwitchToDragView();
        }
示例#3
0
        private void Show(IScreenFactory <IScreenBase> screenFactory)
        {
            _modal = false;

            _screen = screenFactory.Create(_aggregator);
            Initialize();
            _windowService.ShowWindow(_window, modal: false);
        }
示例#4
0
        public void ScreenFactoriesForConcreteScree_CanBeAssignedToScreenBaseFactoryVariable()
        {
            IScreenFactory <TestScreen>  concreteFactory = ScreenFactory.For <TestScreen>();
            IScreenFactory <IScreenBase> factory         = concreteFactory;

            IScreenBase screen = factory.Create(Aggregator);

            Assert.IsInstanceOfType(screen, typeof(TestScreen));
        }
示例#5
0
        public void Create_ScreenFactoryForInstance_CallsInitialize()
        {
            var expected = new InitializableScreen(Aggregator);

            IScreenFactory <InitializableScreen> factory = ScreenFactory.For <InitializableScreen>(Locator);

            var actual = factory.Create(Aggregator);

            Assert.IsTrue(actual.InitializeWasCalled);
        }
示例#6
0
        public void Create_ScreenFactoryForInstance_ReturnsThisInstance()
        {
            var expected = new InitializableScreen(Aggregator);

            IScreenFactory <InitializableScreen> factory = ScreenFactory.For(expected);

            var actual = factory.Create(Aggregator);

            Assert.AreEqual(expected, actual);
        }
示例#7
0
        public TestScreenResult ShowDialog <TScreen>(
            IScreenFactory <TScreen> screen
            ) where TScreen : IScreenBase
        {
            IScreenBase s         = screen.Create(_aggregator);
            var         lifecycle = new DialogLifecycle(s);

            s.Children.Add(lifecycle);
            s.Children.Add(new ScreenCloseHandler(_ => { })); // TODO: Remove code duplication between here and responder
            return(new TestScreenResult(lifecycle));
        }
        public TScreen AddScreen <TScreen>(IScreenFactory <TScreen> screen)
            where TScreen : T, IScreenBase
        {
            TScreen s = screen.Create(_aggregator);

            // The screen is added AFTER it was initialized by the screen
            // factory.
            Attach(s);

            return(s);
        }
示例#9
0
        /// <inheritdoc />
        public void ChangeScreen <T>()
            where T : IScreen
        {
            IScreen screen = _screenFactory.Create(typeof(T));

            _screen?.Close();
            _world.Clear();

            _screen = screen;
            _screen.Initialize();
        }
示例#10
0
        public void Initialize(GraphicsDeviceManager graphics, Type screenType)
        {
            if (!typeof(IScreen).IsAssignableFrom(screenType))
            {
                throw new Exception("screenType must implement the IScreen interface.");
            }
            _systemLoader.Load();

            IScreen initialScreen = _screenFactory.Create(screenType);

            _screenManager.ChangeScreen(initialScreen);
        }
示例#11
0
 public void SwitchToDragView()
 {
     ActivateItem(_dragScreenFactory.Create());
 }