From 131f2ed0d95e8cfad47e5a26d0a023e58caebffd Mon Sep 17 00:00:00 2001 From: Todd Berman Date: Thu, 4 Nov 2004 04:06:07 +0000 Subject: [PATCH] 2004-11-03 Todd Berman * gtk/FileChooserDialog.custom: * gtk/FileChooserWidget.custom: Properly implement .Filenames. The old code was a really bad c&p job. svn path=/trunk/gtk-sharp/; revision=35619 --- ChangeLog | 6 ++++++ gtk/FileChooserDialog.custom | 22 ++++++++-------------- gtk/FileChooserWidget.custom | 21 ++++++++------------- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index b1822b774..48c4c4394 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-11-03 Todd Berman + + * gtk/FileChooserDialog.custom: + * gtk/FileChooserWidget.custom: Properly implement .Filenames. The old + code was a really bad c&p job. + 2004-11-02 Jeroen Zwartepoorte * gnomevfs/AsyncDirectoryLoadCallback.cs: diff --git a/gtk/FileChooserDialog.custom b/gtk/FileChooserDialog.custom index 1fbae681a..a51804b96 100644 --- a/gtk/FileChooserDialog.custom +++ b/gtk/FileChooserDialog.custom @@ -54,21 +54,15 @@ [DllImport ("libgtk-win32-2.0-0.dll")] static extern IntPtr gtk_file_chooser_get_filenames (IntPtr raw); - - [DllImport("libglib-2.0-0.dll")] - static extern void g_strfreev (IntPtr handle); - public string[] Filenames { get { - IntPtr strv = gtk_file_chooser_get_filenames (Handle); - System.Collections.ArrayList result = new System.Collections.ArrayList (); - int i = 0; - IntPtr strptr = Marshal.ReadIntPtr (strv, IntPtr.Size * i++); - while (strptr != IntPtr.Zero) { - result.Add (Marshal.PtrToStringAnsi (strptr)); - strptr = Marshal.ReadIntPtr (strv, IntPtr.Size * i++); - } - g_strfreev (strv); - return result.ToArray (typeof (string)) as string[]; + IntPtr raw_ret = gtk_file_chooser_get_filenames (Handle); + if (raw_ret == IntPtr.Zero) + return new string[0]; + GLib.SList list = new GLib.SList (raw_ret, typeof (string)); + string[] result = new string [list.Count]; + for (int i = 0; i < list.Count; i++) + result [i] = (string) list [i]; + return result; } } diff --git a/gtk/FileChooserWidget.custom b/gtk/FileChooserWidget.custom index 66f8116e6..df898ecba 100644 --- a/gtk/FileChooserWidget.custom +++ b/gtk/FileChooserWidget.custom @@ -22,20 +22,15 @@ [DllImport ("libgtk-win32-2.0-0.dll")] static extern IntPtr gtk_file_chooser_get_filenames (IntPtr raw); -[DllImport("libglib-2.0-0.dll")] -static extern void g_strfreev (IntPtr handle); - public string[] Filenames { get { - IntPtr strv = gtk_file_chooser_get_filenames (Handle); - System.Collections.ArrayList result = new System.Collections.ArrayList (); - int i = 0; - IntPtr strptr = Marshal.ReadIntPtr (strv, IntPtr.Size * i++); - while (strptr != IntPtr.Zero) { - result.Add (Marshal.PtrToStringAnsi (strptr)); - strptr = Marshal.ReadIntPtr (strv, IntPtr.Size * i++); - } - g_strfreev (strv); - return result.ToArray (typeof (string)) as string[]; + IntPtr raw_ret = gtk_file_chooser_get_filenames (Handle); + if (raw_ret == IntPtr.Zero) + return new string[0]; + GLib.SList list = new GLib.SList (raw_ret, typeof (string)); + string[] result = new string [list.Count]; + for (int i = 0; i < list.Count; i++) + result [i] = (string) list [i]; + return result; } }