/// <summary> /// Close all the notifications /// </summary> public static void ForceClose() { YamuiNotification.CloseEverything(); foreach (var yamuiInput in _openedMessage) { if (yamuiInput != null) { yamuiInput.Tag = true; yamuiInput.Close(); yamuiInput.Dispose(); } } }
/// <summary> /// Displays a notification on the bottom right of the screen /// </summary> /// <param name="id"></param> /// <param name="htmlContent"></param> /// <param name="clickHandler"></param> /// <param name="subTitle"></param> /// <param name="duration"></param> /// <param name="width"></param> /// <param name="imageType"></param> /// <param name="title"></param> public static void NotifyUnique(string id, string htmlContent, MessageImg imageType, string title, string subTitle, Action <HtmlLinkClickedEventArgs> clickHandler, int duration = 0, int width = 450) { if (!UiThread.BeginInvoke(() => { try { var nppScreen = Npp.NppScreen; var toastNotification = new YamuiNotification( HtmlHelper.FormatTitle(imageType, title, subTitle), HtmlHelper.FormatContent(htmlContent), duration, nppScreen, Math.Min(width, nppScreen.WorkingArea.Width / 3), nppScreen.WorkingArea.Width / 3, nppScreen.WorkingArea.Height / 3, (sender, args) => { if (clickHandler != null) { clickHandler(args); } if (!args.Handled) { Utils.OpenPathClickHandler(sender, args); } }); if (id != null) { // close existing notification with the same id CloseUniqueNotif(id); // Remember this notification _registeredNotif.Add(id, toastNotification); } toastNotification.Show(); } catch (Exception e) { ErrorHandler.LogError(e, "Error in NotifyUnique"); // if we are here, display the error message the old way MessageBox.Show("An error has occurred and we couldn't display a notification.\n\nCheck the log at the following location to learn more about this error : " + Config.FileErrorLog.Quoter() + "\n\nTry to restart Notepad++, consider opening an issue on : " + Config.UrlIssues + " if the problem persists.", AssemblyInfo.AssemblyProduct + " error message", MessageBoxButtons.OK, MessageBoxIcon.Error); } })) { ErrorHandler.LogError(new Exception("No UIThread!"), "Error in NotifyUnique"); // show the old way MessageBox.Show("An error has occurred and we couldn't display a notification.\n\nCheck the log at the following location to learn more about this error : " + Config.FileErrorLog.Quoter() + "\n\nTry to restart Notepad++, consider opening an issue on : " + Config.UrlIssues + " if the problem persists.\n\nThe initial message was :\n" + htmlContent.Replace("<br>", "\n"), AssemblyInfo.AssemblyProduct + " error message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Displays a notification on the bottom right of the screen /// </summary> /// <param name="id"></param> /// <param name="htmlContent"></param> /// <param name="clickHandler"></param> /// <param name="subTitle"></param> /// <param name="duration"></param> /// <param name="width"></param> /// <param name="imageType"></param> /// <param name="title"></param> public static void NotifyUnique(string id, string htmlContent, MessageImg imageType, string title, string subTitle, Action <HtmlLinkClickedEventArgs> clickHandler, int duration = 0, int width = 450) { Task.Factory.StartNew(() => { try { if (Ready) { _anchorForm.BeginInvoke((Action) delegate { var nppScreen = Npp.NppScreen; var toastNotification = new YamuiNotification( ThemeManager.FormatTitle(imageType, title, subTitle), ThemeManager.FormatContent(htmlContent), duration, nppScreen, Math.Min(width, nppScreen.WorkingArea.Width / 3), nppScreen.WorkingArea.Width / 3, nppScreen.WorkingArea.Height / 3, (sender, args) => { if (clickHandler != null) { clickHandler(args); } else { Utils.OpenPathClickHandler(sender, args); } }); if (id != null) { // close existing notification with the same id CloseUniqueNotif(id); // Remember this notification _registeredNotif.Add(id, toastNotification); } toastNotification.Show(); }); } } catch (Exception e) { ErrorHandler.LogError(e); // if we are here, display the error message the old way MessageBox.Show("An error has occurred and we couldn't display a notification.\n\nCheck the log at the following location to learn more about this error : " + Config.FileErrorLog.ProQuoter() + "\n\nTry to restart Notepad++, consider opening an issue on : " + Config.IssueUrl + " if the problem persists.", AssemblyInfo.AssemblyProduct + " error message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }); }