#include "widgets/todo.hpp" #include #include #include TodoPopover::TodoPopover(std::string icon, std::string title) : Popover(icon, title) { this->name = title; this->popover->set_size_request(300, -1); container.set_orientation(Gtk::Orientation::VERTICAL); container.set_spacing(10); container.add_css_class("todo-popover-container"); auto entry = Gtk::make_managed(); entry->set_placeholder_text("Enter your to-do item..."); entry->add_css_class("todo-input"); entry->set_hexpand(true); entry->set_halign(Gtk::Align::FILL); entry->set_valign(Gtk::Align::START); inputArea.append(*entry); inputArea.add_css_class("todo-input-area"); inputArea.set_hexpand(true); inputArea.set_halign(Gtk::Align::FILL); entry->signal_activate().connect([this, entry]() { std::string text = entry->get_text(); if (!text.empty()) { this->todoService->addTodo(text); entry->set_text(""); } }); container.append(inputArea); this->todoList = Gtk::make_managed(Gtk::Orientation::VERTICAL); container.append(*todoList); todoList->add_css_class("todo-list"); auto signal = sigc::signal(); this->todoService = new TodoService(signal); signal.connect(sigc::mem_fun(*this, &TodoPopover::update)); this->set_popover_child(this->container); this->update(); } void TodoPopover::update() { auto todos = this->todoService->getTodos(); Gtk::Widget *child = todoList->get_first_child(); while (child) { Gtk::Widget *next = child->get_next_sibling(); bool found = false; for (auto &[id, todo] : todos) { if (child == todo) { found = true; break; } } if (!found) { todoList->remove(*child); } child = next; } for (auto &[id, todo] : todos) { if (todo->get_parent() == nullptr) { todoList->append(*todo); } } }