using MaterialDesignThemes.Wpf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Tango.Core.Commands;
using Tango.MachineStudio.Common.Controls;
namespace Tango.MachineStudio.DB.Managers
{
///
/// Represents a registered MDI child (data table) view
///
///
public class RegisteredView : MdiChild
{
private static Random rnd = new Random();
///
/// Adds the view to the display.
///
public RelayCommand AddCommand { get; set; }
///
/// Initializes a new instance of the class.
///
/// The header.
/// The view.
/// The action.
public RegisteredView(String header, FrameworkElement view, Action action)
{
Location = new Point(rnd.Next(30, 200), rnd.Next(30, 200));
Icon = PackIconKind.Table;
if (header.Length < 5)
{
header = header.ToUpper();
}
Header = header;
View = view;
View.MaxWidth = 1500;
View.MaxHeight = 800;
if (action != null)
{
AddCommand = new RelayCommand(action);
}
else
{
AddCommand = new RelayCommand(() =>
{
if (!ViewsManager.DisplayedViews.Contains(this))
{
ViewsManager.DisplayedViews.Add(this);
View.BringIntoView();
View.Focus();
}
else
{
View.BringIntoView();
View.Focus();
}
});
}
}
///
/// Initializes a new instance of the class.
///
/// The header.
/// The view.
public RegisteredView(String header, FrameworkElement view) : this(header, view, null)
{
if (header.Length < 5)
{
header = header.ToUpper();
}
view.MaxWidth = 1500;
view.MaxHeight = 800;
Header = header;
View = view;
}
///
/// Returns a that represents this instance.
///
///
/// A that represents this instance.
///
public override string ToString()
{
return Header;
}
}
}