Ejemplo n.º 1
0
        private IWindowView GetOrCreateWindowView(
            IWindowContent windowContent,
            IWindowSettings setting,
            IWindowView ownerWindow,
            bool isCreate,
            Type windowType = null)
        {
            this.CheckAndRemoveInvalidCache();

            var needCreateView = this._windowCaches.ContainsKey(windowContent) == false || isCreate;

            if (needCreateView)
            {
                this.CreateWindowView(windowContent, setting, windowType);
            }

            var window = this._windowCaches[windowContent];

            if (ownerWindow != null)
            {
                window.View.SetOwner(ownerWindow);
            }

            return(window.View);
        }
Ejemplo n.º 2
0
        public void SetOwner(IWindowView windowView)
        {
            if (windowView is Window == false)
            {
                return;
            }

            var ownerWindow = (Window)windowView;

            this.Owner = ownerWindow;
        }
Ejemplo n.º 3
0
 public static void Show(IWindowView content,
                         Action <ToolWindow> hideCallback = null,
                         Action loadedCallback            = null,
                         double width          = 400,
                         double height         = 300,
                         ResizeMode resizeMode = ResizeMode.NoResize,
                         bool showInTaskBar    = false,
                         WindowStartupLocation startupLocation = WindowStartupLocation.CenterOwner)
 {
     ShowWindow(content, hideCallback, loadedCallback, width, height, resizeMode, showInTaskBar, startupLocation, false);
 }
Ejemplo n.º 4
0
        private TController CreateWindowInternal <TView, TController> (IWindowView parentWindow)
            where TView : IWindowView
        {
            TView      view      = viewsCreator.CreateView <TView> ();
            IPresenter presenter = CreatePresenterForView(view);

            presenter.View = view;

            if (parentWindow != null)
            {
                view.SetParent(parentWindow);
            }

            return(presenter is TController ? (TController)presenter : default(TController));
        }
Ejemplo n.º 5
0
        public void CloseWindow(IWindowView windowView)
        {
            windowView.Close();

            var targetPair = this._windowCaches.FirstOrDefault(w => w.Value.View.Equals(windowView));

            if (Equals(targetPair, default(KeyValuePair <IWindowContent, WindowViewStore>)))
            {
                // TODO : need logging.
                return;
            }

            this._windowCaches.Remove(targetPair.Key);

            this.CheckAndRemoveInvalidCache();
        }
Ejemplo n.º 6
0
        private static void ShowWindow(IWindowView content,
                                       Action <ToolWindow> hideCallback = null,
                                       Action loadedCallback            = null,
                                       double width          = 400,
                                       double height         = 300,
                                       ResizeMode resizeMode = ResizeMode.NoResize,
                                       bool showInTaskBar    = false,
                                       WindowStartupLocation startupLocation = WindowStartupLocation.CenterOwner,
                                       bool isModal      = false,
                                       WindowStyle style = WindowStyle.SingleBorderWindow)
        {
            if (Application.Current.MainWindow == null || !Application.Current.MainWindow.IsLoaded)
            {
                DispatcherObjectExt.BeginInvoke(() => ShowWindow(content, hideCallback, loadedCallback, width, height, resizeMode, showInTaskBar, startupLocation, isModal, style), DispatcherPriority.Background);

                return;
            }
            var toolWindow = new ToolWindow
            {
                Width                 = width,
                Height                = height,
                Content               = content,
                ResizeMode            = resizeMode,
                ShowInTaskbar         = showInTaskBar,
                WindowStartupLocation = startupLocation,
                Owner                 = Application.Current.MainWindow,
                hideCallback          = hideCallback,
                loadedCallback        = loadedCallback,
                WindowStyle           = style,
            };

            toolWindow.Loaded += OnLoaded;

            toolWindow.AfterHide += OnAfterHide;

            if (isModal)
            {
                toolWindow.ShowDialog();
            }
            else
            {
                toolWindow.Show();
            }
        }
        void SetMainContent(Views.IWindowView view)
        {
            if (view == null)
            {
                return;
            }

            var content = view.GetMainContent();

            if (content != null)
            {
                panel1.Child = content;
                if (_currentView != null)
                {
                    if (_currentView is IDisposable)
                    {
                        ((IDisposable)(_currentView)).Dispose();
                    }
                }
                _currentView = view;
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Creates a new MVP triad for a window.
 /// </summary>
 /// <typeparam name="TView">The type of the window's View.</typeparam>
 /// <typeparam name="TController">The type of the Controller.</typeparam>
 /// <param name="parentWindow">The window to be set as parent of the new window.</param>
 /// <returns>The Controller of the new window.</returns>
 public TController CreateWindow <TView, TController> (IWindowView parentWindow)
     where TView : IWindowView
 {
     return(CreateWindowInternal <TView, TController> (parentWindow));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Sets the parent for the current form.
 /// The <see cref="parent"/> parameter is of type <see cref="IWindowView"/>, but for the procedure to success,
 /// it has to also inherits from <see cref="Form"/> class. If the <see cref="parent"/> does not inherits from <see cref="Form"/>
 /// the parent is set to null.
 /// </summary>
 /// <param name="parent">The parent view for the current form.</param>
 public void SetParent(IWindowView parent)
 {
     Owner = parent as Form;
 }
Ejemplo n.º 10
0
 protected AWindowPresenter(IWindowView view)
 {
     _windowView = view;
 }
Ejemplo n.º 11
0
 public void ChangeWindowState(IWindowView windowView, WindowViewStates states)
 {
     windowView.ChangeWindowState(states);
 }
Ejemplo n.º 12
0
 public void SetOwner(IWindowView targetView, IWindowView ownerView)
 {
     targetView.SetOwner(ownerView);
 }
Ejemplo n.º 13
0
 public void DragMove(IWindowView windowView)
 {
     windowView.MoveWindow();
 }
Ejemplo n.º 14
0
        private void InternalShowView(IView view, FrameworkElement target, IViewModel sourceVM)
        {
            switch (target)
            {
#if WPF
            case FrameworkElement targetWindow when view is IWindowView:
                var         viewWindow  = view.ViewObject as Window;
                IWindowView iviewWindow = view as IWindowView;

                if (targetWindow == null)
                {
                    targetWindow = sourceVM.StageManager.CurrentBindingView as Window;
                }
                if (iviewWindow.IsAutoOwnerSetNeeded)
                {
                    //viewWindow.Owner = targetWindow;
                }
                viewWindow.Show();
                break;

            case Frame targetFrame:

                var ipv = (view as IPageView);

                if (ipv != null)
                {
                    ipv.FrameObject = this.Target;
                }
                targetFrame.Navigate(view.ViewObject);

                break;
#endif
#if WINDOWS_UWP
            case ContentDialog targetCDControl:
                targetCDControl.Content = view.ViewObject;
                var         viewModel          = view.ViewModel;
                IDisposable closeFromViewModel = null;
                closeFromViewModel = Observable.FromAsync(x => viewModel.WaitForClose())
                                     .ObserveOnDispatcher()
                                     .Subscribe(_ =>
                {
                    viewModel.IsDisposingWhenUnloadRequired = true;
                    targetCDControl.Hide();
                    targetCDControl.Content = null;
                    closeFromViewModel?.Dispose();
                    closeFromViewModel = null;
                });
                var t = targetCDControl.ShowAsync();
                break;
#endif
            case ContentControl targetCControl:
                targetCControl.Content = view.ViewObject;
                break;

            case Panel targetPanelControl:
                targetPanelControl.Children.Add(view.ViewObject as UIElement);
                break;

            default:
                throw new InvalidOperationException(string.Format("This view {0} is not support show in {1} ", view.GetType(), target.GetType()));
            }
        }
Ejemplo n.º 15
0
 public void Init(IWindowView view)
 {
     View         = view;
     ConcreteView = (TView)View;
 }