using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using Dragablz; using Dragablz.Dockablz; using Visualizer.Services; using Visualizer.Visualizers; namespace Visualizer { public class ShellViewModel : ViewModelBase { private readonly IInterTabClient _interTabClient = new ShellInterTabClient(); private readonly ObservableCollection _items; private readonly ObservableCollection _toolItems = new ObservableCollection(); // selected view ?? public ShellViewModel() : base(new ShellView()) { _items = new ObservableCollection(new HeaderedItemViewModel[] { NewItemFactory() }); } public ShellViewModel(bool addCreateTab) : base(new ShellView()) { _items = addCreateTab ? new ObservableCollection(new[] { NewItemFactory() }) : new ObservableCollection(); } public ShellViewModel(params HeaderedItemViewModel[] items) : base(new ShellView()) { _items = new ObservableCollection(items); } public Func NewItemFactory => () => new NewVisualizerViewModel(CreateVizualizer); public Action CreateVizualizer { get { return (tabModel) => { var index = Items.IndexOf(tabModel); var newModel = GetVisualizerModel(tabModel); Items.Insert(index, newModel); Items.Remove(tabModel); }; } } private static HeaderedItemViewModel GetVisualizerModel(NewVisualizerViewModel tabModel) { return TabViewFactory.VisualizerTypeViews[tabModel.SelectedVisualizerType].Invoke(tabModel.GridSize); } public ObservableCollection Items { get { return _items; } } public static Guid TabPartition { get { return new Guid("2AE89D18-F236-4D20-9605-6C03319038E6"); } } public IInterTabClient InterTabClient { get { return _interTabClient; } } public ObservableCollection ToolItems { get { return _toolItems; } } public ItemActionCallback ClosingTabItemHandler { get { return ClosingTabItemHandlerImpl; } } /// /// Callback to handle tab closing. /// private static void ClosingTabItemHandlerImpl(ItemActionCallbackArgs args) { //in here you can dispose stuff or cancel the close //here's your view model: var viewModel = args.DragablzItem.DataContext as HeaderedItemViewModel; //Debug.Assert(viewModel != null); //here's how you can cancel stuff: //args.Cancel(); } public ClosingFloatingItemCallback ClosingFloatingItemHandler { get { return ClosingFloatingItemHandlerImpl; } } /// /// Callback to handle floating toolbar/MDI window closing. /// private static void ClosingFloatingItemHandlerImpl(ItemActionCallbackArgs args) { //in here you can dispose stuff or cancel the close //here's your view model: var disposable = args.DragablzItem.DataContext as IDisposable; if (disposable != null) disposable.Dispose(); //here's how you can cancel stuff: //args.Cancel(); } } }