From 6e36209a767e84ded4600b643c05c8f460a5f706 Mon Sep 17 00:00:00 2001 From: JKlingen Date: Sun, 15 Jul 2012 09:17:37 +0000 Subject: [PATCH] refactoring: extracted new method "ShowPrintOptionsDialog" git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1948 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- Greenshot/Helpers/PrintHelper.cs | 40 +++++++++++++++----------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/Greenshot/Helpers/PrintHelper.cs b/Greenshot/Helpers/PrintHelper.cs index 5bac2484a..0ee466d0e 100644 --- a/Greenshot/Helpers/PrintHelper.cs +++ b/Greenshot/Helpers/PrintHelper.cs @@ -96,17 +96,9 @@ namespace Greenshot.Helpers { /// printer settings if actually printed, or null if print was cancelled or has failed public PrinterSettings PrintTo(string printerName) { PrinterSettings returnPrinterSettings = null; - bool cancelled = false; - if (conf.OutputPrintPromptOptions) { - using (PrintOptionsDialog printOptionsDialog = new PrintOptionsDialog()) { - DialogResult result = printOptionsDialog.ShowDialog(); - if (result != DialogResult.OK) { - cancelled = true; - } - } - } - try { - if (!cancelled) { + DialogResult? printOptionsResult = ShowPrintOptionsDialog(); + try { + if (printOptionsResult == null || printOptionsResult == DialogResult.OK) { printDocument.PrinterSettings.PrinterName = printerName; if (conf.OutputPrintGrayscale) { printDocument.DefaultPageSettings.Color = false; @@ -131,17 +123,9 @@ namespace Greenshot.Helpers { public PrinterSettings PrintWithDialog() { PrinterSettings returnPrinterSettings = null; if (printDialog.ShowDialog() == DialogResult.OK) { - bool cancelled = false; - if (conf.OutputPrintPromptOptions) { - using (PrintOptionsDialog printOptionsDialog = new PrintOptionsDialog()) { - DialogResult result = printOptionsDialog.ShowDialog(); - if (result != DialogResult.OK) { - cancelled = true; - } - } - } + DialogResult? printOptionsResult = ShowPrintOptionsDialog(); try { - if (!cancelled) { + if (printOptionsResult == null || printOptionsResult == DialogResult.OK) { if (conf.OutputPrintGrayscale) { printDocument.DefaultPageSettings.Color = false; } @@ -159,6 +143,20 @@ namespace Greenshot.Helpers { return returnPrinterSettings; } + /// + /// display print options dialog (if the user has not configured Greenshot not to) + /// + /// result of the print dialog, or null if the dialog has not been displayed by config + private DialogResult? ShowPrintOptionsDialog() { + DialogResult? ret = null; + if (conf.OutputPrintPromptOptions) { + using (PrintOptionsDialog printOptionsDialog = new PrintOptionsDialog()) { + ret = printOptionsDialog.ShowDialog(); + } + } + return ret; + } + void DrawImageForPrint(object sender, PrintPageEventArgs e) { ContentAlignment alignment = conf.OutputPrintCenter ? ContentAlignment.MiddleCenter : ContentAlignment.TopLeft;