Esempio n. 1
0
        /// <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);
            }
        }
Esempio n. 2
0
        private static int Message(ref object data, string htmlContent, MessageImg imageType, string title, string subTitle, List <string> buttonsList = null, bool waitResponse = true, Action <HtmlLinkClickedEventArgs> clickHandler = null, int minWidth = 450)
        {
            var clickedButton = -1;

            if (buttonsList == null)
            {
                buttonsList = new List <string> {
                    "Ok", "Cancel"
                }
            }
            ;

            if (waitResponse && data != null)
            {
                clickedButton = YamuiInput.ShowDialog(
                    Npp.Handle,
                    "3P: " + title,
                    HtmlHelper.FormatTitle(imageType, title, subTitle),
                    HtmlHelper.FormatContent(htmlContent),
                    buttonsList,
                    ref data,
                    Npp.NppScreen.WorkingArea.Width * 3 / 5,
                    Npp.NppScreen.WorkingArea.Height * 9 / 10,
                    minWidth,
                    (sender, args) => {
                    if (clickHandler != null)
                    {
                        clickHandler(args);
                    }
                    else
                    {
                        Utils.OpenPathClickHandler(sender, args);
                    }
                });
            }
            else if (waitResponse)
            {
                UiThread.Invoke(() => {
                    object nullObject = null;
                    clickedButton     = YamuiInput.ShowDialog(
                        Npp.Handle,
                        "3P: " + title,
                        HtmlHelper.FormatTitle(imageType, title, subTitle),
                        HtmlHelper.FormatContent(htmlContent),
                        buttonsList,
                        ref nullObject,
                        Npp.NppScreen.WorkingArea.Width * 3 / 5,
                        Npp.NppScreen.WorkingArea.Height * 9 / 10,
                        minWidth,
                        (sender, args) => {
                        if (clickHandler != null)
                        {
                            clickHandler(args);
                        }
                        else
                        {
                            Utils.OpenPathClickHandler(sender, args);
                        }
                    });
                });
            }
            else
            {
                UiThread.BeginInvoke(() => {
                    YamuiInput form;
                    object nullObject = null;
                    clickedButton     = YamuiInput.Show(
                        Npp.Handle,
                        "3P: " + title,
                        HtmlHelper.FormatTitle(imageType, title, subTitle),
                        HtmlHelper.FormatContent(htmlContent),
                        buttonsList,
                        ref nullObject,
                        out form,
                        Npp.NppScreen.WorkingArea.Width * 3 / 5,
                        Npp.NppScreen.WorkingArea.Height * 9 / 10,
                        minWidth,
                        (sender, args) => {
                        if (clickHandler != null)
                        {
                            clickHandler(args);
                        }
                        else
                        {
                            Utils.OpenPathClickHandler(sender, args);
                        }
                    });
                    _openedMessage.Add(form);
                });
            }
            return(clickedButton);
        }

        #endregion
    }