mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 05:23:24 -07:00
Made the printer-destination work like the others, with dynamic selection of the printer
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1798 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
9bf5e44c94
commit
514a36751f
3 changed files with 63 additions and 5 deletions
|
@ -39,7 +39,14 @@ namespace Greenshot.Destinations {
|
|||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(PrinterDestination));
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
public const string DESIGNATION = "Printer";
|
||||
public string printerName = null;
|
||||
|
||||
public PrinterDestination() {
|
||||
}
|
||||
|
||||
public PrinterDestination(string printerName) {
|
||||
this.printerName = printerName;
|
||||
}
|
||||
public override string Designation {
|
||||
get {
|
||||
return DESIGNATION;
|
||||
|
@ -48,9 +55,13 @@ namespace Greenshot.Destinations {
|
|||
|
||||
public override string Description {
|
||||
get {
|
||||
if (printerName != null) {
|
||||
return Language.GetString(LangKey.settings_destination_printer) + " - " + printerName;
|
||||
} else {
|
||||
return Language.GetString(LangKey.settings_destination_printer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override int Priority {
|
||||
get {
|
||||
|
@ -70,10 +81,26 @@ namespace Greenshot.Destinations {
|
|||
}
|
||||
}
|
||||
|
||||
public override bool isDynamic {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerable<IDestination> DynamicDestinations() {
|
||||
foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters) {
|
||||
yield return new PrinterDestination(printer);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
|
||||
PrinterSettings printerSettings = null;
|
||||
using (Image image = surface.GetImageForExport()) {
|
||||
if (!string.IsNullOrEmpty(printerName)) {
|
||||
printerSettings = new PrintHelper(image, captureDetails).PrintTo(printerName);
|
||||
} else {
|
||||
printerSettings = new PrintHelper(image, captureDetails).PrintWithDialog();
|
||||
}
|
||||
if (printerSettings != null) {
|
||||
surface.Modified = false;
|
||||
surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.editor_senttoprinter, printerSettings.PrinterName));
|
||||
|
|
|
@ -94,13 +94,43 @@ namespace Greenshot.Helpers {
|
|||
printOptionsDialog = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// displays options dialog (if not disabled via settings) and windows
|
||||
/// print dialog.
|
||||
/// </summary>
|
||||
/// <returns>printer settings if actually printed, or null if print was cancelled or has failed</returns>
|
||||
public PrinterSettings PrintTo(string printerName) {
|
||||
PrinterSettings returnPrinterSettings = null;
|
||||
bool cancelled = false;
|
||||
printOptionsDialog = new PrintOptionsDialog();
|
||||
if (conf.OutputPrintPromptOptions) {
|
||||
DialogResult result = printOptionsDialog.ShowDialog();
|
||||
if (result != DialogResult.OK) {
|
||||
cancelled = true;
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (!cancelled) {
|
||||
printDocument.PrinterSettings.PrinterName = printerName;
|
||||
printDocument.Print();
|
||||
returnPrinterSettings = printDocument.PrinterSettings;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.Error("An error ocurred while trying to print", e);
|
||||
MessageBox.Show(Language.GetString(LangKey.print_error), Language.GetString(LangKey.error));
|
||||
}
|
||||
image.Dispose();
|
||||
image = null;
|
||||
return returnPrinterSettings;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// displays options dialog (if not disabled via settings) and windows
|
||||
/// print dialog.
|
||||
/// </summary>
|
||||
/// <returns>printer settings if actually printed, or null if print was cancelled or has failed</returns>
|
||||
public PrinterSettings PrintWithDialog() {
|
||||
PrinterSettings ret = null;
|
||||
PrinterSettings returnPrinterSettings = null;
|
||||
if (printDialog.ShowDialog() == DialogResult.OK) {
|
||||
bool cancelled = false;
|
||||
printOptionsDialog = new PrintOptionsDialog();
|
||||
|
@ -113,7 +143,7 @@ namespace Greenshot.Helpers {
|
|||
try {
|
||||
if (!cancelled) {
|
||||
printDocument.Print();
|
||||
ret = printDialog.PrinterSettings;
|
||||
returnPrinterSettings = printDialog.PrinterSettings;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.Error("An error ocurred while trying to print", e);
|
||||
|
@ -123,7 +153,7 @@ namespace Greenshot.Helpers {
|
|||
}
|
||||
image.Dispose();
|
||||
image = null;
|
||||
return ret;
|
||||
return returnPrinterSettings;
|
||||
}
|
||||
|
||||
void DrawImageForPrint(object sender, PrintPageEventArgs e) {
|
||||
|
|
|
@ -18,6 +18,7 @@ Features added:
|
|||
* Added rotate clockwise & counter clockwise
|
||||
* Added a preview when using the window capture from the context menu (Windows Vista and later)
|
||||
* Added color reduction as an option and auto detection for image with less than 256 color. When using reduction this results in smaller files.
|
||||
* Added direct printing to a selected printer
|
||||
|
||||
Bugs resolved:
|
||||
* Fixed a problem with temp-files being removed before they were used, now using a delay of ~10 hours
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue