Notifications fonctionnelles

This commit is contained in:
Adrien Bourmault 2023-01-25 23:14:55 +01:00
parent 70348674cd
commit 0a494a6b21
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
4 changed files with 52 additions and 22 deletions

View File

@ -101,6 +101,10 @@ void on_savefile_action(GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
void on_toast_close_action(GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
static const GActionEntry app_actions[] = {
{ "quit", on_quit_action, NULL, NULL, NULL },
@ -113,6 +117,7 @@ static const GActionEntry app_actions[] = {
{ "openfile", on_openfile_action, NULL, NULL, NULL },
{ "closefile", on_closefile_action, NULL, NULL, NULL },
{ "savefile", on_savefile_action, NULL, NULL, NULL },
{ "toastclose", on_toast_close_action, NULL, NULL, NULL },
};
void ui_enable_action(const char *name);
@ -140,3 +145,4 @@ void ui_set_stack(const char *mode);
void ui_send_notification(const char *message);
void ui_send_internal_notification(const char *message);
void ui_close_internal_notification(void);

View File

@ -69,7 +69,7 @@ void on_preferences_action(GSimpleAction *action,
g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self));
ui_send_notification("Not implemented !");
ui_send_internal_notification("Not implemented !");
}
void on_togglesidebar_action(GSimpleAction *action,
@ -80,7 +80,7 @@ void on_togglesidebar_action(GSimpleAction *action,
g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self));
ui_send_notification("Not implemented !");
ui_send_internal_notification("Not implemented !");
}
void on_editmode_action(GSimpleAction *action,
@ -170,6 +170,17 @@ void on_savefile_action(GSimpleAction *action,
}
void on_toast_close_action(GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GemGraphClientApplication *self = user_data;
g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self));
ui_close_internal_notification();
}
/* -------------------------------------------------------------------------- */
/*

View File

@ -162,33 +162,22 @@
<property name="halign">center</property>
<property name="valign">start</property>
<child>
<object class="GtkBox" id="box2">
<object class="GtkBox" id="toast_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">start</property>
<property name="spacing">20</property>
<child>
<object class="GtkLabel" id="label2">
<object class="GtkLabel" id="toast_text">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">This is an app-notification. Click the button to dismiss</property>
<property name="label" translatable="yes">(null)</property>
</object>
</child>
<child>
<object class="GtkButton" id="toast_close_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<child>
<object class="GtkImage" id="image2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">window-close-symbolic</property>
</object>
</child>
<style>
<class name="image-button"/>
</style>
<object class="GtkToggleButton" id="toast_close_button">
<property name="icon-name">window-close-symbolic</property>
<property name="action-name">app.toastclose</property>
</object>
</child>
<style>

View File

@ -207,7 +207,8 @@ struct _GemGraphClientWindow
GtkMenuButton *main_button_mode;
GtkToggleButton *main_button_sidebar;
GtkRevealer *toast_revealer;
GtkButton *toast_close_button;
GtkToggleButton *toast_close_button;
GtkLabel *toast_text;
};
G_DEFINE_FINAL_TYPE (GemGraphClientWindow,
@ -253,6 +254,9 @@ static void gem_graph_client_window_class_init(GemGraphClientWindowClass *klass)
gtk_widget_class_bind_template_child(widget_class,
GemGraphClientWindow,
toast_close_button);
gtk_widget_class_bind_template_child(widget_class,
GemGraphClientWindow,
toast_text);
}
static void gem_graph_client_window_init(GemGraphClientWindow *self)
@ -312,6 +316,26 @@ void ui_send_internal_notification(const char *message)
return;
}
//gtk_overlay_add_overlay(self->toast_overlay, //XXX);
g_print("NOTIFICATION: %s\n", message);
if (window->toast_text == NULL) {
g_printerr("Can't find self->toast_overlay !\n");
return;
}
gtk_label_set_label(window->toast_text, message);
gtk_revealer_set_reveal_child(window->toast_revealer, true);
}
void ui_close_internal_notification(void)
{
if (window->toast_revealer == NULL) {
g_printerr("Can't find self->toast_overlay !\n");
return;
}
if (window->toast_text == NULL) {
g_printerr("Can't find self->toast_overlay !\n");
return;
}
gtk_revealer_set_reveal_child(window->toast_revealer, false);
}