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

Refactor FormMessage uses with the new DialogResult parameter

This commit is contained in:
chylex 2017-03-23 16:11:42 +01:00
parent c1420bac88
commit f1db1ba708
3 changed files with 11 additions and 27 deletions

View File

@ -13,26 +13,19 @@ bool IJsDialogHandler.OnJSDialog(IWebBrowser browserControl, IBrowser browser, s
((ChromiumWebBrowser)browserControl).InvokeSafe(() => { ((ChromiumWebBrowser)browserControl).InvokeSafe(() => {
FormMessage form = new FormMessage(Program.BrandName, messageText, MessageBoxIcon.None); FormMessage form = new FormMessage(Program.BrandName, messageText, MessageBoxIcon.None);
Button btnConfirm;
if (dialogType == CefJsDialogType.Alert){ if (dialogType == CefJsDialogType.Alert){
btnConfirm = form.AddButton("OK"); form.AddButton("OK");
} }
else if (dialogType == CefJsDialogType.Confirm){ else if (dialogType == CefJsDialogType.Confirm){
form.AddButton("No"); form.AddButton("No", DialogResult.No);
btnConfirm = form.AddButton("Yes"); form.AddButton("Yes");
} }
else{ else{
return; return;
} }
if (form.ShowDialog() == DialogResult.OK && form.ClickedButton == btnConfirm){ callback.Continue(form.ShowDialog() == DialogResult.OK);
callback.Continue(true);
}
else{
callback.Continue(false);
}
form.Dispose(); form.Dispose();
}); });

View File

@ -76,13 +76,11 @@ private static void Main(){
else if (attempt == 20){ else if (attempt == 20){
using(FormMessage form = new FormMessage(BrandName+" Cannot Restart", BrandName+" is taking too long to close.", MessageBoxIcon.Warning)){ using(FormMessage form = new FormMessage(BrandName+" Cannot Restart", BrandName+" is taking too long to close.", MessageBoxIcon.Warning)){
form.AddButton("Exit"); form.AddButton("Exit");
Button btnRetry = form.AddButton("Retry"); form.AddButton("Retry", DialogResult.Retry);
if (form.ShowDialog() == DialogResult.OK){ if (form.ShowDialog() == DialogResult.Retry){
if (form.ClickedButton == btnRetry){ attempt /= 2;
attempt /= 2; continue;
continue;
}
} }
return; return;

View File

@ -47,9 +47,8 @@ public void HandleException(string caption, string message, bool canIgnore, Exce
bool loggedSuccessfully = Log(e.ToString()); bool loggedSuccessfully = Log(e.ToString());
FormMessage form = new FormMessage(caption, message+"\r\nError: "+e.Message, canIgnore ? MessageBoxIcon.Warning : MessageBoxIcon.Error); FormMessage form = new FormMessage(caption, message+"\r\nError: "+e.Message, canIgnore ? MessageBoxIcon.Warning : MessageBoxIcon.Error);
form.AddButton("Exit"); form.AddButton("Exit");
Button btnIgnore = form.AddButton("Ignore"); form.AddButton("Ignore", DialogResult.Ignore).Enabled = canIgnore;
Button btnOpenLog = new Button{ Button btnOpenLog = new Button{
Anchor = AnchorStyles.Bottom | AnchorStyles.Left, Anchor = AnchorStyles.Bottom | AnchorStyles.Left,
@ -68,14 +67,8 @@ public void HandleException(string caption, string message, bool canIgnore, Exce
form.AddActionControl(btnOpenLog); form.AddActionControl(btnOpenLog);
if (!canIgnore){ if (form.ShowDialog() == DialogResult.Ignore){
btnIgnore.Enabled = false; return;
}
if (form.ShowDialog() == DialogResult.OK){
if (form.ClickedButton == btnIgnore){
return;
}
} }
try{ try{