Korero – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 using System;
2 using System.Diagnostics;
3 using System.Drawing;
4 using System.IO;
5 using System.Media;
6 using System.Threading.Tasks;
7 using System.Windows.Forms;
8 using Korero.Utilities;
9  
10 namespace Korero.Notifications
11 {
12 public partial class NotificationForm : Form
13 {
14 #region Public Enums, Properties and Fields
15  
16 public int Index { get; }
17  
18 #endregion
19  
20 #region Private Delegates, Events, Enums, Properties, Indexers and Fields
21  
22 private readonly Action _clickAction;
23  
24 private Point _displayLocation;
25  
26 #endregion
27  
28 #region Constructors, Destructors and Finalizers
29  
30 public NotificationForm()
31 {
32 InitializeComponent();
33 Utilities.WindowState.FormTracker.Track(this);
34 }
35  
36 public NotificationForm(int index, string title, string text, int milliseconds) : this()
37 {
38 Index = index;
39  
40 readOnlyRichTextBox1.InvokeIfRequired(richTextBox => { richTextBox.Text = title; });
41 richTextBox1.InvokeIfRequired(richTextBox => { richTextBox.Text = text; });
42  
43 Task.Delay(milliseconds).ContinueWith(task =>
44 this.InvokeIfRequired(form => form.Close()));
45 }
46  
47 public NotificationForm(int index, string title, string message, int timeout, UnmanagedMemoryStream sound) :
48 this(index, title, message, timeout)
49 {
50 using (var soundPlayer = new SoundPlayer(sound))
51 {
52 soundPlayer.Play();
53 }
54 }
55  
56 public NotificationForm(int index, string title, string message, int timeout, UnmanagedMemoryStream sound,
57 Action action) : this(index, title, message, timeout, sound)
58 {
59 _clickAction = action;
60 }
61  
62 #endregion
63  
64 #region Private Overrides
65  
66 protected override void OnLoad(EventArgs e)
67 {
68 Location = _displayLocation;
69 base.OnLoad(e);
70 }
71  
72 protected override bool ShowWithoutActivation => true;
73  
74 #endregion
75  
76 #region Event Handlers
77  
78 private void PictureBox2_Click(object sender, EventArgs e)
79 {
80 this.InvokeIfRequired(form => { form.Close(); });
81 }
82  
83 private void RichTextBox1_LinkClicked(object sender, LinkClickedEventArgs e)
84 {
85 Process.Start(e.LinkText);
86 }
87  
88 private void ReadOnlyRichTextBox1_LinkClicked(object sender, LinkClickedEventArgs e)
89 {
90 Process.Start(e.LinkText);
91 }
92  
93 private void ReadONlyRichTextBox1_Click(object sender, EventArgs e)
94 {
95 _clickAction?.Invoke();
96 }
97  
98 private void RichTextBox1_Click(object sender, EventArgs e)
99 {
100 _clickAction?.Invoke();
101 }
102  
103 private void PictureBox1_Click(object sender, EventArgs e)
104 {
105 _clickAction?.Invoke();
106 }
107  
108 private void NotificationForm_Click(object sender, EventArgs e)
109 {
110 _clickAction?.Invoke();
111 }
112  
113 #endregion
114  
115 #region Public Methods
116  
117 public void UpdateLocation(int x, int y)
118 {
119 _displayLocation = new Point(x, y);
120 }
121  
122 #endregion
123 }
124 }