/// <summary>
        /// Creates a window in non-modal state. If a window with the specified viewModelType exists, the window is activated instead of being created.
        /// </summary>
        /// <param name="uiVisualizerService">The UI visualizer service.</param>
        /// <typeparam name="TViewModel">The type of the view model.</typeparam>
        /// <param name="model">The model to be injected into the view model, can be <c>null</c>.</param>
        /// <param name="completedProc">The completed proc. Not applicable if window already exists.</param>
        /// <returns><c>true</c> if shown or activated successfully, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="uiVisualizerService" /> is <c>null</c>.</exception>
        public static Task <bool?> ShowOrActivateAsync <TViewModel>(this IUIVisualizerService uiVisualizerService, object model = null, EventHandler <UICompletedEventArgs> completedProc = null)
            where TViewModel : IViewModel
        {
            Argument.IsNotNull("uiVisualizerService", uiVisualizerService);

            var dependencyResolver = uiVisualizerService.GetDependencyResolver();

            var viewModelManager = dependencyResolver.Resolve <IViewModelManager>();
            var viewModel        = viewModelManager.GetFirstOrDefaultInstance(typeof(TViewModel));

            if (viewModel == null)
            {
                var viewModelFactory = GetViewModelFactory(uiVisualizerService);
                var vm = viewModelFactory.CreateViewModel(typeof(TViewModel), model);
                return(uiVisualizerService.ShowAsync(vm, completedProc));
            }

            var viewLocator = dependencyResolver.Resolve <IViewLocator>();
            var viewType    = viewLocator.ResolveView(viewModel.GetType());
            var viewManager = dependencyResolver.Resolve <IViewManager>();
            var view        = viewManager.GetFirstOrDefaultInstance(viewType);
            var window      = view as System.Windows.Window;

            if (view == null || window == null)
            {
                return(uiVisualizerService.ShowAsync(viewModel, completedProc));
            }

            var activated = ActivateWindow(window);

            return(TaskHelper <bool?> .FromResult(activated));
        }
Esempio n. 2
0
        /// <summary>
        /// Shows a window that is registered with the specified view model in a non-modal state.
        /// </summary>
        /// <param name="this">The <see cref="IUIVisualizerService" /> service self instance.</param>
        /// <param name="viewModel">The view model.</param>
        /// <param name="openedProc">The callback procedure that will be invoked when the window is opened (registered in the <see cref="IViewManager" />). This value can be <c>null</c>.</param>
        /// <param name="completedProc">The callback procedure that will be invoked as soon as the window is closed. This value can be <c>null</c>.</param>
        /// <param name="timeOutInMilliseconds">The time out in milliseconds.</param>
        /// <returns><c>true</c> if the popup window is successfully opened; otherwise <c>false</c>.</returns>
        /// <exception cref="System.ArgumentNullException">The <paramref name="this" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="viewModel" /> is <c>null</c>.</exception>
        /// <exception cref="ViewModelNotRegisteredException">The <paramref name="viewModel" /> is not registered by the
        /// <see cref="IUIVisualizerService.Register(string,System.Type,bool)" />
        /// method first.</exception>
        /// <remarks>If the <see cref="IViewManager.GetViewsOfViewModel" /> method returns no active views for the <paramref name="viewModel" /> in the expected <paramref name="timeOutInMilliseconds" /> time
        /// then this method will assume that the view is actually opened and invokes <paramref name="openedProc" /> anyway.</remarks>
        public static Task <bool?> ShowAsync(this IUIVisualizerService @this, IViewModel viewModel, Action openedProc = null, EventHandler <UICompletedEventArgs> completedProc = null, uint timeOutInMilliseconds = 10000)
        {
            Argument.IsNotNull("@this", @this);

            return(new Task <bool?>(() =>
            {
                var innerTask = @this.ShowAsync(viewModel, completedProc);
                return innerTask.ContinueWith(t =>
                {
                    if ((t.Result ?? false) && openedProc != null)
                    {
                        var startTime = DateTime.Now;
                        ThreadPool.QueueUserWorkItem(state =>
                        {
                            var viewManager = ResolveTypeFromContainer <IViewManager>();
                            while (viewManager.GetViewsOfViewModel(viewModel).Length == 0 && DateTime.Now.Subtract(startTime).TotalMilliseconds < timeOutInMilliseconds)
                            {
                                ThreadHelper.Sleep(100);
                            }

                            var dispatcherService = ResolveTypeFromContainer <IDispatcherService>();
                            dispatcherService.Invoke(openedProc, true);
                        });
                    }

                    return t.Result;
                }).Result;
            }));
        }
Esempio n. 3
0
        protected override void OnOpen(object parameter = null)
        {
            _findReplaceViewModel = new FindReplaceViewModel(_findReplaceSettings, _findReplaceService);

            _uiVisualizerService.ShowAsync(_findReplaceViewModel);

            _findReplaceViewModel.ClosedAsync += OnClosedAsync;
        }
        protected override void OnOpen()
        {
            _findReplaceViewModel = new FindReplaceViewModel(_findReplaceSerivce, CsvTextEditorService);

            _uiVisualizerService.ShowAsync(_findReplaceViewModel);

            _findReplaceViewModel.ClosedAsync += OnClosedAsync;
        }
Esempio n. 5
0
        /// <summary>
        /// Shows the window in non-modal state and creates the view model automatically using the specified model.
        /// </summary>
        /// <typeparam name="TViewModel">The type of the view model.</typeparam>
        /// <param name="uiVisualizerService">The UI visualizer service.</param>
        /// <param name="model">The model to be injected into the view model, can be <c>null</c>.</param>
        /// <param name="completedProc">The completed proc.</param>
        /// <returns><c>true</c> if shown successfully, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="uiVisualizerService" /> is <c>null</c>.</exception>
        public static Task <bool?> ShowAsync <TViewModel>(this IUIVisualizerService uiVisualizerService, object model = null, EventHandler <UICompletedEventArgs> completedProc = null)
            where TViewModel : IViewModel
        {
            Argument.IsNotNull("uiVisualizerService", uiVisualizerService);

            var viewModelFactory = GetViewModelFactory(uiVisualizerService);
            var vm = viewModelFactory.CreateViewModel(typeof(TViewModel), model);

            return(uiVisualizerService.ShowAsync(vm, completedProc));
        }
Esempio n. 6
0
        private static Task OnPropertiesCommandExecute(HeaderCommandParameter parameter)
        {
            var managePropertiesModel = new ManagePropertiesModel();

            managePropertiesModel.Grid = parameter.Grid;

            managePropertiesModel.SelectedColumn = parameter.Column;// parameter.Grid.Selection != null ? parameter.Grid.Columns[parameter.ColumnClicked].Header : null;

            var viewModel = ViewModelFactory.CreateViewModel <ManagePropertiesViewModel>(managePropertiesModel, null);

            return(UIVisualizerService.ShowAsync(viewModel, OnPropertiesCommandCompleted));
        }
Esempio n. 7
0
        protected override void OnOpen(object parameter = null)
        {
            Parameter = parameter;

            WindowViewModel              = InitializeViewModel();
            WindowViewModel.ClosedAsync += OnClosedAsync;
            ApplyParameter(parameter);

            if (IsModal)
            {
                _uiVisualizerService.ShowDialogAsync(WindowViewModel, OnWindowCompleted);
            }
            else
            {
                _uiVisualizerService.ShowAsync(WindowViewModel, OnWindowCompleted);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a window in non-modal state. If a window with the specified viewModelType exists, the window is activated instead of being created.
        /// </summary>
        /// <typeparam name="TViewModel">The view model type.</typeparam>
        /// <param name="uiVisualizerService">The uiVisualizerService</param>
        /// <param name="dataContext">The data context.</param>
        /// <param name="scope">The scope.</param>
        /// <returns>
        /// A task.
        /// </returns>
        public static async Task ShowOrActivateAsync <TViewModel>(this IUIVisualizerService uiVisualizerService, object dataContext = null, object scope = null)
            where TViewModel : IViewModel
        {
            var dependencyResolver = uiVisualizerService.GetDependencyResolver();
            var viewModelManager   = dependencyResolver.Resolve <IViewModelManager>();
            var viewModelFactory   = dependencyResolver.Resolve <IViewModelFactory>();

            var existingViewModel = viewModelManager.GetFirstOrDefaultInstance <TViewModel>();

            if (existingViewModel != null)
            {
                await uiVisualizerService.ShowOrActivateAsync <TViewModel>(dataContext, scope);
            }
            else
            {
                var vm = viewModelFactory.CreateViewModel(typeof(TViewModel), dataContext, scope);
                await uiVisualizerService.ShowAsync(vm);
            }
        }
Esempio n. 9
0
        private async void OpenChat(ChatViewModel chat)
        {
            try
            {
                Logger.Info($"Gonna open chat '{chat.Chat.UserInfo.Name}'");

                var restoreViewMessage = RestoreExistingViewMessage.Create(chat);
                MessageMediator.Default.SendMessage(restoreViewMessage);

                if (restoreViewMessage.Restored)
                {
                    return;
                }

                await _visualizer.ShowAsync(chat);
            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
        }
        protected override async void Execute(object parameter)
        {
            try
            {
                var location  = parameter as string;
                var viewModel = _serviceLocator.ResolveType <ProjectWizardViewModel>();

                var r = await _uIVisualizerService.ShowAsync(viewModel, (sender, args) =>
                {
                    if (args.DataContext is not ProjectWizardViewModel res)
                    {
                        return;
                    }

                    var result = args.Result;
                    if (!result.HasValue || !result.Value)
                    {
                        return;
                    }

                    location = Path.Combine(res.ProjectPath, res.ProjectName);
                    var type = res.ProjectType.First();
                    if (type.Equals(ProjectWizardViewModel.WitcherGameName))
                    {
                        location += ".w3modproj";
                    }
                    else if (type.Equals(ProjectWizardViewModel.CyberpunkGameName))
                    {
                        location += ".cpmodproj";
                    }
                });

                if (string.IsNullOrWhiteSpace(location))
                {
                    return;
                }

                RibbonViewModel.GlobalRibbonVM.StartScreenShown = false;
                RibbonViewModel.GlobalRibbonVM.BackstageIsOpen  = false;
                using (_pleaseWaitService.PushInScope())
                {
                    switch (Path.GetExtension(location))
                    {
                    case ".w3modproj":
                    {
                        var np = new Tw3Project(location)
                        {
                            Name    = Path.GetFileNameWithoutExtension(location),
                            Author  = "WolvenKit",
                            Email   = "",
                            Version = "1.0"
                        };
                        _projectManager.ActiveProject = np;
                        await _projectManager.SaveAsync();

                        np.CreateDefaultDirectories();
                        //saveProjectImg(location);
                        break;
                    }

                    case ".cpmodproj":
                    {
                        var np = new Cp77Project(location)
                        {
                            Name    = Path.GetFileNameWithoutExtension(location),
                            Author  = "WolvenKit",
                            Email   = "",
                            Version = "1.0"
                        };
                        _projectManager.ActiveProject = np;
                        await _projectManager.SaveAsync();

                        np.CreateDefaultDirectories();
                        //saveProjectImg(location);
                        break;
                    }

                    default:
                        _loggerService.LogString("Invalid project path!", Logtype.Error);
                        break;
                    }
                }

                await _projectManager.LoadAsync(location);

                switch (Path.GetExtension(location))
                {
                case ".w3modproj":
                    await _tw3Controller.HandleStartup().ContinueWith(t =>
                    {
                        _notificationService.Success(
                            "Project " + Path.GetFileNameWithoutExtension(location) +
                            " loaded!");
                    }, TaskContinuationOptions.OnlyOnRanToCompletion);

                    break;

                case ".cpmodproj":
                    await _cp77Controller.HandleStartup().ContinueWith(
                        t =>
                    {
                        _notificationService.Success("Project " +
                                                     Path.GetFileNameWithoutExtension(location) +
                                                     " loaded!");
                    },
                        TaskContinuationOptions.OnlyOnRanToCompletion);

                    break;

                default:
                    break;
                }
            }
        public static async Task <bool?> GetFromPrompt(IUIVisualizerService _uiVisualizerService, ViewModelBase viewModel)
        {
            var result = await _uiVisualizerService.ShowAsync(viewModel, DocumentAdded) ?? false;

            return(result);
        }
 private async Task OnOpenCustomerWindowCommandExecuteAsync()
 {
     var typeFactory       = this.GetTypeFactory();
     var customerViewModel = typeFactory.CreateInstanceWithParametersAndAutoCompletion <CustomerWindowViewModel>();
     await _uiVisualizerService.ShowAsync(customerViewModel);
 }
Esempio n. 13
0
 private async Task OnShowViewExecuteAsync()
 {
     //TODO remake it to 1 window 2 usercontrols
     await _uiVisualizerService.ShowAsync <FavoritesViewModel>();
 }
Esempio n. 14
0
        private void OnOpenStudents()
        {
            PersonViewModel studentsVM = new PersonViewModel(PersonType.Student);

            uiVisualizerService.ShowAsync(studentsVM);
        }
        private async Task OnShowLogWindowExecuteAsync()
        {
#pragma warning disable 4014
            _uiVisualizerService.ShowAsync <LogWindowViewModel>();
#pragma warning restore 4014
        }