forked from AuroraMiddleware/gtk
Merge branch 'dialog-improvements' into 'main'
gtk-demo: Test cancellation support for file dialog See merge request GNOME/gtk!5257
This commit is contained in:
commit
4fdeec118a
@ -33,17 +33,35 @@ file_opened (GObject *source,
|
||||
g_free (name);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
abort_mission (gpointer data)
|
||||
{
|
||||
GCancellable *cancellable = data;
|
||||
|
||||
g_cancellable_cancel (cancellable);
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static void
|
||||
open_file (GtkButton *picker,
|
||||
GtkLabel *label)
|
||||
{
|
||||
GtkWindow *parent = GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (picker)));
|
||||
GtkFileDialog *dialog;
|
||||
GCancellable *cancellable;
|
||||
|
||||
dialog = gtk_file_dialog_new ();
|
||||
|
||||
gtk_file_dialog_open (dialog, parent, NULL, NULL, file_opened, label);
|
||||
cancellable = g_cancellable_new ();
|
||||
|
||||
g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
|
||||
20,
|
||||
abort_mission, g_object_ref (cancellable), g_object_unref);
|
||||
|
||||
gtk_file_dialog_open (dialog, parent, NULL, cancellable, file_opened, label);
|
||||
|
||||
g_object_unref (cancellable);
|
||||
g_object_unref (dialog);
|
||||
}
|
||||
|
||||
|
@ -388,7 +388,8 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
}
|
||||
else if (response == GTK_RESPONSE_CLOSE)
|
||||
g_task_return_new_error (task, GTK_DIALOG_ERROR, GTK_DIALOG_ERROR_ABORTED, "Aborted by application");
|
||||
else if (response == GTK_RESPONSE_CANCEL)
|
||||
else if (response == GTK_RESPONSE_CANCEL ||
|
||||
response == GTK_RESPONSE_DELETE_EVENT)
|
||||
g_task_return_new_error (task, GTK_DIALOG_ERROR, GTK_DIALOG_ERROR_CANCELLED, "Cancelled by user");
|
||||
else
|
||||
g_task_return_new_error (task, GTK_DIALOG_ERROR, GTK_DIALOG_ERROR_FAILED, "Unknown failure (%d)", response);
|
||||
|
@ -628,7 +628,8 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
}
|
||||
else if (response == GTK_RESPONSE_CLOSE)
|
||||
g_task_return_new_error (task, GTK_DIALOG_ERROR, GTK_DIALOG_ERROR_ABORTED, "Aborted by application");
|
||||
else if (response == GTK_RESPONSE_CANCEL)
|
||||
else if (response == GTK_RESPONSE_CANCEL ||
|
||||
response == GTK_RESPONSE_DELETE_EVENT)
|
||||
g_task_return_new_error (task, GTK_DIALOG_ERROR, GTK_DIALOG_ERROR_CANCELLED, "Cancelled by user");
|
||||
else
|
||||
g_task_return_new_error (task, GTK_DIALOG_ERROR, GTK_DIALOG_ERROR_FAILED, "Unknown failure (%d)", response);
|
||||
|
Loading…
Reference in New Issue
Block a user