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] 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 (