From 2fea813c3d70009ecb8fca1efdb2b3858cc41617 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Fri, 13 Jan 2017 14:33:16 +0100 Subject: [PATCH] fix(github): Clear label on empty notifications Fixes #278 --- include/drawtypes/label.hpp | 1 + src/drawtypes/label.cpp | 4 ++++ src/modules/github.cpp | 12 +++++++++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/drawtypes/label.hpp b/include/drawtypes/label.hpp index 70866bb7..3adf884b 100644 --- a/include/drawtypes/label.hpp +++ b/include/drawtypes/label.hpp @@ -60,6 +60,7 @@ namespace drawtypes { string get() const; operator bool(); label_t clone(); + void clear(); void reset_tokens(); bool has_token(const string& token); void replace_token(const string& token, string replacement); diff --git a/src/drawtypes/label.cpp b/src/drawtypes/label.cpp index 15b6e40d..fd7e120a 100644 --- a/src/drawtypes/label.cpp +++ b/src/drawtypes/label.cpp @@ -24,6 +24,10 @@ namespace drawtypes { m_margin, m_maxlen, m_ellipsis, move(tokens)); } + void label::clear() { + m_tokenized.clear(); + } + void label::reset_tokens() { m_tokenized = m_text; } diff --git a/src/modules/github.cpp b/src/modules/github.cpp index c6f37b93..ce4d968f 100644 --- a/src/modules/github.cpp +++ b/src/modules/github.cpp @@ -1,5 +1,7 @@ -#include "modules/github.hpp" +#include + #include "drawtypes/label.hpp" +#include "modules/github.hpp" #include "modules/meta/base.inl" @@ -23,6 +25,8 @@ namespace modules { m_label = load_optional_label(m_conf, name(), TAG_LABEL, "Notifications: %notifications%"); m_label->replace_token("%notifications%", m_empty_notifications ? "0" : ""); } + + assert(static_cast(m_label)); } /** @@ -50,9 +54,11 @@ namespace modules { notifications++; } - if (m_label) { + if (notifications || m_empty_notifications) { m_label->reset_tokens(); - m_label->replace_token("%notifications%", notifications || m_empty_notifications ? to_string(notifications) : ""); + m_label->replace_token("%notifications%", to_string(notifications)); + } else { + m_label->clear(); } return true;