Esempio n. 1
0
        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];
            }
        }