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
open_response_cb (GtkWidget *dialog,
int response,
GtkPicture *picture)
open_response_cb (GtkNativeDialog *dialog,
int response,
GtkPicture *picture)
{
gtk_widget_hide (dialog);
gtk_native_dialog_hide (dialog);
if (response == GTK_RESPONSE_ACCEPT)
{
@ -31,7 +31,7 @@ open_response_cb (GtkWidget *dialog,
g_object_unref (file);
}
gtk_window_destroy (GTK_WINDOW (dialog));
gtk_native_dialog_destroy (dialog);
}
static void
@ -39,24 +39,20 @@ show_file_open (GtkWidget *button,
GtkPicture *picture)
{
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_FILE_CHOOSER_ACTION_OPEN,
"_Cancel", GTK_RESPONSE_CANCEL,
"_Load", GTK_RESPONSE_ACCEPT,
NULL);
"_Load",
"_Cancel");
filter = gtk_file_filter_new ();
gtk_file_filter_add_mime_type (filter, "image/svg+xml");
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
gtk_native_dialog_set_modal (GTK_NATIVE_DIALOG (dialog), TRUE);
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;