mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-12-22 20:25:35 +00:00
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:
parent
0915bf8076
commit
c362ad1468
|
@ -1,49 +1,49 @@
|
||||||
// Gtk.FileChooserNative.cs - Gtk FileChooserNative class customizations
|
// Gtk.FileChooserNative.cs - Gtk FileChooserNative class customizations
|
||||||
//
|
//
|
||||||
// Author: Mikkel Kruse Johnsen <mikkel@xmedicus.com>
|
// Author: Mikkel Kruse Johnsen <mikkel@xmedicus.com>
|
||||||
//
|
//
|
||||||
// Copyright (c) 2016 XMedicus ApS
|
// Copyright (c) 2016 XMedicus ApS
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or
|
// This program is free software; you can redistribute it and/or
|
||||||
// modify it under the terms of version 2 of the Lesser GNU General
|
// modify it under the terms of version 2 of the Lesser GNU General
|
||||||
// Public License as published by the Free Software Foundation.
|
// Public License as published by the Free Software Foundation.
|
||||||
//
|
//
|
||||||
// This program is distributed in the hope that it will be useful,
|
// This program is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
// Lesser General Public License for more details.
|
// Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
// License along with this program; if not, write to the
|
// License along with this program; if not, write to the
|
||||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
// Boston, MA 02111-1307, USA.
|
// Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
namespace Gtk {
|
namespace Gtk {
|
||||||
using GLib;
|
using GLib;
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
public partial class FileChooserNative : Gtk.NativeDialog, Gtk.IFileChooser {
|
public partial class FileChooserNative : Gtk.NativeDialog, Gtk.IFileChooser {
|
||||||
private FileChooserAdapter fileChooser;
|
private FileChooserAdapter fileChooser;
|
||||||
|
|
||||||
public FileChooserNative (IntPtr raw) : base(raw)
|
public FileChooserNative (IntPtr raw) : base(raw)
|
||||||
{
|
{
|
||||||
fileChooser = new FileChooserAdapter(raw);
|
fileChooser = new FileChooserAdapter(raw);
|
||||||
}
|
}
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
delegate IntPtr d_gtk_file_chooser_native_new(IntPtr title, IntPtr parent, int action, IntPtr accept_label, IntPtr cancel_label);
|
delegate IntPtr d_gtk_file_chooser_native_new(IntPtr title, IntPtr parent, int action, IntPtr accept_label, IntPtr cancel_label);
|
||||||
static d_gtk_file_chooser_native_new gtk_file_chooser_native_new = FuncLoader.LoadFunction<d_gtk_file_chooser_native_new>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_file_chooser_native_new"));
|
static d_gtk_file_chooser_native_new gtk_file_chooser_native_new = FuncLoader.LoadFunction<d_gtk_file_chooser_native_new>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_file_chooser_native_new"));
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
delegate string d_gtk_file_chooser_native_get_accept_label(IntPtr self);
|
delegate string d_gtk_file_chooser_native_get_accept_label(IntPtr self);
|
||||||
static d_gtk_file_chooser_native_get_accept_label gtk_file_chooser_native_get_accept_label = FuncLoader.LoadFunction<d_gtk_file_chooser_native_get_accept_label>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_file_chooser_native_get_accept_label"));
|
static d_gtk_file_chooser_native_get_accept_label gtk_file_chooser_native_get_accept_label = FuncLoader.LoadFunction<d_gtk_file_chooser_native_get_accept_label>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_file_chooser_native_get_accept_label"));
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
delegate string d_gtk_file_chooser_native_set_accept_label(IntPtr self, string accept_label);
|
delegate string d_gtk_file_chooser_native_set_accept_label(IntPtr self, string accept_label);
|
||||||
static d_gtk_file_chooser_native_set_accept_label gtk_file_chooser_native_set_accept_label = FuncLoader.LoadFunction<d_gtk_file_chooser_native_set_accept_label>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_file_chooser_native_set_accept_label"));
|
static d_gtk_file_chooser_native_set_accept_label gtk_file_chooser_native_set_accept_label = FuncLoader.LoadFunction<d_gtk_file_chooser_native_set_accept_label>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_file_chooser_native_set_accept_label"));
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
delegate string d_gtk_file_chooser_native_get_cancel_label(IntPtr self);
|
delegate string d_gtk_file_chooser_native_get_cancel_label(IntPtr self);
|
||||||
static d_gtk_file_chooser_native_get_cancel_label gtk_file_chooser_native_get_cancel_label = FuncLoader.LoadFunction<d_gtk_file_chooser_native_get_cancel_label>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_file_chooser_native_get_cancel_label"));
|
static d_gtk_file_chooser_native_get_cancel_label gtk_file_chooser_native_get_cancel_label = FuncLoader.LoadFunction<d_gtk_file_chooser_native_get_cancel_label>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_file_chooser_native_get_cancel_label"));
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
delegate string d_gtk_file_chooser_native_set_cancel_label(IntPtr self, string cancel_label);
|
delegate string d_gtk_file_chooser_native_set_cancel_label(IntPtr self, string cancel_label);
|
||||||
static d_gtk_file_chooser_native_set_cancel_label gtk_file_chooser_native_set_cancel_label = FuncLoader.LoadFunction<d_gtk_file_chooser_native_set_cancel_label>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_file_chooser_native_set_cancel_label"));
|
static d_gtk_file_chooser_native_set_cancel_label gtk_file_chooser_native_set_cancel_label = FuncLoader.LoadFunction<d_gtk_file_chooser_native_set_cancel_label>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Gtk), "gtk_file_chooser_native_set_cancel_label"));
|
||||||
|
|
||||||
public string CurrentFolder => fileChooser.CurrentFolder;
|
public string CurrentFolder => fileChooser.CurrentFolder;
|
||||||
|
@ -90,27 +90,27 @@ namespace Gtk {
|
||||||
public bool DoOverwriteConfirmation { get => fileChooser.DoOverwriteConfirmation; set => fileChooser.DoOverwriteConfirmation = value; }
|
public bool DoOverwriteConfirmation { get => fileChooser.DoOverwriteConfirmation; set => fileChooser.DoOverwriteConfirmation = value; }
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler FileActivated
|
public event EventHandler FileActivated
|
||||||
|
@ -178,26 +178,20 @@ 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;
|
IntPtr raw = gtk_file_chooser_native_new(native_title, parent != null ? parent.Handle : IntPtr.Zero, (int) action, native_accept_label, native_cancel_label);
|
||||||
if (cancel_label != null)
|
|
||||||
native_cancel_label = GLib.Marshaller.StringToPtrGStrdup (cancel_label);
|
GLib.Marshaller.Free(native_title);
|
||||||
|
GLib.Marshaller.Free(native_accept_label);
|
||||||
IntPtr raw = gtk_file_chooser_native_new(native_title, parent.Handle, (int) action, native_accept_label, native_cancel_label);
|
GLib.Marshaller.Free(native_cancel_label);
|
||||||
|
|
||||||
/*GLib.Marshaller.Free (native_title);
|
return raw;
|
||||||
if (accept_label != null)
|
}
|
||||||
GLib.Marshaller.Free (native_accept_label);
|
|
||||||
if (cancel_label != null)
|
|
||||||
GLib.Marshaller.Free (native_cancel_label);*/
|
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
@ -318,6 +312,5 @@ namespace Gtk {
|
||||||
{
|
{
|
||||||
fileChooser.UnselectUri(uri);
|
fileChooser.UnselectUri(uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue