More fixed static usages.

This commit is contained in:
Robin 2019-01-04 01:57:11 +01:00
commit f802de6dc9
8 changed files with 49 additions and 49 deletions

View file

@ -39,14 +39,18 @@ namespace Greenshot.Addons.Controls
/// </summary> /// </summary>
public class ContextMenuToolStripProfessionalRenderer : ToolStripProfessionalRenderer public class ContextMenuToolStripProfessionalRenderer : ToolStripProfessionalRenderer
{ {
// TODO: Solve, was static reference! private readonly ICoreConfiguration _coreConfiguration = new CoreConfigurationImpl();
private static readonly ICoreConfiguration CoreConfig = new CoreConfigurationImpl();
public ContextMenuToolStripProfessionalRenderer(ICoreConfiguration coreConfiguration)
{
_coreConfiguration = coreConfiguration;
}
private Image _scaledCheckbox; private Image _scaledCheckbox;
private bool _newImage; private bool _newImage;
protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e) protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e)
{ {
if (_scaledCheckbox == null || (NativeSize)_scaledCheckbox.Size != CoreConfig.IconSize) if (_scaledCheckbox == null || (NativeSize)_scaledCheckbox.Size != _coreConfiguration.IconSize)
{ {
if (_newImage) if (_newImage)
{ {

View file

@ -43,23 +43,18 @@ namespace Greenshot.Addons.Controls
public class SaveImageFileDialog : IDisposable public class SaveImageFileDialog : IDisposable
{ {
private static readonly LogSource Log = new LogSource(); private static readonly LogSource Log = new LogSource();
// TODO: Solve, was static reference! private readonly ICoreConfiguration _coreConfiguration;
private static readonly ICoreConfiguration CoreConfiguration = new CoreConfigurationImpl();
private readonly ICaptureDetails _captureDetails; private readonly ICaptureDetails _captureDetails;
private DirectoryInfo _eagerlyCreatedDirectory; private DirectoryInfo _eagerlyCreatedDirectory;
private FilterOption[] _filterOptions; private FilterOption[] _filterOptions;
protected SaveFileDialog SaveFileDialog; protected SaveFileDialog SaveFileDialog;
public SaveImageFileDialog() public SaveImageFileDialog(ICoreConfiguration coreConfiguration, ICaptureDetails captureDetails = null)
{ {
Init(); _coreConfiguration = coreConfiguration;
} _captureDetails = captureDetails;
Init();
public SaveImageFileDialog(ICaptureDetails captureDetails) }
{
_captureDetails = captureDetails;
Init();
}
/// <summary> /// <summary>
/// filename exactly as typed in the filename field /// filename exactly as typed in the filename field
@ -146,21 +141,21 @@ namespace Greenshot.Addons.Controls
string initialDirectory = null; string initialDirectory = null;
try try
{ {
CoreConfiguration.ValidateAndCorrect(); _coreConfiguration.ValidateAndCorrect();
initialDirectory = Path.GetDirectoryName(CoreConfiguration.OutputFileAsFullpath); initialDirectory = Path.GetDirectoryName(_coreConfiguration.OutputFileAsFullpath);
} }
catch catch
{ {
Log.Warn().WriteLine("OutputFileAsFullpath was set to {0}, ignoring due to problem in path.", CoreConfiguration.OutputFileAsFullpath); Log.Warn().WriteLine("OutputFileAsFullpath was set to {0}, ignoring due to problem in path.", _coreConfiguration.OutputFileAsFullpath);
} }
if (!string.IsNullOrEmpty(initialDirectory) && Directory.Exists(initialDirectory)) if (!string.IsNullOrEmpty(initialDirectory) && Directory.Exists(initialDirectory))
{ {
SaveFileDialog.InitialDirectory = initialDirectory; SaveFileDialog.InitialDirectory = initialDirectory;
} }
else if (Directory.Exists(CoreConfiguration.OutputFilePath)) else if (Directory.Exists(_coreConfiguration.OutputFilePath))
{ {
SaveFileDialog.InitialDirectory = CoreConfiguration.OutputFilePath; SaveFileDialog.InitialDirectory = _coreConfiguration.OutputFilePath;
} }
// 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;
@ -175,7 +170,7 @@ namespace Greenshot.Addons.Controls
PrepareFilterOptions(); PrepareFilterOptions();
var fdf = ""; var fdf = "";
var preselect = 0; var preselect = 0;
var outputFileFormatAsString = Enum.GetName(typeof(OutputFormats), CoreConfiguration.OutputFileFormat); var outputFileFormatAsString = Enum.GetName(typeof(OutputFormats), _coreConfiguration.OutputFileFormat);
for (var i = 0; i < _filterOptions.Length; i++) for (var i = 0; i < _filterOptions.Length; i++)
{ {
var fo = _filterOptions[i]; var fo = _filterOptions[i];
@ -224,7 +219,7 @@ namespace Greenshot.Addons.Controls
private void ApplySuggestedValues() private void ApplySuggestedValues()
{ {
// build the full path and set dialog properties // build the full path and set dialog properties
FileName = FilenameHelper.GetFilenameWithoutExtensionFromPattern(CoreConfiguration.OutputFileFilenamePattern, _captureDetails); FileName = FilenameHelper.GetFilenameWithoutExtensionFromPattern(_coreConfiguration.OutputFileFilenamePattern, _captureDetails);
} }
private void CleanUp() private void CleanUp()

View file

@ -48,17 +48,14 @@ namespace Greenshot.Addons.Controls
/// </summary> /// </summary>
public sealed class ThumbnailForm : FormWithoutActivation public sealed class ThumbnailForm : FormWithoutActivation
{ {
// TODO: Solve, was static reference!
private static readonly ICoreConfiguration coreConfiguration = new CoreConfigurationImpl();
private IntPtr _thumbnailHandle = IntPtr.Zero; private IntPtr _thumbnailHandle = IntPtr.Zero;
/// <summary> /// <summary>
/// Constructor for the Thumbnail form /// Constructor for the Thumbnail form
/// </summary> /// </summary>
public ThumbnailForm() public ThumbnailForm(ICoreConfiguration coreConfiguration)
{ {
ShowInTaskbar = false; ShowInTaskbar = false;
FormBorderStyle = FormBorderStyle.None; FormBorderStyle = FormBorderStyle.None;
TopMost = false; TopMost = false;
Enabled = false; Enabled = false;

View file

@ -128,7 +128,7 @@ namespace Greenshot.Addons.Core
public static string SaveWithDialog(ISurface surface, ICaptureDetails captureDetails) public static string SaveWithDialog(ISurface surface, ICaptureDetails captureDetails)
{ {
string returnValue = null; string returnValue = null;
using (var saveImageFileDialog = new SaveImageFileDialog(captureDetails)) using (var saveImageFileDialog = new SaveImageFileDialog(CoreConfig, captureDetails))
{ {
var dialogResult = saveImageFileDialog.ShowDialog(); var dialogResult = saveImageFileDialog.ShowDialog();
if (dialogResult.Equals(DialogResult.OK)) if (dialogResult.Equals(DialogResult.OK))

View file

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using Greenshot.Addon.InternetExplorer; using Greenshot.Addon.InternetExplorer;
using Greenshot.Addons.Core;
using Greenshot.Addons.Interfaces; using Greenshot.Addons.Interfaces;
namespace Greenshot.Components namespace Greenshot.Components
@ -10,19 +11,22 @@ namespace Greenshot.Components
public class CaptureSupportInfo public class CaptureSupportInfo
{ {
/// <summary> /// <summary>
/// Constructor /// Constructor for DI
/// </summary> /// </summary>
/// <param name="internetExplorerCaptureHelper">InternetExplorerCaptureHelper</param> /// <param name="internetExplorerCaptureHelper">InternetExplorerCaptureHelper</param>
/// <param name="formEnhancers">IEnumerable with IFormEnhancer</param> /// <param name="formEnhancers">IEnumerable with IFormEnhancer</param>
public CaptureSupportInfo( public CaptureSupportInfo(
ICoreConfiguration coreConfiguration,
InternetExplorerCaptureHelper internetExplorerCaptureHelper, InternetExplorerCaptureHelper internetExplorerCaptureHelper,
IEnumerable<IFormEnhancer> formEnhancers = null IEnumerable<IFormEnhancer> formEnhancers = null
) )
{ {
CoreConfiguration = coreConfiguration;
InternetExplorerCaptureHelper = internetExplorerCaptureHelper; InternetExplorerCaptureHelper = internetExplorerCaptureHelper;
FormEnhancers = formEnhancers; FormEnhancers = formEnhancers;
} }
public ICoreConfiguration CoreConfiguration { get; }
public InternetExplorerCaptureHelper InternetExplorerCaptureHelper { get; } public InternetExplorerCaptureHelper InternetExplorerCaptureHelper { get; }
public IEnumerable<IFormEnhancer> FormEnhancers { get; } public IEnumerable<IFormEnhancer> FormEnhancers { get; }

View file

@ -105,7 +105,7 @@ namespace Greenshot.Forms {
this.contextMenu.Name = "contextMenu"; this.contextMenu.Name = "contextMenu";
this.contextMenu.Closing += new System.Windows.Forms.ToolStripDropDownClosingEventHandler(this.ContextMenuClosing); this.contextMenu.Closing += new System.Windows.Forms.ToolStripDropDownClosingEventHandler(this.ContextMenuClosing);
this.contextMenu.Opening += new System.ComponentModel.CancelEventHandler(this.ContextMenuOpening); this.contextMenu.Opening += new System.ComponentModel.CancelEventHandler(this.ContextMenuOpening);
this.contextMenu.Renderer = new ContextMenuToolStripProfessionalRenderer(); this.contextMenu.Renderer = new ContextMenuToolStripProfessionalRenderer(_coreConfiguration);
// //
// contextmenu_capturearea // contextmenu_capturearea
// //

View file

@ -676,7 +676,7 @@ namespace Greenshot.Forms
var window = captureWindowItem.Tag as IInteropWindow; var window = captureWindowItem.Tag as IInteropWindow;
if (_thumbnailForm == null) if (_thumbnailForm == null)
{ {
_thumbnailForm = new ThumbnailForm(); _thumbnailForm = new ThumbnailForm(_coreConfiguration);
} }
_thumbnailForm.ShowThumbnail(window, captureWindowItem.GetCurrentParent().TopLevelControl); _thumbnailForm.ShowThumbnail(window, captureWindowItem.GetCurrentParent().TopLevelControl);
} }

View file

@ -61,8 +61,7 @@ namespace Greenshot.Helpers
public class CaptureHelper : IDisposable public class CaptureHelper : IDisposable
{ {
private static readonly LogSource Log = new LogSource(); private static readonly LogSource Log = new LogSource();
// TODO: Solve, was static reference! private readonly ICoreConfiguration _coreConfiguration;
private static readonly ICoreConfiguration CoreConfig = new CoreConfigurationImpl();
private readonly bool _captureMouseCursor; private readonly bool _captureMouseCursor;
private ICapture _capture; private ICapture _capture;
private readonly CaptureSupportInfo _captureSupportInfo; private readonly CaptureSupportInfo _captureSupportInfo;
@ -78,6 +77,7 @@ namespace Greenshot.Helpers
public CaptureHelper(CaptureSupportInfo captureSupportInfo, CaptureMode captureMode) public CaptureHelper(CaptureSupportInfo captureSupportInfo, CaptureMode captureMode)
{ {
_captureSupportInfo = captureSupportInfo; _captureSupportInfo = captureSupportInfo;
_coreConfiguration = captureSupportInfo.CoreConfiguration;
_captureMode = captureMode; _captureMode = captureMode;
_capture = new Capture(); _capture = new Capture();
_destinationHolder = DestinationHolder.Instance; _destinationHolder = DestinationHolder.Instance;
@ -134,7 +134,7 @@ namespace Greenshot.Helpers
SelectedCaptureWindow = null; SelectedCaptureWindow = null;
_capture = null; _capture = null;
// Empty working set after capturing // Empty working set after capturing
if (CoreConfig.MinimizeWorkingSetSize) if (_coreConfiguration.MinimizeWorkingSetSize)
{ {
PsApi.EmptyWorkingSet(); PsApi.EmptyWorkingSet();
} }
@ -248,7 +248,7 @@ namespace Greenshot.Helpers
private void DoCaptureFeedback() private void DoCaptureFeedback()
{ {
if (CoreConfig.PlayCameraSound) if (_coreConfiguration.PlayCameraSound)
{ {
SoundHelper.Play(); SoundHelper.Play();
} }
@ -282,7 +282,7 @@ namespace Greenshot.Helpers
{ {
// This fixes a problem when a balloon is still visible and a capture needs to be taken // This fixes a problem when a balloon is still visible and a capture needs to be taken
// forcefully removes the balloon! // forcefully removes the balloon!
if (!CoreConfig.HideTrayicon) if (!_coreConfiguration.HideTrayicon)
{ {
MainForm.Instance.NotifyIcon.Visible = false; MainForm.Instance.NotifyIcon.Visible = false;
MainForm.Instance.NotifyIcon.Visible = true; MainForm.Instance.NotifyIcon.Visible = true;
@ -313,20 +313,20 @@ namespace Greenshot.Helpers
} }
// Delay for the Context menu // Delay for the Context menu
if (CoreConfig.CaptureDelay > 0) if (_coreConfiguration.CaptureDelay > 0)
{ {
Thread.Sleep(CoreConfig.CaptureDelay); Thread.Sleep(_coreConfiguration.CaptureDelay);
} }
else else
{ {
CoreConfig.CaptureDelay = 0; _coreConfiguration.CaptureDelay = 0;
} }
// Capture Mousecursor if we are not loading from file or clipboard, only show when needed // Capture Mousecursor if we are not loading from file or clipboard, only show when needed
if (_captureMode != CaptureMode.File && _captureMode != CaptureMode.Clipboard) if (_captureMode != CaptureMode.File && _captureMode != CaptureMode.Clipboard)
{ {
_capture = WindowCapture.CaptureCursor(_capture); _capture = WindowCapture.CaptureCursor(_capture);
_capture.CursorVisible = _captureMouseCursor && CoreConfig.CaptureMousepointer; _capture.CursorVisible = _captureMouseCursor && _coreConfiguration.CaptureMousepointer;
} }
switch (_captureMode) switch (_captureMode)
@ -382,9 +382,9 @@ namespace Greenshot.Helpers
} }
break; break;
case ScreenCaptureMode.Fixed: case ScreenCaptureMode.Fixed:
if (CoreConfig.ScreenToCapture > 0 && CoreConfig.ScreenToCapture <= Screen.AllScreens.Length) if (_coreConfiguration.ScreenToCapture > 0 && _coreConfiguration.ScreenToCapture <= Screen.AllScreens.Length)
{ {
_capture = WindowCapture.CaptureRectangle(_capture, Screen.AllScreens[CoreConfig.ScreenToCapture].Bounds); _capture = WindowCapture.CaptureRectangle(_capture, Screen.AllScreens[_coreConfiguration.ScreenToCapture].Bounds);
captureTaken = true; captureTaken = true;
} }
break; break;
@ -497,9 +497,9 @@ namespace Greenshot.Helpers
} }
break; break;
case CaptureMode.LastRegion: case CaptureMode.LastRegion:
if (!CoreConfig.LastCapturedRegion.IsEmpty) if (!_coreConfiguration.LastCapturedRegion.IsEmpty)
{ {
_capture = WindowCapture.CaptureRectangle(_capture, CoreConfig.LastCapturedRegion); _capture = WindowCapture.CaptureRectangle(_capture, _coreConfiguration.LastCapturedRegion);
// Move cursor, fixing bug #3569703 // Move cursor, fixing bug #3569703
_capture.MoveMouseLocation(_capture.ScreenBounds.Location.X - _capture.Location.X, _capture.ScreenBounds.Location.Y - _capture.Location.Y); _capture.MoveMouseLocation(_capture.ScreenBounds.Location.X - _capture.Location.X, _capture.ScreenBounds.Location.Y - _capture.Location.Y);
@ -559,7 +559,7 @@ namespace Greenshot.Helpers
private void AddConfiguredDestination() private void AddConfiguredDestination()
{ {
foreach (var destinationDesignation in CoreConfig.OutputDestinations) foreach (var destinationDesignation in _coreConfiguration.OutputDestinations)
{ {
var destination = _destinationHolder.SortedActiveDestinations.Find(destinationDesignation); var destination = _destinationHolder.SortedActiveDestinations.Find(destinationDesignation);
if (destination != null) if (destination != null)
@ -714,8 +714,8 @@ namespace Greenshot.Helpers
return false; return false;
} }
// Fix for Bug #3430560 // Fix for Bug #3430560
CoreConfig.LastCapturedRegion = SelectedCaptureWindow.GetInfo().Bounds; _coreConfiguration.LastCapturedRegion = SelectedCaptureWindow.GetInfo().Bounds;
var returnValue = CaptureWindow(SelectedCaptureWindow, _capture, CoreConfig.WindowCaptureMode) != null; var returnValue = CaptureWindow(SelectedCaptureWindow, _capture, _coreConfiguration.WindowCaptureMode) != null;
return returnValue; return returnValue;
} }
@ -802,7 +802,7 @@ namespace Greenshot.Helpers
// 3) Otherwise use GDI (Screen might be also okay but might lose content) // 3) Otherwise use GDI (Screen might be also okay but might lose content)
if (isAutoMode) if (isAutoMode)
{ {
if (CoreConfig.IECapture && _captureSupportInfo.InternetExplorerCaptureHelper.IsIeWindow(windowToCapture)) if (_coreConfiguration.IECapture && _captureSupportInfo.InternetExplorerCaptureHelper.IsIeWindow(windowToCapture))
{ {
try try
{ {
@ -1032,7 +1032,7 @@ namespace Greenshot.Helpers
// } // }
//} //}
using (var captureForm = new CaptureForm(CoreConfig, _capture, _windows, _captureSupportInfo.FormEnhancers)) using (var captureForm = new CaptureForm(_coreConfiguration, _capture, _windows, _captureSupportInfo.FormEnhancers))
{ {
// Make sure the form is hidden after showing, even if an exception occurs, so all errors will be shown // Make sure the form is hidden after showing, even if an exception occurs, so all errors will be shown
DialogResult result; DialogResult result;
@ -1086,7 +1086,7 @@ namespace Greenshot.Helpers
// save for re-capturing later and show recapture context menu option // save for re-capturing later and show recapture context menu option
// Important here is that the location needs to be offsetted back to screen coordinates! // Important here is that the location needs to be offsetted back to screen coordinates!
var tmpRectangle = _captureRect.Offset(_capture.ScreenBounds.Location.X, _capture.ScreenBounds.Location.Y); var tmpRectangle = _captureRect.Offset(_capture.ScreenBounds.Location.X, _capture.ScreenBounds.Location.Y);
CoreConfig.LastCapturedRegion = tmpRectangle; _coreConfiguration.LastCapturedRegion = tmpRectangle;
HandleCapture(); HandleCapture();
} }
} }