aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Managers/RegisteredView.cs
blob: fc9051edbe501b9081a237b3200ab3443ce11d97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
{
    public class RegisteredView : MdiChild
    {
        private static Random rnd = new Random();

        public RelayCommand AddCommand { get; set; }

        public RegisteredView(String header, FrameworkElement view, Action action)
        {
            Location = new Point(rnd.Next(30, 200), rnd.Next(30, 200));
            Icon = PackIconKind.Table;
            Header = header;
            View = view;

            if (action != null)
            {
                AddCommand = new RelayCommand(action);
            }
            else
            {
                AddCommand = new RelayCommand(() =>
                {
                    if (!ViewsManager.DisplayedViews.Contains(this))
                    {
                        ViewsManager.DisplayedViews.Add(this);
                    }
                    else
                    {
                        View.BringIntoView();
                        View.Focus();
                    }
                });
            }
        }

        public RegisteredView(String header, FrameworkElement view) : this(header, view, null)
        {
            Header = header;
            View = view;
        }

        public override string ToString()
        {
            return Header;
        }
    }
}