Commit 1216e524 authored by Sebastian Ramacher's avatar Sebastian Ramacher

Check if add/remove class is necessary

Signed-off-by: Sebastian Ramacher's avatarSebastian Ramacher <sebastian+dev@ramacher.at>
parent e9bd0f2e
......@@ -670,18 +670,15 @@ girara_notify(girara_session_t* session, int level, const char* format, ...)
return;
}
widget_remove_class(session->gtk.notification_area, "notification-error");
widget_remove_class(session->gtk.notification_text, "notification-error");
widget_remove_class(session->gtk.notification_area, "notification-warning");
widget_remove_class(session->gtk.notification_text, "notification-warning");
bool error_class = false;
bool warning_class = false;
const char* cssclass = NULL;
switch (level) {
case GIRARA_ERROR:
cssclass = "notification-error";
error_class = true;
break;
case GIRARA_WARNING:
cssclass = "notification-warning";
warning_class = true;
break;
case GIRARA_INFO:
break;
......@@ -689,9 +686,19 @@ girara_notify(girara_session_t* session, int level, const char* format, ...)
return;
}
if (cssclass != NULL) {
widget_add_class(session->gtk.notification_area, cssclass);
widget_add_class(session->gtk.notification_text, cssclass);
if (error_class == true) {
widget_add_class(session->gtk.notification_area, "notification-error");
widget_add_class(session->gtk.notification_text, "notification-error");
} else {
widget_remove_class(session->gtk.notification_area, "notification-error");
widget_remove_class(session->gtk.notification_text, "notification-error");
}
if (warning_class == true) {
widget_add_class(session->gtk.notification_area, "notification-warning");
widget_add_class(session->gtk.notification_text, "notification-warning");
} else {
widget_remove_class(session->gtk.notification_area, "notification-warning");
widget_remove_class(session->gtk.notification_text, "notification-warning");
}
/* prepare message */
......
......@@ -539,7 +539,9 @@ widget_add_class(GtkWidget* widget, const char* styleclass)
}
GtkStyleContext* context = gtk_widget_get_style_context(widget);
gtk_style_context_add_class(context, styleclass);
if (gtk_style_context_has_class(context, styleclass) == FALSE) {
gtk_style_context_add_class(context, styleclass);
}
}
void
......@@ -550,5 +552,7 @@ widget_remove_class(GtkWidget* widget, const char* styleclass)
}
GtkStyleContext* context = gtk_widget_get_style_context(widget);
gtk_style_context_remove_class(context, styleclass);
if (gtk_style_context_has_class(context, styleclass) == TRUE) {
gtk_style_context_remove_class(context, styleclass);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment