Skip to content

Commit

Permalink
Simplified more delegate invocations
Browse files Browse the repository at this point in the history
  • Loading branch information
Lehonti Ramos committed Sep 21, 2023
1 parent 64910b9 commit 98909bd
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 64 deletions.
3 changes: 1 addition & 2 deletions Pinta.Core/Actions/AppActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public void RegisterHandlers ()
#region Event Invokers
public void RaiseBeforeQuit ()
{
if (BeforeQuit != null)
BeforeQuit (this, EventArgs.Empty);
BeforeQuit?.Invoke (this, EventArgs.Empty);
}
#endregion
}
3 changes: 1 addition & 2 deletions Pinta.Core/Actions/FileActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ internal int RaiseModifyCompression (int defaultCompression, Gtk.Window parent)
{
ModifyCompressionEventArgs e = new ModifyCompressionEventArgs (defaultCompression, parent);

if (ModifyCompression != null)
ModifyCompression (this, e);
ModifyCompression?.Invoke (this, e);

return e.Cancel ? -1 : e.Quality;
}
Expand Down
18 changes: 6 additions & 12 deletions Pinta.Core/Classes/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Pinta.Core;
// somewhat arbitrary. In general:
// Document - Data about the image itself
// Workspace - Data about Pinta's state for the image
public class Document
public sealed class Document
{
private string display_name = string.Empty;
private Gio.File? file = null;
Expand Down Expand Up @@ -393,25 +393,19 @@ public bool Save (bool saveAs)
/// </summary>
public void SignalSurfaceCloned ()
{
if (LayerCloned != null) {
LayerCloned ();
}
LayerCloned?.Invoke ();
}
#endregion

#region Protected Methods
protected void OnIsDirtyChanged ()
private void OnIsDirtyChanged ()
{
if (IsDirtyChanged != null)
IsDirtyChanged (this, EventArgs.Empty);
IsDirtyChanged?.Invoke (this, EventArgs.Empty);
}

protected void OnRenamed ()
private void OnRenamed ()
{
if (Renamed != null)
Renamed (this, EventArgs.Empty);
Renamed?.Invoke (this, EventArgs.Empty);
}
#endregion

#region Private Methods
private void OnSelectionChanged ()
Expand Down
3 changes: 1 addition & 2 deletions Pinta.Core/Classes/DocumentWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@ public void ZoomToCanvasRectangle (RectangleD rect)
#region Private Methods
private void OnCanvasInvalidated (CanvasInvalidatedEventArgs e)
{
if (CanvasInvalidated != null)
CanvasInvalidated (this, e);
CanvasInvalidated?.Invoke (this, e);
}

public void OnViewSizeChanged ()
Expand Down
3 changes: 1 addition & 2 deletions Pinta.Core/Classes/ObservableObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ protected void SetValue<T> (string propertyName, ref T member, T value)

protected void FirePropertyChanged (string? propertyName)
{
if (PropertyChanged != null)
PropertyChanged (this, new PropertyChangedEventArgs (propertyName));
PropertyChanged?.Invoke (this, new PropertyChangedEventArgs (propertyName));
}
}
3 changes: 1 addition & 2 deletions Pinta.Core/Classes/Palette.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ private Palette ()

private void OnPaletteChanged ()
{
if (PaletteChanged != null)
PaletteChanged (this, EventArgs.Empty);
PaletteChanged?.Invoke (this, EventArgs.Empty);
}

public int Count => colors.Count;
Expand Down
4 changes: 1 addition & 3 deletions Pinta.Core/Classes/Re-editable/Text/TextEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,7 @@ private static int UTF8OffsetToCharacterOffset (string s, int offset)

private void OnModified ()
{
EventHandler? handler = Modified;
if (handler != null)
handler (this, EventArgs.Empty);
Modified?.Invoke (this, EventArgs.Empty);
}

private void DeleteSelection ()
Expand Down
4 changes: 1 addition & 3 deletions Pinta.Core/Effects/Histogram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ protected internal Histogram (int channels, int entries, ImmutableArray<ColorBgr
public event EventHandler? HistogramChanged;
protected void OnHistogramUpdated ()
{
if (HistogramChanged != null) {
HistogramChanged (this, EventArgs.Empty);
}
HistogramChanged?.Invoke (this, EventArgs.Empty);
}

protected readonly ImmutableArray<ColorBgra> visual_colors;
Expand Down
15 changes: 6 additions & 9 deletions Pinta.Core/Managers/ChromeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

namespace Pinta.Core;

public class ChromeManager
public sealed class ChromeManager
{
private PointI last_canvas_cursor_point;
private bool main_window_busy;
Expand Down Expand Up @@ -164,19 +164,16 @@ public void LaunchSimpleEffectDialog (BaseEffect effect, IAddinLocalizer localiz
simple_effect_dialog_handler (effect, localizer);
}
#endregion
#region Protected Methods
protected void OnLastCanvasCursorPointChanged ()

private void OnLastCanvasCursorPointChanged ()
{
if (LastCanvasCursorPointChanged != null)
LastCanvasCursorPointChanged (this, EventArgs.Empty);
LastCanvasCursorPointChanged?.Invoke (this, EventArgs.Empty);
}

protected void OnStatusBarTextChanged (string text)
private void OnStatusBarTextChanged (string text)
{
if (StatusBarTextChanged != null)
StatusBarTextChanged (this, new TextChangedEventArgs (text));
StatusBarTextChanged?.Invoke (this, new TextChangedEventArgs (text));
}
#endregion

#region Public Events
public event EventHandler? LastCanvasCursorPointChanged;
Expand Down
8 changes: 2 additions & 6 deletions Pinta.Core/Managers/LivePreviewManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ public void Start (BaseEffect effect)
if (effect.EffectData != null)
effect.EffectData.PropertyChanged += EffectData_PropertyChanged;

if (Started != null) {
Started (this, new LivePreviewStartedEventArgs ());
}
Started?.Invoke (this, new LivePreviewStartedEventArgs ());

var settings = new AsyncEffectRenderer.Settings () {
ThreadCount = PintaCore.System.RenderThreads,
Expand Down Expand Up @@ -305,9 +303,7 @@ void FireLivePreviewEndedEvent (RenderStatus status, Exception? ex)
void FireLivePreviewRenderUpdatedEvent (double progress, RectangleI bounds)
{

if (RenderUpdated != null) {
RenderUpdated (this, new LivePreviewRenderUpdatedEventArgs (progress, bounds));
}
RenderUpdated?.Invoke (this, new LivePreviewRenderUpdatedEventArgs (progress, bounds));
}

private void LivePreview_RenderUpdated (object? o, LivePreviewRenderUpdatedEventArgs args)
Expand Down
8 changes: 2 additions & 6 deletions Pinta.Core/Managers/PaintBrushManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,12 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()

private void OnBrushAdded (BasePaintBrush brush)
{
var handler = BrushAdded;
if (handler != null)
handler (this, new BrushEventArgs (brush));
BrushAdded?.Invoke (this, new BrushEventArgs (brush));
}

private void OnBrushRemoved (BasePaintBrush brush)
{
var handler = BrushRemoved;
if (handler != null)
handler (this, new BrushEventArgs (brush));
BrushRemoved?.Invoke (this, new BrushEventArgs (brush));
}

private sealed class BrushSorter : Comparer<BasePaintBrush>
Expand Down
12 changes: 4 additions & 8 deletions Pinta.Core/Managers/WorkspaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,7 @@ internal void SetActiveDocumentInternal (Document document)

private void OnActiveDocumentChanged (EventArgs e)
{
if (ActiveDocumentChanged != null)
ActiveDocumentChanged (this, EventArgs.Empty);
ActiveDocumentChanged?.Invoke (this, EventArgs.Empty);

OnSelectionChanged ();

Expand All @@ -354,20 +353,17 @@ private void OnDocumentCreated (DocumentEventArgs e)
OnSelectionChanged ();
};

if (DocumentCreated != null)
DocumentCreated (this, e);
DocumentCreated?.Invoke (this, e);
}

private void OnDocumentOpened (DocumentEventArgs e)
{
if (DocumentOpened != null)
DocumentOpened (this, e);
DocumentOpened?.Invoke (this, e);
}

private void OnDocumentClosed (DocumentEventArgs e)
{
if (DocumentClosed != null)
DocumentClosed (this, e);
DocumentClosed?.Invoke (this, e);
}

private void OnSelectionChanged ()
Expand Down
3 changes: 1 addition & 2 deletions Pinta.Core/Widgets/ToolBarDropDownButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ private void SetSelectedItem (ToolBarItem item)

private void OnSelectedItemChanged ()
{
if (SelectedItemChanged != null)
SelectedItemChanged (this, EventArgs.Empty);
SelectedItemChanged?.Invoke (this, EventArgs.Empty);
}

public event EventHandler? SelectedItemChanged;
Expand Down
8 changes: 3 additions & 5 deletions Pinta.Gui.Widgets/Widgets/PointPickerGraphic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

namespace Pinta.Gui.Widgets;

public class PointPickerGraphic : Gtk.DrawingArea
public sealed class PointPickerGraphic : Gtk.DrawingArea
{
private ImageSurface? thumbnail;
private PointI position;
Expand Down Expand Up @@ -138,11 +138,9 @@ private RectangleI GetDrawBounds ()
#region Public Events
public event EventHandler? PositionChanged;

protected virtual void OnPositionChange ()
private void OnPositionChange ()
{
if (PositionChanged != null) {
PositionChanged (this, EventArgs.Empty);
}
PositionChanged?.Invoke (this, EventArgs.Empty);
}
#endregion

Expand Down

0 comments on commit 98909bd

Please sign in to comment.