namespace VideoBrowser.ViewModels
{
using Dragablz;
using System;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using VideoBrowser.Common;
using VideoBrowser.Controls.CefSharpBrowser;
using VideoBrowser.Controls.CefSharpBrowser.ViewModels;
using VideoBrowser.Core;
using VideoBrowser.Models;
using VideoBrowser.Views;
///
/// Defines the .
///
public class MainWindowViewModel : NotifyPropertyChanged
{
#region Constructors
///
/// Initializes a new instance of the class.
///
/// The globalData.
/// The globalBrowserData.
public MainWindowViewModel(GlobalBrowserData globalBrowserData)
{
this.ClosingCommand = new RelayCommand(this.OnClosing);
this.LoadedCommand = new RelayCommand(this.OnLoaded);
this.PressEscCommand = new RelayCommand(this.OnPressEsc);
this.PressF2Command = new RelayCommand(this.OnPressF2);
this.About = new AboutViewModel();
var downloadItemModels = globalBrowserData.DownloadItemModels;
this.DownloadQueueViewModel = new DownloadQueueViewModel(downloadItemModels) { ShowMessageAsync = this.ShowMessageAsync };
this.DownloadFlyoutViewModel = new DownloadFlyoutViewModel(downloadItemModels) { ShowDownloadTabAction = this.ShowDownloadTabAction };
this.WebBrowserTabControlViewModel = new WebBrowserTabControlViewModel(globalBrowserData)
{
CreateBrowserFunc = this.CreateBrowser
};
this.Initialize();
}
#endregion Constructors
#region Properties
///
/// Gets the About.
///
public AboutViewModel About { get; }
///
/// Gets the CefWindowData.
///
public CefWindowData CefWindowData => this.WebBrowserTabControlViewModel.CefWindowData;
///
/// Gets the ClosingCommand.
///
public RelayCommand ClosingCommand { get; }
///
/// Gets the DownloadFlyoutViewModel.
///
public DownloadFlyoutViewModel DownloadFlyoutViewModel { get; }
///
/// Gets the DownloadQueueViewModel.
///
public DownloadQueueViewModel DownloadQueueViewModel { get; }
///
/// Gets the GlobalBrowserData.
///
public GlobalBrowserData GlobalBrowserData => this.WebBrowserTabControlViewModel.GlobalBrowserData;
///
/// Gets the LoadedCommand.
///
public ICommand LoadedCommand { get; }
///
/// Gets the PressEscCommand.
///
public ICommand PressEscCommand { get; }
///
/// Gets the PressF2Command.
///
public ICommand PressF2Command { get; }
///
/// Gets the Settings.
///
public SettingsViewModel Settings => this.GlobalBrowserData.Settings;
///
/// Gets the Title.
///
public string Title => $"{AppEnvironment.Name}";
///
/// Gets the WebBrowserTabControlViewModel.
///
public WebBrowserTabControlViewModel WebBrowserTabControlViewModel { get; }
///
/// Gets the DownloadAction.
///
private Action DownloadAction => this.DownloadQueueViewModel.Download;
#endregion Properties
#region Methods
///
/// The CreateBrowser.
///
/// The .
internal TabItem CreateBrowser()
{
var model = new WebBrowserHeaderedItemViewModel(this.GlobalBrowserData, this.CefWindowData, this.DownloadAction);
return model;
}
///
/// The Dispose.
///
private void Dispose()
{
this.WebBrowserTabControlViewModel.Dispose();
var viewModels = this.GlobalBrowserData.WindowViewModels;
if (viewModels.Contains(this))
{
viewModels.Remove(this);
}
if (!viewModels.Any())
{
this.GlobalBrowserData.Dispose();
}
}
///
/// The Initialize.
///
private void Initialize()
{
var args = AppEnvironment.Arguments;
var url = Properties.Settings.Default.LastUrl;
if (args != null && args.Any())
{
url = args.First();
}
if (this.WebBrowserTabControlViewModel.TabItems.Any())
{
var browser = this.WebBrowserTabControlViewModel.TabItems.First();
if (browser is WebBrowserHeaderedItemViewModel model)
{
model.VideoBrowserViewModel.NavigateUrl = url;
}
}
}
///
/// The OnClosing.
///
/// The obj.
private void OnClosing(object obj)
{
var (_, _, commandParameter) = (ValueTuple