1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-06-09 08:34:08 +02:00

Tweak new lines in FormMessage, add ControlType enum for FormMessage buttons

This commit is contained in:
chylex 2017-07-09 02:40:37 +02:00
parent 530b44762b
commit a453888ca2
4 changed files with 24 additions and 13 deletions

View File

@ -341,7 +341,7 @@ private void soundNotification_PlaybackError(object sender, PlaybackErrorEventAr
e.Ignore = true; e.Ignore = true;
using(FormMessage form = new FormMessage("Notification Sound Error", "Could not play custom notification sound.\n"+e.Message, MessageBoxIcon.Error)){ using(FormMessage form = new FormMessage("Notification Sound Error", "Could not play custom notification sound.\n"+e.Message, MessageBoxIcon.Error)){
form.CancelButton = form.AddButton("Ignore"); form.AddButton("Ignore", ControlType.Cancel | ControlType.Focused);
Button btnOpenSettings = form.AddButton("View Options"); Button btnOpenSettings = form.AddButton("View Options");
btnOpenSettings.Width += 16; btnOpenSettings.Width += 16;

View File

@ -9,19 +9,19 @@ namespace TweetDuck.Core.Handling {
class JavaScriptDialogHandler : IJsDialogHandler{ class JavaScriptDialogHandler : IJsDialogHandler{
bool IJsDialogHandler.OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage){ bool IJsDialogHandler.OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage){
((ChromiumWebBrowser)browserControl).InvokeSafe(() => { ((ChromiumWebBrowser)browserControl).InvokeSafe(() => {
FormMessage form = new FormMessage(Program.BrandName, messageText.Replace("\r", ""), MessageBoxIcon.None); FormMessage form = new FormMessage(Program.BrandName, messageText, MessageBoxIcon.None);
TextBox input = null; TextBox input = null;
if (dialogType == CefJsDialogType.Alert){ if (dialogType == CefJsDialogType.Alert){
form.AcceptButton = form.AddButton("OK"); form.AddButton("OK", ControlType.Accept | ControlType.Focused);
} }
else if (dialogType == CefJsDialogType.Confirm){ else if (dialogType == CefJsDialogType.Confirm){
form.CancelButton = form.AddButton("No", DialogResult.No); form.AddButton("No", DialogResult.No, ControlType.Cancel);
form.AcceptButton = form.AddButton("Yes"); form.AddButton("Yes", ControlType.Focused);
} }
else if (dialogType == CefJsDialogType.Prompt){ else if (dialogType == CefJsDialogType.Prompt){
form.CancelButton = form.AddButton("Cancel", DialogResult.Cancel); form.AddButton("Cancel", DialogResult.Cancel, ControlType.Cancel);
form.AcceptButton = form.AddButton("OK"); form.AddButton("OK", ControlType.Accept | ControlType.Focused);
input = new TextBox{ input = new TextBox{
Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom, Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom,

View File

@ -5,6 +5,14 @@
using TweetDuck.Core.Utils; using TweetDuck.Core.Utils;
namespace TweetDuck.Core.Other{ namespace TweetDuck.Core.Other{
[Flags]
public enum ControlType{
None = 0,
Accept = 1, // triggered by pressing enter when a non-button is focused
Cancel = 2, // triggered by closing the dialog without pressing a button
Focused = 4 // active control after the dialog is showed
}
sealed partial class FormMessage : Form{ sealed partial class FormMessage : Form{
public Button ClickedButton { get; private set; } public Button ClickedButton { get; private set; }
@ -63,14 +71,18 @@ public FormMessage(string caption, string text, MessageBoxIcon messageIcon){
this.isReady = true; this.isReady = true;
this.Text = caption; this.Text = caption;
this.labelMessage.Text = text.Replace("\n", Environment.NewLine); // TODO replace all \r\n this.labelMessage.Text = text.Replace("\r", "").Replace("\n", Environment.NewLine);
} }
private void FormMessage_SizeChanged(object sender, EventArgs e){ private void FormMessage_SizeChanged(object sender, EventArgs e){
RecalculateButtonLocation(); RecalculateButtonLocation();
} }
public Button AddButton(string title, DialogResult result = DialogResult.OK){ public Button AddButton(string title, ControlType type){
return AddButton(title, DialogResult.OK, type);
}
public Button AddButton(string title, DialogResult result = DialogResult.OK, ControlType type = ControlType.None){
Button button = new Button{ Button button = new Button{
Anchor = AnchorStyles.Bottom, Anchor = AnchorStyles.Bottom,
Font = SystemFonts.MessageBoxFont, Font = SystemFonts.MessageBoxFont,

View File

@ -43,14 +43,13 @@ public bool Log(string data){
public void HandleException(string caption, string message, bool canIgnore, Exception e){ public void HandleException(string caption, string message, bool canIgnore, Exception e){
bool loggedSuccessfully = Log(e.ToString()); bool loggedSuccessfully = Log(e.ToString());
FormMessage form = new FormMessage(caption, message+"\nError: "+e.Message.Replace("\r", ""), canIgnore ? MessageBoxIcon.Warning : MessageBoxIcon.Error); FormMessage form = new FormMessage(caption, message+"\nError: "+e.Message, canIgnore ? MessageBoxIcon.Warning : MessageBoxIcon.Error);
Button btnExit = form.AddButton("Exit"); Button btnExit = form.AddButton("Exit");
Button btnIgnore = form.AddButton("Ignore", DialogResult.Ignore); Button btnIgnore = form.AddButton("Ignore", DialogResult.Ignore, ControlType.Cancel);
btnIgnore.Enabled = canIgnore; btnIgnore.Enabled = canIgnore;
form.ActiveControl = canIgnore ? btnIgnore : btnExit; form.ActiveControl = canIgnore ? btnIgnore : btnExit;
form.CancelButton = btnIgnore;
Button btnOpenLog = new Button{ Button btnOpenLog = new Button{
Anchor = AnchorStyles.Bottom | AnchorStyles.Left, Anchor = AnchorStyles.Bottom | AnchorStyles.Left,
@ -85,7 +84,7 @@ public static void HandleEarlyFailure(string caption, string message){
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
using(FormMessage form = new FormMessage(caption, message, MessageBoxIcon.Error)){ using(FormMessage form = new FormMessage(caption, message, MessageBoxIcon.Error)){
form.ActiveControl = form.AddButton("Exit"); form.AddButton("Exit", ControlType.Focused);
form.ShowDialog(); form.ShowDialog();
} }