Fixing some NPR Exceptions.

This commit is contained in:
Robin 2016-06-16 21:35:32 +02:00
commit 9fe00fdbdb
4 changed files with 24 additions and 43 deletions

View file

@ -50,24 +50,20 @@ namespace Greenshot.Drawing {
}
public override void Invalidate() {
if (_parent == null)
{
return;
}
_parent.Invalidate();
_parent?.Invalidate();
}
/// <summary>
/// We need to override the DrawingBound, return a rectangle in the size of the image, to make sure this element is always draw
/// (we create a transparent brown over the complete picture)
/// </summary>
public override Rectangle DrawingBounds {
get {
return new Rectangle(0,0,_parent.Width, _parent.Height);
}
}
public override Rectangle DrawingBounds => new Rectangle(0,0,_parent?.Width??0, _parent?.Height ?? 0);
public override void Draw(Graphics g, RenderMode rm) {
if (_parent == null)
{
return;
}
using (Brush cropBrush = new SolidBrush(Color.FromArgb(100, 150, 150, 100))) {
Rectangle cropRectangle = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
Rectangle selectionRect = new Rectangle(cropRectangle.Left - 1, cropRectangle.Top - 1, cropRectangle.Width + 1, cropRectangle.Height + 1);

View file

@ -89,14 +89,7 @@ namespace Greenshot.Drawing
if (!disposing) {
return;
}
if (_parent != null)
{
FieldAggregator fieldAggregator = _parent.FieldAggregator;
if (fieldAggregator != null)
{
fieldAggregator.UnbindElement(this);
}
}
_parent?.FieldAggregator?.UnbindElement(this);
}
~DrawableContainer() {
@ -306,7 +299,7 @@ namespace Greenshot.Drawing
public virtual void Invalidate() {
if (Status != EditStatus.UNDRAWN) {
_parent.Invalidate(DrawingBounds);
_parent?.Invalidate(DrawingBounds);
}
}
@ -491,15 +484,7 @@ namespace Greenshot.Drawing
{
return;
}
if (_parent != null)
{
// Remove FieldAggregator
FieldAggregator fieldAggregator = _parent.FieldAggregator;
if (fieldAggregator != null)
{
fieldAggregator.UnbindElement(this);
}
}
_parent.FieldAggregator?.UnbindElement(this);
_parent = newParent;
foreach(IFilter filter in Filters) {
@ -521,7 +506,7 @@ namespace Greenshot.Drawing
/// <param name="fieldToBeChanged">The field to be changed</param>
/// <param name="newValue">The new value</param>
public virtual void BeforeFieldChange(IField fieldToBeChanged, object newValue) {
_parent.MakeUndoable(new ChangeFieldHolderMemento(this, fieldToBeChanged), true);
_parent?.MakeUndoable(new ChangeFieldHolderMemento(this, fieldToBeChanged), true);
Invalidate();
}

View file

@ -217,7 +217,7 @@ namespace Greenshot.Drawing {
int safetymargin = 10;
return new Rectangle(myBounds.Left + Left - (safetymargin+lineThickness), myBounds.Top + Top - (safetymargin+lineThickness), myBounds.Width + 2*(lineThickness+safetymargin), myBounds.Height + 2*(lineThickness+safetymargin));
}
return new Rectangle(0, 0, _parent.Width, _parent.Height);
return new Rectangle(0, 0, _parent?.Width??0, _parent?.Height?? 0);
}
}

View file

@ -40,14 +40,12 @@ namespace Greenshot.Drawing {
public class TextContainer : RectangleContainer, ITextContainer {
// If makeUndoable is true the next text-change will make the change undoable.
// This is set to true AFTER the first change is made, as there is already a "add element" on the undo stack
// Although the name is wrong, we can't change it due to file serialization
// ReSharper disable once InconsistentNaming
private bool makeUndoable;
[NonSerialized]
private Font _font;
public Font Font {
get {
return _font;
}
}
public Font Font => _font;
[NonSerialized]
private TextBox _textBox;
@ -57,11 +55,10 @@ namespace Greenshot.Drawing {
/// </summary>
[NonSerialized]
StringFormat _stringFormat = new StringFormat();
public StringFormat StringFormat {
get {
return _stringFormat;
}
}
public StringFormat StringFormat => _stringFormat;
// Although the name is wrong, we can't change it due to file serialization
// ReSharper disable once InconsistentNaming
private string text;
// there is a binding on the following property!
public string Text {
@ -168,7 +165,7 @@ namespace Greenshot.Drawing {
HideTextBox();
} else if (Selected && Status == EditStatus.DRAWING) {
ShowTextBox();
} else if (Selected && Status == EditStatus.IDLE && _textBox.Visible) {
} else if (_parent != null && Selected && Status == EditStatus.IDLE && _textBox.Visible) {
// Fix (workaround) for BUG-1698
_parent.KeysLocked = true;
}
@ -221,8 +218,11 @@ namespace Greenshot.Drawing {
}
private void ShowTextBox() {
if (_parent != null)
{
_parent.KeysLocked = true;
_parent.Controls.Add(_textBox);
}
EnsureTextBoxContrast();
_textBox.Show();
_textBox.Focus();