Skip to content

Commit

Permalink
Changed return type of LaunchConfiguration from `Task<Gtk.ResponseT…
Browse files Browse the repository at this point in the history
…ype>` to `Task<bool>`
  • Loading branch information
Lehonti committed Oct 3, 2024
1 parent 1ed6ba5 commit 6bff15e
Show file tree
Hide file tree
Showing 47 changed files with 67 additions and 72 deletions.
7 changes: 4 additions & 3 deletions Pinta.Core/Effects/BaseEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
public virtual Task<Gtk.ResponseType> LaunchConfiguration ()
/// <returns>Whether the user's response was positive or negative</returns>
public virtual Task<bool> 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
}

/// <summary>
Expand All @@ -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.
/// </param>
protected Task<Gtk.ResponseType> LaunchSimpleEffectDialog (AddinLocalizer localizer)
protected Task<bool> LaunchSimpleEffectDialog (AddinLocalizer localizer)
{
return PintaCore.Chrome.LaunchSimpleEffectDialog (this, new AddinLocalizerWrapper (localizer));
}
Expand Down
16 changes: 4 additions & 12 deletions Pinta.Core/Managers/ChromeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Pinta.Core;
public interface IChromeService
{
Gtk.Window MainWindow { get; }
Task<Gtk.ResponseType> LaunchSimpleEffectDialog (BaseEffect effect, IAddinLocalizer localizer);
Task<bool> LaunchSimpleEffectDialog (BaseEffect effect, IAddinLocalizer localizer);
}

public sealed class ChromeManager : IChromeService
Expand All @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -165,11 +160,10 @@ public void SetStatusBarText (string text)
OnStatusBarTextChanged (text);
}

public Task<Gtk.ResponseType> LaunchSimpleEffectDialog (BaseEffect effect, IAddinLocalizer localizer)
public Task<bool> LaunchSimpleEffectDialog (BaseEffect effect, IAddinLocalizer localizer)
{
return simple_effect_dialog_handler (effect, localizer);
}
#endregion

private void OnLastCanvasCursorPointChanged ()
{
Expand All @@ -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<TextChangedEventArgs>? StatusBarTextChanged;
#endregion
}

public interface IProgressDialog
Expand All @@ -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<Gtk.ResponseType> SimpleEffectDialogHandler (BaseEffect effect, IAddinLocalizer localizer);
public delegate Task<bool> SimpleEffectDialogHandler (BaseEffect effect, IAddinLocalizer localizer);
4 changes: 2 additions & 2 deletions Pinta.Core/Managers/LivePreviewManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Adjustments/BrightnessContrastEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void HandleEffectDataPropertyChanged (object? sender, System.ComponentModel.Prop
table_calculated = false;
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

public override void Render (ImageSurface src, ImageSurface dest, ReadOnlySpan<RectangleI> rois)
Expand Down
6 changes: 3 additions & 3 deletions Pinta.Effects/Adjustments/CurvesEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ public CurvesEffect (IServiceProvider services)
EffectData = new CurvesData ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
{
TaskCompletionSource<Gtk.ResponseType> completionSource = new ();
TaskCompletionSource<bool> completionSource = new ();

CurvesDialog dialog = new (chrome, Data) {
Title = Name,
IconName = Icon,
};

dialog.OnResponse += (_, args) => {
completionSource.SetResult ((Gtk.ResponseType) args.ResponseId);
completionSource.SetResult (Gtk.ResponseType.Ok == (Gtk.ResponseType) args.ResponseId);
dialog.Destroy ();
};

Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Adjustments/HueSaturationEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public HueSaturationEffect (IServiceProvider services)
EffectData = new HueSaturationData ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

private UnaryPixelOp CreateOptimalOp ()
Expand Down
6 changes: 3 additions & 3 deletions Pinta.Effects/Adjustments/LevelsEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ public LevelsEffect (IServiceProvider services)
EffectData = new LevelsData ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
{
TaskCompletionSource<Gtk.ResponseType> completionSource = new ();
TaskCompletionSource<bool> completionSource = new ();

LevelsDialog dialog = new (chrome, workspace, Data) {
Title = Name,
IconName = Icon,
};

dialog.OnResponse += (_, args) => {
completionSource.SetResult ((Gtk.ResponseType) args.ResponseId);
completionSource.SetResult (Gtk.ResponseType.Ok == (Gtk.ResponseType) args.ResponseId);
dialog.Destroy ();
};

Expand Down
6 changes: 3 additions & 3 deletions Pinta.Effects/Adjustments/PosterizeEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public PosterizeEffect (IServiceProvider services)
EffectData = new PosterizeData ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
{
TaskCompletionSource<Gtk.ResponseType> completionSource = new ();
TaskCompletionSource<bool> completionSource = new ();

PosterizeDialog dialog = new (chrome) {
Title = Name,
Expand All @@ -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 ();
};

Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/AddNoiseEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public AddNoiseEffect (IServiceProvider services)
EffectData = new NoiseData ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

#region Algorithm Code Ported From PDN
Expand Down
10 changes: 6 additions & 4 deletions Pinta.Effects/Effects/AlignObjectEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,21 @@ public AlignObjectEffect (IServiceProvider services)
chrome = services.GetService<IChromeService> ();
EffectData = new AlignObjectData ();
}
public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
{
TaskCompletionSource<Gtk.ResponseType> completionSource = new ();
TaskCompletionSource<bool> 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 ();
};

Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/BulgeEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public BulgeEffect (IServiceProvider services)
EffectData = new BulgeData ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

#region Algorithm Code Ported From PDN
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/CloudsEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public CloudsEffect (IServiceProvider services)
EffectData = new CloudsData ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

#region Algorithm Code Ported From PDN
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/DitheringEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public DitheringEffect (IServiceProvider services)
EffectData = new DitheringData ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

private sealed record DitheringSettings (
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/EdgeDetectEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public EdgeDetectEffect (IServiceProvider services)
EffectData = new EdgeDetectData ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

public override void Render (ImageSurface src, ImageSurface dest, ReadOnlySpan<RectangleI> rois)
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/EmbossEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public EmbossEffect (IServiceProvider services)
EffectData = new EmbossData ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

#region Algorithm Code Ported From PDN
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/FeatherEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public FeatherEffect (IServiceProvider services)
EffectData = new FeatherData ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

protected override void Render (
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/FragmentEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public FragmentEffect (IServiceProvider services)
EffectData = new FragmentData ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

#region Algorithm Code Ported From PDN
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/FrostedGlassEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public FrostedGlassEffect (IServiceProvider services)
EffectData = new FrostedGlassData ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

#region Algorithm Code Ported From PDN
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/GaussianBlurEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public GaussianBlurEffect (IServiceProvider services)
EffectData = new GaussianBlurData ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

#region Algorithm Code Ported From PDN
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/GlowEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public GlowEffect (IServiceProvider services)
this.services = services;
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

#region Algorithm Code Ported From PDN
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/InkSketchEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static InkSketchEffect ()
);
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

#region Algorithm Code Ported From PDN
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/JuliaFractalEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public JuliaFractalEffect (IServiceProvider services)
EffectData = new JuliaFractalData ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

#region Algorithm Code Ported From PDN
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/MandelbrotFractalEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public MandelbrotFractalEffect (IServiceProvider services)
EffectData = new MandelbrotFractalData ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

#region Algorithm Code Ported From PDN
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/MedianEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public MedianEffect (IServiceProvider services)
EffectData = new MedianData ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

#region Algorithm Code Ported From PDN
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/MotionBlurEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public MotionBlurEffect (IServiceProvider services)
EffectData = new MotionBlurData ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

#region Algorithm Code Ported From PDN
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/OilPaintingEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public OilPaintingEffect (IServiceProvider services)
EffectData = new OilPaintingData ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

#region Algorithm Code Ported From PDN
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/OutlineEdgeEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public OutlineEdgeEffect (IServiceProvider services)
EffectData = new OutlineEdgeData ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

#region Algorithm Code Ported From PDN
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/OutlineObjectEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public OutlineObjectEffect (IServiceProvider services)
EffectData = new OutlineObjectData ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

protected override void Render (ImageSurface src, ImageSurface dest, RectangleI roi)
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/PencilSketchEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public PencilSketchEffect (IServiceProvider services)
color_dodge_op = new UserBlendOps.ColorDodgeBlendOp ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

#region Algorithm Code Ported From PDN
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/PixelateEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public PixelateEffect (IServiceProvider services)
EffectData = new PixelateData ();
}

public override Task<Gtk.ResponseType> LaunchConfiguration ()
public override Task<bool> LaunchConfiguration ()
=> chrome.LaunchSimpleEffectDialog (this);

#region Algorithm Code Ported From PDN
Expand Down
Loading

0 comments on commit 6bff15e

Please sign in to comment.