Esempio n. 1
0
 public static extern IntPtr CreateFileDialog(
     IntPtr title,
     IntPtr parent,
     GtkFileChooserAction action,
     IntPtr firstButtonText,
     GtkResponseType firstButtonResponse,
     IntPtr secondButtonText,
     GtkResponseType secondButtonResponse,
     IntPtr terminator);
Esempio n. 2
0
        private DialogResult MapResult(GtkResponseType result)
        {
            switch (result)
            {
            case GtkResponseType.Ok:
                return(DialogResult.Ok);

            case GtkResponseType.Cancel:
                return(DialogResult.Cancel);

            case GtkResponseType.Yes:
                return(DialogResult.Yes);

            case GtkResponseType.No:
                return(DialogResult.No);

            default:
                return(DialogResult.None);
            }
        }
Esempio n. 3
0
        private DialogResult MapResult(GtkResponseType result)
        {
            switch (result)
            {
            case GtkResponseType.Accept:
            case GtkResponseType.Ok:
            case GtkResponseType.Yes:
            case GtkResponseType.Apply:
                return(DialogResult.Ok);

            case GtkResponseType.Reject:
            case GtkResponseType.Cancel:
            case GtkResponseType.Close:
            case GtkResponseType.No:
                return(DialogResult.Cancel);

            default:
                return(DialogResult.None);
            }
        }
Esempio n. 4
0
 static extern IntPtr gtk_file_chooser_dialog_new([MarshalAs(UnmanagedType.LPUTF8Str)] string title,
                                                  IntPtr parent, GtkFileChooserAction action,
                                                  [MarshalAs(UnmanagedType.LPUTF8Str)] string btn1, GtkResponseType resp1,
                                                  [MarshalAs(UnmanagedType.LPUTF8Str)] string btn2, GtkResponseType res2,
                                                  IntPtr terminatingNull);
Esempio n. 5
0
        public static string getFileName()
        {
            byte[]      cmdLine = File.ReadAllBytes($"/proc/{ Process.GetCurrentProcess().Id }/cmdline");
            Span <byte> span    = stackalloc byte[cmdLine.Length + 1];

            cmdLine.AsSpan().CopyTo(span);
            span[cmdLine.Length] = 0;

            unsafe
            {
                fixed(byte *p = span)
                {
                    IntPtr pointer       = (IntPtr)p;
                    IntPtr doublePointer = (IntPtr)(&pointer);
                    int    argc          = 1;

                    gtk_init(ref argc, ref doublePointer);
                }
            }

            // https://developer.gnome.org/gtk3/stable/GtkFileChooserDialog.html#gtk-file-chooser-dialog-new
            IntPtr dialog = gtk_file_chooser_dialog_new("Pick a media file to play",
                                                        IntPtr.Zero,
                                                        GtkFileChooserAction.Open,
                                                        "_Cancel",
                                                        GtkResponseType.Cancel,
                                                        "_Open",
                                                        GtkResponseType.Accept,
                                                        IntPtr.Zero);

            if (IntPtr.Zero == dialog)
            {
                // Console.WriteLine( "gtk_file_chooser_dialog_new failed" );
                return(null);
            }

            g_object_ref_sink(dialog);

            try
            {
                IntPtr chooser = g_type_check_instance_cast(dialog, gtk_file_chooser_get_type());
                setupFilters(chooser);

                GtkResponseType res = gtk_dialog_run(dialog);
                if (res != GtkResponseType.Accept)
                {
                    return(null);
                }
                IntPtr u8  = gtk_file_chooser_get_filename(chooser);
                string str = Marshal.PtrToStringUTF8(u8);
                return(str);
            }
            finally
            {
                gtk_widget_destroy(dialog);
                g_object_unref(dialog);

                // GTK's version of DestroyWindow is asynchronous.
                // Unless dispatching some final messages, the window stays on the screen in some weird state.
                // Attempting to close brings a message from Linux telling me my software is broken, with a helpful option to kill the complete process.
                while (gtk_events_pending())
                {
                    gtk_main_iteration();
                }
            }
        }
Esempio n. 6
0
 gtk_dialog_add_button(IntPtr raw, Utf8Buffer button_text, GtkResponseType response_id);