mirror of
https://github.com/greenshot/greenshot
synced 2025-07-16 10:03:44 -07:00
BUG-2021 & BUG-2022: Fixes for exceptions.
This commit is contained in:
parent
14086923df
commit
35ed3b8d60
6 changed files with 51 additions and 26 deletions
|
@ -153,7 +153,7 @@ namespace Greenshot.Drawing.Fields
|
|||
{
|
||||
ClearFields();
|
||||
internalUpdateRunning = true;
|
||||
foreach (Field field in FindCommonFields())
|
||||
foreach (var field in FindCommonFields())
|
||||
{
|
||||
SetFieldValue(field.FieldType, field.Value);
|
||||
}
|
||||
|
|
|
@ -1910,7 +1910,7 @@ namespace Greenshot.Drawing
|
|||
FieldAggregator.UnbindElement(container);
|
||||
if (generateEvents && _movingElementChanged != null)
|
||||
{
|
||||
SurfaceElementEventArgs eventArgs = new SurfaceElementEventArgs {Elements = selectedElements};
|
||||
var eventArgs = new SurfaceElementEventArgs {Elements = selectedElements};
|
||||
_movingElementChanged(this, eventArgs);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,8 @@ namespace Greenshot.Drawing
|
|||
/// The StringFormat object is not serializable!!
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
StringFormat _stringFormat = new StringFormat();
|
||||
private StringFormat _stringFormat = new StringFormat();
|
||||
|
||||
public StringFormat StringFormat => _stringFormat;
|
||||
|
||||
// Although the name is wrong, we can't change it due to file serialization
|
||||
|
@ -172,8 +173,13 @@ namespace Greenshot.Drawing
|
|||
Height = textSize.Height + lineThickness;
|
||||
}
|
||||
|
||||
void TextContainer_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
private void TextContainer_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (_textBox == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_textBox.Visible)
|
||||
{
|
||||
_textBox.Invalidate();
|
||||
|
@ -203,7 +209,7 @@ namespace Greenshot.Drawing
|
|||
}
|
||||
}
|
||||
|
||||
void TextContainer_FieldChanged(object sender, FieldChangedEventArgs e)
|
||||
private void TextContainer_FieldChanged(object sender, FieldChangedEventArgs e)
|
||||
{
|
||||
if (_textBox == null)
|
||||
{
|
||||
|
@ -467,7 +473,7 @@ namespace Greenshot.Drawing
|
|||
_textBox.ForeColor = lineColor;
|
||||
}
|
||||
|
||||
void textBox_KeyDown(object sender, KeyEventArgs e)
|
||||
private void textBox_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
// ESC and Enter/Return (w/o Shift) hide text editor
|
||||
if (e.KeyCode == Keys.Escape || ((e.KeyCode == Keys.Return || e.KeyCode == Keys.Enter) && e.Modifiers == Keys.None))
|
||||
|
@ -477,7 +483,7 @@ namespace Greenshot.Drawing
|
|||
}
|
||||
}
|
||||
|
||||
void textBox_LostFocus(object sender, EventArgs e)
|
||||
private void textBox_LostFocus(object sender, EventArgs e)
|
||||
{
|
||||
// next change will be made undoable
|
||||
makeUndoable = true;
|
||||
|
|
|
@ -80,7 +80,7 @@ namespace Greenshot.Memento
|
|||
var other = otherMemento as DrawableContainerBoundsChangeMemento;
|
||||
if (other != null)
|
||||
{
|
||||
if (Objects.CompareLists<IDrawableContainer>(listOfdrawableContainer, other.listOfdrawableContainer))
|
||||
if (ObjectExtensions.CompareLists<IDrawableContainer>(listOfdrawableContainer, other.listOfdrawableContainer))
|
||||
{
|
||||
// Lists are equal, as we have the state already we can ignore the new memento
|
||||
return true;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
@ -26,7 +27,10 @@ using System.Runtime.Serialization;
|
|||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
public static class Objects {
|
||||
/// <summary>
|
||||
/// Extension methods which work for objects
|
||||
/// </summary>
|
||||
public static class ObjectExtensions {
|
||||
|
||||
/// <summary>
|
||||
/// Perform a deep Copy of the object.
|
||||
|
@ -34,41 +38,56 @@ namespace GreenshotPlugin.Core {
|
|||
/// <typeparam name="T">The type of object being copied.</typeparam>
|
||||
/// <param name="source">The object instance to copy.</param>
|
||||
/// <returns>The copied object.</returns>
|
||||
public static T Clone<T>(this T source) {
|
||||
if (!typeof(T).IsSerializable) {
|
||||
throw new ArgumentException("The type must be serializable.", "source");
|
||||
public static T Clone<T>(this T source)
|
||||
{
|
||||
var typeparam = typeof(T);
|
||||
if (!typeparam.IsInterface && !typeparam.IsSerializable)
|
||||
{
|
||||
throw new ArgumentException("The type must be serializable.", nameof(source));
|
||||
}
|
||||
|
||||
|
||||
// Don't serialize a null object, simply return the default for that object
|
||||
if (ReferenceEquals(source, null)) {
|
||||
if (source == null) {
|
||||
return default(T);
|
||||
}
|
||||
|
||||
IFormatter formatter = new BinaryFormatter();
|
||||
Stream stream = new MemoryStream();
|
||||
using (stream) {
|
||||
using (var stream = new MemoryStream()) {
|
||||
formatter.Serialize(stream, source);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
return (T)formatter.Deserialize(stream);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clone the content from source to destination
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type to clone</typeparam>
|
||||
/// <param name="source">Instance to copy from</param>
|
||||
/// <param name="destination">Instance to copy to</param>
|
||||
public static void CloneTo<T>(this T source, T destination) {
|
||||
Type type = typeof(T);
|
||||
FieldInfo[] myObjectFields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
|
||||
var type = typeof(T);
|
||||
var myObjectFields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
|
||||
|
||||
foreach (FieldInfo fi in myObjectFields) {
|
||||
fi.SetValue(destination, fi.GetValue(source));
|
||||
foreach (var fieldInfo in myObjectFields) {
|
||||
fieldInfo.SetValue(destination, fieldInfo.GetValue(source));
|
||||
}
|
||||
PropertyInfo[] myObjectProperties = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
|
||||
var myObjectProperties = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
|
||||
|
||||
foreach (PropertyInfo pi in myObjectProperties) {
|
||||
if (pi.CanWrite) {
|
||||
pi.SetValue(destination, pi.GetValue(source, null), null);
|
||||
foreach (var propertyInfo in myObjectProperties) {
|
||||
if (propertyInfo.CanWrite) {
|
||||
propertyInfo.SetValue(destination, propertyInfo.GetValue(source, null), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Compare two lists
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="l1">IList</param>
|
||||
/// <param name="l2">IList</param>
|
||||
/// <returns>true if they are the same</returns>
|
||||
public static bool CompareLists<T>(IList<T> l1, IList<T> l2) {
|
||||
if (l1.Count != l2.Count) {
|
||||
return false;
|
|
@ -189,7 +189,7 @@
|
|||
<Compile Include="Core\LogHelper.cs" />
|
||||
<Compile Include="Core\NetworkHelper.cs" />
|
||||
<Compile Include="Core\OAuthHelper.cs" />
|
||||
<Compile Include="Core\Objects.cs" />
|
||||
<Compile Include="Core\ObjectExtensions.cs" />
|
||||
<Compile Include="Core\PluginUtils.cs" />
|
||||
<Compile Include="Core\QuantizerHelper.cs" />
|
||||
<Compile Include="Core\RssHelper.cs" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue