mirror of
https://github.com/greenshot/greenshot
synced 2025-08-22 22:34:27 -07:00
More fixed static usages.
This commit is contained in:
parent
505e4d7be5
commit
f802de6dc9
8 changed files with 49 additions and 49 deletions
|
@ -39,14 +39,18 @@ namespace Greenshot.Addons.Controls
|
|||
/// </summary>
|
||||
public class ContextMenuToolStripProfessionalRenderer : ToolStripProfessionalRenderer
|
||||
{
|
||||
// TODO: Solve, was static reference!
|
||||
private static readonly ICoreConfiguration CoreConfig = new CoreConfigurationImpl();
|
||||
private readonly ICoreConfiguration _coreConfiguration = new CoreConfigurationImpl();
|
||||
|
||||
public ContextMenuToolStripProfessionalRenderer(ICoreConfiguration coreConfiguration)
|
||||
{
|
||||
_coreConfiguration = coreConfiguration;
|
||||
}
|
||||
|
||||
private Image _scaledCheckbox;
|
||||
private bool _newImage;
|
||||
protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e)
|
||||
{
|
||||
if (_scaledCheckbox == null || (NativeSize)_scaledCheckbox.Size != CoreConfig.IconSize)
|
||||
if (_scaledCheckbox == null || (NativeSize)_scaledCheckbox.Size != _coreConfiguration.IconSize)
|
||||
{
|
||||
if (_newImage)
|
||||
{
|
||||
|
|
|
@ -43,20 +43,15 @@ namespace Greenshot.Addons.Controls
|
|||
public class SaveImageFileDialog : IDisposable
|
||||
{
|
||||
private static readonly LogSource Log = new LogSource();
|
||||
// TODO: Solve, was static reference!
|
||||
private static readonly ICoreConfiguration CoreConfiguration = new CoreConfigurationImpl();
|
||||
private readonly ICoreConfiguration _coreConfiguration;
|
||||
private readonly ICaptureDetails _captureDetails;
|
||||
private DirectoryInfo _eagerlyCreatedDirectory;
|
||||
private FilterOption[] _filterOptions;
|
||||
protected SaveFileDialog SaveFileDialog;
|
||||
|
||||
public SaveImageFileDialog()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
public SaveImageFileDialog(ICaptureDetails captureDetails)
|
||||
public SaveImageFileDialog(ICoreConfiguration coreConfiguration, ICaptureDetails captureDetails = null)
|
||||
{
|
||||
_coreConfiguration = coreConfiguration;
|
||||
_captureDetails = captureDetails;
|
||||
Init();
|
||||
}
|
||||
|
@ -146,21 +141,21 @@ namespace Greenshot.Addons.Controls
|
|||
string initialDirectory = null;
|
||||
try
|
||||
{
|
||||
CoreConfiguration.ValidateAndCorrect();
|
||||
initialDirectory = Path.GetDirectoryName(CoreConfiguration.OutputFileAsFullpath);
|
||||
_coreConfiguration.ValidateAndCorrect();
|
||||
initialDirectory = Path.GetDirectoryName(_coreConfiguration.OutputFileAsFullpath);
|
||||
}
|
||||
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))
|
||||
{
|
||||
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)
|
||||
SaveFileDialog.RestoreDirectory = true;
|
||||
|
@ -175,7 +170,7 @@ namespace Greenshot.Addons.Controls
|
|||
PrepareFilterOptions();
|
||||
var fdf = "";
|
||||
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++)
|
||||
{
|
||||
var fo = _filterOptions[i];
|
||||
|
@ -224,7 +219,7 @@ namespace Greenshot.Addons.Controls
|
|||
private void ApplySuggestedValues()
|
||||
{
|
||||
// build the full path and set dialog properties
|
||||
FileName = FilenameHelper.GetFilenameWithoutExtensionFromPattern(CoreConfiguration.OutputFileFilenamePattern, _captureDetails);
|
||||
FileName = FilenameHelper.GetFilenameWithoutExtensionFromPattern(_coreConfiguration.OutputFileFilenamePattern, _captureDetails);
|
||||
}
|
||||
|
||||
private void CleanUp()
|
||||
|
|
|
@ -48,15 +48,12 @@ namespace Greenshot.Addons.Controls
|
|||
/// </summary>
|
||||
public sealed class ThumbnailForm : FormWithoutActivation
|
||||
{
|
||||
// TODO: Solve, was static reference!
|
||||
private static readonly ICoreConfiguration coreConfiguration = new CoreConfigurationImpl();
|
||||
|
||||
private IntPtr _thumbnailHandle = IntPtr.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for the Thumbnail form
|
||||
/// </summary>
|
||||
public ThumbnailForm()
|
||||
public ThumbnailForm(ICoreConfiguration coreConfiguration)
|
||||
{
|
||||
ShowInTaskbar = false;
|
||||
FormBorderStyle = FormBorderStyle.None;
|
||||
|
|
|
@ -128,7 +128,7 @@ namespace Greenshot.Addons.Core
|
|||
public static string SaveWithDialog(ISurface surface, ICaptureDetails captureDetails)
|
||||
{
|
||||
string returnValue = null;
|
||||
using (var saveImageFileDialog = new SaveImageFileDialog(captureDetails))
|
||||
using (var saveImageFileDialog = new SaveImageFileDialog(CoreConfig, captureDetails))
|
||||
{
|
||||
var dialogResult = saveImageFileDialog.ShowDialog();
|
||||
if (dialogResult.Equals(DialogResult.OK))
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using Greenshot.Addon.InternetExplorer;
|
||||
using Greenshot.Addons.Core;
|
||||
using Greenshot.Addons.Interfaces;
|
||||
|
||||
namespace Greenshot.Components
|
||||
|
@ -10,19 +11,22 @@ namespace Greenshot.Components
|
|||
public class CaptureSupportInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// Constructor for DI
|
||||
/// </summary>
|
||||
/// <param name="internetExplorerCaptureHelper">InternetExplorerCaptureHelper</param>
|
||||
/// <param name="formEnhancers">IEnumerable with IFormEnhancer</param>
|
||||
public CaptureSupportInfo(
|
||||
ICoreConfiguration coreConfiguration,
|
||||
InternetExplorerCaptureHelper internetExplorerCaptureHelper,
|
||||
IEnumerable<IFormEnhancer> formEnhancers = null
|
||||
)
|
||||
{
|
||||
CoreConfiguration = coreConfiguration;
|
||||
InternetExplorerCaptureHelper = internetExplorerCaptureHelper;
|
||||
FormEnhancers = formEnhancers;
|
||||
}
|
||||
|
||||
public ICoreConfiguration CoreConfiguration { get; }
|
||||
public InternetExplorerCaptureHelper InternetExplorerCaptureHelper { get; }
|
||||
|
||||
public IEnumerable<IFormEnhancer> FormEnhancers { get; }
|
||||
|
|
2
src/Greenshot/Forms/MainForm.Designer.cs
generated
2
src/Greenshot/Forms/MainForm.Designer.cs
generated
|
@ -105,7 +105,7 @@ namespace Greenshot.Forms {
|
|||
this.contextMenu.Name = "contextMenu";
|
||||
this.contextMenu.Closing += new System.Windows.Forms.ToolStripDropDownClosingEventHandler(this.ContextMenuClosing);
|
||||
this.contextMenu.Opening += new System.ComponentModel.CancelEventHandler(this.ContextMenuOpening);
|
||||
this.contextMenu.Renderer = new ContextMenuToolStripProfessionalRenderer();
|
||||
this.contextMenu.Renderer = new ContextMenuToolStripProfessionalRenderer(_coreConfiguration);
|
||||
//
|
||||
// contextmenu_capturearea
|
||||
//
|
||||
|
|
|
@ -676,7 +676,7 @@ namespace Greenshot.Forms
|
|||
var window = captureWindowItem.Tag as IInteropWindow;
|
||||
if (_thumbnailForm == null)
|
||||
{
|
||||
_thumbnailForm = new ThumbnailForm();
|
||||
_thumbnailForm = new ThumbnailForm(_coreConfiguration);
|
||||
}
|
||||
_thumbnailForm.ShowThumbnail(window, captureWindowItem.GetCurrentParent().TopLevelControl);
|
||||
}
|
||||
|
|
|
@ -61,8 +61,7 @@ namespace Greenshot.Helpers
|
|||
public class CaptureHelper : IDisposable
|
||||
{
|
||||
private static readonly LogSource Log = new LogSource();
|
||||
// TODO: Solve, was static reference!
|
||||
private static readonly ICoreConfiguration CoreConfig = new CoreConfigurationImpl();
|
||||
private readonly ICoreConfiguration _coreConfiguration;
|
||||
private readonly bool _captureMouseCursor;
|
||||
private ICapture _capture;
|
||||
private readonly CaptureSupportInfo _captureSupportInfo;
|
||||
|
@ -78,6 +77,7 @@ namespace Greenshot.Helpers
|
|||
public CaptureHelper(CaptureSupportInfo captureSupportInfo, CaptureMode captureMode)
|
||||
{
|
||||
_captureSupportInfo = captureSupportInfo;
|
||||
_coreConfiguration = captureSupportInfo.CoreConfiguration;
|
||||
_captureMode = captureMode;
|
||||
_capture = new Capture();
|
||||
_destinationHolder = DestinationHolder.Instance;
|
||||
|
@ -134,7 +134,7 @@ namespace Greenshot.Helpers
|
|||
SelectedCaptureWindow = null;
|
||||
_capture = null;
|
||||
// Empty working set after capturing
|
||||
if (CoreConfig.MinimizeWorkingSetSize)
|
||||
if (_coreConfiguration.MinimizeWorkingSetSize)
|
||||
{
|
||||
PsApi.EmptyWorkingSet();
|
||||
}
|
||||
|
@ -248,7 +248,7 @@ namespace Greenshot.Helpers
|
|||
|
||||
private void DoCaptureFeedback()
|
||||
{
|
||||
if (CoreConfig.PlayCameraSound)
|
||||
if (_coreConfiguration.PlayCameraSound)
|
||||
{
|
||||
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
|
||||
// forcefully removes the balloon!
|
||||
if (!CoreConfig.HideTrayicon)
|
||||
if (!_coreConfiguration.HideTrayicon)
|
||||
{
|
||||
MainForm.Instance.NotifyIcon.Visible = false;
|
||||
MainForm.Instance.NotifyIcon.Visible = true;
|
||||
|
@ -313,20 +313,20 @@ namespace Greenshot.Helpers
|
|||
}
|
||||
|
||||
// Delay for the Context menu
|
||||
if (CoreConfig.CaptureDelay > 0)
|
||||
if (_coreConfiguration.CaptureDelay > 0)
|
||||
{
|
||||
Thread.Sleep(CoreConfig.CaptureDelay);
|
||||
Thread.Sleep(_coreConfiguration.CaptureDelay);
|
||||
}
|
||||
else
|
||||
{
|
||||
CoreConfig.CaptureDelay = 0;
|
||||
_coreConfiguration.CaptureDelay = 0;
|
||||
}
|
||||
|
||||
// Capture Mousecursor if we are not loading from file or clipboard, only show when needed
|
||||
if (_captureMode != CaptureMode.File && _captureMode != CaptureMode.Clipboard)
|
||||
{
|
||||
_capture = WindowCapture.CaptureCursor(_capture);
|
||||
_capture.CursorVisible = _captureMouseCursor && CoreConfig.CaptureMousepointer;
|
||||
_capture.CursorVisible = _captureMouseCursor && _coreConfiguration.CaptureMousepointer;
|
||||
}
|
||||
|
||||
switch (_captureMode)
|
||||
|
@ -382,9 +382,9 @@ namespace Greenshot.Helpers
|
|||
}
|
||||
break;
|
||||
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;
|
||||
}
|
||||
break;
|
||||
|
@ -497,9 +497,9 @@ namespace Greenshot.Helpers
|
|||
}
|
||||
break;
|
||||
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
|
||||
_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()
|
||||
{
|
||||
foreach (var destinationDesignation in CoreConfig.OutputDestinations)
|
||||
foreach (var destinationDesignation in _coreConfiguration.OutputDestinations)
|
||||
{
|
||||
var destination = _destinationHolder.SortedActiveDestinations.Find(destinationDesignation);
|
||||
if (destination != null)
|
||||
|
@ -714,8 +714,8 @@ namespace Greenshot.Helpers
|
|||
return false;
|
||||
}
|
||||
// Fix for Bug #3430560
|
||||
CoreConfig.LastCapturedRegion = SelectedCaptureWindow.GetInfo().Bounds;
|
||||
var returnValue = CaptureWindow(SelectedCaptureWindow, _capture, CoreConfig.WindowCaptureMode) != null;
|
||||
_coreConfiguration.LastCapturedRegion = SelectedCaptureWindow.GetInfo().Bounds;
|
||||
var returnValue = CaptureWindow(SelectedCaptureWindow, _capture, _coreConfiguration.WindowCaptureMode) != null;
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
@ -802,7 +802,7 @@ namespace Greenshot.Helpers
|
|||
// 3) Otherwise use GDI (Screen might be also okay but might lose content)
|
||||
if (isAutoMode)
|
||||
{
|
||||
if (CoreConfig.IECapture && _captureSupportInfo.InternetExplorerCaptureHelper.IsIeWindow(windowToCapture))
|
||||
if (_coreConfiguration.IECapture && _captureSupportInfo.InternetExplorerCaptureHelper.IsIeWindow(windowToCapture))
|
||||
{
|
||||
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
|
||||
DialogResult result;
|
||||
|
@ -1086,7 +1086,7 @@ namespace Greenshot.Helpers
|
|||
// 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!
|
||||
var tmpRectangle = _captureRect.Offset(_capture.ScreenBounds.Location.X, _capture.ScreenBounds.Location.Y);
|
||||
CoreConfig.LastCapturedRegion = tmpRectangle;
|
||||
_coreConfiguration.LastCapturedRegion = tmpRectangle;
|
||||
HandleCapture();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue