public MainWindowVm(ConfigService configService, Project project, ThumbnailService thumbnailService, IWindowService windowService, DocumentOperator documentOperator, ILogger logger)
        {
            Tags      = configService.Tags.ToReadOnlyReactiveCollection(x => new TagItemVm(x, false)).AddTo(Disposables);
            Recent    = configService.Recent.ToReadOnlyReactiveCollection(x => new RecentVm(project.Documents.FirstOrDefault(doc => doc.MetaData.Id == x))).AddTo(Disposables);
            Documents = project.Documents.ToReadOnlyReactiveCollection(x => new DocumentVm(x, documentOperator, thumbnailService)).AddTo(Disposables);

            // ドキュメントの非同期読み込み
            _ = project.LoadDocumentAsync();
            project.DocumentLoaded += (s, e) =>
            {
                configService.ReloadRecent();
            };

            AddTagCommand = new DelegateCommand <string>(configService.AddTag);
            ReloadCommand = new DelegateCommand(() => _ = project.LoadDocumentAsync());

            ShowDocumentCommand = new DelegateCommand <object>(args =>
            {
                var option = new WindowOpenOption()
                {
                    Maximize = true,
                };

                if (args is DocumentVm documentVm)
                {
                    windowService.Show <DocumentWindow, DocumentVm>(documentVm, option);
                    configService.AddRecent(documentVm.Document.MetaData.Id);
                }

                if (args is RecentVm recentVm)
                {
                    var context = Documents.FirstOrDefault(x => x.Document.MetaData.Id == recentVm.Document?.MetaData.Id);
                    if (context != null)
                    {
                        windowService.Show <DocumentWindow, DocumentVm>(context, option);
                    }
                }
            });

            ShowRenbanEditorCommand = new DelegateCommand(() =>
            {
                var editor      = new RenbanDownLoader(project, configService.Config, logger);
                var dataContext = new RenbanVm(editor);
                windowService.Show <RenbanDownloadWindow, RenbanVm>(dataContext, WindowOpenOption.Default);
            });
        }
Esempio n. 2
0
        public async Task ShowAsync <T, TViewModel>(TViewModel dataContext, WindowOpenOption option)
            where T : Window, new ()
        {
            var window = new T()
            {
                DataContext           = dataContext,
                Owner                 = Application.Current.MainWindow,
                WindowStartupLocation = WindowStartupLocation.CenterOwner,
            };

            if (option.Maximize)
            {
                window.WindowState = WindowState.Maximized;
            }

            if (option.Width > 0)
            {
                window.Width = option.Width;
            }
            if (option.Height > 0)
            {
                window.Height = option.Height;
            }

            // wait & focus
            await Task.Delay(1);

            if (option.IsModal)
            {
                window.ShowDialog();
            }
            else
            {
                window.Show();
                await Task.Delay(1);

                window.Focus();
            }
        }
Esempio n. 3
0
 public async void Show <T, TViewModel>(TViewModel dataContext, WindowOpenOption option)
     where T : Window, new ()
 {
     await ShowAsync <T, TViewModel>(dataContext, option);
 }