public void NewContentTab(IEnumerable <BookViewModel> list) { var newTabViewModel = (App.Current.Resources["Ioc"] as IUnityContainer).Resolve <IDocumentViewModelBase>("ContentDocumentViewModel"); newTabViewModel.Title = "Filtered"; newTabViewModel.BookCabinet = LibraryVM.CreateBookStorage(); newTabViewModel.BookCabinet.BookSource = new ObservableCollection <BookViewModel>(); newTabViewModel.BookCabinet.BookSource.AddRange(list); newTabViewModel.BookCabinet.Sorting = (App.Current.MainWindow.DataContext as MainWindowViewModel).ActiveDocumentViewModel.BookCabinet.Sorting; newTabViewModel.BookCabinet.DisplayType = (App.Current.MainWindow.DataContext as MainWindowViewModel).ActiveDocumentViewModel.BookCabinet.DisplayType; DockingDocumentViewModels.Add(newTabViewModel); (LibraryVM as IObservable <BookCollectionChanged>) .Subscribe(newTabViewModel.BookCabinet as IObserver <BookCollectionChanged>) .AddTo(_disposable); newTabViewModel.IsVisible = true; }
public void NewSearchTab(ObservableCollection <BookViewModel> onStage) { var newTabViewModel = (App.Current.Resources["Ioc"] as IUnityContainer).Resolve <IDocumentViewModelBase>("SearchDocumentViewModel"); newTabViewModel.Title = "Search results"; newTabViewModel.BookCabinet = LibraryVM.CreateBookStorage(); newTabViewModel.BookCabinet.BookSource = new ObservableCollection <BookViewModel>(onStage); newTabViewModel.BookCabinet.Sorting = (App.Current.MainWindow.DataContext as MainWindowViewModel).ActiveDocumentViewModel.BookCabinet.Sorting; newTabViewModel.BookCabinet.DisplayType = (App.Current.MainWindow.DataContext as MainWindowViewModel).ActiveDocumentViewModel.BookCabinet.DisplayType; DockingDocumentViewModels.Add(newTabViewModel); (LibraryVM as IObservable <BookCollectionChanged>) .Subscribe(newTabViewModel.BookCabinet as IObserver <BookCollectionChanged>) .AddTo(_disposable); newTabViewModel.IsVisible = true; newTabViewModel.IsSelected = true; ActiveDocumentViewModel = newTabViewModel; }
public async Task Initialize(bool starting, bool shiftPressed = false) { if (starting) { LibraryVM.ProgressManager.PropertyChanged += ProgressManager_PropertyChanged; TagPaneViewModel.BuildContextMenus_Tags(); AuthorPaneViewModel.BuildContextMenus_Authors(); } WindowLeft = Configuration.ApplicationConfiguration.WindowRect.X; WindowTop = Configuration.ApplicationConfiguration.WindowRect.Y; WindowWidth = Configuration.ApplicationConfiguration.WindowRect.Width; WindowHeight = Configuration.ApplicationConfiguration.WindowRect.Height; if (shiftPressed || Configuration.ApplicationConfiguration.WorkingDirectory == null) { if (!OpenSwitchLibraryDialogAndChangeWorkingDirectory()) { Close(); return; } } CloseAllTab(); var authorSorting = Configuration.ApplicationConfiguration.AuthorSorting; if (authorSorting != null) { AuthorManager.Sorting = AuthorSorting.GetReferenceByName(authorSorting); } var tagSorting = Configuration.ApplicationConfiguration.TagSorting; if (tagSorting != null) { TagManager.Sorting = ImageTagCountSorting.GetReferenceByName(tagSorting); } SetMainWindowTitle(); HomeDocumentViewModel.ClearSearchResult(); InitializeWindowComponent(); ManageAppDB(); IncrementNumberOfBoots(); Configuration.ApplicationConfiguration.ConnectionString = Specifications.GenerateConnectionString(Configuration.ApplicationConfiguration.WorkingDirectory); ConnectionManager.SetDefaultConnection(Configuration.ApplicationConfiguration.ConnectionString, typeof(SQLiteConnection)); try { await LibraryVM.Initialize(); LibraryVM.UnlockIfLocked(); await LibraryVM.Load() .ContinueWith(_ => { HomeDocumentViewModel.BookCabinet = LibraryVM.CreateBookStorage(); (LibraryVM as IObservable <BookCollectionChanged>) .Subscribe(HomeDocumentViewModel.BookCabinet as IObserver <BookCollectionChanged>) .AddTo(_disposable); this.Subscribe((IObserver <ActiveTabChanged>)TagManager) .AddTo(_disposable); this.Subscribe((IObserver <ActiveTabChanged>)AuthorManager) .AddTo(_disposable); var sorting = Configuration.ApplicationConfiguration.BookSorting; if (sorting != null) { HomeDocumentViewModel.BookCabinet.Sorting = BookSorting.GetReferenceByName(sorting); } var displayType = Configuration.ApplicationConfiguration.DisplayType; if (displayType != null) { HomeDocumentViewModel.BookCabinet.DisplayType = DisplayType.GetReferenceByName(displayType); } ((DocumentViewModelBase)HomeDocumentViewModel).IsVisible = true; ((DocumentViewModelBase)HomeDocumentViewModel).IsSelected = true; SetEvent(); NotifyActiveTabChanged(); }); } catch (Exception e) { Close(); } }