aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/ItemBase.cs
blob: 41bfb8e4d5c9e4fc7745c6505a7b613ce6320eea (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core;
using Tango.Core.Commands;

namespace Tango.PPC.Common.Notifications
{
    /// <summary>
    /// Represents a base notification item class.
    /// </summary>
    /// <seealso cref="Tango.Core.ExtendedObject" />
    /// <seealso cref="System.IDisposable" />
    public abstract class ItemBase : ExtendedObject, IDisposable
    {
        /// <summary>
        /// Occurs when the item has been closed.
        /// </summary>
        public event EventHandler Closed;

        /// <summary>
        /// Occurs when the item has been pressed.
        /// </summary>
        public event EventHandler Pressed;

        /// <summary>
        /// Gets or sets the remove action.
        /// </summary>
        internal Action RemoveAction { get; set; }

        /// <summary>
        /// Gets or sets the view type.
        /// </summary>
        public abstract Type ViewType { get; }

        /// <summary>
        /// Gets or sets the close command.
        /// </summary>
        public RelayCommand CloseCommand { get; set; }

        /// <summary>
        /// Gets or sets the pressed command.
        /// </summary
        public RelayCommand PressedCommand { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="ItemBase"/> class.
        /// </summary>
        public ItemBase()
        {
            CloseCommand = new RelayCommand(Close);
            PressedCommand = new RelayCommand(OnPreesed);
        }

        /// <summary>
        /// Called when the item has been pressed.
        /// </summary>
        protected virtual void OnPreesed()
        {
            Pressed?.Invoke(this, new EventArgs());
        }

        /// <summary>
        /// Called after the close command has been raised.
        /// </summary>
        public virtual void Close()
        {
            RemoveAction?.Invoke();
            Closed?.Invoke(this, new EventArgs());
        }

        /// <summary>
        /// Disposes the item.
        /// </summary>
        public void Dispose()
        {
            Close();
        }
    }
}