From c43dd5214ae97551d9cbaef13abb756488e20257 Mon Sep 17 00:00:00 2001 From: Lehonti Ramos <17771375+Lehonti@users.noreply.github.com> Date: Thu, 3 Oct 2024 01:44:12 +0200 Subject: [PATCH 01/11] Made `LaunchConfiguration` asynchronous through `Task` --- Pinta.Core/Effects/BaseEffect.cs | 30 +++--------- Pinta.Core/Managers/ChromeManager.cs | 46 +++++++++---------- Pinta.Core/Managers/LivePreviewManager.cs | 32 +++++-------- .../Adjustments/BrightnessContrastEffect.cs | 3 +- Pinta.Effects/Adjustments/CurvesEffect.cs | 9 +++- .../Adjustments/HueSaturationEffect.cs | 3 +- Pinta.Effects/Adjustments/LevelsEffect.cs | 13 +++--- Pinta.Effects/Adjustments/PosterizeEffect.cs | 11 +++-- Pinta.Effects/Effects/AddNoiseEffect.cs | 3 +- Pinta.Effects/Effects/AlignObjectEffect.cs | 9 +++- Pinta.Effects/Effects/BulgeEffect.cs | 3 +- Pinta.Effects/Effects/CloudsEffect.cs | 3 +- Pinta.Effects/Effects/DitheringEffect.cs | 3 +- Pinta.Effects/Effects/EdgeDetectEffect.cs | 3 +- Pinta.Effects/Effects/EmbossEffect.cs | 3 +- Pinta.Effects/Effects/FeatherEffect.cs | 2 +- Pinta.Effects/Effects/FragmentEffect.cs | 3 +- Pinta.Effects/Effects/FrostedGlassEffect.cs | 3 +- Pinta.Effects/Effects/GaussianBlurEffect.cs | 3 +- Pinta.Effects/Effects/GlowEffect.cs | 3 +- Pinta.Effects/Effects/InkSketchEffect.cs | 3 +- Pinta.Effects/Effects/JuliaFractalEffect.cs | 3 +- .../Effects/MandelbrotFractalEffect.cs | 3 +- Pinta.Effects/Effects/MedianEffect.cs | 3 +- Pinta.Effects/Effects/MotionBlurEffect.cs | 3 +- Pinta.Effects/Effects/OilPaintingEffect.cs | 3 +- Pinta.Effects/Effects/OutlineEdgeEffect.cs | 3 +- Pinta.Effects/Effects/OutlineObjectEffect.cs | 2 +- Pinta.Effects/Effects/PencilSketchEffect.cs | 3 +- Pinta.Effects/Effects/PixelateEffect.cs | 3 +- Pinta.Effects/Effects/RadialBlurEffect.cs | 3 +- Pinta.Effects/Effects/RedEyeRemoveEffect.cs | 3 +- Pinta.Effects/Effects/ReduceNoiseEffect.cs | 3 +- Pinta.Effects/Effects/ReliefEffect.cs | 3 +- Pinta.Effects/Effects/SharpenEffect.cs | 3 +- Pinta.Effects/Effects/SoftenPortraitEffect.cs | 3 +- Pinta.Effects/Effects/TileEffect.cs | 3 +- Pinta.Effects/Effects/TwistEffect.cs | 3 +- Pinta.Effects/Effects/UnfocusEffect.cs | 3 +- Pinta.Effects/Effects/VignetteEffect.cs | 3 +- Pinta.Effects/Effects/VoronoiDiagramEffect.cs | 3 +- Pinta.Effects/Effects/WarpEffect.cs | 3 +- Pinta.Effects/Effects/ZoomBlurEffect.cs | 3 +- Pinta.Effects/Utilities/EffectHelper.cs | 3 +- .../Dialogs/SimpleEffectDialog.cs | 14 ++++-- .../Mocks/MockChromeManager.cs | 8 ++-- .../Mocks/MockChromeManager.cs | 5 +- 47 files changed, 157 insertions(+), 129 deletions(-) diff --git a/Pinta.Core/Effects/BaseEffect.cs b/Pinta.Core/Effects/BaseEffect.cs index a2bb434485..79989b10df 100644 --- a/Pinta.Core/Effects/BaseEffect.cs +++ b/Pinta.Core/Effects/BaseEffect.cs @@ -25,7 +25,7 @@ // THE SOFTWARE. using System; -using System.Diagnostics; +using System.Threading.Tasks; using Cairo; using Mono.Addins; using Mono.Addins.Localization; @@ -84,10 +84,12 @@ public abstract class BaseEffect /// Launches the configuration dialog for this effect/adjustment. /// If IsConfigurable is true, the ConfigDialogResponse event will be invoked when the user accepts or cancels the dialog. /// - public virtual void LaunchConfiguration () + public virtual Task LaunchConfiguration () { if (IsConfigurable) throw new NotImplementedException ($"{GetType ()} is marked as configurable, but has not implemented LaunchConfiguration"); + + return Task.FromResult (Gtk.ResponseType.Ok); // Placeholder } /// @@ -97,22 +99,9 @@ public virtual void LaunchConfiguration () /// The localizer for the effect add-in. This is used to fetch translations for the /// strings in the dialog. /// - protected void LaunchSimpleEffectDialog (AddinLocalizer localizer) + protected Task LaunchSimpleEffectDialog (AddinLocalizer localizer) { - PintaCore.Chrome.LaunchSimpleEffectDialog (this, new AddinLocalizerWrapper (localizer)); - } - - /// - /// Emitted when the configuration dialog is accepted or cancelled by the user. - /// - public event EventHandler? ConfigDialogResponse; - - /// - /// Notify that the configuration dialog was accepted or cancelled by the user. - /// - public void OnConfigDialogResponse (bool accepted) - { - ConfigDialogResponse?.Invoke (this, new ConfigDialogResponseEventArgs (accepted)); + return PintaCore.Chrome.LaunchSimpleEffectDialog (this, new AddinLocalizerWrapper (localizer)); } #region Overridable Render Methods @@ -188,13 +177,6 @@ public virtual BaseEffect Clone () return effect; } - - public class ConfigDialogResponseEventArgs : EventArgs - { - public ConfigDialogResponseEventArgs (bool accepted) { Accepted = accepted; } - - public bool Accepted { get; } - } } /// diff --git a/Pinta.Core/Managers/ChromeManager.cs b/Pinta.Core/Managers/ChromeManager.cs index bd01619dfd..23f83f9e9b 100644 --- a/Pinta.Core/Managers/ChromeManager.cs +++ b/Pinta.Core/Managers/ChromeManager.cs @@ -25,15 +25,15 @@ // THE SOFTWARE. using System; -using Gtk; +using System.Threading.Tasks; using Mono.Addins.Localization; namespace Pinta.Core; public interface IChromeService { - Window MainWindow { get; } - void LaunchSimpleEffectDialog (BaseEffect effect, IAddinLocalizer localizer); + Gtk.Window MainWindow { get; } + Task LaunchSimpleEffectDialog (BaseEffect effect, IAddinLocalizer localizer); } public sealed class ChromeManager : IChromeService @@ -43,18 +43,18 @@ public sealed class ChromeManager : IChromeService // NRT - These are all initialized via the Initialize* functions // but it would be nice to rewrite it to provably non-null. - public Application Application { get; private set; } = null!; - public Window MainWindow { get; private set; } = null!; - public Widget ImageTabsNotebook { get; private set; } = null!; + public Gtk.Application Application { get; private set; } = null!; + public Gtk.Window MainWindow { get; private set; } = null!; + public Gtk.Widget ImageTabsNotebook { get; private set; } = null!; private IProgressDialog progress_dialog = null!; private ErrorDialogHandler error_dialog_handler = null!; private MessageDialogHandler message_dialog_handler = null!; private SimpleEffectDialogHandler simple_effect_dialog_handler = null!; - public Box? MainToolBar { get; private set; } - public Box ToolToolBar { get; private set; } = null!; - public Widget ToolBox { get; private set; } = null!; - public Box StatusBar { get; private set; } = null!; + public Gtk.Box? MainToolBar { get; private set; } + public Gtk.Box ToolToolBar { get; private set; } = null!; + public Gtk.Widget ToolBox { get; private set; } = null!; + public Gtk.Box StatusBar { get; private set; } = null!; public IProgressDialog ProgressDialog => progress_dialog; public Gio.Menu AdjustmentsMenu { get; private set; } = null!; @@ -94,32 +94,32 @@ public void InitializeApplication (Gtk.Application application) Application = application; } - public void InitializeWindowShell (Window shell) + public void InitializeWindowShell (Gtk.Window shell) { MainWindow = shell; } - public void InitializeToolToolBar (Box toolToolBar) + public void InitializeToolToolBar (Gtk.Box toolToolBar) { ToolToolBar = toolToolBar; } - public void InitializeMainToolBar (Box mainToolBar) + public void InitializeMainToolBar (Gtk.Box mainToolBar) { MainToolBar = mainToolBar; } - public void InitializeStatusBar (Box statusbar) + public void InitializeStatusBar (Gtk.Box statusbar) { StatusBar = statusbar; } - public void InitializeToolBox (Widget toolbox) + public void InitializeToolBox (Gtk.Widget toolbox) { ToolBox = toolbox; } - public void InitializeImageTabsNotebook (Widget notebook) + public void InitializeImageTabsNotebook (Gtk.Widget notebook) { ImageTabsNotebook = notebook; } @@ -150,12 +150,12 @@ public void InitializeSimpleEffectDialog (SimpleEffectDialogHandler handler) simple_effect_dialog_handler = handler; } - public void ShowErrorDialog (Window parent, string message, string body, string details) + public void ShowErrorDialog (Gtk.Window parent, string message, string body, string details) { error_dialog_handler (parent, message, body, details); } - public void ShowMessageDialog (Window parent, string message, string body) + public void ShowMessageDialog (Gtk.Window parent, string message, string body) { message_dialog_handler (parent, message, body); } @@ -165,9 +165,9 @@ public void SetStatusBarText (string text) OnStatusBarTextChanged (text); } - public void LaunchSimpleEffectDialog (BaseEffect effect, IAddinLocalizer localizer) + public Task LaunchSimpleEffectDialog (BaseEffect effect, IAddinLocalizer localizer) { - simple_effect_dialog_handler (effect, localizer); + return simple_effect_dialog_handler (effect, localizer); } #endregion @@ -197,6 +197,6 @@ public interface IProgressDialog event EventHandler Canceled; } -public delegate void ErrorDialogHandler (Window parent, string message, string body, string details); -public delegate void MessageDialogHandler (Window parent, string message, string body); -public delegate void SimpleEffectDialogHandler (BaseEffect effect, IAddinLocalizer localizer); +public delegate void ErrorDialogHandler (Gtk.Window parent, string message, string body, string details); +public delegate void MessageDialogHandler (Gtk.Window parent, string message, string body); +public delegate Task SimpleEffectDialogHandler (BaseEffect effect, IAddinLocalizer localizer); diff --git a/Pinta.Core/Managers/LivePreviewManager.cs b/Pinta.Core/Managers/LivePreviewManager.cs index 44a87ae3ab..2fc86027fc 100644 --- a/Pinta.Core/Managers/LivePreviewManager.cs +++ b/Pinta.Core/Managers/LivePreviewManager.cs @@ -81,7 +81,7 @@ internal LivePreviewManager ( public event EventHandler? RenderUpdated; public event EventHandler? Ended; - public void Start (BaseEffect effect) + public async void Start (BaseEffect effect) { if (live_preview_enabled) throw new InvalidOperationException ("LivePreviewManager.Start() called while live preview is already enabled."); @@ -137,23 +137,13 @@ public void Start (BaseEffect effect) renderer.Start (effect, layer.Surface, live_preview_surface); if (effect.IsConfigurable) { - EventHandler? handler = null; - handler = (_, args) => { - if (!args.Accepted) { - chrome_manager.MainWindowBusy = true; - Cancel (); - } else { - chrome_manager.MainWindowBusy = true; - Apply (); - } - // Unsubscribe once we're done. - effect.ConfigDialogResponse -= handler; - }; - - effect.ConfigDialogResponse += handler; - - effect.LaunchConfiguration (); + Gtk.ResponseType response = await effect.LaunchConfiguration (); + chrome_manager.MainWindowBusy = true; + if (response == Gtk.ResponseType.Ok) + Cancel (); + else + Apply (); } else { chrome_manager.MainWindowBusy = true; @@ -277,15 +267,15 @@ void EffectData_PropertyChanged (object? sender, PropertyChangedEventArgs e) private sealed class Renderer : AsyncEffectRenderer { readonly LivePreviewManager manager; - readonly ChromeManager chrome_manager; + readonly ChromeManager chrome; internal Renderer ( LivePreviewManager manager, AsyncEffectRenderer.Settings settings, - ChromeManager chromeManager) + ChromeManager chrome) : base (settings) { this.manager = manager; - this.chrome_manager = chromeManager; + this.chrome = chrome; } protected override void OnUpdate ( @@ -293,7 +283,7 @@ protected override void OnUpdate ( RectangleI updatedBounds) { Debug.WriteLine (DateTime.Now.ToString ("HH:mm:ss:ffff") + " LivePreviewManager.OnUpdate() progress: " + progress); - chrome_manager.ProgressDialog.Progress = progress; + chrome.ProgressDialog.Progress = progress; manager.FireLivePreviewRenderUpdatedEvent (progress, updatedBounds); } diff --git a/Pinta.Effects/Adjustments/BrightnessContrastEffect.cs b/Pinta.Effects/Adjustments/BrightnessContrastEffect.cs index 3a0a5f5997..0f7dd1488f 100644 --- a/Pinta.Effects/Adjustments/BrightnessContrastEffect.cs +++ b/Pinta.Effects/Adjustments/BrightnessContrastEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -50,7 +51,7 @@ void HandleEffectDataPropertyChanged (object? sender, System.ComponentModel.Prop table_calculated = false; } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); public override void Render (ImageSurface src, ImageSurface dest, ReadOnlySpan rois) diff --git a/Pinta.Effects/Adjustments/CurvesEffect.cs b/Pinta.Effects/Adjustments/CurvesEffect.cs index 108787ac60..3cae7854fc 100644 --- a/Pinta.Effects/Adjustments/CurvesEffect.cs +++ b/Pinta.Effects/Adjustments/CurvesEffect.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Threading.Tasks; using Cairo; using Pinta.Core; @@ -40,19 +41,23 @@ public CurvesEffect (IServiceProvider services) EffectData = new CurvesData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () { + TaskCompletionSource completionSource = new (); + CurvesDialog dialog = new (chrome, Data) { Title = Name, IconName = Icon, }; dialog.OnResponse += (_, args) => { - OnConfigDialogResponse (args.ResponseId == (int) Gtk.ResponseType.Ok); + completionSource.SetResult ((Gtk.ResponseType) args.ResponseId); dialog.Destroy (); }; dialog.Present (); + + return completionSource.Task; } public override void Render (ImageSurface src, ImageSurface dest, ReadOnlySpan rois) diff --git a/Pinta.Effects/Adjustments/HueSaturationEffect.cs b/Pinta.Effects/Adjustments/HueSaturationEffect.cs index 06bcbe74ee..b39536bd1b 100644 --- a/Pinta.Effects/Adjustments/HueSaturationEffect.cs +++ b/Pinta.Effects/Adjustments/HueSaturationEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -34,7 +35,7 @@ public HueSaturationEffect (IServiceProvider services) EffectData = new HueSaturationData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); private UnaryPixelOp CreateOptimalOp () diff --git a/Pinta.Effects/Adjustments/LevelsEffect.cs b/Pinta.Effects/Adjustments/LevelsEffect.cs index dd20240d80..c850a6dbb6 100644 --- a/Pinta.Effects/Adjustments/LevelsEffect.cs +++ b/Pinta.Effects/Adjustments/LevelsEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; @@ -40,23 +41,23 @@ public LevelsEffect (IServiceProvider services) EffectData = new LevelsData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () { + TaskCompletionSource completionSource = new (); + LevelsDialog dialog = new (chrome, workspace, Data) { Title = Name, IconName = Icon, }; dialog.OnResponse += (_, args) => { - - if (args.ResponseId == (int) Gtk.ResponseType.None) - return; - - OnConfigDialogResponse (args.ResponseId == (int) Gtk.ResponseType.Ok); + completionSource.SetResult ((Gtk.ResponseType) args.ResponseId); dialog.Destroy (); }; dialog.Present (); + + return completionSource.Task; } public override void Render (ImageSurface src, ImageSurface dest, ReadOnlySpan rois) diff --git a/Pinta.Effects/Adjustments/PosterizeEffect.cs b/Pinta.Effects/Adjustments/PosterizeEffect.cs index a4955b47fc..4b552b2566 100644 --- a/Pinta.Effects/Adjustments/PosterizeEffect.cs +++ b/Pinta.Effects/Adjustments/PosterizeEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; @@ -38,20 +39,24 @@ public PosterizeEffect (IServiceProvider services) EffectData = new PosterizeData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () { + TaskCompletionSource completionSource = new (); + PosterizeDialog dialog = new (chrome) { Title = Name, IconName = Icon, - EffectData = Data + EffectData = Data, }; dialog.OnResponse += (_, args) => { - OnConfigDialogResponse (args.ResponseId == (int) Gtk.ResponseType.Ok); + completionSource.SetResult ((Gtk.ResponseType) args.ResponseId); dialog.Destroy (); }; dialog.Present (); + + return completionSource.Task; } public override void Render (ImageSurface src, ImageSurface dest, ReadOnlySpan rois) diff --git a/Pinta.Effects/Effects/AddNoiseEffect.cs b/Pinta.Effects/Effects/AddNoiseEffect.cs index 4e6e1734e5..2b03240df8 100644 --- a/Pinta.Effects/Effects/AddNoiseEffect.cs +++ b/Pinta.Effects/Effects/AddNoiseEffect.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Immutable; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -42,7 +43,7 @@ public AddNoiseEffect (IServiceProvider services) EffectData = new NoiseData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/AlignObjectEffect.cs b/Pinta.Effects/Effects/AlignObjectEffect.cs index d73b733635..06a7912dc6 100644 --- a/Pinta.Effects/Effects/AlignObjectEffect.cs +++ b/Pinta.Effects/Effects/AlignObjectEffect.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -26,8 +27,10 @@ public AlignObjectEffect (IServiceProvider services) chrome = services.GetService (); EffectData = new AlignObjectData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () { + TaskCompletionSource completionSource = new (); + AlignmentDialog dialog = new (chrome); // Align to the default position @@ -36,11 +39,13 @@ public override void LaunchConfiguration () dialog.PositionChanged += (_, _) => Data.Position = dialog.SelectedPosition; dialog.OnResponse += (_, args) => { - OnConfigDialogResponse (args.ResponseId == (int) Gtk.ResponseType.Ok); + completionSource.SetResult ((Gtk.ResponseType) args.ResponseId); dialog.Destroy (); }; dialog.Present (); + + return completionSource.Task; } public override void Render (ImageSurface src, ImageSurface dest, ReadOnlySpan rois) diff --git a/Pinta.Effects/Effects/BulgeEffect.cs b/Pinta.Effects/Effects/BulgeEffect.cs index 66e784041a..4cdb03cac5 100644 --- a/Pinta.Effects/Effects/BulgeEffect.cs +++ b/Pinta.Effects/Effects/BulgeEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -36,7 +37,7 @@ public BulgeEffect (IServiceProvider services) EffectData = new BulgeData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/CloudsEffect.cs b/Pinta.Effects/Effects/CloudsEffect.cs index 1cf644fcea..f47188c8f5 100644 --- a/Pinta.Effects/Effects/CloudsEffect.cs +++ b/Pinta.Effects/Effects/CloudsEffect.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -50,7 +51,7 @@ public CloudsEffect (IServiceProvider services) EffectData = new CloudsData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/DitheringEffect.cs b/Pinta.Effects/Effects/DitheringEffect.cs index 5d9d7fcbfc..3d8c5129d0 100644 --- a/Pinta.Effects/Effects/DitheringEffect.cs +++ b/Pinta.Effects/Effects/DitheringEffect.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Immutable; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -24,7 +25,7 @@ public DitheringEffect (IServiceProvider services) EffectData = new DitheringData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); private sealed record DitheringSettings ( diff --git a/Pinta.Effects/Effects/EdgeDetectEffect.cs b/Pinta.Effects/Effects/EdgeDetectEffect.cs index f458eeeca6..634839fe3b 100644 --- a/Pinta.Effects/Effects/EdgeDetectEffect.cs +++ b/Pinta.Effects/Effects/EdgeDetectEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -41,7 +42,7 @@ public EdgeDetectEffect (IServiceProvider services) EffectData = new EdgeDetectData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); public override void Render (ImageSurface src, ImageSurface dest, ReadOnlySpan rois) diff --git a/Pinta.Effects/Effects/EmbossEffect.cs b/Pinta.Effects/Effects/EmbossEffect.cs index 591f40d9fc..f7e3e01a19 100644 --- a/Pinta.Effects/Effects/EmbossEffect.cs +++ b/Pinta.Effects/Effects/EmbossEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -41,7 +42,7 @@ public EmbossEffect (IServiceProvider services) EffectData = new EmbossData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/FeatherEffect.cs b/Pinta.Effects/Effects/FeatherEffect.cs index 8dd4e8a311..bb6993c8e8 100644 --- a/Pinta.Effects/Effects/FeatherEffect.cs +++ b/Pinta.Effects/Effects/FeatherEffect.cs @@ -34,7 +34,7 @@ public FeatherEffect (IServiceProvider services) EffectData = new FeatherData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); protected override void Render ( diff --git a/Pinta.Effects/Effects/FragmentEffect.cs b/Pinta.Effects/Effects/FragmentEffect.cs index b04de78a97..2d39ff4970 100644 --- a/Pinta.Effects/Effects/FragmentEffect.cs +++ b/Pinta.Effects/Effects/FragmentEffect.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Immutable; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -43,7 +44,7 @@ public FragmentEffect (IServiceProvider services) EffectData = new FragmentData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/FrostedGlassEffect.cs b/Pinta.Effects/Effects/FrostedGlassEffect.cs index 585277faed..1abadef6d2 100644 --- a/Pinta.Effects/Effects/FrostedGlassEffect.cs +++ b/Pinta.Effects/Effects/FrostedGlassEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -36,7 +37,7 @@ public FrostedGlassEffect (IServiceProvider services) EffectData = new FrostedGlassData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/GaussianBlurEffect.cs b/Pinta.Effects/Effects/GaussianBlurEffect.cs index bb671a3e37..6e46acd06b 100644 --- a/Pinta.Effects/Effects/GaussianBlurEffect.cs +++ b/Pinta.Effects/Effects/GaussianBlurEffect.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Immutable; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -37,7 +38,7 @@ public GaussianBlurEffect (IServiceProvider services) EffectData = new GaussianBlurData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/GlowEffect.cs b/Pinta.Effects/Effects/GlowEffect.cs index b24eb01edd..c6f3d0a480 100644 --- a/Pinta.Effects/Effects/GlowEffect.cs +++ b/Pinta.Effects/Effects/GlowEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -41,7 +42,7 @@ public GlowEffect (IServiceProvider services) this.services = services; } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/InkSketchEffect.cs b/Pinta.Effects/Effects/InkSketchEffect.cs index e46c0f4c96..46489dc726 100644 --- a/Pinta.Effects/Effects/InkSketchEffect.cs +++ b/Pinta.Effects/Effects/InkSketchEffect.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Immutable; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -60,7 +61,7 @@ static InkSketchEffect () ); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/JuliaFractalEffect.cs b/Pinta.Effects/Effects/JuliaFractalEffect.cs index 5f562d9465..3436b0b6b5 100644 --- a/Pinta.Effects/Effects/JuliaFractalEffect.cs +++ b/Pinta.Effects/Effects/JuliaFractalEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -44,7 +45,7 @@ public JuliaFractalEffect (IServiceProvider services) EffectData = new JuliaFractalData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/MandelbrotFractalEffect.cs b/Pinta.Effects/Effects/MandelbrotFractalEffect.cs index 650c948dcf..e6e844123d 100644 --- a/Pinta.Effects/Effects/MandelbrotFractalEffect.cs +++ b/Pinta.Effects/Effects/MandelbrotFractalEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -45,7 +46,7 @@ public MandelbrotFractalEffect (IServiceProvider services) EffectData = new MandelbrotFractalData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/MedianEffect.cs b/Pinta.Effects/Effects/MedianEffect.cs index c53d14b5f7..b8011761de 100644 --- a/Pinta.Effects/Effects/MedianEffect.cs +++ b/Pinta.Effects/Effects/MedianEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -39,7 +40,7 @@ public MedianEffect (IServiceProvider services) EffectData = new MedianData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/MotionBlurEffect.cs b/Pinta.Effects/Effects/MotionBlurEffect.cs index 8ac2bdaf8b..3d4c2bc4a5 100644 --- a/Pinta.Effects/Effects/MotionBlurEffect.cs +++ b/Pinta.Effects/Effects/MotionBlurEffect.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Immutable; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -43,7 +44,7 @@ public MotionBlurEffect (IServiceProvider services) EffectData = new MotionBlurData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/OilPaintingEffect.cs b/Pinta.Effects/Effects/OilPaintingEffect.cs index 00a024d85a..148297a7d1 100644 --- a/Pinta.Effects/Effects/OilPaintingEffect.cs +++ b/Pinta.Effects/Effects/OilPaintingEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -36,7 +37,7 @@ public OilPaintingEffect (IServiceProvider services) EffectData = new OilPaintingData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/OutlineEdgeEffect.cs b/Pinta.Effects/Effects/OutlineEdgeEffect.cs index e585ef9e42..2bb2beb92e 100644 --- a/Pinta.Effects/Effects/OutlineEdgeEffect.cs +++ b/Pinta.Effects/Effects/OutlineEdgeEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -39,7 +40,7 @@ public OutlineEdgeEffect (IServiceProvider services) EffectData = new OutlineEdgeData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/OutlineObjectEffect.cs b/Pinta.Effects/Effects/OutlineObjectEffect.cs index 0861ef3b44..561924abf6 100644 --- a/Pinta.Effects/Effects/OutlineObjectEffect.cs +++ b/Pinta.Effects/Effects/OutlineObjectEffect.cs @@ -36,7 +36,7 @@ public OutlineObjectEffect (IServiceProvider services) EffectData = new OutlineObjectData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); protected override void Render (ImageSurface src, ImageSurface dest, RectangleI roi) diff --git a/Pinta.Effects/Effects/PencilSketchEffect.cs b/Pinta.Effects/Effects/PencilSketchEffect.cs index 4c67eced07..095ce7333f 100644 --- a/Pinta.Effects/Effects/PencilSketchEffect.cs +++ b/Pinta.Effects/Effects/PencilSketchEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -49,7 +50,7 @@ public PencilSketchEffect (IServiceProvider services) color_dodge_op = new UserBlendOps.ColorDodgeBlendOp (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/PixelateEffect.cs b/Pinta.Effects/Effects/PixelateEffect.cs index 70d113d393..adebfeedd5 100644 --- a/Pinta.Effects/Effects/PixelateEffect.cs +++ b/Pinta.Effects/Effects/PixelateEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -37,7 +38,7 @@ public PixelateEffect (IServiceProvider services) EffectData = new PixelateData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/RadialBlurEffect.cs b/Pinta.Effects/Effects/RadialBlurEffect.cs index e6057b9bed..797d830369 100644 --- a/Pinta.Effects/Effects/RadialBlurEffect.cs +++ b/Pinta.Effects/Effects/RadialBlurEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -37,7 +38,7 @@ public RadialBlurEffect (IServiceProvider services) EffectData = new RadialBlurData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/RedEyeRemoveEffect.cs b/Pinta.Effects/Effects/RedEyeRemoveEffect.cs index e7ef363657..92a563f93d 100644 --- a/Pinta.Effects/Effects/RedEyeRemoveEffect.cs +++ b/Pinta.Effects/Effects/RedEyeRemoveEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -37,7 +38,7 @@ public RedEyeRemoveEffect (IServiceProvider services) EffectData = new RedEyeRemoveData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); public override void Render (ImageSurface src, ImageSurface dest, ReadOnlySpan rois) diff --git a/Pinta.Effects/Effects/ReduceNoiseEffect.cs b/Pinta.Effects/Effects/ReduceNoiseEffect.cs index a332b65739..4d6e2b724c 100644 --- a/Pinta.Effects/Effects/ReduceNoiseEffect.cs +++ b/Pinta.Effects/Effects/ReduceNoiseEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -40,7 +41,7 @@ public ReduceNoiseEffect (IServiceProvider services) EffectData = new ReduceNoiseData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/ReliefEffect.cs b/Pinta.Effects/Effects/ReliefEffect.cs index 0b9e6c356a..a3802b9e6e 100644 --- a/Pinta.Effects/Effects/ReliefEffect.cs +++ b/Pinta.Effects/Effects/ReliefEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Pinta.Core; using Pinta.Gui.Widgets; @@ -32,7 +33,7 @@ public ReliefEffect (IServiceProvider services) public override string EffectMenuCategory => Translations.GetString ("Stylize"); - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); public override string Icon => Pinta.Resources.Icons.EffectsStylizeRelief; diff --git a/Pinta.Effects/Effects/SharpenEffect.cs b/Pinta.Effects/Effects/SharpenEffect.cs index a5c893e0e5..653c5a8a7a 100644 --- a/Pinta.Effects/Effects/SharpenEffect.cs +++ b/Pinta.Effects/Effects/SharpenEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -37,7 +38,7 @@ public SharpenEffect (IServiceProvider services) EffectData = new SharpenData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); public override void Render (ImageSurface src, ImageSurface dest, ReadOnlySpan rois) diff --git a/Pinta.Effects/Effects/SoftenPortraitEffect.cs b/Pinta.Effects/Effects/SoftenPortraitEffect.cs index 8a021bd36a..b03d3e6c4d 100644 --- a/Pinta.Effects/Effects/SoftenPortraitEffect.cs +++ b/Pinta.Effects/Effects/SoftenPortraitEffect.cs @@ -34,6 +34,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -73,7 +74,7 @@ public SoftenPortraitEffect (IServiceProvider services) overlay_op = new UserBlendOps.OverlayBlendOp (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); private sealed record SoftenPortraitSettings ( diff --git a/Pinta.Effects/Effects/TileEffect.cs b/Pinta.Effects/Effects/TileEffect.cs index 1dee738304..b0a7f69739 100644 --- a/Pinta.Effects/Effects/TileEffect.cs +++ b/Pinta.Effects/Effects/TileEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -37,7 +38,7 @@ public TileEffect (IServiceProvider services) EffectData = new TileData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/TwistEffect.cs b/Pinta.Effects/Effects/TwistEffect.cs index 2a56b9a0cd..4fcded93fe 100644 --- a/Pinta.Effects/Effects/TwistEffect.cs +++ b/Pinta.Effects/Effects/TwistEffect.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Immutable; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -38,7 +39,7 @@ public TwistEffect (IServiceProvider services) EffectData = new TwistData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/UnfocusEffect.cs b/Pinta.Effects/Effects/UnfocusEffect.cs index af7b20b51e..e27752153d 100644 --- a/Pinta.Effects/Effects/UnfocusEffect.cs +++ b/Pinta.Effects/Effects/UnfocusEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -39,7 +40,7 @@ public UnfocusEffect (IServiceProvider services) EffectData = new UnfocusData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/VignetteEffect.cs b/Pinta.Effects/Effects/VignetteEffect.cs index bf3fada8b3..557c79482e 100644 --- a/Pinta.Effects/Effects/VignetteEffect.cs +++ b/Pinta.Effects/Effects/VignetteEffect.cs @@ -30,6 +30,7 @@ // THE SOFTWARE. using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -64,7 +65,7 @@ public VignetteEffect (IServiceProvider services) EffectData = new VignetteData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); private sealed record VignetteSettings ( diff --git a/Pinta.Effects/Effects/VoronoiDiagramEffect.cs b/Pinta.Effects/Effects/VoronoiDiagramEffect.cs index 22fdbf6b04..5a7d34f201 100644 --- a/Pinta.Effects/Effects/VoronoiDiagramEffect.cs +++ b/Pinta.Effects/Effects/VoronoiDiagramEffect.cs @@ -3,6 +3,7 @@ using System.Collections.Immutable; using System.ComponentModel; using System.Linq; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -36,7 +37,7 @@ public VoronoiDiagramEffect (IServiceProvider services) EffectData = new VoronoiDiagramData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); private sealed record VoronoiSettings ( diff --git a/Pinta.Effects/Effects/WarpEffect.cs b/Pinta.Effects/Effects/WarpEffect.cs index 4d801504e3..087e219874 100644 --- a/Pinta.Effects/Effects/WarpEffect.cs +++ b/Pinta.Effects/Effects/WarpEffect.cs @@ -9,6 +9,7 @@ using System; using System.Drawing; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -48,7 +49,7 @@ public WarpEffect () EffectData = new WarpData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => Chrome.LaunchSimpleEffectDialog (this); protected double DefaultRadius { get; private set; } = 0; diff --git a/Pinta.Effects/Effects/ZoomBlurEffect.cs b/Pinta.Effects/Effects/ZoomBlurEffect.cs index 6e82a61730..bbf0b2d68a 100644 --- a/Pinta.Effects/Effects/ZoomBlurEffect.cs +++ b/Pinta.Effects/Effects/ZoomBlurEffect.cs @@ -8,6 +8,7 @@ ///////////////////////////////////////////////////////////////////////////////// using System; +using System.Threading.Tasks; using Cairo; using Pinta.Core; using Pinta.Gui.Widgets; @@ -36,7 +37,7 @@ public ZoomBlurEffect (IServiceProvider services) EffectData = new ZoomBlurData (); } - public override void LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Utilities/EffectHelper.cs b/Pinta.Effects/Utilities/EffectHelper.cs index 2d8bcaed37..c6a05c450e 100644 --- a/Pinta.Effects/Utilities/EffectHelper.cs +++ b/Pinta.Effects/Utilities/EffectHelper.cs @@ -24,6 +24,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using System.Threading.Tasks; using Mono.Addins.Localization; using Pinta.Core; @@ -34,7 +35,7 @@ internal static class EffectHelper /// /// Launch an effect dialog using Pinta's translation template. /// - internal static void LaunchSimpleEffectDialog (this IChromeService chrome, BaseEffect effect) + internal static Task LaunchSimpleEffectDialog (this IChromeService chrome, BaseEffect effect) => chrome.LaunchSimpleEffectDialog (effect, new PintaLocalizer ()); } diff --git a/Pinta.Gui.Widgets/Dialogs/SimpleEffectDialog.cs b/Pinta.Gui.Widgets/Dialogs/SimpleEffectDialog.cs index 0152a73f71..a37dd9f31c 100644 --- a/Pinta.Gui.Widgets/Dialogs/SimpleEffectDialog.cs +++ b/Pinta.Gui.Widgets/Dialogs/SimpleEffectDialog.cs @@ -33,6 +33,7 @@ using System.ComponentModel; using System.Linq; using System.Reflection; +using System.Threading.Tasks; using Mono.Addins.Localization; using Pinta.Core; @@ -85,9 +86,12 @@ public SimpleEffectDialog ( /// The IAddinLocalizer provides a generic way to get translated strings both for /// Pinta's effects and for effect add-ins. /// - public static void Launch (BaseEffect effect, IAddinLocalizer localizer) + public static Task Launch (BaseEffect effect, IAddinLocalizer localizer) { - ArgumentNullException.ThrowIfNull (effect.EffectData); + if (effect.EffectData == null) + throw new ArgumentException ($"{effect.EffectData} should not be null", nameof (effect)); + + TaskCompletionSource responseCompletion = new (); SimpleEffectDialog dialog = new ( effect.Name, @@ -96,14 +100,16 @@ public static void Launch (BaseEffect effect, IAddinLocalizer localizer) localizer); // Hookup event handling for live preview. - dialog.EffectDataChanged += (o, e) => effect.EffectData?.FirePropertyChanged (e.PropertyName); + dialog.EffectDataChanged += (o, e) => effect.EffectData.FirePropertyChanged (e.PropertyName); dialog.OnResponse += (_, args) => { - effect.OnConfigDialogResponse (args.ResponseId == (int) Gtk.ResponseType.Ok); + responseCompletion.SetResult ((Gtk.ResponseType) args.ResponseId); dialog.Destroy (); }; dialog.Present (); + + return responseCompletion.Task; } public event PropertyChangedEventHandler? EffectDataChanged; diff --git a/tests/Pinta.Effects.Tests/Mocks/MockChromeManager.cs b/tests/Pinta.Effects.Tests/Mocks/MockChromeManager.cs index bcc469c993..f54a43c49b 100644 --- a/tests/Pinta.Effects.Tests/Mocks/MockChromeManager.cs +++ b/tests/Pinta.Effects.Tests/Mocks/MockChromeManager.cs @@ -1,5 +1,5 @@ using System; -using Gtk; +using System.Threading.Tasks; using Mono.Addins.Localization; using Pinta.Core; @@ -7,10 +7,10 @@ namespace Pinta.Effects; internal sealed class MockChromeManager : IChromeService { - public Window MainWindow => throw new NotImplementedException (); + public Gtk.Window MainWindow => throw new NotImplementedException (); - public void LaunchSimpleEffectDialog (BaseEffect effect, IAddinLocalizer localizer) + public Task LaunchSimpleEffectDialog (BaseEffect effect, IAddinLocalizer localizer) { - throw new System.NotImplementedException (); + throw new NotImplementedException (); } } diff --git a/tests/PintaBenchmarks/Mocks/MockChromeManager.cs b/tests/PintaBenchmarks/Mocks/MockChromeManager.cs index 5f744cb144..e33eca0557 100644 --- a/tests/PintaBenchmarks/Mocks/MockChromeManager.cs +++ b/tests/PintaBenchmarks/Mocks/MockChromeManager.cs @@ -1,4 +1,3 @@ -using Gtk; using Mono.Addins.Localization; using Pinta.Core; @@ -6,9 +5,9 @@ namespace PintaBenchmarks; internal sealed class MockChromeManager : IChromeService { - public Window MainWindow => throw new NotImplementedException (); + public Gtk.Window MainWindow => throw new NotImplementedException (); - public void LaunchSimpleEffectDialog (BaseEffect effect, IAddinLocalizer localizer) + public Task LaunchSimpleEffectDialog (BaseEffect effect, IAddinLocalizer localizer) { throw new NotImplementedException (); } From 46db3f2fee3acaeaa10f273a0dd89460cd01f855 Mon Sep 17 00:00:00 2001 From: Lehonti Ramos <17771375+Lehonti@users.noreply.github.com> Date: Thu, 3 Oct 2024 01:48:55 +0200 Subject: [PATCH 02/11] Fixed mixed up `Cancel` and `Apply` methods --- Pinta.Core/Managers/LivePreviewManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Pinta.Core/Managers/LivePreviewManager.cs b/Pinta.Core/Managers/LivePreviewManager.cs index 2fc86027fc..6610f63b63 100644 --- a/Pinta.Core/Managers/LivePreviewManager.cs +++ b/Pinta.Core/Managers/LivePreviewManager.cs @@ -141,9 +141,9 @@ public async void Start (BaseEffect effect) Gtk.ResponseType response = await effect.LaunchConfiguration (); chrome_manager.MainWindowBusy = true; if (response == Gtk.ResponseType.Ok) - Cancel (); - else Apply (); + else + Cancel (); } else { chrome_manager.MainWindowBusy = true; From 130c5691e404ffd89789bdc319a8a5ae58a1114a Mon Sep 17 00:00:00 2001 From: Lehonti Ramos <17771375+Lehonti@users.noreply.github.com> Date: Thu, 3 Oct 2024 01:52:20 +0200 Subject: [PATCH 03/11] Removed unused method --- Pinta.Core/Effects/BaseEffect.cs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Pinta.Core/Effects/BaseEffect.cs b/Pinta.Core/Effects/BaseEffect.cs index 79989b10df..c4c614ab98 100644 --- a/Pinta.Core/Effects/BaseEffect.cs +++ b/Pinta.Core/Effects/BaseEffect.cs @@ -92,18 +92,6 @@ public abstract class BaseEffect return Task.FromResult (Gtk.ResponseType.Ok); // Placeholder } - /// - /// Launches the standard configuration dialog for this effect. - /// - /// - /// The localizer for the effect add-in. This is used to fetch translations for the - /// strings in the dialog. - /// - protected Task LaunchSimpleEffectDialog (AddinLocalizer localizer) - { - return PintaCore.Chrome.LaunchSimpleEffectDialog (this, new AddinLocalizerWrapper (localizer)); - } - #region Overridable Render Methods /// /// Performs the actual work of rendering an effect. Do not call base.Render (). From 1ed6ba55f26353c218b9e17ffbc8844a5972da4d Mon Sep 17 00:00:00 2001 From: Lehonti Ramos <17771375+Lehonti@users.noreply.github.com> Date: Thu, 3 Oct 2024 12:10:57 +0200 Subject: [PATCH 04/11] Revert "Removed unused method" This reverts commit 130c5691e404ffd89789bdc319a8a5ae58a1114a. --- Pinta.Core/Effects/BaseEffect.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Pinta.Core/Effects/BaseEffect.cs b/Pinta.Core/Effects/BaseEffect.cs index c4c614ab98..79989b10df 100644 --- a/Pinta.Core/Effects/BaseEffect.cs +++ b/Pinta.Core/Effects/BaseEffect.cs @@ -92,6 +92,18 @@ public abstract class BaseEffect return Task.FromResult (Gtk.ResponseType.Ok); // Placeholder } + /// + /// Launches the standard configuration dialog for this effect. + /// + /// + /// The localizer for the effect add-in. This is used to fetch translations for the + /// strings in the dialog. + /// + protected Task LaunchSimpleEffectDialog (AddinLocalizer localizer) + { + return PintaCore.Chrome.LaunchSimpleEffectDialog (this, new AddinLocalizerWrapper (localizer)); + } + #region Overridable Render Methods /// /// Performs the actual work of rendering an effect. Do not call base.Render (). From 6bff15ec96f63589551e4772c6499cd0ca8369a5 Mon Sep 17 00:00:00 2001 From: Lehonti Ramos <17771375+Lehonti@users.noreply.github.com> Date: Thu, 3 Oct 2024 12:30:57 +0200 Subject: [PATCH 05/11] Changed return type of `LaunchConfiguration` from `Task` to `Task` --- Pinta.Core/Effects/BaseEffect.cs | 7 ++++--- Pinta.Core/Managers/ChromeManager.cs | 16 ++++------------ Pinta.Core/Managers/LivePreviewManager.cs | 4 ++-- .../Adjustments/BrightnessContrastEffect.cs | 2 +- Pinta.Effects/Adjustments/CurvesEffect.cs | 6 +++--- Pinta.Effects/Adjustments/HueSaturationEffect.cs | 2 +- Pinta.Effects/Adjustments/LevelsEffect.cs | 6 +++--- Pinta.Effects/Adjustments/PosterizeEffect.cs | 6 +++--- Pinta.Effects/Effects/AddNoiseEffect.cs | 2 +- Pinta.Effects/Effects/AlignObjectEffect.cs | 10 ++++++---- Pinta.Effects/Effects/BulgeEffect.cs | 2 +- Pinta.Effects/Effects/CloudsEffect.cs | 2 +- Pinta.Effects/Effects/DitheringEffect.cs | 2 +- Pinta.Effects/Effects/EdgeDetectEffect.cs | 2 +- Pinta.Effects/Effects/EmbossEffect.cs | 2 +- Pinta.Effects/Effects/FeatherEffect.cs | 2 +- Pinta.Effects/Effects/FragmentEffect.cs | 2 +- Pinta.Effects/Effects/FrostedGlassEffect.cs | 2 +- Pinta.Effects/Effects/GaussianBlurEffect.cs | 2 +- Pinta.Effects/Effects/GlowEffect.cs | 2 +- Pinta.Effects/Effects/InkSketchEffect.cs | 2 +- Pinta.Effects/Effects/JuliaFractalEffect.cs | 2 +- Pinta.Effects/Effects/MandelbrotFractalEffect.cs | 2 +- Pinta.Effects/Effects/MedianEffect.cs | 2 +- Pinta.Effects/Effects/MotionBlurEffect.cs | 2 +- Pinta.Effects/Effects/OilPaintingEffect.cs | 2 +- Pinta.Effects/Effects/OutlineEdgeEffect.cs | 2 +- Pinta.Effects/Effects/OutlineObjectEffect.cs | 2 +- Pinta.Effects/Effects/PencilSketchEffect.cs | 2 +- Pinta.Effects/Effects/PixelateEffect.cs | 2 +- Pinta.Effects/Effects/RadialBlurEffect.cs | 2 +- Pinta.Effects/Effects/RedEyeRemoveEffect.cs | 2 +- Pinta.Effects/Effects/ReduceNoiseEffect.cs | 2 +- Pinta.Effects/Effects/ReliefEffect.cs | 2 +- Pinta.Effects/Effects/SharpenEffect.cs | 2 +- Pinta.Effects/Effects/SoftenPortraitEffect.cs | 2 +- Pinta.Effects/Effects/TileEffect.cs | 2 +- Pinta.Effects/Effects/TwistEffect.cs | 2 +- Pinta.Effects/Effects/UnfocusEffect.cs | 2 +- Pinta.Effects/Effects/VignetteEffect.cs | 2 +- Pinta.Effects/Effects/VoronoiDiagramEffect.cs | 2 +- Pinta.Effects/Effects/WarpEffect.cs | 2 +- Pinta.Effects/Effects/ZoomBlurEffect.cs | 2 +- Pinta.Effects/Utilities/EffectHelper.cs | 2 +- Pinta.Gui.Widgets/Dialogs/SimpleEffectDialog.cs | 6 +++--- .../Mocks/MockChromeManager.cs | 2 +- tests/PintaBenchmarks/Mocks/MockChromeManager.cs | 2 +- 47 files changed, 67 insertions(+), 72 deletions(-) diff --git a/Pinta.Core/Effects/BaseEffect.cs b/Pinta.Core/Effects/BaseEffect.cs index 79989b10df..c714b1750f 100644 --- a/Pinta.Core/Effects/BaseEffect.cs +++ b/Pinta.Core/Effects/BaseEffect.cs @@ -84,12 +84,13 @@ public abstract class BaseEffect /// Launches the configuration dialog for this effect/adjustment. /// If IsConfigurable is true, the ConfigDialogResponse event will be invoked when the user accepts or cancels the dialog. /// - public virtual Task LaunchConfiguration () + /// Whether the user's response was positive or negative + public virtual Task LaunchConfiguration () { if (IsConfigurable) throw new NotImplementedException ($"{GetType ()} is marked as configurable, but has not implemented LaunchConfiguration"); - return Task.FromResult (Gtk.ResponseType.Ok); // Placeholder + return Task.FromResult (true); // Placeholder } /// @@ -99,7 +100,7 @@ public abstract class BaseEffect /// The localizer for the effect add-in. This is used to fetch translations for the /// strings in the dialog. /// - protected Task LaunchSimpleEffectDialog (AddinLocalizer localizer) + protected Task LaunchSimpleEffectDialog (AddinLocalizer localizer) { return PintaCore.Chrome.LaunchSimpleEffectDialog (this, new AddinLocalizerWrapper (localizer)); } diff --git a/Pinta.Core/Managers/ChromeManager.cs b/Pinta.Core/Managers/ChromeManager.cs index 23f83f9e9b..88cf22124e 100644 --- a/Pinta.Core/Managers/ChromeManager.cs +++ b/Pinta.Core/Managers/ChromeManager.cs @@ -33,7 +33,7 @@ namespace Pinta.Core; public interface IChromeService { Gtk.Window MainWindow { get; } - Task LaunchSimpleEffectDialog (BaseEffect effect, IAddinLocalizer localizer); + Task LaunchSimpleEffectDialog (BaseEffect effect, IAddinLocalizer localizer); } public sealed class ChromeManager : IChromeService @@ -60,11 +60,8 @@ public sealed class ChromeManager : IChromeService public Gio.Menu AdjustmentsMenu { get; private set; } = null!; public Gio.Menu EffectsMenu { get; private set; } = null!; - public ChromeManager () - { - } + public ChromeManager () { } - #region Public Properties public PointI LastCanvasCursorPoint { get => last_canvas_cursor_point; set { @@ -86,9 +83,7 @@ public bool MainWindowBusy { MainWindow.Cursor = Gdk.Cursor.NewFromName (Pinta.Resources.StandardCursors.Default, null); } } - #endregion - #region Public Methods public void InitializeApplication (Gtk.Application application) { Application = application; @@ -165,11 +160,10 @@ public void SetStatusBarText (string text) OnStatusBarTextChanged (text); } - public Task LaunchSimpleEffectDialog (BaseEffect effect, IAddinLocalizer localizer) + public Task LaunchSimpleEffectDialog (BaseEffect effect, IAddinLocalizer localizer) { return simple_effect_dialog_handler (effect, localizer); } - #endregion private void OnLastCanvasCursorPointChanged () { @@ -181,10 +175,8 @@ private void OnStatusBarTextChanged (string text) StatusBarTextChanged?.Invoke (this, new TextChangedEventArgs (text)); } - #region Public Events public event EventHandler? LastCanvasCursorPointChanged; public event EventHandler? StatusBarTextChanged; - #endregion } public interface IProgressDialog @@ -199,4 +191,4 @@ public interface IProgressDialog public delegate void ErrorDialogHandler (Gtk.Window parent, string message, string body, string details); public delegate void MessageDialogHandler (Gtk.Window parent, string message, string body); -public delegate Task SimpleEffectDialogHandler (BaseEffect effect, IAddinLocalizer localizer); +public delegate Task SimpleEffectDialogHandler (BaseEffect effect, IAddinLocalizer localizer); diff --git a/Pinta.Core/Managers/LivePreviewManager.cs b/Pinta.Core/Managers/LivePreviewManager.cs index 6610f63b63..b27d911602 100644 --- a/Pinta.Core/Managers/LivePreviewManager.cs +++ b/Pinta.Core/Managers/LivePreviewManager.cs @@ -138,9 +138,9 @@ public async void Start (BaseEffect effect) if (effect.IsConfigurable) { - Gtk.ResponseType response = await effect.LaunchConfiguration (); + bool response = await effect.LaunchConfiguration (); chrome_manager.MainWindowBusy = true; - if (response == Gtk.ResponseType.Ok) + if (response) Apply (); else Cancel (); diff --git a/Pinta.Effects/Adjustments/BrightnessContrastEffect.cs b/Pinta.Effects/Adjustments/BrightnessContrastEffect.cs index 0f7dd1488f..ced0d9e14e 100644 --- a/Pinta.Effects/Adjustments/BrightnessContrastEffect.cs +++ b/Pinta.Effects/Adjustments/BrightnessContrastEffect.cs @@ -51,7 +51,7 @@ void HandleEffectDataPropertyChanged (object? sender, System.ComponentModel.Prop table_calculated = false; } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); public override void Render (ImageSurface src, ImageSurface dest, ReadOnlySpan rois) diff --git a/Pinta.Effects/Adjustments/CurvesEffect.cs b/Pinta.Effects/Adjustments/CurvesEffect.cs index 3cae7854fc..a95dc56fe2 100644 --- a/Pinta.Effects/Adjustments/CurvesEffect.cs +++ b/Pinta.Effects/Adjustments/CurvesEffect.cs @@ -41,9 +41,9 @@ public CurvesEffect (IServiceProvider services) EffectData = new CurvesData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () { - TaskCompletionSource completionSource = new (); + TaskCompletionSource completionSource = new (); CurvesDialog dialog = new (chrome, Data) { Title = Name, @@ -51,7 +51,7 @@ public CurvesEffect (IServiceProvider services) }; dialog.OnResponse += (_, args) => { - completionSource.SetResult ((Gtk.ResponseType) args.ResponseId); + completionSource.SetResult (Gtk.ResponseType.Ok == (Gtk.ResponseType) args.ResponseId); dialog.Destroy (); }; diff --git a/Pinta.Effects/Adjustments/HueSaturationEffect.cs b/Pinta.Effects/Adjustments/HueSaturationEffect.cs index b39536bd1b..18c03ccf97 100644 --- a/Pinta.Effects/Adjustments/HueSaturationEffect.cs +++ b/Pinta.Effects/Adjustments/HueSaturationEffect.cs @@ -35,7 +35,7 @@ public HueSaturationEffect (IServiceProvider services) EffectData = new HueSaturationData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); private UnaryPixelOp CreateOptimalOp () diff --git a/Pinta.Effects/Adjustments/LevelsEffect.cs b/Pinta.Effects/Adjustments/LevelsEffect.cs index c850a6dbb6..80e8e62154 100644 --- a/Pinta.Effects/Adjustments/LevelsEffect.cs +++ b/Pinta.Effects/Adjustments/LevelsEffect.cs @@ -41,9 +41,9 @@ public LevelsEffect (IServiceProvider services) EffectData = new LevelsData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () { - TaskCompletionSource completionSource = new (); + TaskCompletionSource completionSource = new (); LevelsDialog dialog = new (chrome, workspace, Data) { Title = Name, @@ -51,7 +51,7 @@ public LevelsEffect (IServiceProvider services) }; dialog.OnResponse += (_, args) => { - completionSource.SetResult ((Gtk.ResponseType) args.ResponseId); + completionSource.SetResult (Gtk.ResponseType.Ok == (Gtk.ResponseType) args.ResponseId); dialog.Destroy (); }; diff --git a/Pinta.Effects/Adjustments/PosterizeEffect.cs b/Pinta.Effects/Adjustments/PosterizeEffect.cs index 4b552b2566..3d80850274 100644 --- a/Pinta.Effects/Adjustments/PosterizeEffect.cs +++ b/Pinta.Effects/Adjustments/PosterizeEffect.cs @@ -39,9 +39,9 @@ public PosterizeEffect (IServiceProvider services) EffectData = new PosterizeData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () { - TaskCompletionSource completionSource = new (); + TaskCompletionSource completionSource = new (); PosterizeDialog dialog = new (chrome) { Title = Name, @@ -50,7 +50,7 @@ public PosterizeEffect (IServiceProvider services) }; dialog.OnResponse += (_, args) => { - completionSource.SetResult ((Gtk.ResponseType) args.ResponseId); + completionSource.SetResult (Gtk.ResponseType.Ok == (Gtk.ResponseType) args.ResponseId); dialog.Destroy (); }; diff --git a/Pinta.Effects/Effects/AddNoiseEffect.cs b/Pinta.Effects/Effects/AddNoiseEffect.cs index 2b03240df8..a895d60b42 100644 --- a/Pinta.Effects/Effects/AddNoiseEffect.cs +++ b/Pinta.Effects/Effects/AddNoiseEffect.cs @@ -43,7 +43,7 @@ public AddNoiseEffect (IServiceProvider services) EffectData = new NoiseData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/AlignObjectEffect.cs b/Pinta.Effects/Effects/AlignObjectEffect.cs index 06a7912dc6..995f145ff1 100644 --- a/Pinta.Effects/Effects/AlignObjectEffect.cs +++ b/Pinta.Effects/Effects/AlignObjectEffect.cs @@ -27,19 +27,21 @@ public AlignObjectEffect (IServiceProvider services) chrome = services.GetService (); EffectData = new AlignObjectData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () { - TaskCompletionSource completionSource = new (); + TaskCompletionSource completionSource = new (); AlignmentDialog dialog = new (chrome); // Align to the default position Data.Position = dialog.SelectedPosition; - dialog.PositionChanged += (_, _) => Data.Position = dialog.SelectedPosition; + dialog.PositionChanged += (_, _) => { + Data.Position = dialog.SelectedPosition; + }; dialog.OnResponse += (_, args) => { - completionSource.SetResult ((Gtk.ResponseType) args.ResponseId); + completionSource.SetResult (Gtk.ResponseType.Ok == (Gtk.ResponseType) args.ResponseId); dialog.Destroy (); }; diff --git a/Pinta.Effects/Effects/BulgeEffect.cs b/Pinta.Effects/Effects/BulgeEffect.cs index 4cdb03cac5..bc6c0d8d33 100644 --- a/Pinta.Effects/Effects/BulgeEffect.cs +++ b/Pinta.Effects/Effects/BulgeEffect.cs @@ -37,7 +37,7 @@ public BulgeEffect (IServiceProvider services) EffectData = new BulgeData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/CloudsEffect.cs b/Pinta.Effects/Effects/CloudsEffect.cs index f47188c8f5..dd96bc7ac0 100644 --- a/Pinta.Effects/Effects/CloudsEffect.cs +++ b/Pinta.Effects/Effects/CloudsEffect.cs @@ -51,7 +51,7 @@ public CloudsEffect (IServiceProvider services) EffectData = new CloudsData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/DitheringEffect.cs b/Pinta.Effects/Effects/DitheringEffect.cs index 3d8c5129d0..e6677c0aa6 100644 --- a/Pinta.Effects/Effects/DitheringEffect.cs +++ b/Pinta.Effects/Effects/DitheringEffect.cs @@ -25,7 +25,7 @@ public DitheringEffect (IServiceProvider services) EffectData = new DitheringData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); private sealed record DitheringSettings ( diff --git a/Pinta.Effects/Effects/EdgeDetectEffect.cs b/Pinta.Effects/Effects/EdgeDetectEffect.cs index 634839fe3b..d75471deaa 100644 --- a/Pinta.Effects/Effects/EdgeDetectEffect.cs +++ b/Pinta.Effects/Effects/EdgeDetectEffect.cs @@ -42,7 +42,7 @@ public EdgeDetectEffect (IServiceProvider services) EffectData = new EdgeDetectData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); public override void Render (ImageSurface src, ImageSurface dest, ReadOnlySpan rois) diff --git a/Pinta.Effects/Effects/EmbossEffect.cs b/Pinta.Effects/Effects/EmbossEffect.cs index f7e3e01a19..d38f5b2f8d 100644 --- a/Pinta.Effects/Effects/EmbossEffect.cs +++ b/Pinta.Effects/Effects/EmbossEffect.cs @@ -42,7 +42,7 @@ public EmbossEffect (IServiceProvider services) EffectData = new EmbossData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/FeatherEffect.cs b/Pinta.Effects/Effects/FeatherEffect.cs index bb6993c8e8..21b437c6ca 100644 --- a/Pinta.Effects/Effects/FeatherEffect.cs +++ b/Pinta.Effects/Effects/FeatherEffect.cs @@ -34,7 +34,7 @@ public FeatherEffect (IServiceProvider services) EffectData = new FeatherData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); protected override void Render ( diff --git a/Pinta.Effects/Effects/FragmentEffect.cs b/Pinta.Effects/Effects/FragmentEffect.cs index 2d39ff4970..74b5222add 100644 --- a/Pinta.Effects/Effects/FragmentEffect.cs +++ b/Pinta.Effects/Effects/FragmentEffect.cs @@ -44,7 +44,7 @@ public FragmentEffect (IServiceProvider services) EffectData = new FragmentData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/FrostedGlassEffect.cs b/Pinta.Effects/Effects/FrostedGlassEffect.cs index 1abadef6d2..bbc647aba2 100644 --- a/Pinta.Effects/Effects/FrostedGlassEffect.cs +++ b/Pinta.Effects/Effects/FrostedGlassEffect.cs @@ -37,7 +37,7 @@ public FrostedGlassEffect (IServiceProvider services) EffectData = new FrostedGlassData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/GaussianBlurEffect.cs b/Pinta.Effects/Effects/GaussianBlurEffect.cs index 6e46acd06b..22fc48385a 100644 --- a/Pinta.Effects/Effects/GaussianBlurEffect.cs +++ b/Pinta.Effects/Effects/GaussianBlurEffect.cs @@ -38,7 +38,7 @@ public GaussianBlurEffect (IServiceProvider services) EffectData = new GaussianBlurData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/GlowEffect.cs b/Pinta.Effects/Effects/GlowEffect.cs index c6f3d0a480..e2f111430b 100644 --- a/Pinta.Effects/Effects/GlowEffect.cs +++ b/Pinta.Effects/Effects/GlowEffect.cs @@ -42,7 +42,7 @@ public GlowEffect (IServiceProvider services) this.services = services; } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/InkSketchEffect.cs b/Pinta.Effects/Effects/InkSketchEffect.cs index 46489dc726..2fc864ae6b 100644 --- a/Pinta.Effects/Effects/InkSketchEffect.cs +++ b/Pinta.Effects/Effects/InkSketchEffect.cs @@ -61,7 +61,7 @@ static InkSketchEffect () ); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/JuliaFractalEffect.cs b/Pinta.Effects/Effects/JuliaFractalEffect.cs index 3436b0b6b5..1d505fea2a 100644 --- a/Pinta.Effects/Effects/JuliaFractalEffect.cs +++ b/Pinta.Effects/Effects/JuliaFractalEffect.cs @@ -45,7 +45,7 @@ public JuliaFractalEffect (IServiceProvider services) EffectData = new JuliaFractalData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/MandelbrotFractalEffect.cs b/Pinta.Effects/Effects/MandelbrotFractalEffect.cs index e6e844123d..a037e27744 100644 --- a/Pinta.Effects/Effects/MandelbrotFractalEffect.cs +++ b/Pinta.Effects/Effects/MandelbrotFractalEffect.cs @@ -46,7 +46,7 @@ public MandelbrotFractalEffect (IServiceProvider services) EffectData = new MandelbrotFractalData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/MedianEffect.cs b/Pinta.Effects/Effects/MedianEffect.cs index b8011761de..ecdc1d6c46 100644 --- a/Pinta.Effects/Effects/MedianEffect.cs +++ b/Pinta.Effects/Effects/MedianEffect.cs @@ -40,7 +40,7 @@ public MedianEffect (IServiceProvider services) EffectData = new MedianData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/MotionBlurEffect.cs b/Pinta.Effects/Effects/MotionBlurEffect.cs index 3d4c2bc4a5..50881bdd38 100644 --- a/Pinta.Effects/Effects/MotionBlurEffect.cs +++ b/Pinta.Effects/Effects/MotionBlurEffect.cs @@ -44,7 +44,7 @@ public MotionBlurEffect (IServiceProvider services) EffectData = new MotionBlurData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/OilPaintingEffect.cs b/Pinta.Effects/Effects/OilPaintingEffect.cs index 148297a7d1..12740916f3 100644 --- a/Pinta.Effects/Effects/OilPaintingEffect.cs +++ b/Pinta.Effects/Effects/OilPaintingEffect.cs @@ -37,7 +37,7 @@ public OilPaintingEffect (IServiceProvider services) EffectData = new OilPaintingData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/OutlineEdgeEffect.cs b/Pinta.Effects/Effects/OutlineEdgeEffect.cs index 2bb2beb92e..e640f2dbf8 100644 --- a/Pinta.Effects/Effects/OutlineEdgeEffect.cs +++ b/Pinta.Effects/Effects/OutlineEdgeEffect.cs @@ -40,7 +40,7 @@ public OutlineEdgeEffect (IServiceProvider services) EffectData = new OutlineEdgeData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/OutlineObjectEffect.cs b/Pinta.Effects/Effects/OutlineObjectEffect.cs index 561924abf6..8b90a7f016 100644 --- a/Pinta.Effects/Effects/OutlineObjectEffect.cs +++ b/Pinta.Effects/Effects/OutlineObjectEffect.cs @@ -36,7 +36,7 @@ public OutlineObjectEffect (IServiceProvider services) EffectData = new OutlineObjectData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); protected override void Render (ImageSurface src, ImageSurface dest, RectangleI roi) diff --git a/Pinta.Effects/Effects/PencilSketchEffect.cs b/Pinta.Effects/Effects/PencilSketchEffect.cs index 095ce7333f..c672c83fc6 100644 --- a/Pinta.Effects/Effects/PencilSketchEffect.cs +++ b/Pinta.Effects/Effects/PencilSketchEffect.cs @@ -50,7 +50,7 @@ public PencilSketchEffect (IServiceProvider services) color_dodge_op = new UserBlendOps.ColorDodgeBlendOp (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/PixelateEffect.cs b/Pinta.Effects/Effects/PixelateEffect.cs index adebfeedd5..9c9bf7e690 100644 --- a/Pinta.Effects/Effects/PixelateEffect.cs +++ b/Pinta.Effects/Effects/PixelateEffect.cs @@ -38,7 +38,7 @@ public PixelateEffect (IServiceProvider services) EffectData = new PixelateData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/RadialBlurEffect.cs b/Pinta.Effects/Effects/RadialBlurEffect.cs index 797d830369..11fed5a39b 100644 --- a/Pinta.Effects/Effects/RadialBlurEffect.cs +++ b/Pinta.Effects/Effects/RadialBlurEffect.cs @@ -38,7 +38,7 @@ public RadialBlurEffect (IServiceProvider services) EffectData = new RadialBlurData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/RedEyeRemoveEffect.cs b/Pinta.Effects/Effects/RedEyeRemoveEffect.cs index 92a563f93d..c2533a1f3b 100644 --- a/Pinta.Effects/Effects/RedEyeRemoveEffect.cs +++ b/Pinta.Effects/Effects/RedEyeRemoveEffect.cs @@ -38,7 +38,7 @@ public RedEyeRemoveEffect (IServiceProvider services) EffectData = new RedEyeRemoveData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); public override void Render (ImageSurface src, ImageSurface dest, ReadOnlySpan rois) diff --git a/Pinta.Effects/Effects/ReduceNoiseEffect.cs b/Pinta.Effects/Effects/ReduceNoiseEffect.cs index 4d6e2b724c..7c0f2c61f7 100644 --- a/Pinta.Effects/Effects/ReduceNoiseEffect.cs +++ b/Pinta.Effects/Effects/ReduceNoiseEffect.cs @@ -41,7 +41,7 @@ public ReduceNoiseEffect (IServiceProvider services) EffectData = new ReduceNoiseData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/ReliefEffect.cs b/Pinta.Effects/Effects/ReliefEffect.cs index a3802b9e6e..d3ee6d8413 100644 --- a/Pinta.Effects/Effects/ReliefEffect.cs +++ b/Pinta.Effects/Effects/ReliefEffect.cs @@ -33,7 +33,7 @@ public ReliefEffect (IServiceProvider services) public override string EffectMenuCategory => Translations.GetString ("Stylize"); - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); public override string Icon => Pinta.Resources.Icons.EffectsStylizeRelief; diff --git a/Pinta.Effects/Effects/SharpenEffect.cs b/Pinta.Effects/Effects/SharpenEffect.cs index 653c5a8a7a..8dfd08ebd7 100644 --- a/Pinta.Effects/Effects/SharpenEffect.cs +++ b/Pinta.Effects/Effects/SharpenEffect.cs @@ -38,7 +38,7 @@ public SharpenEffect (IServiceProvider services) EffectData = new SharpenData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); public override void Render (ImageSurface src, ImageSurface dest, ReadOnlySpan rois) diff --git a/Pinta.Effects/Effects/SoftenPortraitEffect.cs b/Pinta.Effects/Effects/SoftenPortraitEffect.cs index b03d3e6c4d..8aee43911b 100644 --- a/Pinta.Effects/Effects/SoftenPortraitEffect.cs +++ b/Pinta.Effects/Effects/SoftenPortraitEffect.cs @@ -74,7 +74,7 @@ public SoftenPortraitEffect (IServiceProvider services) overlay_op = new UserBlendOps.OverlayBlendOp (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); private sealed record SoftenPortraitSettings ( diff --git a/Pinta.Effects/Effects/TileEffect.cs b/Pinta.Effects/Effects/TileEffect.cs index b0a7f69739..1e84412840 100644 --- a/Pinta.Effects/Effects/TileEffect.cs +++ b/Pinta.Effects/Effects/TileEffect.cs @@ -38,7 +38,7 @@ public TileEffect (IServiceProvider services) EffectData = new TileData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/TwistEffect.cs b/Pinta.Effects/Effects/TwistEffect.cs index 4fcded93fe..fcd7d7d3c3 100644 --- a/Pinta.Effects/Effects/TwistEffect.cs +++ b/Pinta.Effects/Effects/TwistEffect.cs @@ -39,7 +39,7 @@ public TwistEffect (IServiceProvider services) EffectData = new TwistData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/UnfocusEffect.cs b/Pinta.Effects/Effects/UnfocusEffect.cs index e27752153d..4d0d83b43c 100644 --- a/Pinta.Effects/Effects/UnfocusEffect.cs +++ b/Pinta.Effects/Effects/UnfocusEffect.cs @@ -40,7 +40,7 @@ public UnfocusEffect (IServiceProvider services) EffectData = new UnfocusData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Effects/VignetteEffect.cs b/Pinta.Effects/Effects/VignetteEffect.cs index 557c79482e..8d1ecb45c7 100644 --- a/Pinta.Effects/Effects/VignetteEffect.cs +++ b/Pinta.Effects/Effects/VignetteEffect.cs @@ -65,7 +65,7 @@ public VignetteEffect (IServiceProvider services) EffectData = new VignetteData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); private sealed record VignetteSettings ( diff --git a/Pinta.Effects/Effects/VoronoiDiagramEffect.cs b/Pinta.Effects/Effects/VoronoiDiagramEffect.cs index 5a7d34f201..e9805dd6be 100644 --- a/Pinta.Effects/Effects/VoronoiDiagramEffect.cs +++ b/Pinta.Effects/Effects/VoronoiDiagramEffect.cs @@ -37,7 +37,7 @@ public VoronoiDiagramEffect (IServiceProvider services) EffectData = new VoronoiDiagramData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); private sealed record VoronoiSettings ( diff --git a/Pinta.Effects/Effects/WarpEffect.cs b/Pinta.Effects/Effects/WarpEffect.cs index 087e219874..4bcf748575 100644 --- a/Pinta.Effects/Effects/WarpEffect.cs +++ b/Pinta.Effects/Effects/WarpEffect.cs @@ -49,7 +49,7 @@ public WarpEffect () EffectData = new WarpData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => Chrome.LaunchSimpleEffectDialog (this); protected double DefaultRadius { get; private set; } = 0; diff --git a/Pinta.Effects/Effects/ZoomBlurEffect.cs b/Pinta.Effects/Effects/ZoomBlurEffect.cs index bbf0b2d68a..64a00146d7 100644 --- a/Pinta.Effects/Effects/ZoomBlurEffect.cs +++ b/Pinta.Effects/Effects/ZoomBlurEffect.cs @@ -37,7 +37,7 @@ public ZoomBlurEffect (IServiceProvider services) EffectData = new ZoomBlurData (); } - public override Task LaunchConfiguration () + public override Task LaunchConfiguration () => chrome.LaunchSimpleEffectDialog (this); #region Algorithm Code Ported From PDN diff --git a/Pinta.Effects/Utilities/EffectHelper.cs b/Pinta.Effects/Utilities/EffectHelper.cs index c6a05c450e..1866bda0f5 100644 --- a/Pinta.Effects/Utilities/EffectHelper.cs +++ b/Pinta.Effects/Utilities/EffectHelper.cs @@ -35,7 +35,7 @@ internal static class EffectHelper /// /// Launch an effect dialog using Pinta's translation template. /// - internal static Task LaunchSimpleEffectDialog (this IChromeService chrome, BaseEffect effect) + internal static Task LaunchSimpleEffectDialog (this IChromeService chrome, BaseEffect effect) => chrome.LaunchSimpleEffectDialog (effect, new PintaLocalizer ()); } diff --git a/Pinta.Gui.Widgets/Dialogs/SimpleEffectDialog.cs b/Pinta.Gui.Widgets/Dialogs/SimpleEffectDialog.cs index a37dd9f31c..7594ab4820 100644 --- a/Pinta.Gui.Widgets/Dialogs/SimpleEffectDialog.cs +++ b/Pinta.Gui.Widgets/Dialogs/SimpleEffectDialog.cs @@ -86,12 +86,12 @@ public SimpleEffectDialog ( /// The IAddinLocalizer provides a generic way to get translated strings both for /// Pinta's effects and for effect add-ins. /// - public static Task Launch (BaseEffect effect, IAddinLocalizer localizer) + public static Task Launch (BaseEffect effect, IAddinLocalizer localizer) { if (effect.EffectData == null) throw new ArgumentException ($"{effect.EffectData} should not be null", nameof (effect)); - TaskCompletionSource responseCompletion = new (); + TaskCompletionSource responseCompletion = new (); SimpleEffectDialog dialog = new ( effect.Name, @@ -103,7 +103,7 @@ public SimpleEffectDialog ( dialog.EffectDataChanged += (o, e) => effect.EffectData.FirePropertyChanged (e.PropertyName); dialog.OnResponse += (_, args) => { - responseCompletion.SetResult ((Gtk.ResponseType) args.ResponseId); + responseCompletion.SetResult (Gtk.ResponseType.Ok == (Gtk.ResponseType) args.ResponseId); dialog.Destroy (); }; diff --git a/tests/Pinta.Effects.Tests/Mocks/MockChromeManager.cs b/tests/Pinta.Effects.Tests/Mocks/MockChromeManager.cs index f54a43c49b..ff229b7947 100644 --- a/tests/Pinta.Effects.Tests/Mocks/MockChromeManager.cs +++ b/tests/Pinta.Effects.Tests/Mocks/MockChromeManager.cs @@ -9,7 +9,7 @@ internal sealed class MockChromeManager : IChromeService { public Gtk.Window MainWindow => throw new NotImplementedException (); - public Task LaunchSimpleEffectDialog (BaseEffect effect, IAddinLocalizer localizer) + public Task LaunchSimpleEffectDialog (BaseEffect effect, IAddinLocalizer localizer) { throw new NotImplementedException (); } diff --git a/tests/PintaBenchmarks/Mocks/MockChromeManager.cs b/tests/PintaBenchmarks/Mocks/MockChromeManager.cs index e33eca0557..66cd271ca8 100644 --- a/tests/PintaBenchmarks/Mocks/MockChromeManager.cs +++ b/tests/PintaBenchmarks/Mocks/MockChromeManager.cs @@ -7,7 +7,7 @@ internal sealed class MockChromeManager : IChromeService { public Gtk.Window MainWindow => throw new NotImplementedException (); - public Task LaunchSimpleEffectDialog (BaseEffect effect, IAddinLocalizer localizer) + public Task LaunchSimpleEffectDialog (BaseEffect effect, IAddinLocalizer localizer) { throw new NotImplementedException (); } From c13f80f204e14671c57520a8b258c7449c9709a4 Mon Sep 17 00:00:00 2001 From: Lehonti Ramos <17771375+Lehonti@users.noreply.github.com> Date: Thu, 3 Oct 2024 12:57:34 +0200 Subject: [PATCH 06/11] Changed signature of `MessageDialogHandler` --- Pinta.Core/Managers/ChromeManager.cs | 6 +++--- Pinta.Effects/Effects/ReduceNoiseEffect.cs | 6 +++--- Pinta/Dialogs/ErrorDialog.cs | 12 ++++++++++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Pinta.Core/Managers/ChromeManager.cs b/Pinta.Core/Managers/ChromeManager.cs index 88cf22124e..34b7d558f3 100644 --- a/Pinta.Core/Managers/ChromeManager.cs +++ b/Pinta.Core/Managers/ChromeManager.cs @@ -150,9 +150,9 @@ public void ShowErrorDialog (Gtk.Window parent, string message, string body, str error_dialog_handler (parent, message, body, details); } - public void ShowMessageDialog (Gtk.Window parent, string message, string body) + public Task ShowMessageDialog (Gtk.Window parent, string message, string body) { - message_dialog_handler (parent, message, body); + return message_dialog_handler (parent, message, body); } public void SetStatusBarText (string text) @@ -190,5 +190,5 @@ public interface IProgressDialog } public delegate void ErrorDialogHandler (Gtk.Window parent, string message, string body, string details); -public delegate void MessageDialogHandler (Gtk.Window parent, string message, string body); +public delegate Task MessageDialogHandler (Gtk.Window parent, string message, string body); public delegate Task SimpleEffectDialogHandler (BaseEffect effect, IAddinLocalizer localizer); diff --git a/Pinta.Effects/Effects/ReduceNoiseEffect.cs b/Pinta.Effects/Effects/ReduceNoiseEffect.cs index 7c0f2c61f7..ffd0e9e4d3 100644 --- a/Pinta.Effects/Effects/ReduceNoiseEffect.cs +++ b/Pinta.Effects/Effects/ReduceNoiseEffect.cs @@ -20,7 +20,7 @@ public sealed class ReduceNoiseEffect : LocalHistogramEffect private int radius; private double strength; - public override string Icon => Pinta.Resources.Icons.EffectsNoiseReduceNoise; + public override string Icon => Resources.Icons.EffectsNoiseReduceNoise; public sealed override bool IsTileable => true; @@ -47,13 +47,13 @@ public override Task LaunchConfiguration () #region Algorithm Code Ported From PDN public override ColorBgra Apply (in ColorBgra color, int area, Span hb, Span hg, Span hr, Span ha) { - ColorBgra normalized = GetPercentileOfColor (color, area, hb, hg, hr, ha); + ColorBgra normalized = GetPercentileOfColor (color, area, hb, hg, hr); double lerp = strength * (1 - 0.75 * color.GetIntensity ()); return ColorBgra.Lerp (color, normalized, lerp); } - private static ColorBgra GetPercentileOfColor (ColorBgra color, int area, Span hb, Span hg, Span hr, Span ha) + private static ColorBgra GetPercentileOfColor (ColorBgra color, int area, Span hb, Span hg, Span hr) { int rc = 0; int gc = 0; diff --git a/Pinta/Dialogs/ErrorDialog.cs b/Pinta/Dialogs/ErrorDialog.cs index a0b8b083d0..731acc98dd 100644 --- a/Pinta/Dialogs/ErrorDialog.cs +++ b/Pinta/Dialogs/ErrorDialog.cs @@ -24,6 +24,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using System.Threading.Tasks; using Pinta.Core; namespace Pinta; @@ -36,21 +37,28 @@ internal ErrorDialog (HelpActions help) this.help = help; } - internal static void ShowMessage ( + internal static Task ShowMessage ( Gtk.Window parent, string message, string body) { + TaskCompletionSource completionSource = new (); + System.Console.Error.WriteLine ("Pinta: {0}\n{1}", message, body); - var dialog = Adw.MessageDialog.New (parent, message, body); + Adw.MessageDialog dialog = Adw.MessageDialog.New (parent, message, body); const string ok_response = "ok"; + dialog.AddResponse (ok_response, Translations.GetString ("_OK")); dialog.DefaultResponse = ok_response; dialog.CloseResponse = ok_response; + dialog.OnResponse += (_, _) => completionSource.SetResult (); + dialog.Present (); + + return completionSource.Task; } internal void ShowError ( From 8003a4ee3b02d48ddd30a02c8bbd4386b1215d52 Mon Sep 17 00:00:00 2001 From: Lehonti Ramos <17771375+Lehonti@users.noreply.github.com> Date: Thu, 3 Oct 2024 12:57:34 +0200 Subject: [PATCH 07/11] awaiting task of `ShowErrorDialog` in one placeChanged signature of `MessageDialogHandler` --- Pinta.Core/Managers/ChromeManager.cs | 6 +++--- Pinta.Effects/Effects/ReduceNoiseEffect.cs | 6 +++--- Pinta/Actions/File/NewScreenshotAction.cs | 6 +++--- Pinta/Dialogs/ErrorDialog.cs | 12 ++++++++++-- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Pinta.Core/Managers/ChromeManager.cs b/Pinta.Core/Managers/ChromeManager.cs index 88cf22124e..34b7d558f3 100644 --- a/Pinta.Core/Managers/ChromeManager.cs +++ b/Pinta.Core/Managers/ChromeManager.cs @@ -150,9 +150,9 @@ public void ShowErrorDialog (Gtk.Window parent, string message, string body, str error_dialog_handler (parent, message, body, details); } - public void ShowMessageDialog (Gtk.Window parent, string message, string body) + public Task ShowMessageDialog (Gtk.Window parent, string message, string body) { - message_dialog_handler (parent, message, body); + return message_dialog_handler (parent, message, body); } public void SetStatusBarText (string text) @@ -190,5 +190,5 @@ public interface IProgressDialog } public delegate void ErrorDialogHandler (Gtk.Window parent, string message, string body, string details); -public delegate void MessageDialogHandler (Gtk.Window parent, string message, string body); +public delegate Task MessageDialogHandler (Gtk.Window parent, string message, string body); public delegate Task SimpleEffectDialogHandler (BaseEffect effect, IAddinLocalizer localizer); diff --git a/Pinta.Effects/Effects/ReduceNoiseEffect.cs b/Pinta.Effects/Effects/ReduceNoiseEffect.cs index 7c0f2c61f7..ffd0e9e4d3 100644 --- a/Pinta.Effects/Effects/ReduceNoiseEffect.cs +++ b/Pinta.Effects/Effects/ReduceNoiseEffect.cs @@ -20,7 +20,7 @@ public sealed class ReduceNoiseEffect : LocalHistogramEffect private int radius; private double strength; - public override string Icon => Pinta.Resources.Icons.EffectsNoiseReduceNoise; + public override string Icon => Resources.Icons.EffectsNoiseReduceNoise; public sealed override bool IsTileable => true; @@ -47,13 +47,13 @@ public override Task LaunchConfiguration () #region Algorithm Code Ported From PDN public override ColorBgra Apply (in ColorBgra color, int area, Span hb, Span hg, Span hr, Span ha) { - ColorBgra normalized = GetPercentileOfColor (color, area, hb, hg, hr, ha); + ColorBgra normalized = GetPercentileOfColor (color, area, hb, hg, hr); double lerp = strength * (1 - 0.75 * color.GetIntensity ()); return ColorBgra.Lerp (color, normalized, lerp); } - private static ColorBgra GetPercentileOfColor (ColorBgra color, int area, Span hb, Span hg, Span hr, Span ha) + private static ColorBgra GetPercentileOfColor (ColorBgra color, int area, Span hb, Span hg, Span hr) { int rc = 0; int gc = 0; diff --git a/Pinta/Actions/File/NewScreenshotAction.cs b/Pinta/Actions/File/NewScreenshotAction.cs index 91c0549fd2..316b9d042b 100644 --- a/Pinta/Actions/File/NewScreenshotAction.cs +++ b/Pinta/Actions/File/NewScreenshotAction.cs @@ -82,7 +82,7 @@ private async void Activated (object sender, EventArgs args) } catch (NoHandlersForOSException e) { - chrome.ShowMessageDialog ( + await chrome.ShowMessageDialog ( chrome.MainWindow, e.Message, string.Empty); @@ -133,7 +133,7 @@ private async Task HandleX11 () } ); - var portal = systemConnection.CreateProxy ( + IScreenshot portal = systemConnection.CreateProxy ( "org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop"); @@ -141,7 +141,7 @@ private async Task HandleX11 () // However, the necessary functions are not correctly wrapped. // The empty string means that the compositor may unfortunately place the dialog wherever it pleases. // https://flatpak.github.io/xdg-desktop-portal/#parent_window - var rootWindowID = ""; + string rootWindowID = ""; // Enables options such as delay, specific windows, etc. Dictionary portalOptions = new () { diff --git a/Pinta/Dialogs/ErrorDialog.cs b/Pinta/Dialogs/ErrorDialog.cs index a0b8b083d0..731acc98dd 100644 --- a/Pinta/Dialogs/ErrorDialog.cs +++ b/Pinta/Dialogs/ErrorDialog.cs @@ -24,6 +24,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using System.Threading.Tasks; using Pinta.Core; namespace Pinta; @@ -36,21 +37,28 @@ internal ErrorDialog (HelpActions help) this.help = help; } - internal static void ShowMessage ( + internal static Task ShowMessage ( Gtk.Window parent, string message, string body) { + TaskCompletionSource completionSource = new (); + System.Console.Error.WriteLine ("Pinta: {0}\n{1}", message, body); - var dialog = Adw.MessageDialog.New (parent, message, body); + Adw.MessageDialog dialog = Adw.MessageDialog.New (parent, message, body); const string ok_response = "ok"; + dialog.AddResponse (ok_response, Translations.GetString ("_OK")); dialog.DefaultResponse = ok_response; dialog.CloseResponse = ok_response; + dialog.OnResponse += (_, _) => completionSource.SetResult (); + dialog.Present (); + + return completionSource.Task; } internal void ShowError ( From f93444a9fd790f190738d011fa50d6cbe8f08320 Mon Sep 17 00:00:00 2001 From: Lehonti Ramos <17771375+Lehonti@users.noreply.github.com> Date: Thu, 3 Oct 2024 13:15:45 +0200 Subject: [PATCH 08/11] awaiting in several sites --- Pinta.Core/Classes/Palette.cs | 11 ++++++----- Pinta/Actions/Edit/PasteAction.cs | 18 +++++++++--------- Pinta/Actions/Edit/PasteIntoNewImageAction.cs | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Pinta.Core/Classes/Palette.cs b/Pinta.Core/Classes/Palette.cs index 849a9a7735..ca51a08d2b 100644 --- a/Pinta.Core/Classes/Palette.cs +++ b/Pinta.Core/Classes/Palette.cs @@ -28,6 +28,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading.Tasks; using Cairo; using Gtk; @@ -140,7 +141,7 @@ private static IEnumerable EnumerateDefaultColors () yield return new (255 / 255f, 127 / 255f, 182 / 255f); } - public void Load (PaletteFormatManager paletteFormats, Gio.File file) + public async void Load (PaletteFormatManager paletteFormats, Gio.File file) { (var loadedColors, var errors) = LoadColors (paletteFormats, file); @@ -150,7 +151,7 @@ public void Load (PaletteFormatManager paletteFormats, Gio.File file) OnPaletteChanged (); } else { var parent = PintaCore.Chrome.MainWindow; - ShowUnsupportedFormatDialog (parent, file.GetParseName (), Translations.GetString ("Unsupported palette format"), errors); + await ShowUnsupportedFormatDialog (parent, file.GetParseName (), Translations.GetString ("Unsupported palette format"), errors); } } @@ -185,9 +186,9 @@ public void Save (Gio.File file, IPaletteSaver saver) saver.Save (colors, file); } - private static void ShowUnsupportedFormatDialog (Window parent, string filename, string message, string errors) + private static async Task ShowUnsupportedFormatDialog (Window parent, string filename, string message, string errors) { - var details = new StringBuilder (); + StringBuilder details = new (); details.AppendLine (Translations.GetString ("Could not open file: {0}", filename)); details.AppendLine (Translations.GetString ("Pinta supports the following palette formats:")); @@ -203,6 +204,6 @@ orderby extension details.AppendLine (); details.AppendLine (errors); - PintaCore.Chrome.ShowMessageDialog (parent, message, details.ToString ()); + await PintaCore.Chrome.ShowMessageDialog (parent, message, details.ToString ()); } } diff --git a/Pinta/Actions/Edit/PasteAction.cs b/Pinta/Actions/Edit/PasteAction.cs index 4884725153..b259e65ed7 100644 --- a/Pinta/Actions/Edit/PasteAction.cs +++ b/Pinta/Actions/Edit/PasteAction.cs @@ -115,24 +115,24 @@ public static async void Paste ( { // Create a compound history item for recording several // operations so that they can all be undone/redone together. - var history_text = toNewLayer ? Translations.GetString ("Paste Into New Layer") : Translations.GetString ("Paste"); + string history_text = toNewLayer ? Translations.GetString ("Paste Into New Layer") : Translations.GetString ("Paste"); CompoundHistoryItem paste_action = new (Resources.StandardIcons.EditPaste, history_text); - var cb = GdkExtensions.GetDefaultClipboard (); + Gdk.Clipboard clipboard = GdkExtensions.GetDefaultClipboard (); // See if the current tool wants to handle the paste // operation (e.g., the text tool could paste text) if (!toNewLayer) { - if (await tools.DoHandlePaste (doc, cb)) + if (await tools.DoHandlePaste (doc, clipboard)) return; } // Commit any unfinished tool actions tools.Commit (); - Gdk.Texture? cb_texture = await cb.ReadTextureAsync (); + Gdk.Texture? cb_texture = await clipboard.ReadTextureAsync (); if (cb_texture is null) { - ShowClipboardEmptyDialog (chrome); + await ShowClipboardEmptyDialog (chrome); return; } @@ -199,11 +199,11 @@ public static async void Paste ( doc.History.PushNewItem (paste_action); } - public static void ShowClipboardEmptyDialog (ChromeManager chrome) + public static async Task ShowClipboardEmptyDialog (ChromeManager chrome) { - var primary = Translations.GetString ("Image cannot be pasted"); - var secondary = Translations.GetString ("The clipboard does not contain an image."); - chrome.ShowMessageDialog (chrome.MainWindow, primary, secondary); + string primary = Translations.GetString ("Image cannot be pasted"); + string secondary = Translations.GetString ("The clipboard does not contain an image."); + await chrome.ShowMessageDialog (chrome.MainWindow, primary, secondary); } public static async Task ShowExpandCanvasDialog (ChromeManager chrome) diff --git a/Pinta/Actions/Edit/PasteIntoNewImageAction.cs b/Pinta/Actions/Edit/PasteIntoNewImageAction.cs index dfc4a577b3..76ac1d7646 100644 --- a/Pinta/Actions/Edit/PasteIntoNewImageAction.cs +++ b/Pinta/Actions/Edit/PasteIntoNewImageAction.cs @@ -62,6 +62,6 @@ private async void Activated (object sender, EventArgs e) if (cb_texture is not null) workspace.NewDocumentFromImage (actions, cb_texture.ToSurface ()); else - PasteAction.ShowClipboardEmptyDialog (chrome); + await PasteAction.ShowClipboardEmptyDialog (chrome); } } From c6a2be5fd9dc95db620f8c15610b065e1f8ee476 Mon Sep 17 00:00:00 2001 From: Lehonti Ramos <17771375+Lehonti@users.noreply.github.com> Date: Thu, 3 Oct 2024 13:23:51 +0200 Subject: [PATCH 09/11] Revert "awaiting in several sites" This reverts commit f93444a9fd790f190738d011fa50d6cbe8f08320. --- Pinta.Core/Classes/Palette.cs | 11 +++++------ Pinta/Actions/Edit/PasteAction.cs | 18 +++++++++--------- Pinta/Actions/Edit/PasteIntoNewImageAction.cs | 2 +- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Pinta.Core/Classes/Palette.cs b/Pinta.Core/Classes/Palette.cs index ca51a08d2b..849a9a7735 100644 --- a/Pinta.Core/Classes/Palette.cs +++ b/Pinta.Core/Classes/Palette.cs @@ -28,7 +28,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; using Cairo; using Gtk; @@ -141,7 +140,7 @@ private static IEnumerable EnumerateDefaultColors () yield return new (255 / 255f, 127 / 255f, 182 / 255f); } - public async void Load (PaletteFormatManager paletteFormats, Gio.File file) + public void Load (PaletteFormatManager paletteFormats, Gio.File file) { (var loadedColors, var errors) = LoadColors (paletteFormats, file); @@ -151,7 +150,7 @@ public async void Load (PaletteFormatManager paletteFormats, Gio.File file) OnPaletteChanged (); } else { var parent = PintaCore.Chrome.MainWindow; - await ShowUnsupportedFormatDialog (parent, file.GetParseName (), Translations.GetString ("Unsupported palette format"), errors); + ShowUnsupportedFormatDialog (parent, file.GetParseName (), Translations.GetString ("Unsupported palette format"), errors); } } @@ -186,9 +185,9 @@ public void Save (Gio.File file, IPaletteSaver saver) saver.Save (colors, file); } - private static async Task ShowUnsupportedFormatDialog (Window parent, string filename, string message, string errors) + private static void ShowUnsupportedFormatDialog (Window parent, string filename, string message, string errors) { - StringBuilder details = new (); + var details = new StringBuilder (); details.AppendLine (Translations.GetString ("Could not open file: {0}", filename)); details.AppendLine (Translations.GetString ("Pinta supports the following palette formats:")); @@ -204,6 +203,6 @@ orderby extension details.AppendLine (); details.AppendLine (errors); - await PintaCore.Chrome.ShowMessageDialog (parent, message, details.ToString ()); + PintaCore.Chrome.ShowMessageDialog (parent, message, details.ToString ()); } } diff --git a/Pinta/Actions/Edit/PasteAction.cs b/Pinta/Actions/Edit/PasteAction.cs index b259e65ed7..4884725153 100644 --- a/Pinta/Actions/Edit/PasteAction.cs +++ b/Pinta/Actions/Edit/PasteAction.cs @@ -115,24 +115,24 @@ public static async void Paste ( { // Create a compound history item for recording several // operations so that they can all be undone/redone together. - string history_text = toNewLayer ? Translations.GetString ("Paste Into New Layer") : Translations.GetString ("Paste"); + var history_text = toNewLayer ? Translations.GetString ("Paste Into New Layer") : Translations.GetString ("Paste"); CompoundHistoryItem paste_action = new (Resources.StandardIcons.EditPaste, history_text); - Gdk.Clipboard clipboard = GdkExtensions.GetDefaultClipboard (); + var cb = GdkExtensions.GetDefaultClipboard (); // See if the current tool wants to handle the paste // operation (e.g., the text tool could paste text) if (!toNewLayer) { - if (await tools.DoHandlePaste (doc, clipboard)) + if (await tools.DoHandlePaste (doc, cb)) return; } // Commit any unfinished tool actions tools.Commit (); - Gdk.Texture? cb_texture = await clipboard.ReadTextureAsync (); + Gdk.Texture? cb_texture = await cb.ReadTextureAsync (); if (cb_texture is null) { - await ShowClipboardEmptyDialog (chrome); + ShowClipboardEmptyDialog (chrome); return; } @@ -199,11 +199,11 @@ public static async void Paste ( doc.History.PushNewItem (paste_action); } - public static async Task ShowClipboardEmptyDialog (ChromeManager chrome) + public static void ShowClipboardEmptyDialog (ChromeManager chrome) { - string primary = Translations.GetString ("Image cannot be pasted"); - string secondary = Translations.GetString ("The clipboard does not contain an image."); - await chrome.ShowMessageDialog (chrome.MainWindow, primary, secondary); + var primary = Translations.GetString ("Image cannot be pasted"); + var secondary = Translations.GetString ("The clipboard does not contain an image."); + chrome.ShowMessageDialog (chrome.MainWindow, primary, secondary); } public static async Task ShowExpandCanvasDialog (ChromeManager chrome) diff --git a/Pinta/Actions/Edit/PasteIntoNewImageAction.cs b/Pinta/Actions/Edit/PasteIntoNewImageAction.cs index 76ac1d7646..dfc4a577b3 100644 --- a/Pinta/Actions/Edit/PasteIntoNewImageAction.cs +++ b/Pinta/Actions/Edit/PasteIntoNewImageAction.cs @@ -62,6 +62,6 @@ private async void Activated (object sender, EventArgs e) if (cb_texture is not null) workspace.NewDocumentFromImage (actions, cb_texture.ToSurface ()); else - await PasteAction.ShowClipboardEmptyDialog (chrome); + PasteAction.ShowClipboardEmptyDialog (chrome); } } From cb942b409230604b7d4fdfc1a23ddfec283314da Mon Sep 17 00:00:00 2001 From: Lehonti Ramos <17771375+Lehonti@users.noreply.github.com> Date: Thu, 3 Oct 2024 13:25:45 +0200 Subject: [PATCH 10/11] Revert "Changed signature of `MessageDialogHandler`" This reverts commit c13f80f204e14671c57520a8b258c7449c9709a4. --- Pinta.Core/Managers/ChromeManager.cs | 6 +++--- Pinta.Effects/Effects/ReduceNoiseEffect.cs | 6 +++--- Pinta/Dialogs/ErrorDialog.cs | 12 ++---------- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/Pinta.Core/Managers/ChromeManager.cs b/Pinta.Core/Managers/ChromeManager.cs index 34b7d558f3..88cf22124e 100644 --- a/Pinta.Core/Managers/ChromeManager.cs +++ b/Pinta.Core/Managers/ChromeManager.cs @@ -150,9 +150,9 @@ public void ShowErrorDialog (Gtk.Window parent, string message, string body, str error_dialog_handler (parent, message, body, details); } - public Task ShowMessageDialog (Gtk.Window parent, string message, string body) + public void ShowMessageDialog (Gtk.Window parent, string message, string body) { - return message_dialog_handler (parent, message, body); + message_dialog_handler (parent, message, body); } public void SetStatusBarText (string text) @@ -190,5 +190,5 @@ public interface IProgressDialog } public delegate void ErrorDialogHandler (Gtk.Window parent, string message, string body, string details); -public delegate Task MessageDialogHandler (Gtk.Window parent, string message, string body); +public delegate void MessageDialogHandler (Gtk.Window parent, string message, string body); public delegate Task SimpleEffectDialogHandler (BaseEffect effect, IAddinLocalizer localizer); diff --git a/Pinta.Effects/Effects/ReduceNoiseEffect.cs b/Pinta.Effects/Effects/ReduceNoiseEffect.cs index ffd0e9e4d3..7c0f2c61f7 100644 --- a/Pinta.Effects/Effects/ReduceNoiseEffect.cs +++ b/Pinta.Effects/Effects/ReduceNoiseEffect.cs @@ -20,7 +20,7 @@ public sealed class ReduceNoiseEffect : LocalHistogramEffect private int radius; private double strength; - public override string Icon => Resources.Icons.EffectsNoiseReduceNoise; + public override string Icon => Pinta.Resources.Icons.EffectsNoiseReduceNoise; public sealed override bool IsTileable => true; @@ -47,13 +47,13 @@ public override Task LaunchConfiguration () #region Algorithm Code Ported From PDN public override ColorBgra Apply (in ColorBgra color, int area, Span hb, Span hg, Span hr, Span ha) { - ColorBgra normalized = GetPercentileOfColor (color, area, hb, hg, hr); + ColorBgra normalized = GetPercentileOfColor (color, area, hb, hg, hr, ha); double lerp = strength * (1 - 0.75 * color.GetIntensity ()); return ColorBgra.Lerp (color, normalized, lerp); } - private static ColorBgra GetPercentileOfColor (ColorBgra color, int area, Span hb, Span hg, Span hr) + private static ColorBgra GetPercentileOfColor (ColorBgra color, int area, Span hb, Span hg, Span hr, Span ha) { int rc = 0; int gc = 0; diff --git a/Pinta/Dialogs/ErrorDialog.cs b/Pinta/Dialogs/ErrorDialog.cs index 731acc98dd..a0b8b083d0 100644 --- a/Pinta/Dialogs/ErrorDialog.cs +++ b/Pinta/Dialogs/ErrorDialog.cs @@ -24,7 +24,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -using System.Threading.Tasks; using Pinta.Core; namespace Pinta; @@ -37,28 +36,21 @@ internal ErrorDialog (HelpActions help) this.help = help; } - internal static Task ShowMessage ( + internal static void ShowMessage ( Gtk.Window parent, string message, string body) { - TaskCompletionSource completionSource = new (); - System.Console.Error.WriteLine ("Pinta: {0}\n{1}", message, body); - Adw.MessageDialog dialog = Adw.MessageDialog.New (parent, message, body); + var dialog = Adw.MessageDialog.New (parent, message, body); const string ok_response = "ok"; - dialog.AddResponse (ok_response, Translations.GetString ("_OK")); dialog.DefaultResponse = ok_response; dialog.CloseResponse = ok_response; - dialog.OnResponse += (_, _) => completionSource.SetResult (); - dialog.Present (); - - return completionSource.Task; } internal void ShowError ( From ec1d13629f6df919955bd7e9f5d05d2d6a59d0f2 Mon Sep 17 00:00:00 2001 From: Lehonti Ramos <17771375+Lehonti@users.noreply.github.com> Date: Thu, 3 Oct 2024 13:25:57 +0200 Subject: [PATCH 11/11] Revert "awaiting task of `ShowErrorDialog` in one placeChanged signature of `MessageDialogHandler`" This reverts commit 8003a4ee3b02d48ddd30a02c8bbd4386b1215d52. --- Pinta/Actions/File/NewScreenshotAction.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Pinta/Actions/File/NewScreenshotAction.cs b/Pinta/Actions/File/NewScreenshotAction.cs index 316b9d042b..91c0549fd2 100644 --- a/Pinta/Actions/File/NewScreenshotAction.cs +++ b/Pinta/Actions/File/NewScreenshotAction.cs @@ -82,7 +82,7 @@ private async void Activated (object sender, EventArgs args) } catch (NoHandlersForOSException e) { - await chrome.ShowMessageDialog ( + chrome.ShowMessageDialog ( chrome.MainWindow, e.Message, string.Empty); @@ -133,7 +133,7 @@ private async Task HandleX11 () } ); - IScreenshot portal = systemConnection.CreateProxy ( + var portal = systemConnection.CreateProxy ( "org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop"); @@ -141,7 +141,7 @@ private async Task HandleX11 () // However, the necessary functions are not correctly wrapped. // The empty string means that the compositor may unfortunately place the dialog wherever it pleases. // https://flatpak.github.io/xdg-desktop-portal/#parent_window - string rootWindowID = ""; + var rootWindowID = ""; // Enables options such as delay, specific windows, etc. Dictionary portalOptions = new () {