gtk-demo: Use a native file chooser in the svg demo

This commit is contained in:
Matthias Clasen 2020-12-03 19:44:45 -05:00
parent 2688b94133
commit d83554121f

View File

@ -13,11 +13,11 @@
static void static void
open_response_cb (GtkWidget *dialog, open_response_cb (GtkNativeDialog *dialog,
int response, int response,
GtkPicture *picture) GtkPicture *picture)
{ {
gtk_widget_hide (dialog); gtk_native_dialog_hide (dialog);
if (response == GTK_RESPONSE_ACCEPT) if (response == GTK_RESPONSE_ACCEPT)
{ {
@ -31,7 +31,7 @@ open_response_cb (GtkWidget *dialog,
g_object_unref (file); g_object_unref (file);
} }
gtk_window_destroy (GTK_WINDOW (dialog)); gtk_native_dialog_destroy (dialog);
} }
static void static void
@ -39,24 +39,20 @@ show_file_open (GtkWidget *button,
GtkPicture *picture) GtkPicture *picture)
{ {
GtkFileFilter *filter; GtkFileFilter *filter;
GtkWidget *dialog; GtkFileChooserNative *dialog;
dialog = gtk_file_chooser_dialog_new ("Open node file", dialog = gtk_file_chooser_native_new ("Open node file",
GTK_WINDOW (gtk_widget_get_root (button)), GTK_WINDOW (gtk_widget_get_root (button)),
GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_OPEN,
"_Cancel", GTK_RESPONSE_CANCEL, "_Load",
"_Load", GTK_RESPONSE_ACCEPT, "_Cancel");
NULL);
filter = gtk_file_filter_new (); filter = gtk_file_filter_new ();
gtk_file_filter_add_mime_type (filter, "image/svg+xml"); gtk_file_filter_add_mime_type (filter, "image/svg+xml");
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter); gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
gtk_native_dialog_set_modal (GTK_NATIVE_DIALOG (dialog), TRUE);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
g_signal_connect (dialog, "response", G_CALLBACK (open_response_cb), picture); g_signal_connect (dialog, "response", G_CALLBACK (open_response_cb), picture);
gtk_widget_show (dialog); gtk_native_dialog_show (GTK_NATIVE_DIALOG (dialog));
} }
static GtkWidget *window; static GtkWidget *window;