FileChooserNative: allow null parent, free memory (#322)

* FileChooserNative: allow null parent, free memory

Also make consistent whitespaces, new lines.

* Re-run checks
This commit is contained in:
zii-dmg 2022-01-26 23:08:42 +03:00 committed by GitHub
parent 0915bf8076
commit c362ad1468
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -91,24 +91,24 @@ namespace Gtk {
public bool CreateFolders { get => fileChooser.CreateFolders; set => fileChooser.CreateFolders = value; } public bool CreateFolders { get => fileChooser.CreateFolders; set => fileChooser.CreateFolders = value; }
public FileChooserNative (string title, Gtk.Window parent, Gtk.FileChooserAction action, string accept_label, string cancel_label) : base(FileChooserNativeCreate(title, parent, action, accept_label, cancel_label)) public FileChooserNative (string title, Gtk.Window parent, Gtk.FileChooserAction action, string accept_label, string cancel_label) : base(FileChooserNativeCreate(title, parent, action, accept_label, cancel_label))
{ {
/* /*
if (GetType () != typeof (FileChooserNative)) { if (GetType () != typeof (FileChooserNative)) {
var vals = new List<GLib.Value> (); var vals = new List<GLib.Value> ();
var names = new List<string> (); var names = new List<string> ();
names.Add ("title"); names.Add ("title");
vals.Add (new GLib.Value (title)); vals.Add (new GLib.Value (title));
names.Add ("parent"); names.Add ("parent");
vals.Add (new GLib.Value (parent)); vals.Add (new GLib.Value (parent));
names.Add ("action"); names.Add ("action");
vals.Add (new GLib.Value (action)); vals.Add (new GLib.Value (action));
names.Add ("accept_label"); names.Add ("accept_label");
vals.Add (new GLib.Value (accept_label)); vals.Add (new GLib.Value (accept_label));
names.Add ("cancel_label"); names.Add ("cancel_label");
vals.Add (new GLib.Value (cancel_label)); vals.Add (new GLib.Value (cancel_label));
CreateNativeObject (names.ToArray (), vals.ToArray ()); CreateNativeObject (names.ToArray (), vals.ToArray ());
return; return;
} }
*/ */
fileChooser = new FileChooserAdapter(Handle); fileChooser = new FileChooserAdapter(Handle);
} }
@ -180,24 +180,18 @@ namespace Gtk {
static IntPtr FileChooserNativeCreate (string title, Gtk.Window parent, Gtk.FileChooserAction action, string accept_label, string cancel_label) static IntPtr FileChooserNativeCreate (string title, Gtk.Window parent, Gtk.FileChooserAction action, string accept_label, string cancel_label)
{ {
IntPtr native_title = GLib.Marshaller.StringToPtrGStrdup (title); IntPtr native_title = GLib.Marshaller.StringToPtrGStrdup(title);
IntPtr native_accept_label = IntPtr.Zero; IntPtr native_accept_label = GLib.Marshaller.StringToPtrGStrdup(accept_label);
if (accept_label != null) IntPtr native_cancel_label = GLib.Marshaller.StringToPtrGStrdup(cancel_label);
native_accept_label = GLib.Marshaller.StringToPtrGStrdup (accept_label);
IntPtr native_cancel_label = IntPtr.Zero;
if (cancel_label != null)
native_cancel_label = GLib.Marshaller.StringToPtrGStrdup (cancel_label);
IntPtr raw = gtk_file_chooser_native_new(native_title, parent.Handle, (int) action, native_accept_label, native_cancel_label); IntPtr raw = gtk_file_chooser_native_new(native_title, parent != null ? parent.Handle : IntPtr.Zero, (int) action, native_accept_label, native_cancel_label);
/*GLib.Marshaller.Free (native_title); GLib.Marshaller.Free(native_title);
if (accept_label != null) GLib.Marshaller.Free(native_accept_label);
GLib.Marshaller.Free (native_accept_label); GLib.Marshaller.Free(native_cancel_label);
if (cancel_label != null)
GLib.Marshaller.Free (native_cancel_label);*/
return raw; return raw;
} }
public void AddChoice(string id, string label, string options, string option_labels) public void AddChoice(string id, string label, string options, string option_labels)
{ {
@ -320,4 +314,3 @@ namespace Gtk {
} }
} }
} }