Example #1
0
        static unsafe string GtkSave()
        {
            if (!Gtk.gtk_init_check(IntPtr.Zero, IntPtr.Zero))
            {
                throw new Exception();
            }
            var dlg = Gtk.gtk_file_chooser_dialog_new("Save File", IntPtr.Zero,
                                                      Gtk.GTK_FILE_CHOOSER_ACTION_SAVE,
                                                      IntPtr.Zero);

            Gtk.gtk_dialog_add_button(dlg, "_Cancel", Gtk.GTK_RESPONSE_CANCEL);
            Gtk.gtk_dialog_add_button(dlg, "_Accept", Gtk.GTK_RESPONSE_ACCEPT);
            Gtk.gtk_window_set_keep_above(dlg, true);             //better than it disappearing
            string result = null;

            if (Gtk.gtk_dialog_run(dlg) == Gtk.GTK_RESPONSE_ACCEPT)
            {
                var file = Gtk.gtk_file_chooser_get_filename(dlg);
                int i    = 0;
                var ptr  = (byte *)file;
                while (ptr[i] != 0)
                {
                    i++;
                }
                var bytes = new byte[i];
                Marshal.Copy(file, bytes, 0, i);
                result = Encoding.UTF8.GetString(bytes);
            }
            WaitCleanup();
            Gtk.gtk_widget_destroy(dlg);
            WaitCleanup();
            return(result);
        }
Example #2
0
        static string GtkSave()
        {
            if (!Gtk.gtk_init_check(IntPtr.Zero, IntPtr.Zero))
            {
                throw new Exception();
            }
            var dlg = Gtk.gtk_file_chooser_dialog_new("Save File", IntPtr.Zero,
                                                      Gtk.GTK_FILE_CHOOSER_ACTION_SAVE,
                                                      IntPtr.Zero);

            Gtk.gtk_dialog_add_button(dlg, "_Cancel", Gtk.GTK_RESPONSE_CANCEL);
            Gtk.gtk_dialog_add_button(dlg, "_Accept", Gtk.GTK_RESPONSE_ACCEPT);
            string result = null;

            if (Gtk.gtk_dialog_run(dlg) == Gtk.GTK_RESPONSE_ACCEPT)
            {
                var file = Gtk.gtk_file_chooser_get_filename(dlg);
                result = Marshal.PtrToStringAnsi(file);
            }
            WaitCleanup();
            Gtk.gtk_widget_destroy(dlg);
            WaitCleanup();
            return(result);
        }