diff --git a/Core/Handling/General/JavaScriptDialogHandler.cs b/Core/Handling/General/JavaScriptDialogHandler.cs index 1ce5540f..fc6c3fff 100644 --- a/Core/Handling/General/JavaScriptDialogHandler.cs +++ b/Core/Handling/General/JavaScriptDialogHandler.cs @@ -8,31 +8,51 @@ namespace TweetDuck.Core.Handling.General{ sealed class JavaScriptDialogHandler : IJsDialogHandler{ + private static FormMessage CreateMessageForm(string caption, string text){ + MessageBoxIcon icon = MessageBoxIcon.None; + int pipe = text.IndexOf('|'); + + if (pipe != -1){ + switch(text.Substring(0, pipe)){ + case "error": icon = MessageBoxIcon.Error; break; + case "warning": icon = MessageBoxIcon.Warning; break; + case "info": icon = MessageBoxIcon.Information; break; + case "question": icon = MessageBoxIcon.Question; break; + default: return new FormMessage(caption, text, icon); + } + + text = text.Substring(pipe+1); + } + + return new FormMessage(caption, text, icon); + } + bool IJsDialogHandler.OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage){ ((ChromiumWebBrowser)browserControl).InvokeSafe(() => { FormMessage form; TextBox input = null; if (dialogType == CefJsDialogType.Alert){ - form = new FormMessage("Browser Message", messageText, MessageBoxIcon.None); + form = CreateMessageForm("Browser Message", messageText); form.AddButton(FormMessage.OK, ControlType.Accept | ControlType.Focused); } else if (dialogType == CefJsDialogType.Confirm){ - form = new FormMessage("Browser Confirmation", messageText, MessageBoxIcon.None); + form = CreateMessageForm("Browser Confirmation", messageText); form.AddButton(FormMessage.No, DialogResult.No, ControlType.Cancel); form.AddButton(FormMessage.Yes, ControlType.Focused); } else if (dialogType == CefJsDialogType.Prompt){ - form = new FormMessage("Browser Prompt", messageText, MessageBoxIcon.None); + form = CreateMessageForm("Browser Prompt", messageText); form.AddButton(FormMessage.Cancel, DialogResult.Cancel, ControlType.Cancel); form.AddButton(FormMessage.OK, ControlType.Accept | ControlType.Focused); float dpiScale = form.GetDPIScale(); + int inputPad = form.HasIcon ? 43 : 0; input = new TextBox{ Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom, - Location = new Point(BrowserUtils.Scale(22, dpiScale), form.ActionPanelY-BrowserUtils.Scale(46, dpiScale)), - Size = new Size(form.ClientSize.Width-BrowserUtils.Scale(44, dpiScale), 20) + Location = new Point(BrowserUtils.Scale(22+inputPad, dpiScale), form.ActionPanelY-BrowserUtils.Scale(46, dpiScale)), + Size = new Size(form.ClientSize.Width-BrowserUtils.Scale(44+inputPad, dpiScale), 20) }; form.Controls.Add(input); diff --git a/Core/Other/FormMessage.cs b/Core/Other/FormMessage.cs index 379c8d18..a9401e47 100644 --- a/Core/Other/FormMessage.cs +++ b/Core/Other/FormMessage.cs @@ -60,6 +60,7 @@ public static bool Show(string caption, string text, MessageBoxIcon icon, string public Button ClickedButton { get; private set; } + public bool HasIcon => icon != null; public int ActionPanelY => panelActions.Location.Y; private int ClientWidth{