1
0
mirror of https://gitlab.cvh-server.de/skrause/flashcards.git synced 2026-04-30 19:27:06 +00:00
Files
flashcards/src/create-category.c
2026-03-06 15:48:13 +01:00

55 lines
1.5 KiB
C

#include "create-category.h"
struct _FlashcardsCreateCategoryDialog
{
AdwAlertDialog parent;
GtkEditable *entry;
FlashcardsAppWindow *win;
};
G_DEFINE_TYPE (FlashcardsCreateCategoryDialog,
flashcards_create_category_dialog, ADW_TYPE_ALERT_DIALOG);
static void
on_response (__attribute__ ((unused)) AdwAlertDialog *dialog,
const gchar *response, gpointer user_data)
{
FlashcardsCreateCategoryDialog *self = user_data;
const gchar *category = gtk_editable_get_text (self->entry);
if (strcmp (response, "add") == 0 && strlen (category) > 0)
flashcards_app_window_add_category (self->win, category);
}
static void
flashcards_create_category_dialog_init (FlashcardsCreateCategoryDialog *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
}
static void
flashcards_create_category_dialog_class_init (
FlashcardsCreateCategoryDialogClass *klass)
{
gtk_widget_class_set_template_from_resource (
GTK_WIDGET_CLASS (klass), "/li/sopht/flashcards/create-category.ui");
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass),
FlashcardsCreateCategoryDialog, entry);
gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (klass),
on_response);
}
FlashcardsCreateCategoryDialog *
flashcards_create_category_dialog_new (FlashcardsAppWindow *win)
{
FlashcardsCreateCategoryDialog *self
= g_object_new (FLASHCARDS_CREATE_CATEGORY_DIALOG_TYPE, nullptr);
self->win = win;
return self;
}