Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to the latest version of gir.core #488

Merged
merged 3 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="GirCore.Adw-1" Version="0.4.0" />
<PackageVersion Include="GirCore.Gtk-4.0" Version="0.4.0" />
<PackageVersion Include="GirCore.PangoCairo-1.0" Version="0.4.0" />
<PackageVersion Include="GirCore.Adw-1" Version="0.5.0-preview.2" />
<PackageVersion Include="GirCore.Gtk-4.0" Version="0.5.0-preview.2" />
<PackageVersion Include="GirCore.PangoCairo-1.0" Version="0.5.0-preview.2" />
<!-- Note: at least 1.4.2-alpha3 is required for fixes to uninstalling addins, from https://github.com/mono/mono-addins/pull/198 -->
<PackageVersion Include="Mono.Addins" Version="1.4.2-alpha.4" />
<PackageVersion Include="Mono.Addins.Setup" Version="1.4.2-alpha.4" />
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Core/Actions/LayerActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private void HandlePintaCoreActionsLayersImportFromFileActivated (object sender,

using var fs = file.Read (null);
try {
var bg = GdkPixbuf.Pixbuf.NewFromStream (fs, cancellable: null);
var bg = GdkPixbuf.Pixbuf.NewFromStream (fs, cancellable: null)!; // NRT: only nullable when an error is thrown
var context = new Cairo.Context (layer.Surface);
context.DrawPixbuf (bg, 0, 0);
} finally {
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Core/Classes/Re-editable/Text/TextEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public TextEngine Clone ()
State = State,
current_pos = current_pos,
selection_start = selection_start,
Font = Font.Copy (),
Font = Font.Copy ()!, // NRT: pango_font_description_copy only returns null when given nullptr
Alignment = Alignment,
Underline = Underline,
Origin = new PointI (Origin.X, Origin.Y)
Expand Down
38 changes: 20 additions & 18 deletions Pinta.Core/Extensions/GdkExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ public static Key ToUpper (this Key k1)

Gdk.Internal.Clipboard.ReadTextAsync (clipboard.Handle, IntPtr.Zero, new Gio.Internal.AsyncReadyCallbackAsyncHandler ((_, args, _) => {
string? result = Gdk.Internal.Clipboard.ReadTextFinish (clipboard.Handle, args.Handle, out var error).ConvertToString ();
GLib.Error.ThrowOnError (error);
if (!error.IsInvalid)
throw new GLib.GException (error);

tcs.SetResult (result);
}).NativeCallback, IntPtr.Zero);
Expand All @@ -201,11 +202,8 @@ public static Key ToUpper (this Key k1)

Texture? texture = texture = GObject.Internal.ObjectWrapper.WrapNullableHandle<Texture> (result, ownedRef: true);

try {
GLib.Error.ThrowOnError (error);
} catch (Exception) {
if (!error.IsInvalid)
texture = null;
}

tcs.SetResult (texture);
}).NativeCallback, IntPtr.Zero);
Expand Down Expand Up @@ -243,25 +241,29 @@ public unsafe static Cairo.ImageSurface ToSurface (this Gdk.Texture texture)
return surf;
}

// TODO-GTK4 (bindings) - structs are not generated (https://github.com/gircore/gir.core/issues/622)
public static nuint GetFileListGType () => Gdk.Internal.FileList.GetGType ();

// TODO-GTK4 (bindings) - structs are not generated (https://github.com/gircore/gir.core/issues/622)
public static Gio.File[] GetFiles (this Gdk.FileList file_list)
// TODO-GTK4 (bindings) - struct methods are not generated (https://github.com/gircore/gir.core/issues/622)
public static Gio.File[] GetFilesHelper (this Gdk.FileList file_list)
{
// FIXME: this is needed to avoid errors because SListOwnedHandle doesn't have a free function.
var slist_owned_handle = Gdk.Internal.FileList.GetFiles (file_list.Handle);
var slist_handle = new GLib.Internal.SListUnownedHandle (slist_owned_handle.DangerousGetHandle ());
slist_owned_handle.SetHandleAsInvalid ();
var slist = file_list.GetFiles ();

uint n = GLib.Internal.SList.Length (slist_handle);
uint n = GLib.Internal.SList.Length (slist.Handle);
var result = new Gio.File[n];
for (uint i = 0; i < n; ++i) {
result[i] = new Gio.FileHelper (GLib.Internal.SList.NthData (slist_handle, i), ownedRef: false);
result[i] = new Gio.FileHelper (GLib.Internal.SList.NthData (slist.Handle, i), ownedRef: false);
}

GLib.Internal.SList.Free (slist_handle);

return result;
}

/// <summary>
/// Wrapper for Gdk.Cursor.NewFromName which handles errors instead of returning null.
/// </summary>
public static Gdk.Cursor CursorFromName (string name)
{
var cursor = Gdk.Cursor.NewFromName (name, null);
if (cursor is null)
throw new ArgumentException ("Cursor does not exist", nameof (name));

return cursor;
}
}
10 changes: 5 additions & 5 deletions Pinta.Core/Extensions/GdkPixbufExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ static GdkPixbufExtensions ()
public static byte[] SaveToBuffer (this Pixbuf pixbuf, string type)
{
SaveToBufferv (pixbuf.Handle, out IntPtr buffer, out uint buffer_size, type, IntPtr.Zero, IntPtr.Zero, out var error);
GLib.Error.ThrowOnError (error);
if (!error.IsInvalid)
throw new GLib.GException (error);

var result = new byte[buffer_size];
Marshal.Copy (buffer, result, 0, (int) buffer_size);
Expand Down Expand Up @@ -86,13 +87,12 @@ public static bool IsWritable (this PixbufFormat format)
// TODO-GTK4 (bindings) - record methods are not generated (https://github.com/gircore/gir.core/issues/743)
public static string[] GetMimeTypes (this PixbufFormat format)
{
IntPtr resultNative = GetMimeTypes (format.Handle);
// FIXME - this does not free the result!
return GLib.Internal.StringHelper.ToStringArrayUtf8 (resultNative);
var result = GetMimeTypes (format.Handle);
return result.ConvertToStringArray () ?? Array.Empty<string> ();
}

[DllImport (PixbufLibraryName, EntryPoint = "gdk_pixbuf_format_get_mime_types")]
private static extern IntPtr GetMimeTypes (GdkPixbuf.Internal.PixbufFormatHandle format);
private static extern GLib.Internal.Utf8StringArrayNullTerminatedOwnedHandle GetMimeTypes (GdkPixbuf.Internal.PixbufFormatHandle format);

[DllImport (PixbufLibraryName, EntryPoint = "gdk_pixbuf_get_formats")]
private static extern GLib.Internal.SListUnownedHandle GetFormatsNative ();
Expand Down
8 changes: 4 additions & 4 deletions Pinta.Core/Extensions/GtkExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static MouseButton GetCurrentMouseButton (this Gtk.GestureClick gesture)
}

// TODO-GTK4 (bindings) - add pre-defined VariantType's to gir.core (https://github.com/gircore/gir.core/issues/843)
public static readonly GLib.VariantType IntVariantType = new ("i");
public static readonly GLib.VariantType IntVariantType = GLib.VariantType.New ("i");

/// <summary>
/// In GTK4, toolbars are just a Box with a different CSS style class.
Expand Down Expand Up @@ -289,7 +289,7 @@ public static bool FindString (this StringList list, string s, out uint index)
public static string RunBlocking (this Adw.MessageDialog dialog)
{
string response = "";
GLib.MainLoop loop = new ();
var loop = GLib.MainLoop.New (null, false);

if (!dialog.Modal)
dialog.Modal = true;
Expand All @@ -314,7 +314,7 @@ public static string RunBlocking (this Adw.MessageDialog dialog)
public static ResponseType RunBlocking (this Gtk.NativeDialog dialog)
{
var response = ResponseType.None;
GLib.MainLoop loop = new ();
var loop = GLib.MainLoop.New (null, false);

if (!dialog.Modal)
dialog.Modal = true;
Expand All @@ -339,7 +339,7 @@ public static ResponseType RunBlocking (this Gtk.NativeDialog dialog)
public static ResponseType RunBlocking (this Gtk.Dialog dialog)
{
var response = ResponseType.None;
GLib.MainLoop loop = new ();
var loop = GLib.MainLoop.New (null, false);

if (!dialog.Modal)
dialog.Modal = true;
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Core/ImageFormats/GdkPixbufFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void Import (Gio.File file, Gtk.Window parent)
// Handle any EXIF orientation flags
using (var fs = file.Read (cancellable: null)) {
try {
bg = Pixbuf.NewFromStream (fs, cancellable: null);
bg = Pixbuf.NewFromStream (fs, cancellable: null)!; // NRT: only nullable when an error is thrown
} finally {
fs.Close (null);
}
Expand Down
14 changes: 7 additions & 7 deletions Pinta.Core/ImageFormats/OraFormat.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
//
//
// OraFormat.cs
//
//
// Author:
// Maia Kozheva <[email protected]>
//
//
// Copyright (c) 2010 Maia Kozheva <[email protected]>
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -102,7 +102,7 @@ public void Import (Gio.File file, Gtk.Window parent)
layer.Opacity = double.Parse (GetAttribute (layerElement, "opacity", "1"), GetFormat ());
layer.BlendMode = StandardToBlendMode (GetAttribute (layerElement, "composite-op", "svg:src-over"));

var pb = GdkPixbuf.Pixbuf.NewFromFile (tmp_file);
var pb = GdkPixbuf.Pixbuf.NewFromFile (tmp_file)!; // NRT: only nullable when an error is thrown
var g = new Context (layer.Surface);
g.DrawPixbuf (pb, x, y);

Expand Down
4 changes: 2 additions & 2 deletions Pinta.Gui.Widgets/Widgets/Ruler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public Ruler (Orientation orientation)
SetDrawFunc ((area, context, width, height) => Draw (context, new Size (width, height)));

// Determine the size request, based on the font size.
int font_size = GetFontSize (GetPangoContext ().GetFontDescription (), ScaleFactor);
int font_size = GetFontSize (GetPangoContext ().GetFontDescription ()!, ScaleFactor);
int size = 2 + font_size * 2;

int width = 0;
Expand Down Expand Up @@ -210,7 +210,7 @@ private RulerDrawSettings CreateSettings (Size preliminarySize)
double max_size = scaled_upper - scaled_lower;

// There must be enough space between the large ticks for the text labels.
Pango.FontDescription font = GetPangoContext ().GetFontDescription ();
Pango.FontDescription font = GetPangoContext ().GetFontDescription ()!;
int font_size = GetFontSize (font, ScaleFactor);
int max_digits = ((int) -Math.Abs (max_size)).ToString ().Length;
int min_separation = max_digits * font_size * 2;
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Resources/ResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private static bool TryGetIconFromAssembly (Assembly assembly, string name, [Not
var buffer = new byte[stream.Length];
stream.Read (buffer, 0, buffer.Length);

var bytes = GLib.Bytes.From (buffer);
var bytes = GLib.Bytes.New (buffer);
image = Gdk.Texture.NewFromBytes (bytes);
}
} catch (Exception ex) {
Expand Down
16 changes: 8 additions & 8 deletions Pinta.Tools/Editable/EditEngines/BaseEditEngine.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
//
//
// BaseEditEngine.cs
//
//
// Author:
// Andrew Davis <[email protected]>
//
//
// Copyright (c) 2014 Andrew Davis, GSoC 2014
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -176,7 +176,7 @@ public ShapeEngine? SelectedShapeEngine {
SEngines.SelectMany (engine => engine.ControlPointHandles).Append (hover_handle);
private readonly MoveHandle hover_handle = new ();

private readonly Gdk.Cursor grab_cursor = Gdk.Cursor.NewFromName (Pinta.Resources.StandardCursors.Grab, null);
private readonly Gdk.Cursor grab_cursor = GdkExtensions.CursorFromName (Pinta.Resources.StandardCursors.Grab);

protected bool changing_tension = false;
protected PointD last_mouse_pos = new (0d, 0d);
Expand Down Expand Up @@ -353,7 +353,7 @@ public virtual void HandleBuildToolBar (Gtk.Box tb, ISettingsService settings, s
int previousSSI = SelectedShapeIndex;
ActivateCorrespondingTool (selEngine.ShapeType, true);
SelectedShapeIndex = previousSSI;
//Draw the updated shape with organized points generation (for mouse detection).
//Draw the updated shape with organized points generation (for mouse detection).
DrawActiveShape (true, false, true, false, true);
};
}
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Tools/Tools/TextTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ private void HandleSelectedLayerChanged (object? sender, EventArgs e)
private void UpdateFont ()
{
if (PintaCore.Workspace.HasOpenDocuments) {
var font = font_button.GetFontDesc ().Copy ();
var font = font_button.GetFontDesc ()!.Copy ()!; // NRT: Only nullable when nullptr is passed.
font.SetWeight (bold_btn.Active ? Pango.Weight.Bold : Pango.Weight.Normal);
font.SetStyle (italic_btn.Active ? Pango.Style.Italic : Pango.Style.Normal);

Expand Down
16 changes: 8 additions & 8 deletions Pinta.Tools/Tools/ZoomTool.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
//
//
// ZoomTool.cs
//
//
// Author:
// Olivier Dufour <[email protected]>
//
//
// Copyright (c) 2010 Olivier Dufour
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -46,8 +46,8 @@ public ZoomTool (IServiceManager services) : base (services)
{
mouse_down = MouseButton.None;

cursor_zoom_in = Gdk.Cursor.NewFromName (Pinta.Resources.StandardCursors.ZoomIn, null);
cursor_zoom_out = Gdk.Cursor.NewFromName (Pinta.Resources.StandardCursors.ZoomOut, null);
cursor_zoom_in = GdkExtensions.CursorFromName (Pinta.Resources.StandardCursors.ZoomIn);
cursor_zoom_out = GdkExtensions.CursorFromName (Pinta.Resources.StandardCursors.ZoomOut);
cursor_zoom = Gdk.Cursor.NewFromTexture (Resources.GetIcon (Pinta.Resources.Icons.ToolZoom), 0, 0, null);
cursor_zoom_pan = Gdk.Cursor.NewFromTexture (Resources.GetIcon (Pinta.Resources.Icons.ToolPan), 0, 0, null);
}
Expand Down
2 changes: 1 addition & 1 deletion Pinta/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private static void OpenMainWindow (IEnumerable<string> files)
};

// Run with a SynchronizationContext to integrate async methods with GLib.MainLoop.
app.RunWithSynchronizationContext ();
app.RunWithSynchronizationContext (null);
}

private static void OpenFilesFromCommandLine (IEnumerable<string> files)
Expand Down
6 changes: 3 additions & 3 deletions Pinta/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void Activate ()
PintaCore.Actions.App.BeforeQuit += delegate { SaveUserSettings (); };

// We support drag and drop for URIs, which are converted into a Gdk.FileList.
drop_target = Gtk.DropTarget.New (GdkExtensions.GetFileListGType (), Gdk.DragAction.Copy);
drop_target = Gtk.DropTarget.New (Gdk.FileList.GetGType (), Gdk.DragAction.Copy);
drop_target.OnDrop += HandleDrop;
window_shell.Window.AddController (drop_target);

Expand Down Expand Up @@ -495,10 +495,10 @@ private bool HandleCloseRequest (object o, EventArgs args)

private bool HandleDrop (DropTarget sender, DropTarget.DropSignalArgs args)
{
if (args.Value.GetBoxed (GdkExtensions.GetFileListGType ()) is not Gdk.FileList file_list)
if (args.Value.GetBoxed (Gdk.FileList.GetGType ()) is not Gdk.FileList file_list)
return false;

foreach (Gio.File file in file_list.GetFiles ()) {
foreach (Gio.File file in file_list.GetFilesHelper ()) {
PintaCore.Workspace.OpenFile (file);

if (file.GetUriScheme () is string scheme &&
Expand Down
2 changes: 1 addition & 1 deletion tests/Pinta.Effects.Tests/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static ImageSurface LoadImage (string image_name)

using var fs = file.Read (null);
try {
var bg = GdkPixbuf.Pixbuf.NewFromStream (fs, cancellable: null);
var bg = GdkPixbuf.Pixbuf.NewFromStream (fs, cancellable: null)!; // NRT: only nullable when error is thrown.
var surf = CairoExtensions.CreateImageSurface (Format.Argb32, bg.Width, bg.Height);
var context = new Cairo.Context (surf);
context.DrawPixbuf (bg, 0, 0);
Expand Down
2 changes: 1 addition & 1 deletion tests/PintaBenchmarks/Utilities/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static ImageSurface Get2000PixelImage ()

using var fs = file.Read (null);
try {
var bg = GdkPixbuf.Pixbuf.NewFromStream (fs, cancellable: null);
var bg = GdkPixbuf.Pixbuf.NewFromStream (fs, cancellable: null)!; // NRT: only nullable when error is thrown.
var surf = CairoExtensions.CreateImageSurface (Format.Argb32, bg.Width, bg.Height);
var context = new Cairo.Context (surf);
context.DrawPixbuf (bg, 0, 0);
Expand Down