Skip to content

Commit b85de81

Browse files
committed
Added new Notification control
1 parent 63163cd commit b85de81

20 files changed

+1006
-216
lines changed

Plugins/MsCrmTools.SampleTool/MsCrmTools.SampleTool.csproj

Lines changed: 53 additions & 124 deletions
Large diffs are not rendered by default.

Plugins/MsCrmTools.SampleTool/SampleTool.Designer.cs

Lines changed: 269 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Plugins/MsCrmTools.SampleTool/SampleTool.cs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
using Microsoft.Toolkit.Uwp.Notifications;
88
using Microsoft.Xrm.Sdk.Query;
99
using System;
10+
using System.Diagnostics;
1011
using System.Linq;
1112
using System.Windows.Forms;
1213
using XrmToolBox;
1314
using XrmToolBox.Extensibility;
1415
using XrmToolBox.Extensibility.Args;
1516
using XrmToolBox.Extensibility.Interfaces;
17+
using XrmToolBox.Extensibility.UserControls;
1618

1719
namespace MsCrmTools.SampleTool
1820
{
@@ -41,6 +43,11 @@ public SampleTool()
4143
LogInfo("An information message");
4244
LogWarning("A warning message");
4345
LogError("An error message");
46+
47+
cbbNotifType.DataSource = Enum.GetValues(typeof(NotificationType));
48+
cbbNotifType.SelectedIndex = 0;
49+
cbbNotifActions.DataSource = Enum.GetValues(typeof(NotificationAction));
50+
cbbNotifActions.SelectedIndex = 0;
4451
}
4552

4653
public event EventHandler<StatusBarMessageEventArgs> SendMessageToStatusBar;
@@ -288,14 +295,59 @@ private void btnOpenNotif_Click(object sender, EventArgs e)
288295
.Show();
289296
}
290297

298+
private void btnShowNotif_Click(object sender, EventArgs e)
299+
{
300+
Enum.TryParse(cbbNotifType.SelectedValue.ToString(), out NotificationType status);
301+
Enum.TryParse(cbbNotifActions.SelectedValue.ToString(), out NotificationAction action);
302+
303+
notificationControl1.Type = status;
304+
notificationControl1.Message = txtNotifMessage.Text;
305+
notificationControl1.Action = action;
306+
notificationControl1.ButtonText = txtNotifButton.Text;
307+
308+
notificationControl1.ButtonClicked -= NotificationControl1_ButtonClicked;
309+
notificationControl1.ButtonClicked += NotificationControl1_ButtonClicked;
310+
311+
notificationControl1.CanBeClosed = chkNotifCanBeClosed.Checked;
312+
notificationControl1.LinkText = txtNotifLink.Text;
313+
notificationControl1.LinkClicked -= NotificationControl1_LinkClicked;
314+
notificationControl1.LinkClicked += NotificationControl1_LinkClicked;
315+
316+
notificationControl1.SetVisible(true, Convert.ToInt32(nudNotif.Value) * 1000);
317+
}
318+
291319
private void button1_Click(object sender, EventArgs e)
292320
{
293321
throw new Exception("I wasn't expected this exception");
294322
}
295323

324+
private void NotificationControl1_ButtonClicked(object sender, EventArgs e)
325+
{
326+
MessageBox.Show("Button clicked!");
327+
}
328+
329+
private void NotificationControl1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
330+
{
331+
MessageBox.Show("Link clicked!");
332+
}
333+
334+
private void NotificationControl2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
335+
{
336+
Process.Start("http://github.com/MscrmTools/XrmToolBox");
337+
}
338+
296339
private void SampleTool_Load(object sender, EventArgs e)
297340
{
298-
ShowInfoNotification("This is a notification that can lead to XrmToolBox repository", new Uri("http://github.com/MscrmTools/XrmToolBox"));
341+
//ShowInfoNotification("This is a notification that can lead to XrmToolBox repository", new Uri("http://github.com/MscrmTools/XrmToolBox"));
342+
343+
Notification.Message = "This is a notification that can lead to XrmToolBox repository!";
344+
Notification.Type = NotificationType.Info;
345+
Notification.Action = NotificationAction.Link;
346+
Notification.LinkText = "Go to repository";
347+
Notification.LinkClicked -= NotificationControl2_LinkClicked;
348+
Notification.LinkClicked += NotificationControl2_LinkClicked;
349+
Notification.SetVisible(true, 10);
350+
Notification.CanBeClosed = true;
299351
}
300352

301353
#region IMessageBusHost

Plugins/MsCrmTools.SampleTool/app.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
</dependentAssembly>
7777
<dependentAssembly>
7878
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
79-
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
79+
<bindingRedirect oldVersion="0.0.0.0-6.0.3.0" newVersion="6.0.3.0" />
8080
</dependentAssembly>
8181
<dependentAssembly>
8282
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />

Plugins/MsCrmTools.SampleTool/packages.config

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using System.Drawing;
3+
using System.Drawing.Drawing2D;
4+
5+
namespace XrmToolBox.Extensibility
6+
{
7+
public static class DrawExtensions
8+
{
9+
public static void DrawRoundedRectangle(this Graphics graphics, Pen pen, Rectangle bounds, int cornerRadius)
10+
{
11+
if (graphics == null)
12+
throw new ArgumentNullException(nameof(graphics));
13+
if (pen == null)
14+
throw new ArgumentNullException(nameof(pen));
15+
16+
using (GraphicsPath path = RoundedRect(bounds, cornerRadius))
17+
{
18+
graphics.DrawPath(pen, path);
19+
}
20+
}
21+
22+
public static void FillRoundedRectangle(this Graphics graphics, Brush brush, Rectangle bounds, int cornerRadius)
23+
{
24+
if (graphics == null)
25+
throw new ArgumentNullException(nameof(graphics));
26+
if (brush == null)
27+
throw new ArgumentNullException(nameof(brush));
28+
29+
using (GraphicsPath path = RoundedRect(bounds, cornerRadius))
30+
{
31+
graphics.FillPath(brush, path);
32+
}
33+
}
34+
35+
public static GraphicsPath RoundedRect(Rectangle bounds, int radius)
36+
{
37+
int diameter = radius * 2;
38+
Size size = new Size(diameter, diameter);
39+
Rectangle arc = new Rectangle(bounds.Location, new Size(size.Width - 1, size.Height - 1));
40+
GraphicsPath path = new GraphicsPath();
41+
42+
if (radius == 0)
43+
{
44+
path.AddRectangle(bounds);
45+
return path;
46+
}
47+
48+
// top left arc
49+
path.AddArc(arc, 180, 90);
50+
51+
// top right arc
52+
arc.X = bounds.Right - diameter;
53+
path.AddArc(arc, 270, 90);
54+
55+
// bottom right arc
56+
arc.Y = bounds.Bottom - diameter;
57+
path.AddArc(arc, 0, 90);
58+
59+
// bottom left arc
60+
arc.X = bounds.Left;
61+
path.AddArc(arc, 90, 90);
62+
63+
path.CloseFigure();
64+
return path;
65+
}
66+
}
67+
}

XrmToolBox.Extensibility/PluginControlBase.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.ComponentModel.Composition;
1212
using System.Diagnostics;
1313
using System.Drawing;
14+
using System.Linq;
1415
using System.Reflection;
1516
using System.Runtime.InteropServices;
1617
using System.Windows.Forms;
@@ -51,6 +52,7 @@ public PluginControlBase()
5152
}
5253

5354
public ConnectionDetail ConnectionDetail { get; set; }
55+
public NotificationControl Notification => ParentForm.Controls.OfType<Panel>().FirstOrDefault(p => p.Name == "pnlMain")?.Controls.OfType<NotificationControl>().FirstOrDefault();
5456
public Guid PluginControlId { get; } = Guid.NewGuid();
5557

5658
[Category("Tool Control Properties")]
@@ -461,6 +463,7 @@ public void OpenLogFile()
461463

462464
#region Noticiation zone
463465

466+
[Obsolete("Use new Notification control. https://www.xrmtoolbox.com/documentation/for-developers/Use-Notifications/")]
464467
protected void HideNotification()
465468
{
466469
if (Parent == null)
@@ -475,6 +478,7 @@ protected void HideNotification()
475478
}
476479
}
477480

481+
[Obsolete("Use new Notification control. https://www.xrmtoolbox.com/documentation/for-developers/Use-Notifications/")]
478482
protected void ShowErrorNotification(string message, Uri moreInfoUri, int height = 32)
479483
{
480484
if (Parent == null)
@@ -493,6 +497,7 @@ protected void ShowErrorNotification(string message, Uri moreInfoUri, int height
493497
}
494498
}
495499

500+
[Obsolete("Use new Notification control. https://www.xrmtoolbox.com/documentation/for-developers/Use-Notifications/")]
496501
protected void ShowInfoNotification(string message, Uri moreInfoUri, int height = 32)
497502
{
498503
if (Parent == null)
@@ -511,6 +516,7 @@ protected void ShowInfoNotification(string message, Uri moreInfoUri, int height
511516
}
512517
}
513518

519+
[Obsolete("Use new Notification control. https://www.xrmtoolbox.com/documentation/for-developers/Use-Notifications/")]
514520
protected void ShowWarningNotification(string message, Uri moreInfoUri, int height = 32)
515521
{
516522
if (Parent == null)

XrmToolBox.Extensibility/Properties/Resources.Designer.cs

Lines changed: 41 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

XrmToolBox.Extensibility/Properties/Resources.resx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,16 @@
136136
<data name="progress_new" type="System.Resources.ResXFileRef, System.Windows.Forms">
137137
<value>..\Resources\progress_new.gif;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
138138
</data>
139+
<data name="Error32" type="System.Resources.ResXFileRef, System.Windows.Forms">
140+
<value>..\Resources\Error32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
141+
</data>
142+
<data name="info" type="System.Resources.ResXFileRef, System.Windows.Forms">
143+
<value>..\Resources\info.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
144+
</data>
145+
<data name="Success" type="System.Resources.ResXFileRef, System.Windows.Forms">
146+
<value>..\Resources\Success.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
147+
</data>
148+
<data name="warning" type="System.Resources.ResXFileRef, System.Windows.Forms">
149+
<value>..\Resources\warning.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
150+
</data>
139151
</root>
992 Bytes
Loading

0 commit comments

Comments
 (0)