2020-10-25 19:52:14 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Collections.Specialized;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using RGBController2.Commands;
|
|
|
|
|
using RGBController2.ViewModels.Tabs;
|
2020-10-27 12:06:59 +00:00
|
|
|
|
using RGBController2.ViewModels.Dialogs;
|
2020-10-25 19:52:14 +00:00
|
|
|
|
|
|
|
|
|
namespace RGBController2.ViewModels
|
|
|
|
|
{
|
|
|
|
|
class MainViewModel
|
|
|
|
|
{
|
|
|
|
|
private readonly ObservableCollection<ITab> _tabs;
|
|
|
|
|
public ICommand NewTabCommand { get; }
|
2020-10-26 17:20:01 +00:00
|
|
|
|
public static ICollection<ITab> Tabs { get; set; }
|
2020-10-25 19:52:14 +00:00
|
|
|
|
|
|
|
|
|
public MainViewModel()
|
|
|
|
|
{
|
|
|
|
|
NewTabCommand = new ActionCommand(p => NewTab());
|
|
|
|
|
|
|
|
|
|
_tabs = new ObservableCollection<ITab>();
|
|
|
|
|
_tabs.CollectionChanged += Tabs_CollectionChanged;
|
|
|
|
|
|
|
|
|
|
Tabs = _tabs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Tabs_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ITab tab;
|
|
|
|
|
|
|
|
|
|
switch (e.Action)
|
|
|
|
|
{
|
|
|
|
|
case NotifyCollectionChangedAction.Add:
|
|
|
|
|
tab = (ITab) e.NewItems[0];
|
|
|
|
|
tab.CloseRequested += OnTabCloseRequested;
|
|
|
|
|
break;
|
|
|
|
|
case NotifyCollectionChangedAction.Remove:
|
|
|
|
|
tab = (ITab) e.OldItems[0];
|
|
|
|
|
tab.CloseRequested -= OnTabCloseRequested;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnTabCloseRequested(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Tabs.Remove((ITab) sender);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NewTab()
|
|
|
|
|
{
|
2020-10-27 12:06:59 +00:00
|
|
|
|
// Open the add tab dialog
|
|
|
|
|
var dialog = new NewTabDialogViewModel();
|
|
|
|
|
dialog.ShowDialogWindow();
|
|
|
|
|
|
|
|
|
|
// Use the results from the dialog when creating the new tab
|
|
|
|
|
if (dialog.Success)
|
|
|
|
|
{
|
|
|
|
|
Tabs.Add(new ArduinoTab(dialog.DeviceName));
|
|
|
|
|
}
|
2020-10-25 19:52:14 +00:00
|
|
|
|
}
|
2020-10-27 12:06:59 +00:00
|
|
|
|
|
2020-10-25 19:52:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|