private void OpenNonFictionDetailsRequested(object sender, NonFictionSearchResultsTabViewModel.OpenNonFictionDetailsEventArgs e) { Logger.Debug($"Opening non-fiction book with ID = {e.NonFictionBook.Id}, Libgen ID = {e.NonFictionBook.LibgenId}."); SearchSettings.DetailsMode openDetailsMode = mainModel.AppSettings.Search.OpenDetailsMode; if (openDetailsMode == SearchSettings.DetailsMode.NEW_TAB) { NonFictionDetailsTabViewModel nonFictionDetailsTabViewModel = new NonFictionDetailsTabViewModel(mainModel, CurrentWindowContext, e.NonFictionBook, isInModalWindow: false); nonFictionDetailsTabViewModel.CloseTabRequested += NonFictionDetailsCloseTabRequested; TabViewModels.Add(nonFictionDetailsTabViewModel); SelectedTabViewModel = nonFictionDetailsTabViewModel; } else { bool modalWindow = openDetailsMode == SearchSettings.DetailsMode.NEW_MODAL_WINDOW; NonFictionDetailsWindowViewModel detailsWindowViewModel = new NonFictionDetailsWindowViewModel(mainModel, e.NonFictionBook, modalWindow); IWindowContext detailsWindowContext = WindowManager.CreateWindow(RegisteredWindows.WindowKey.NON_FICTION_DETAILS_WINDOW, detailsWindowViewModel, CurrentWindowContext); NonFictionDetailsWindowSettings detailsWindowSettings = mainModel.AppSettings.NonFiction.DetailsWindow; if (modalWindow) { detailsWindowContext.ShowDialog(detailsWindowSettings.Width, detailsWindowSettings.Height); } else { detailsWindowContext.Show(detailsWindowSettings.Width, detailsWindowSettings.Height); } } }
private void Import() { OpenFileDialogParameters selectSqlDumpFileDialogParameters = new OpenFileDialogParameters { DialogTitle = "Выбор SQL-дампа", Filter = "Все поддерживаемые файлы|*.sql;*zip;*.rar;*.gz;*.7z|SQL -дампы (*.sql)|*.sql|Архивы (*.zip, *.rar, *.gz, *.7z)|*zip;*.rar;*.gz;*.7z|Все файлы (*.*)|*.*", Multiselect = false }; OpenFileDialogResult selectSqlDumpFileDialogResult = WindowManager.ShowOpenFileDialog(selectSqlDumpFileDialogParameters); if (selectSqlDumpFileDialogResult.DialogResult) { ImportWindowViewModel importWindowViewModel = new ImportWindowViewModel(mainModel, selectSqlDumpFileDialogResult.SelectedFilePaths.First()); IWindowContext importWindowContext = WindowManager.CreateWindow(RegisteredWindows.WindowKey.IMPORT_WINDOW, importWindowViewModel, CurrentWindowContext); importWindowContext.ShowDialog(); if (IsDefaultSearchTabVisible) { DefaultSearchTabViewModel.Refresh(setFocus: true); } else { foreach (SearchTabViewModel searchTabViewModel in TabViewModels.OfType <SearchTabViewModel>()) { searchTabViewModel.Refresh(setFocus: searchTabViewModel == SelectedTabViewModel); } } } }
private void CloseCurrentTab() { if (TabViewModels.Any()) { CloseTab(SelectedTabViewModel); } }
private void OpenFictionDetailsRequested(object sender, OpenFictionDetailsEventArgs e) { Logger.Debug($"Opening fiction book with ID = {e.FictionBook.Id}, Libgen ID = {e.FictionBook.LibgenId}."); SearchSettings.DetailsMode openDetailsMode = MainModel.AppSettings.Search.OpenDetailsMode; if (openDetailsMode == SearchSettings.DetailsMode.NEW_TAB) { FictionDetailsTabViewModel fictionDetailsTabViewModel = new FictionDetailsTabViewModel(MainModel, CurrentWindowContext, e.FictionBook, isInModalWindow: false); fictionDetailsTabViewModel.SelectDownloadRequested += SelectDownloadRequested; fictionDetailsTabViewModel.CloseTabRequested += FictionDetailsCloseTabRequested; TabViewModels.Add(fictionDetailsTabViewModel); SelectedTabViewModel = fictionDetailsTabViewModel; } else { bool modalWindow = openDetailsMode == SearchSettings.DetailsMode.NEW_MODAL_WINDOW; FictionDetailsWindowViewModel detailsWindowViewModel = new FictionDetailsWindowViewModel(MainModel, e.FictionBook, modalWindow); detailsWindowViewModel.SelectDownloadRequested += SelectDownloadRequested; IWindowContext detailsWindowContext = WindowManager.CreateWindow(RegisteredWindows.WindowKey.FICTION_DETAILS_WINDOW, detailsWindowViewModel, CurrentWindowContext); FictionDetailsWindowSettings detailsWindowSettings = MainModel.AppSettings.Fiction.DetailsWindow; if (modalWindow) { detailsWindowContext.ShowDialog(detailsWindowSettings.Width, detailsWindowSettings.Height); detailsWindowViewModel.SelectDownloadRequested -= SelectDownloadRequested; } else { detailsWindowViewModel.WindowClosed += FictionDetailsWindowClosed; detailsWindowContext.Show(detailsWindowSettings.Width, detailsWindowSettings.Height); } } }
private void OpenSciMagDetailsRequested(object sender, OpenSciMagDetailsEventArgs e) { Logger.Debug($"Opening article with ID = {e.SciMagArticle.Id}, Libgen ID = {e.SciMagArticle.LibgenId}."); SearchSettings.DetailsMode openDetailsMode = MainModel.AppSettings.Search.OpenDetailsMode; if (openDetailsMode == SearchSettings.DetailsMode.NEW_TAB) { SciMagDetailsTabViewModel sciMagDetailsTabViewModel = new SciMagDetailsTabViewModel(MainModel, CurrentWindowContext, e.SciMagArticle, isInModalWindow: false); sciMagDetailsTabViewModel.SelectDownloadRequested += SelectDownloadRequested; sciMagDetailsTabViewModel.CloseTabRequested += SciMagDetailsCloseTabRequested; TabViewModels.Add(sciMagDetailsTabViewModel); SelectedTabViewModel = sciMagDetailsTabViewModel; } else { bool modalWindow = openDetailsMode == SearchSettings.DetailsMode.NEW_MODAL_WINDOW; SciMagDetailsWindowViewModel detailsWindowViewModel = new SciMagDetailsWindowViewModel(MainModel, e.SciMagArticle, modalWindow); detailsWindowViewModel.SelectDownloadRequested += SelectDownloadRequested; IWindowContext detailsWindowContext = WindowManager.CreateWindow(RegisteredWindows.WindowKey.SCI_MAG_DETAILS_WINDOW, detailsWindowViewModel, CurrentWindowContext); SciMagDetailsWindowSettings detailsWindowSettings = MainModel.AppSettings.SciMag.DetailsWindow; if (modalWindow) { detailsWindowContext.ShowDialog(detailsWindowSettings.Width, detailsWindowSettings.Height); detailsWindowViewModel.SelectDownloadRequested -= SelectDownloadRequested; } else { detailsWindowViewModel.WindowClosed += SciMagDetailsWindowClosed; detailsWindowContext.Show(detailsWindowSettings.Width, detailsWindowSettings.Height); } } }
private void RefreshTab(int tabIndex) { TabVM = new TabViewModels(); switch (tabIndex) { case 0: TabVM.ArtistEntryTabVM = new ArtistEntryTabViewModel(_musicLog); break; case 1: TabVM.DatabaseTabVM = new DatabaseTabViewModel(_musicLog); break; case 2: TabVM.HistoryTabVM = new HistoryTabViewModel(_musicLog); break; case 3: TabVM.PlaylistTabVM = new PlaylistTabViewModel(_musicLog); var goToDatabaseAlbum = new Action <object, DoubleClickedEventArgs>(GoToDatabaseAlbum); TabVM.PlaylistTabVM.SetDoubleClickedEvent(goToDatabaseAlbum); break; case 4: TabVM.TrackLookupTabVM = new TrackLookupTabViewModel(_musicLog); break; } }
/// <summary> /// Initializes a new instance of the ViewModelLocator class. /// </summary> public ViewModelLocator() { ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); ////if (ViewModelBase.IsInDesignModeStatic) ////{ //// // Create design time view services and models //// SimpleIoc.Default.Register<IDataService, DesignDataService>(); ////} ////else ////{ //// // Create run time view services and models //// SimpleIoc.Default.Register<IDataService, DataService>(); ////} SimpleIoc.Default.Register <MainViewModel>(); SimpleIoc.Default.Register <BasicThreadFoobarViewModel>(); SimpleIoc.Default.Register <PoolFoobarViewModel>(); SimpleIoc.Default.Register <GoTapFoobarViewModel>(); SimpleIoc.Default.Register <AsyncKeywordFoobarViewModel>(); SimpleIoc.Default.Register <CustomAwaitFoobarViewModel>(); TabViewModels.Add(CustomAwait); TabViewModels.Add(AsyncKeyword); TabViewModels.Add(GoTapFoobar); TabViewModels.Add(PoolFoobar); TabViewModels.Add(BasicThreadFoobar); }
private void CloseTab(TabViewModel tabViewModel) { tabViewModel.HandleTabClosing(); switch (tabViewModel) { case SearchTabViewModel searchTabViewModel: searchTabViewModel.NonFictionSearchComplete -= SearchTabNonFictionSearchComplete; searchTabViewModel.FictionSearchComplete -= SearchTabFictionSearchComplete; searchTabViewModel.SciMagSearchComplete -= SearchTabSciMagSearchComplete; break; case NonFictionSearchResultsTabViewModel nonFictionSearchResultsTabViewModel: nonFictionSearchResultsTabViewModel.OpenNonFictionDetailsRequested -= OpenNonFictionDetailsRequested; break; case FictionSearchResultsTabViewModel fictionSearchResultsTabViewModel: fictionSearchResultsTabViewModel.OpenFictionDetailsRequested -= OpenFictionDetailsRequested; break; case SciMagSearchResultsTabViewModel sciMagSearchResultsTabViewModel: sciMagSearchResultsTabViewModel.OpenSciMagDetailsRequested -= OpenSciMagDetailsRequested; break; case NonFictionDetailsTabViewModel nonFictionDetailsTabViewModel: nonFictionDetailsTabViewModel.SelectDownloadRequested -= SelectDownloadRequested; nonFictionDetailsTabViewModel.CloseTabRequested -= NonFictionDetailsCloseTabRequested; break; case FictionDetailsTabViewModel fictionDetailsTabViewModel: fictionDetailsTabViewModel.SelectDownloadRequested -= SelectDownloadRequested; fictionDetailsTabViewModel.CloseTabRequested -= FictionDetailsCloseTabRequested; break; case SciMagDetailsTabViewModel sciMagDetailsTabViewModel: sciMagDetailsTabViewModel.SelectDownloadRequested -= SelectDownloadRequested; sciMagDetailsTabViewModel.CloseTabRequested -= SciMagDetailsCloseTabRequested; break; } int removingTabIndex = TabViewModels.IndexOf(tabViewModel); TabViewModels.Remove(tabViewModel); NotifyPropertyChanged(nameof(IsDefaultSearchTabVisible)); NotifyPropertyChanged(nameof(AreTabsVisible)); NotifyPropertyChanged(nameof(IsNewTabButtonVisible)); if (!TabViewModels.Any()) { SelectedTabViewModel = null; DefaultSearchTabViewModel.Refresh(setFocus: true); } else { int newSelectedTabIndex = TabViewModels.Count > removingTabIndex ? removingTabIndex : TabViewModels.Count - 1; SelectedTabViewModel = TabViewModels[newSelectedTabIndex]; } }
private void NewTab() { if (IsNewTabButtonVisible) { SearchTabViewModel searchTabViewModel = new SearchTabViewModel(MainModel, CurrentWindowContext); searchTabViewModel.NonFictionSearchComplete += SearchTabNonFictionSearchComplete; searchTabViewModel.FictionSearchComplete += SearchTabFictionSearchComplete; searchTabViewModel.SciMagSearchComplete += SearchTabSciMagSearchComplete; TabViewModels.Add(searchTabViewModel); SelectedTabViewModel = searchTabViewModel; NotifyPropertyChanged(nameof(IsNewTabButtonVisible)); } }
private void RefreshSearchTabCollectionAvailabilities() { if (IsDefaultSearchTabVisible) { DefaultSearchTabViewModel.Refresh(setFocus: true); } else { foreach (SearchTabViewModel searchTabViewModel in TabViewModels.OfType <SearchTabViewModel>()) { searchTabViewModel.Refresh(setFocus: searchTabViewModel == SelectedTabViewModel); } } }
private void ShowSearchResults(SearchTabViewModel searchTabViewModel, TabViewModel searchResultsTabViewModel) { if (searchTabViewModel != DefaultSearchTabViewModel) { searchTabViewModel.NonFictionSearchComplete -= SearchTabNonFictionSearchComplete; searchTabViewModel.FictionSearchComplete -= SearchTabFictionSearchComplete; searchTabViewModel.SciMagSearchComplete -= SearchTabSciMagSearchComplete; TabViewModels.Remove(searchTabViewModel); } TabViewModels.Add(searchResultsTabViewModel); SelectedTabViewModel = searchResultsTabViewModel; NotifyPropertyChanged(nameof(IsDefaultSearchTabVisible)); NotifyPropertyChanged(nameof(AreTabsVisible)); NotifyPropertyChanged(nameof(IsNewTabButtonVisible)); }
public AdbGridViewModel(IDefaultPhoneInfoContainer container) { this.Container = container; SelectedTabModel = InfoDetailTabModel; TabViewModels.Add(InfoDetailTabModel); SelectedTabModel = InfoDetailTabModel; if (MInfoTypeHelper.GetMInfoTypeBox(container.InfoType) == MInfoTypeBox.AdbFile) { TabViewModels.Add(FileHexTabViewModel); if (container.InfoType == MInfoType.Image) { TabViewModels.Add(AdbPreviewViewModel); } } }
private void ShowDownloadManager() { DownloadManagerTabViewModel downloadManagerTabViewModel = DownloadManagerTabViewModel; if (downloadManagerTabViewModel == null) { downloadManagerTabViewModel = new DownloadManagerTabViewModel(MainModel, CurrentWindowContext); TabViewModels.Add(downloadManagerTabViewModel); SelectedTabViewModel = downloadManagerTabViewModel; NotifyPropertyChanged(nameof(IsDefaultSearchTabVisible)); NotifyPropertyChanged(nameof(AreTabsVisible)); NotifyPropertyChanged(nameof(IsNewTabButtonVisible)); } else { SelectedTabViewModel = downloadManagerTabViewModel; } }
public ViewModel() { var editorEnvironment = new EditorEnvironment(); // Disable the undo/redo stack during the node initialization editorEnvironment.UndoRedoStack.IsEnabled = false; // Create a unique copy of the environment, because all tabs use their own node factory, // but can share the same undo stack AddTab(new DataNodes.DataNodeTabViewModel(new EditorEnvironment(editorEnvironment))); AddTab(new Default.DefaultTabViewModel(new EditorEnvironment(editorEnvironment))); AddTab(new Directory.DirectoryTabViewModel(new EditorEnvironment(editorEnvironment))); AddTab(new Dialog.DialogTabViewModel(new EditorEnvironment(editorEnvironment))); // Enable the undo/redo stack after the node initialization editorEnvironment.UndoRedoStack.IsEnabled = true; SelectedTab = TabViewModels.FirstOrDefault(); }
private void LibraryMenuItemClick() { LibraryTabViewModel libraryTabViewModel = LibraryTabViewModel; if (libraryTabViewModel == null) { libraryTabViewModel = new LibraryTabViewModel(MainModel, CurrentWindowContext); libraryTabViewModel.OpenNonFictionDetailsRequested += OpenNonFictionDetailsRequested; libraryTabViewModel.OpenFictionDetailsRequested += OpenFictionDetailsRequested; libraryTabViewModel.OpenSciMagDetailsRequested += OpenSciMagDetailsRequested; TabViewModels.Add(libraryTabViewModel); SelectedTabViewModel = libraryTabViewModel; NotifyPropertyChanged(nameof(IsDefaultSearchTabVisible)); NotifyPropertyChanged(nameof(AreTabsVisible)); NotifyPropertyChanged(nameof(IsNewTabButtonVisible)); } else { SelectedTabViewModel = libraryTabViewModel; } }
private void Import() { ImportLocalizator importLocalizator = MainModel.Localization.CurrentLanguage.Import; StringBuilder filterBuilder = new StringBuilder(); filterBuilder.Append(importLocalizator.AllSupportedFiles); filterBuilder.Append("|*.sql;*zip;*.rar;*.gz;*.7z|"); filterBuilder.Append(importLocalizator.SqlDumps); filterBuilder.Append(" (*.sql)|*.sql|"); filterBuilder.Append(importLocalizator.Archives); filterBuilder.Append(" (*.zip, *.rar, *.gz, *.7z)|*zip;*.rar;*.gz;*.7z|"); filterBuilder.Append(importLocalizator.AllFiles); filterBuilder.Append(" (*.*)|*.*"); OpenFileDialogParameters selectSqlDumpFileDialogParameters = new OpenFileDialogParameters { DialogTitle = importLocalizator.BrowseImportFileDialogTitle, Filter = filterBuilder.ToString(), Multiselect = false }; OpenFileDialogResult selectSqlDumpFileDialogResult = WindowManager.ShowOpenFileDialog(selectSqlDumpFileDialogParameters); if (selectSqlDumpFileDialogResult.DialogResult) { ImportWindowViewModel importWindowViewModel = new ImportWindowViewModel(MainModel, selectSqlDumpFileDialogResult.SelectedFilePaths.First()); IWindowContext importWindowContext = WindowManager.CreateWindow(RegisteredWindows.WindowKey.IMPORT_WINDOW, importWindowViewModel, CurrentWindowContext); importWindowContext.ShowDialog(); if (IsDefaultSearchTabVisible) { DefaultSearchTabViewModel.Refresh(setFocus: true); } else { foreach (SearchTabViewModel searchTabViewModel in TabViewModels.OfType <SearchTabViewModel>()) { searchTabViewModel.Refresh(setFocus: searchTabViewModel == SelectedTabViewModel); } } } }
public MainWindowViewModel(MainWindowModel model) { this.model = model; NewTootBoxViewModel = new NewTootBoxViewModel(this.model.InReplyTo, this.model.Client); TabViewModels = this.model.Tabs.ToReadOnlyReactiveCollection(p => TabContentViewModelBase.FromParam(p, this.model.InReplyTo, this.model.Tabs, this.model.Client)); SelectedTabIndex = this.model.Tabs.SelectedIndex; OpenSettingsCommand = new ReactiveCommand() .WithSubscribe(() => { var w = new SettingsWindow(new SettingsViewModel(this.model.Tabs)); ((SettingsViewModel)w.DataContext).Tabs = this.model.Tabs; w.ShowDialog(); }); CloseTabCommand = new ReactiveCommand <TabContentViewModelBase>() .WithSubscribe(vm => { this.model.Tabs.CloseTab(TabViewModels.IndexOf(vm)); }); NextTabCommand = new ReactiveCommand() .WithSubscribe(this.model.Tabs.SwitchToNextTab); PrevTabCommand = new ReactiveCommand() .WithSubscribe(this.model.Tabs.SwitchToPrevTab); }
public MainViewModel(TabViewModels tableViewModel) { // Get all enabled view models. ViewModels = new ObservableCollection <IViewModel>(tableViewModel.ViewModels); }
private void BookmarksMenuItemClick(BookmarkViewModel bookmarkViewModel) { bool useCurrentTab; if (SelectedTabViewModel != null) { switch (bookmarkViewModel.LibgenObjectType) { case LibgenObjectType.NON_FICTION_BOOK: useCurrentTab = SelectedTabViewModel is NonFictionSearchResultsTabViewModel; break; case LibgenObjectType.FICTION_BOOK: useCurrentTab = SelectedTabViewModel is FictionSearchResultsTabViewModel; break; case LibgenObjectType.SCIMAG_ARTICLE: useCurrentTab = SelectedTabViewModel is SciMagSearchResultsTabViewModel; break; default: useCurrentTab = false; break; } } else { useCurrentTab = false; } if (useCurrentTab) { (SelectedTabViewModel as SearchResultsTabViewModel).Search(bookmarkViewModel.SearchQuery); } else { SearchResultsTabViewModel newTab; switch (bookmarkViewModel.LibgenObjectType) { case LibgenObjectType.NON_FICTION_BOOK: NonFictionSearchResultsTabViewModel nonFictionNewTab = new NonFictionSearchResultsTabViewModel(MainModel, CurrentWindowContext, bookmarkViewModel.SearchQuery, new List <NonFictionBook>()); nonFictionNewTab.OpenNonFictionDetailsRequested += OpenNonFictionDetailsRequested; newTab = nonFictionNewTab; break; case LibgenObjectType.FICTION_BOOK: FictionSearchResultsTabViewModel fictionNewTab = new FictionSearchResultsTabViewModel(MainModel, CurrentWindowContext, bookmarkViewModel.SearchQuery, new List <FictionBook>()); fictionNewTab.OpenFictionDetailsRequested += OpenFictionDetailsRequested; newTab = fictionNewTab; break; case LibgenObjectType.SCIMAG_ARTICLE: SciMagSearchResultsTabViewModel sciMagNewTab = new SciMagSearchResultsTabViewModel(MainModel, CurrentWindowContext, bookmarkViewModel.SearchQuery, new List <SciMagArticle>()); sciMagNewTab.OpenSciMagDetailsRequested += OpenSciMagDetailsRequested; newTab = sciMagNewTab; break; default: newTab = null; break; } if (newTab != null) { newTab.Search(bookmarkViewModel.SearchQuery); TabViewModels.Add(newTab); SelectedTabViewModel = newTab; NotifyPropertyChanged(nameof(IsDefaultSearchTabVisible)); NotifyPropertyChanged(nameof(AreTabsVisible)); NotifyPropertyChanged(nameof(IsNewTabButtonVisible)); } } }
public async Task LoadAsync() { var instance = LoginUserInfo.Instance; var viewSubscriptions = instance.User.ViewSubscriptions; var viewMovies = instance.User.ViewMovies; var viewModelsToAdd = new List <TabViewModelBase>(); var viewModelsToRemove = new List <TabViewModelBase>(); foreach (var tabViewModel in TabViewModels) { if (tabViewModel.Title == Constants.Welcome) { viewModelsToAdd.Add(tabViewModel); } else if (tabViewModel.Title == Constants.UserManagements) { if (instance.Login.IsAdmin) { viewModelsToAdd.Add(tabViewModel); } else { viewModelsToRemove.Add(tabViewModel); } } else if (tabViewModel.Title == Constants.Subscriptions) { if (viewSubscriptions) { viewModelsToAdd.Add(tabViewModel); } else { viewModelsToRemove.Add(tabViewModel); } } else if (tabViewModel.Title == Constants.Movies) { if (viewMovies) { viewModelsToAdd.Add(tabViewModel); } else { viewModelsToRemove.Add(tabViewModel); } } } foreach (var viewModel in viewModelsToRemove) { TabViewModels.Remove(viewModel); } foreach (var viewModel in viewModelsToAdd) { await viewModel.LoadAsync(); } LoginUserName = instance.User.UserName; }