Configuration refactoring: changed SettingsForm and some other classes to use the new IniConfiguration

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@849 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2010-08-23 19:42:33 +00:00
parent 60f72cc0be
commit 5e9772c4e5
6 changed files with 107 additions and 136 deletions

View file

@ -25,6 +25,12 @@ using System.Drawing.Imaging;
using System.IO; using System.IO;
namespace Greenshot.Core { namespace Greenshot.Core {
public enum Destination {
Editor, FileDefault, FileWithDialog, Clipboard, Printer, EMail
}
public enum OutputFormat {
Bmp, Gif, Jepg, Png, Tiff
}
/// <summary> /// <summary>
/// Description of CoreConfiguration. /// Description of CoreConfiguration.
/// </summary> /// </summary>
@ -37,7 +43,7 @@ namespace Greenshot.Core {
[IniProperty("IsFirstLaunch", Description="Is this the first time launch?", DefaultValue="true")] [IniProperty("IsFirstLaunch", Description="Is this the first time launch?", DefaultValue="true")]
public bool IsFirstLaunch; public bool IsFirstLaunch;
[IniProperty("Destinations", Description="Which destinations? Options are: Editor, FileDefault, FileWithDialog, Clipboard, Printer, EMail", DefaultValue="Editor")] [IniProperty("Destinations", Description="Which destinations? Options are: Editor, FileDefault, FileWithDialog, Clipboard, Printer, EMail", DefaultValue="Editor")]
public List<String> OutputDestinations; public List<Destination> OutputDestinations;
[IniProperty("CaptureMousepointer", Description="Should the mouse be captured?", DefaultValue="true")] [IniProperty("CaptureMousepointer", Description="Should the mouse be captured?", DefaultValue="true")]
public bool CaptureMousepointer; public bool CaptureMousepointer;
@ -48,7 +54,7 @@ namespace Greenshot.Core {
[IniProperty("CaptureCompleteWindow", Description="Try capturing the complete window.", DefaultValue="false")] [IniProperty("CaptureCompleteWindow", Description="Try capturing the complete window.", DefaultValue="false")]
public bool CaptureCompleteWindow; public bool CaptureCompleteWindow;
[IniProperty("CaptureWindowContent", Description="Try capturing only the content of the window (IE/Firefox).", DefaultValue="false")] [IniProperty("CaptureWindowContent", Description="Try capturing only the content of the window (IE/Firefox).", DefaultValue="false")]
public bool? CaptureWindowContent; public bool CaptureWindowContent;
[IniProperty("ShowFlashlight", Description="Show a flash after taking a capture.", DefaultValue="false")] [IniProperty("ShowFlashlight", Description="Show a flash after taking a capture.", DefaultValue="false")]
public bool ShowFlash = false; public bool ShowFlash = false;
@ -59,7 +65,7 @@ namespace Greenshot.Core {
[IniProperty("OutputFileFilenamePattern", Description="Filename pattern for screenshot.", DefaultValue="%title%_%YYYY%-%MM%-%DD%_%hh%-%mm%-%ss%")] [IniProperty("OutputFileFilenamePattern", Description="Filename pattern for screenshot.", DefaultValue="%title%_%YYYY%-%MM%-%DD%_%hh%-%mm%-%ss%")]
public string OutputFileFilenamePattern; public string OutputFileFilenamePattern;
[IniProperty("OutputFileFormat", Description="Default file type for writing screenshots. (Bmp, Gif, Jepg, Png, Tiff)", DefaultValue="Png")] [IniProperty("OutputFileFormat", Description="Default file type for writing screenshots. (Bmp, Gif, Jepg, Png, Tiff)", DefaultValue="Png")]
public ImageFormat OutputFileFormat = ImageFormat.Png; public OutputFormat OutputFileFormat = OutputFormat.Png;
[IniProperty("OutputFileCopyPathToClipboard", Description="When saving a screenshot, copy the path to the clipboard?", DefaultValue="true")] [IniProperty("OutputFileCopyPathToClipboard", Description="When saving a screenshot, copy the path to the clipboard?", DefaultValue="true")]
public bool OutputFileCopyPathToClipboard; public bool OutputFileCopyPathToClipboard;
@ -84,18 +90,5 @@ namespace Greenshot.Core {
public bool OutputPrintCenter; public bool OutputPrintCenter;
[IniProperty("OutputPrintTimestamp", Description="Print timestamp on print?", DefaultValue="true")] [IniProperty("OutputPrintTimestamp", Description="Print timestamp on print?", DefaultValue="true")]
public bool OutputPrintTimestamp; public bool OutputPrintTimestamp;
[IniProperty("EditorWindowSize", Description="Size of the editor.", DefaultValue="540, 380")]
public Size EditorWindowSize;
[IniProperty("EditorWindowLocation", Description="Location of the editor.", DefaultValue="100, 100")]
public Point EditorWindowLocation;
[IniProperty("EditorWindowState", Description="The window state of the editor. (Normal or Maximized)", DefaultValue="Normal")]
public String EditorWindowState;
public Color[] Editor_RecentColors = new Color[12];
public Font Editor_Font = null;
// Not storing, this doesn't make sense to store (or does it?)
public Rectangle EditorPreviousScreenbounds = Rectangle.Empty;
} }
} }

View file

@ -30,8 +30,8 @@ namespace Greenshot {
/// Description of JpegQualityDialog. /// Description of JpegQualityDialog.
/// </summary> /// </summary>
public partial class JpegQualityDialog : Form { public partial class JpegQualityDialog : Form {
AppConfig conf; private CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
ILanguage lang; private ILanguage lang;
public int Quality = 0; public int Quality = 0;
public JpegQualityDialog() { public JpegQualityDialog() {
// //
@ -39,10 +39,9 @@ namespace Greenshot {
// //
InitializeComponent(); InitializeComponent();
conf = AppConfig.GetInstance();
lang = Language.GetInstance(); lang = Language.GetInstance();
this.trackBarJpegQuality.Value = conf.Output_File_JpegQuality; this.trackBarJpegQuality.Value = conf.OutputFileJpegQuality;
this.textBoxJpegQuality.Text = conf.Output_File_JpegQuality.ToString(); this.textBoxJpegQuality.Text = conf.OutputFileJpegQuality.ToString();
UpdateUI(); UpdateUI();
} }
@ -50,9 +49,9 @@ namespace Greenshot {
void Button_okClick(object sender, System.EventArgs e) { void Button_okClick(object sender, System.EventArgs e) {
Quality = this.trackBarJpegQuality.Value; Quality = this.trackBarJpegQuality.Value;
if(this.checkbox_dontaskagain.Checked) { if(this.checkbox_dontaskagain.Checked) {
conf.Output_File_JpegQuality = Quality; conf.OutputFileJpegQuality = Quality;
conf.Output_File_PromptJpegQuality = false; conf.OutputFilePromptJpegQuality = false;
conf.Store(); IniConfig.Save();
} }
} }

View file

@ -30,30 +30,21 @@ namespace Greenshot.Forms {
/// Description of PrintOptionsDialog. /// Description of PrintOptionsDialog.
/// </summary> /// </summary>
public partial class PrintOptionsDialog : Form { public partial class PrintOptionsDialog : Form {
AppConfig conf; private CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
ILanguage lang; private ILanguage lang;
public bool AllowPrintCenter; public PrintOptionsDialog() {
public bool AllowPrintEnlarge;
public bool AllowPrintRotate;
public bool AllowPrintShrink;
public bool PrintDateTime;
public PrintOptionsDialog()
{
// //
// The InitializeComponent() call is required for Windows Forms designer support. // The InitializeComponent() call is required for Windows Forms designer support.
// //
InitializeComponent(); InitializeComponent();
conf = AppConfig.GetInstance();
lang = Language.GetInstance(); lang = Language.GetInstance();
this.AllowPrintCenter = this.checkboxAllowCenter.Checked = (bool)conf.Output_Print_Center; this.checkboxAllowCenter.Checked = conf.OutputPrintCenter;
this.AllowPrintEnlarge = this.checkboxAllowEnlarge.Checked = (bool)conf.Output_Print_AllowEnlarge; this.checkboxAllowEnlarge.Checked = conf.OutputPrintAllowEnlarge;
this.AllowPrintRotate = this.checkboxAllowRotate.Checked = (bool)conf.Output_Print_AllowRotate; this.checkboxAllowRotate.Checked = conf.OutputPrintAllowRotate;
this.AllowPrintShrink = this.checkboxAllowShrink.Checked = (bool)conf.Output_Print_AllowShrink; this.checkboxAllowShrink.Checked = conf.OutputPrintAllowShrink;
this.PrintDateTime = this.checkboxDateTime.Checked = (bool)conf.Output_Print_Timestamp; this.checkboxDateTime.Checked = conf.OutputPrintTimestamp;
this.checkbox_dontaskagain.Checked = false; this.checkbox_dontaskagain.Checked = false;
UpdateUI(); UpdateUI();
} }
@ -69,23 +60,15 @@ namespace Greenshot.Forms {
} }
void Button_okClick(object sender, EventArgs e) void Button_okClick(object sender, EventArgs e) {
{
this.AllowPrintCenter = this.checkboxAllowCenter.Checked;
this.AllowPrintEnlarge = this.checkboxAllowEnlarge.Checked;
this.AllowPrintRotate = this.checkboxAllowRotate.Checked;
this.AllowPrintShrink = this.checkboxAllowShrink.Checked;
this.PrintDateTime = this.checkboxDateTime.Checked;
// update config // update config
conf.Output_Print_Center = (bool?)this.AllowPrintCenter; conf.OutputPrintCenter = this.checkboxAllowCenter.Checked;
conf.Output_Print_AllowEnlarge = (bool?)this.AllowPrintEnlarge; conf.OutputPrintAllowEnlarge = this.checkboxAllowEnlarge.Checked;
conf.Output_Print_AllowRotate = (bool?)this.AllowPrintRotate; conf.OutputPrintAllowRotate = this.checkboxAllowRotate.Checked;
conf.Output_Print_AllowShrink = (bool?)this.AllowPrintShrink; conf.OutputPrintAllowShrink = this.checkboxAllowShrink.Checked;
conf.Output_Print_Timestamp = (bool?)this.PrintDateTime; conf.OutputPrintTimestamp = this.checkboxDateTime.Checked;
conf.Output_Print_PromptOptions = !this.checkbox_dontaskagain.Checked; conf.OutputPrintPromptOptions = !this.checkbox_dontaskagain.Checked;
conf.Store(); IniConfig.Save();
} }
} }
} }

View file

@ -28,6 +28,7 @@ using System.Windows.Forms;
using Greenshot.Capturing; using Greenshot.Capturing;
using Greenshot.Configuration; using Greenshot.Configuration;
using Greenshot.Core;
using Greenshot.Helpers; using Greenshot.Helpers;
using Greenshot.Plugin; using Greenshot.Plugin;
@ -42,6 +43,7 @@ namespace Greenshot.Forms {
private FilterOption[] filterOptions; private FilterOption[] filterOptions;
private DirectoryInfo eagerlyCreatedDirectory; private DirectoryInfo eagerlyCreatedDirectory;
private ICaptureDetails captureDetails = null; private ICaptureDetails captureDetails = null;
private CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
public SaveImageFileDialog() { public SaveImageFileDialog() {
init(); init();
@ -55,7 +57,7 @@ namespace Greenshot.Forms {
private void init() { private void init() {
saveFileDialog = new SaveFileDialog(); saveFileDialog = new SaveFileDialog();
applyFilterOptions(); applyFilterOptions();
saveFileDialog.InitialDirectory = Path.GetDirectoryName(AppConfig.GetInstance().Output_FileAs_Fullpath); saveFileDialog.InitialDirectory = Path.GetDirectoryName(conf.Output_FileAs_Fullpath);
// The following property fixes a problem that the directory where we save is locked (bug #2899790) // The following property fixes a problem that the directory where we save is locked (bug #2899790)
saveFileDialog.RestoreDirectory = true; saveFileDialog.RestoreDirectory = true;
@ -66,7 +68,6 @@ namespace Greenshot.Forms {
private void applyFilterOptions() { private void applyFilterOptions() {
prepareFilterOptions(); prepareFilterOptions();
AppConfig conf = AppConfig.GetInstance();
string fdf = ""; string fdf = "";
int preselect = 0; int preselect = 0;
for(int i=0; i<filterOptions.Length; i++){ for(int i=0; i<filterOptions.Length; i++){
@ -153,11 +154,9 @@ namespace Greenshot.Forms {
/// </summary> /// </summary>
/// <param name="sfd">a SaveFileDialog instance</param> /// <param name="sfd">a SaveFileDialog instance</param>
private void ApplySuggestedValues() { private void ApplySuggestedValues() {
AppConfig conf = AppConfig.GetInstance();
string rootDir = GetRootDirFromConfig(); string rootDir = GetRootDirFromConfig();
// build the full path and set dialog properties // build the full path and set dialog properties
string filenameFromPattern = FilenameHelper.GetFilenameWithoutExtensionFromPattern(conf.Output_File_FilenamePattern, captureDetails); string filenameFromPattern = FilenameHelper.GetFilenameWithoutExtensionFromPattern(conf.OutputFileFilenamePattern, captureDetails);
string fullpath = Path.Combine(rootDir, filenameFromPattern); string fullpath = Path.Combine(rootDir, filenameFromPattern);
string dir = CreateDirectoryIfNotExists(fullpath); string dir = CreateDirectoryIfNotExists(fullpath);
@ -204,7 +203,7 @@ namespace Greenshot.Forms {
} }
private string GetRootDirFromConfig() { private string GetRootDirFromConfig() {
string rootDir = AppConfig.GetInstance().Output_File_Path; string rootDir =conf.Output_File_Path;
// the idea was to let the user choose whether to suggest the dir // the idea was to let the user choose whether to suggest the dir
// configured in the settings dialog or just remember the latest path. // configured in the settings dialog or just remember the latest path.
// however, we'd need an extra option for this, making the settings dialog // however, we'd need an extra option for this, making the settings dialog

View file

@ -21,15 +21,16 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using Greenshot.Configuration; using Greenshot.Configuration;
using Greenshot.Core;
using Greenshot.Helpers; using Greenshot.Helpers;
using Greenshot.Plugin; using Greenshot.Plugin;
using Greenshot.Core;
namespace Greenshot { namespace Greenshot {
/// <summary> /// <summary>
@ -38,12 +39,11 @@ namespace Greenshot {
public partial class SettingsForm : Form { public partial class SettingsForm : Form {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(SettingsForm)); private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(SettingsForm));
ILanguage lang; ILanguage lang;
AppConfig conf; private CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
private ToolTip toolTip; private ToolTip toolTip;
public SettingsForm() { public SettingsForm() {
InitializeComponent(); InitializeComponent();
conf = AppConfig.GetInstance();
lang = Language.GetInstance(); lang = Language.GetInstance();
// Force loading of languages // Force loading of languages
lang.Load(); lang.Load();
@ -169,35 +169,35 @@ namespace Greenshot {
private void DisplaySettings() { private void DisplaySettings() {
combobox_language.SelectedValue = lang.CurrentLanguage; combobox_language.SelectedValue = lang.CurrentLanguage;
checkbox_registerhotkeys.Checked = (bool)conf.General_RegisterHotkeys; checkbox_registerhotkeys.Checked = conf.RegisterHotkeys;
textbox_storagelocation.Text = conf.Output_File_Path; textbox_storagelocation.Text = conf.Output_File_Path;
textbox_screenshotname.Text = conf.Output_File_FilenamePattern; textbox_screenshotname.Text = conf.OutputFileFilenamePattern;
combobox_primaryimageformat.Text = conf.Output_File_Format.ToString(); combobox_primaryimageformat.Text = conf.OutputFileFormat.ToString();
checkbox_copypathtoclipboard.Checked = (bool)conf.Output_File_CopyPathToClipboard; checkbox_copypathtoclipboard.Checked = conf.OutputFileCopyPathToClipboard;
trackBarJpegQuality.Value = conf.Output_File_JpegQuality; trackBarJpegQuality.Value = conf.OutputFileJpegQuality;
textBoxJpegQuality.Text = conf.Output_File_JpegQuality+"%"; textBoxJpegQuality.Text = conf.OutputFileJpegQuality+"%";
checkbox_alwaysshowjpegqualitydialog.Checked = (bool)conf.Output_File_PromptJpegQuality; checkbox_alwaysshowjpegqualitydialog.Checked = conf.OutputFilePromptJpegQuality;
checkbox_showflashlight.Checked = (bool)conf.Ui_Effects_Flashlight; checkbox_showflashlight.Checked = conf.ShowFlash;
checkbox_playsound.Checked = (bool)conf.Ui_Effects_CameraSound; checkbox_playsound.Checked = conf.PlayCameraSound;
checkbox_clipboard.Checked = (conf.Output_Destinations&ScreenshotDestinations.Clipboard) == ScreenshotDestinations.Clipboard; checkbox_clipboard.Checked = conf.OutputDestinations.Contains(Destination.Clipboard);
checkbox_file.Checked = (conf.Output_Destinations&ScreenshotDestinations.FileDefault) == ScreenshotDestinations.FileDefault; checkbox_file.Checked = conf.OutputDestinations.Contains(Destination.FileDefault);
checkbox_fileas.Checked = (conf.Output_Destinations&ScreenshotDestinations.FileWithDialog) == ScreenshotDestinations.FileWithDialog; checkbox_fileas.Checked = conf.OutputDestinations.Contains(Destination.FileWithDialog);
checkbox_printer.Checked = (conf.Output_Destinations&ScreenshotDestinations.Printer) == ScreenshotDestinations.Printer; checkbox_printer.Checked = conf.OutputDestinations.Contains(Destination.Printer);
checkbox_editor.Checked = (conf.Output_Destinations&ScreenshotDestinations.Editor) == ScreenshotDestinations.Editor; checkbox_editor.Checked = conf.OutputDestinations.Contains(Destination.Editor);
checkbox_email.Checked = (conf.Output_Destinations&ScreenshotDestinations.EMail) == ScreenshotDestinations.EMail; checkbox_email.Checked = conf.OutputDestinations.Contains(Destination.EMail);
checkboxAllowCenter.Checked = (bool)conf.Output_Print_Center; checkboxAllowCenter.Checked = conf.OutputPrintCenter;
checkboxAllowEnlarge.Checked = (bool)conf.Output_Print_AllowEnlarge; checkboxAllowEnlarge.Checked = conf.OutputPrintAllowEnlarge;
checkboxAllowRotate.Checked = (bool)conf.Output_Print_AllowRotate; checkboxAllowRotate.Checked = conf.OutputPrintAllowRotate;
checkboxAllowShrink.Checked = (bool)conf.Output_Print_AllowShrink; checkboxAllowShrink.Checked = conf.OutputPrintAllowShrink;
checkboxTimestamp.Checked = (bool)conf.Output_Print_Timestamp; checkboxTimestamp.Checked = conf.OutputPrintTimestamp;
checkbox_alwaysshowprintoptionsdialog.Checked = (bool)conf.Output_Print_PromptOptions; checkbox_alwaysshowprintoptionsdialog.Checked = conf.OutputPrintPromptOptions;
checkbox_capture_mousepointer.Checked = (bool)conf.Capture_Mousepointer; checkbox_capture_mousepointer.Checked = conf.CaptureMousepointer;
checkbox_capture_windows_interactive.Checked = (bool)conf.Capture_Windows_Interactive; checkbox_capture_windows_interactive.Checked = conf.CaptureWindowsInteractive;
checkbox_capture_complete_windows.Checked = (bool)conf.Capture_Complete_Window; checkbox_capture_complete_windows.Checked = conf.CaptureCompleteWindow;
checkbox_capture_window_content.Checked = (bool)conf.Capture_Window_Content; checkbox_capture_window_content.Checked = conf.CaptureWindowContent;
numericUpDownWaitTime.Value = conf.Capture_Wait_Time; numericUpDownWaitTime.Value = conf.CaptureDelay;
// If the run for all is set we disable and set the checkbox // If the run for all is set we disable and set the checkbox
if (StartupHelper.checkRunAll()) { if (StartupHelper.checkRunAll()) {
@ -211,27 +211,30 @@ namespace Greenshot {
} }
private void SaveSettings() { private void SaveSettings() {
conf.Ui_Language = combobox_language.SelectedValue.ToString(); conf.Language = combobox_language.SelectedValue.ToString();
// Make sure the current language is reflected in the Main-context menu // Make sure the current language is reflected in the Main-context menu
//MainForm.instance.UpdateUI(); // TODO //MainForm.instance.UpdateUI(); // TODO
conf.General_RegisterHotkeys = (bool?)checkbox_registerhotkeys.Checked; conf.RegisterHotkeys = checkbox_registerhotkeys.Checked;
conf.Output_File_Path = textbox_storagelocation.Text; conf.Output_File_Path = textbox_storagelocation.Text;
conf.Output_File_FilenamePattern = textbox_screenshotname.Text; conf.OutputFileFilenamePattern = textbox_screenshotname.Text;
conf.Output_File_Format = combobox_primaryimageformat.Text; conf.OutputFileFormat = (OutputFormat)Enum.Parse(typeof(OutputFormat), combobox_primaryimageformat.Text);
conf.Output_File_CopyPathToClipboard = (bool?)checkbox_copypathtoclipboard.Checked; conf.OutputFileCopyPathToClipboard = checkbox_copypathtoclipboard.Checked;
conf.Output_File_JpegQuality = trackBarJpegQuality.Value; conf.OutputFileJpegQuality = trackBarJpegQuality.Value;
conf.Output_File_PromptJpegQuality = (bool?)checkbox_alwaysshowjpegqualitydialog.Checked; conf.OutputFilePromptJpegQuality = checkbox_alwaysshowjpegqualitydialog.Checked;
conf.Ui_Effects_Flashlight = (bool?)checkbox_showflashlight.Checked; conf.ShowFlash = checkbox_showflashlight.Checked;
conf.Ui_Effects_CameraSound = (bool?)checkbox_playsound.Checked; conf.PlayCameraSound = checkbox_playsound.Checked;
ScreenshotDestinations dest = 0;
if(checkbox_clipboard.Checked) dest |= ScreenshotDestinations.Clipboard; List<Destination> destinations = new List<Destination>();
if(checkbox_file.Checked) dest |= ScreenshotDestinations.FileDefault; if(checkbox_clipboard.Checked) destinations.Add(Destination.Clipboard);
if(checkbox_fileas.Checked) dest |= ScreenshotDestinations.FileWithDialog; if(checkbox_file.Checked) destinations.Add(Destination.FileDefault);
if(checkbox_printer.Checked) dest |= ScreenshotDestinations.Printer; if(checkbox_fileas.Checked) destinations.Add(Destination.FileWithDialog);
if(checkbox_editor.Checked) dest |= ScreenshotDestinations.Editor; if(checkbox_printer.Checked) destinations.Add(Destination.Printer);
if(checkbox_email.Checked) dest |= ScreenshotDestinations.EMail; if(checkbox_editor.Checked) destinations.Add(Destination.Editor);
if(checkbox_email.Checked) destinations.Add(Destination.EMail);
conf.OutputDestinations = destinations;
if (!MapiMailMessage.HasMAPI()) { if (!MapiMailMessage.HasMAPI()) {
// Disable MAPI functionality as it's not available // Disable MAPI functionality as it's not available
checkbox_email.Enabled = false; checkbox_email.Enabled = false;
@ -241,21 +244,20 @@ namespace Greenshot {
checkbox_email.Enabled = true; checkbox_email.Enabled = true;
} }
conf.Output_Destinations = dest; conf.OutputPrintCenter = checkboxAllowCenter.Checked;
conf.Output_Print_Center = (bool?)checkboxAllowCenter.Checked; conf.OutputPrintAllowEnlarge = checkboxAllowEnlarge.Checked;
conf.Output_Print_AllowEnlarge = (bool?)checkboxAllowEnlarge.Checked; conf.OutputPrintAllowRotate = checkboxAllowRotate.Checked;
conf.Output_Print_AllowRotate = (bool?)checkboxAllowRotate.Checked; conf.OutputPrintAllowShrink = checkboxAllowShrink.Checked;
conf.Output_Print_AllowShrink = (bool?)checkboxAllowShrink.Checked; conf.OutputPrintTimestamp = checkboxTimestamp.Checked;
conf.Output_Print_Timestamp = (bool?)checkboxTimestamp.Checked; conf.OutputPrintPromptOptions = checkbox_alwaysshowprintoptionsdialog.Checked;
conf.Output_Print_PromptOptions = (bool?)checkbox_alwaysshowprintoptionsdialog.Checked; conf.CaptureMousepointer = checkbox_capture_mousepointer.Checked;
conf.Capture_Mousepointer = (bool?)checkbox_capture_mousepointer.Checked; conf.CaptureWindowsInteractive = checkbox_capture_windows_interactive.Checked;
conf.Capture_Windows_Interactive = (bool?)checkbox_capture_windows_interactive.Checked; conf.CaptureWindowContent = checkbox_capture_window_content.Checked;
conf.Capture_Window_Content = (bool?)checkbox_capture_window_content.Checked;
conf.Capture_Complete_Window = (bool?)checkbox_capture_complete_windows.Checked; conf.CaptureCompleteWindow = checkbox_capture_complete_windows.Checked;
conf.Capture_Wait_Time = (int)numericUpDownWaitTime.Value; conf.CaptureDelay = (int)numericUpDownWaitTime.Value;
conf.Store(); IniConfig.Save();
// Check if the Run for all is set // Check if the Run for all is set
if(!StartupHelper.checkRunAll()) { if(!StartupHelper.checkRunAll()) {

View file

@ -41,8 +41,7 @@ namespace Greenshot.Helpers {
private Image image; private Image image;
private PrintDocument printDocument = new PrintDocument(); private PrintDocument printDocument = new PrintDocument();
private PrintDialog printDialog = new PrintDialog(); private PrintDialog printDialog = new PrintDialog();
private AppConfig conf = AppConfig.GetInstance(); private CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
private PrintOptionsDialog printOptionsDialog = null;
public PrintHelper(Image image, ICaptureDetails captureDetails) { public PrintHelper(Image image, ICaptureDetails captureDetails) {
this.image = image; this.image = image;
@ -77,12 +76,10 @@ namespace Greenshot.Helpers {
if(image != null) image.Dispose(); if(image != null) image.Dispose();
if(printDocument != null) printDocument.Dispose(); if(printDocument != null) printDocument.Dispose();
if(printDialog != null) printDialog.Dispose(); if(printDialog != null) printDialog.Dispose();
if(printOptionsDialog != null) printOptionsDialog.Dispose();
} }
image = null; image = null;
printDocument = null; printDocument = null;
printDialog = null; printDialog = null;
printOptionsDialog = null;
} }
/// <summary> /// <summary>
@ -94,8 +91,8 @@ namespace Greenshot.Helpers {
PrinterSettings ret = null; PrinterSettings ret = null;
if (printDialog.ShowDialog() == DialogResult.OK) { if (printDialog.ShowDialog() == DialogResult.OK) {
bool cancelled = false; bool cancelled = false;
printOptionsDialog = new PrintOptionsDialog(); if (conf.OutputPrintPromptOptions == true) {
if (conf.Output_Print_PromptOptions == true) { PrintOptionsDialog printOptionsDialog = new PrintOptionsDialog();
DialogResult result = printOptionsDialog.ShowDialog(); DialogResult result = printOptionsDialog.ShowDialog();
if(result != DialogResult.OK) { if(result != DialogResult.OK) {
cancelled = true; cancelled = true;
@ -119,15 +116,13 @@ namespace Greenshot.Helpers {
} }
void DrawImageForPrint(object sender, PrintPageEventArgs e) { void DrawImageForPrint(object sender, PrintPageEventArgs e) {
PrintOptionsDialog pod = printOptionsDialog; ContentAlignment alignment = conf.OutputPrintCenter ? ContentAlignment.MiddleCenter : ContentAlignment.TopLeft;
ContentAlignment alignment = pod.AllowPrintCenter ? ContentAlignment.MiddleCenter : ContentAlignment.TopLeft;
RectangleF pageRect = e.PageSettings.PrintableArea; RectangleF pageRect = e.PageSettings.PrintableArea;
GraphicsUnit gu = GraphicsUnit.Pixel; GraphicsUnit gu = GraphicsUnit.Pixel;
RectangleF imageRect = image.GetBounds(ref gu); RectangleF imageRect = image.GetBounds(ref gu);
// rotate the image if it fits the page better // rotate the image if it fits the page better
if(pod.AllowPrintRotate) { if(conf.OutputPrintAllowRotate) {
if((pageRect.Width > pageRect.Height && imageRect.Width < imageRect.Height) || if((pageRect.Width > pageRect.Height && imageRect.Width < imageRect.Height) ||
(pageRect.Width < pageRect.Height && imageRect.Width > imageRect.Height)) { (pageRect.Width < pageRect.Height && imageRect.Width > imageRect.Height)) {
image.RotateFlip(RotateFlipType.Rotate90FlipNone); image.RotateFlip(RotateFlipType.Rotate90FlipNone);
@ -137,10 +132,10 @@ namespace Greenshot.Helpers {
} }
RectangleF printRect = new RectangleF(0,0,imageRect.Width, imageRect.Height);; RectangleF printRect = new RectangleF(0,0,imageRect.Width, imageRect.Height);;
// scale the image to fit the page better // scale the image to fit the page better
if(pod.AllowPrintEnlarge || pod.AllowPrintShrink) { if(conf.OutputPrintAllowEnlarge || conf.OutputPrintAllowShrink) {
SizeF resizedRect = ScaleHelper.GetScaledSize(imageRect.Size,pageRect.Size,false); SizeF resizedRect = ScaleHelper.GetScaledSize(imageRect.Size,pageRect.Size,false);
if((pod.AllowPrintShrink && resizedRect.Width < printRect.Width) || if((conf.OutputPrintAllowShrink && resizedRect.Width < printRect.Width) ||
pod.AllowPrintEnlarge && resizedRect.Width > printRect.Width) { conf.OutputPrintAllowEnlarge && resizedRect.Width > printRect.Width) {
printRect.Size = resizedRect; printRect.Size = resizedRect;
} }
@ -149,7 +144,7 @@ namespace Greenshot.Helpers {
// prepare timestamp // prepare timestamp
float dateStringWidth = 0; float dateStringWidth = 0;
float dateStringHeight = 0; float dateStringHeight = 0;
if (conf.Output_Print_Timestamp == true) { if (conf.OutputPrintTimestamp == true) {
Font f = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular); Font f = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular);
string dateString = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(); string dateString = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();
dateStringWidth = e.Graphics.MeasureString(dateString, f).Width; dateStringWidth = e.Graphics.MeasureString(dateString, f).Width;