Fixed FileChooserNative (I hope)

Changed NativeDialog to inherit from GLib.Object, as it does in the C API.

FileChooserNative seems to inherit multiple base classes in the C API,
which isn't possible in C#, but this solution is to mimic multiple
inheritance via a proxy FileChooserAdapter.
This commit is contained in:
Drew Holzworth 2020-07-22 09:49:47 +10:00
parent 42956bfc3e
commit ce11581485
No known key found for this signature in database
GPG key ID: FA9B48A867F57522
2 changed files with 246 additions and 12 deletions

View file

@ -19,13 +19,17 @@
// Boston, MA 02111-1307, USA. // Boston, MA 02111-1307, USA.
namespace Gtk { namespace Gtk {
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;
public FileChooserNative (IntPtr raw) : base(raw) {} public FileChooserNative (IntPtr raw) : base(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"));
@ -42,6 +46,50 @@ namespace Gtk {
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 IFile CurrentFolderFile => fileChooser.CurrentFolderFile;
public string CurrentFolderUri => fileChooser.CurrentFolderUri;
public string CurrentName { get => fileChooser.CurrentName; set => fileChooser.CurrentName = value; }
public IFile File => fileChooser.File;
public string Filename => fileChooser.Filename;
public string[] Filenames => fileChooser.Filenames;
public IFile[] Files => fileChooser.Files;
public IFile PreviewFile => fileChooser.PreviewFile;
public string PreviewFilename => fileChooser.PreviewFilename;
public string PreviewUri => fileChooser.PreviewUri;
public string Uri => fileChooser.Uri;
public string[] Uris => fileChooser.Uris;
public FileFilter[] Filters => fileChooser.Filters;
public string[] ShortcutFolderUris => fileChooser.ShortcutFolderUris;
public string[] ShortcutFolders => fileChooser.ShortcutFolders;
public FileChooserAction Action { get => fileChooser.Action; set => fileChooser.Action = value; }
public FileFilter Filter { get => fileChooser.Filter; set => fileChooser.Filter = value; }
public bool LocalOnly { get => fileChooser.LocalOnly; set => fileChooser.LocalOnly = value; }
public Widget PreviewWidget { get => fileChooser.PreviewWidget; set => fileChooser.PreviewWidget = value; }
public bool PreviewWidgetActive { get => fileChooser.PreviewWidgetActive; set => fileChooser.PreviewWidgetActive = value; }
public bool UsePreviewLabel { get => fileChooser.UsePreviewLabel; set => fileChooser.UsePreviewLabel = value; }
public Widget ExtraWidget { get => fileChooser.ExtraWidget; set => fileChooser.ExtraWidget = value; }
public bool SelectMultiple { get => fileChooser.SelectMultiple; set => fileChooser.SelectMultiple = value; }
public bool ShowHidden { get => fileChooser.ShowHidden; set => fileChooser.ShowHidden = value; }
public bool DoOverwriteConfirmation { get => fileChooser.DoOverwriteConfirmation; set => fileChooser.DoOverwriteConfirmation = 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))
{ {
/* /*
@ -62,6 +110,72 @@ namespace Gtk {
return; return;
} }
*/ */
fileChooser = new FileChooserAdapter(Handle);
}
public event EventHandler FileActivated
{
add
{
fileChooser.FileActivated += value;
}
remove
{
fileChooser.FileActivated -= value;
}
}
public event EventHandler SelectionChanged
{
add
{
fileChooser.SelectionChanged += value;
}
remove
{
fileChooser.SelectionChanged -= value;
}
}
public event EventHandler CurrentFolderChanged
{
add
{
fileChooser.CurrentFolderChanged += value;
}
remove
{
fileChooser.CurrentFolderChanged -= value;
}
}
public event ConfirmOverwriteHandler ConfirmOverwrite
{
add
{
fileChooser.ConfirmOverwrite += value;
}
remove
{
fileChooser.ConfirmOverwrite -= value;
}
}
public event EventHandler UpdatePreview
{
add
{
fileChooser.UpdatePreview += value;
}
remove
{
fileChooser.UpdatePreview -= value;
}
} }
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)
@ -84,6 +198,126 @@ namespace Gtk {
return raw; return raw;
} }
public void AddChoice(string id, string label, string options, string option_labels)
{
fileChooser.AddChoice(id, label, options, option_labels);
}
public void AddFilter(FileFilter filter)
{
fileChooser.AddFilter(filter);
}
public bool AddShortcutFolder(string folder)
{
return fileChooser.AddShortcutFolder(folder);
}
public bool AddShortcutFolderUri(string uri)
{
return fileChooser.AddShortcutFolderUri(uri);
}
public string GetChoice(string id)
{
return fileChooser.GetChoice(id);
}
public void RemoveChoice(string id)
{
fileChooser.RemoveChoice(id);
}
public void RemoveFilter(FileFilter filter)
{
fileChooser.RemoveFilter(filter);
}
public bool RemoveShortcutFolder(string folder)
{
return fileChooser.RemoveShortcutFolder(folder);
}
public bool RemoveShortcutFolderUri(string uri)
{
return fileChooser.RemoveShortcutFolderUri(uri);
}
public void SelectAll()
{
fileChooser.SelectAll();
}
public bool SelectFile(IFile file)
{
return fileChooser.SelectFile(file);
}
public bool SelectFilename(string filename)
{
return fileChooser.SelectFilename(filename);
}
public bool SelectUri(string uri)
{
return fileChooser.SelectUri(uri);
}
public void SetChoice(string id, string option)
{
fileChooser.SetChoice(id, option);
}
public bool SetCurrentFolder(string filename)
{
return fileChooser.SetCurrentFolder(filename);
}
public bool SetCurrentFolderFile(IFile file)
{
return fileChooser.SetCurrentFolderFile(file);
}
public bool SetCurrentFolderUri(string uri)
{
return fileChooser.SetCurrentFolderUri(uri);
}
public bool SetFile(IFile file)
{
return fileChooser.SetFile(file);
}
public bool SetFilename(string filename)
{
return fileChooser.SetFilename(filename);
}
public bool SetUri(string uri)
{
return fileChooser.SetUri(uri);
}
public void UnselectAll()
{
fileChooser.UnselectAll();
}
public void UnselectFile(IFile file)
{
fileChooser.UnselectFile(file);
}
public void UnselectFilename(string filename)
{
fileChooser.UnselectFilename(filename);
}
public void UnselectUri(string uri)
{
fileChooser.UnselectUri(uri);
}
} }
} }

View file

@ -23,7 +23,7 @@ namespace Gtk {
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
public partial class NativeDialog : Gtk.FileChooserAdapter { public partial class NativeDialog : GLib.Object {
public NativeDialog (IntPtr raw) : base(raw) { } public NativeDialog (IntPtr raw) : base(raw) { }
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]