24#include <ftxui/component/captured_mouse.hpp>
25#include <ftxui/component/component.hpp>
26#include <ftxui/component/component_base.hpp>
27#include <ftxui/component/component_options.hpp>
28#include <ftxui/component/screen_interactive.hpp>
29#include <ftxui/dom/elements.hpp>
30#include <ftxui/screen/screen.hpp>
45 for (
auto& c : categories) {
65 component |= Renderer([&](Element inner) {
73 Element document = vbox({
77 | vscroll_indicator | frame;
84 auto ok_button = Button(
"Ok", [&] {
87 vector<shared_ptr<Item>> items;
88 for (
const auto& i : all_items) {
92 vector<shared_ptr<Category>> categories;
95 categories.push_back(sc.category);
97 if (!items.empty() && !categories.empty()) {
102 auto cancel_button = Button(
"Cancel", [&] {
106 auto buttons = Container::Horizontal({ok_button, cancel_button});
108 buttons |= Renderer([&](Element inner) {
109 Element document = vbox({
116 Component component = Container::Vertical({
117 category_list | flex,
121 component |= Renderer([&](Element inner) {
122 Element document = vbox({
123 text(
"Select categories "),
128 | size(WIDTH, GREATER_THAN, 40)
129 | size(HEIGHT, GREATER_THAN, 8)
152 Element document = vbox({
156 action_button->Render(),
157 cancel_button->Render(),
161 | size(WIDTH, GREATER_THAN, 40)
168 std::function<
void()> cancel,
169 std::function<
void()> create_category)
171 InputOption input_option = InputOption::Default();
172 input_option.multiline =
false;
173 input_option.transform = [](InputState state) {
175 state.element |= color(Color::Black);
177 if (state.is_placeholder) {
178 state.element |= dim;
181 if (state.focused || state.hovered) {
182 state.element |= inverted;
184 return state.element;
187 auto component = Container::Vertical({
188 Container::Horizontal({
189 Input(&
category_name,
"Enter name", input_option) | borderEmpty,
191 Container::Horizontal({
192 Button(
"OK", create_category),
193 Button(
"Cancel", cancel),
197 component |= Renderer([&](Element inner) {
199 text(
"Category editor"),
205 | size(WIDTH, GREATER_THAN, 40)
212 std::function<
void()> cancel,
213 std::function<
void()> create_item)
215 InputOption input_option = InputOption::Default();
216 input_option.multiline =
false;
217 input_option.transform = [](InputState state) {
219 state.element |= color(Color::Black);
221 if (state.is_placeholder) {
222 state.element |= dim;
225 if (state.focused || state.hovered) {
226 state.element |= inverted;
228 return state.element;
231 auto component = Container::Vertical({
232 Container::Horizontal({
234 Input(&
item_name,
"Enter name", input_option) | borderEmpty,
236 Container::Horizontal({
237 Button(
"OK", create_item),
238 Button(
"Cancel", cancel),
242 component |= Renderer([&](Element inner) {
250 | size(WIDTH, GREATER_THAN, 40)
262 cerr <<
"File not found: \"" <<
filename <<
"\" - " << e.
what() <<
'\n';
265 cerr <<
"Error parsing file: \"" <<
filename <<
"\" - " << e.
what() <<
'\n';
271 for (
auto& c : categories) {
276 auto screen = ScreenInteractive::Fullscreen();
280 vector<string> filter_entries = {
286 auto button_container = Container::Vertical({
287 Container::Horizontal({
288 Button(
"Quit", screen.ExitLoopClosure()),
289 Maybe(Button(
"Save", [&] {
294 Button(
"Check all", [&] {
299 Button(
"Uncheck all", [&] {
304 Button(
"Toggle all", [&] {
310 Container::Horizontal({
315 Maybe(Button(
"Delete category", [&] {
322 Maybe(Button(
"Copy to categories", [&] {
341 Component button_container_wrap = Renderer(button_container, [&] {
342 return button_container->Render();
347 Component category_container = Container::Vertical({});
351 Component category_container_wrap = Renderer(category_container, [&] {
354 category_container->DetachAllChildren();
372 MenuOption category_menu_option = MenuOption::Vertical();
374 category_menu_option.entries_option.transform = [] (
const EntryState& state) {
375 Element e = text((state.active ?
"> " :
" ") + state.label);
390 category_container->Add(menu);
401 return category_container->Render();
407 Component item_container = Container::Vertical({});
408 Component item_container_wrap = Renderer(item_container, [&] {
409 item_container->DetachAllChildren();
423 for (
const auto& i : items) {
424 CheckboxOption cbx_option;
425 cbx_option.on_change = [&] {
429 item_container->Add(Checkbox(i->get_name(), &i->checked, cbx_option));
431 return item_container->Render();
436 auto inner_container = Container::Horizontal({ category_container_wrap, item_container_wrap });
437 auto layer_0_container = Container::Vertical({ button_container_wrap, inner_container });
452 auto layer_1_container = Container::Horizontal({new_item_dialog});
454 auto layer_1_renderer = Renderer(layer_1_container, [&] {
456 layer_1_container->Render();
475 auto layer_2_container = Container::Horizontal({new_category_dialog});
476 auto layer_2_renderer = Renderer(layer_2_container, [&] {
478 layer_2_container->Render();
482 auto layer_3_renderer = Renderer(layer_3_container, [&] {
484 layer_3_container->Render();
490 auto layer_4_renderer = Renderer(layer_4_container, [&] {
491 return layer_4_container->Render();
496 auto layer_0_renderer = Renderer(layer_0_container, [&] {
501 button_container_wrap->Render(),
504 category_container_wrap->Render() | vscroll_indicator | frame | border,
505 item_container_wrap->Render() | vscroll_indicator | frame | border | xflex,
510 auto main_container = Container::Tab(
520 auto main_renderer = Renderer(main_container, [&] {
521 Element document = layer_0_renderer->Render();
527 layer_1_renderer->Render() | clear_under | center,
533 layer_2_renderer->Render() | clear_under | center,
539 layer_3_renderer->Render() | clear_under | center,
545 layer_4_renderer->Render() | clear_under | center,
552 screen.Loop(main_renderer);
Exception throw when a file is not found.
virtual const char * what() const override
Describes the exeption.
void set_dirty(bool dirty=true) const
auto count_filter_items_for_current_selected_category() const
Returns a count of the filtered items in the currently selected category.
const std::vector< std::shared_ptr< Item > > filter_items_for_current_selected_category() const
Filters the list of Item instances based on the currently selected category (Model::selected_category...
void delete_all_current_checked_items()
Deletes all checked items.
void set_filter(Model::state_filter state) const
Sets filtering of checked items.
int32_t get_selected_category() const
Gets the ID of the currently selected Category.
std::string filename
The current filename the Model was loaded from.
void copy_items_to_categories(std::vector< std::shared_ptr< Item > > &items, std::vector< std::shared_ptr< Category > > &categories) const
Copies all of the passed items to each of the passed categories, updating the model relationships.
void delete_category(int32_t id) const
Deletes the Category having the passed ID.
int32_t new_item(const std::string &name, bool checked) const
creates a new Item in the model using the passed parameters, incrementing Model::max_item_id and assi...
virtual void load_file(const std::string &filename)
Loads the specified file.
void select_category(int32_t id)
Sets the selected Category to that of the passed ID.
void remove_all_current_checked_items()
Removes all checked items from the current category.
const std::vector< std::shared_ptr< Item > > get_all_items_for_current_selected_category() const
Returns all items for the currently selected Category.
const std::shared_ptr< Category > get_category(int32_t id) const
Gets a Category by ID.
const std::string all_items_text
Constant string indicating the option to select no category and therefor display all items.
const std::vector< std::shared_ptr< Category > > get_categories() const
Gets the list of categories.
int32_t new_category(const std::string &name) const
Creates a new Category in the Model using the passed parameters, incrementing Model::max_category_id ...
virtual bool save()
Saves the current Model using the current filename.
void change_all_current_items_checked_states(Model::check_action action) const
Switches the checked state of all items in the currently selected Category.
static const int32_t no_category
Indicates no filtering by category.
@ unchecked
Show only unchecked items.
@ all
Show all items, i.e. no filtering.
@ checked
Show only checked items.
std::vector< std::string > category_menu_entries
The menu entries for the catalog list.
::ftxui::Component copy_category_container
Component for modal dialog for copying items to categories.
::ftxui::Component item_action_dialog()
Component to display options for removing or deleting checked items.
std::vector< std::shared_ptr< Category > > current_categories
The current list of Category instances.
bool refresh_category_container
When true, the category container needs to be refreshed.
void do_refresh_select_category_list()
refreshes the select category list.
std::string item_name
Updated by new_item_component.
bool refresh_select_category_list
When true, the select category list needs to be refreshed.
int selected_filter
Maintained by dropdown giving choices of Model::state_filter.
::ftxui::Component new_item_component(std::function< void()> cancel, std::function< void()> create_item)
Component for modal dialog for the user to create a new Item.
::ftxui::Component item_action_container
Component for modal dialog for delete or removing items.
std::string category_name
Updated by new_category_component.
::ftxui::Component copy_items_dialog()
Modal dialog for selecting target categories.
bool refresh_copy_item_category_container
When true, the copy items to category container needs to be refreshed.
bool show_save
Whether the Save button is shown.
bool item_checked
Updated by new_item_component.
::ftxui::Component select_category_list()
Component displaying a list of all categories with a checkbox.
::ftxui::Component new_category_component(std::function< void()> cancel, std::function< void()> create_item)
Component for modal dialog for the user to create a new Category.
int run(const std::string filename)
The main run loop.
std::vector< SelectCategory > selected_categories
int menu_selected_category
The index position in the list of category menu items.
A namespace for the FTXUI user interface.
An element used in lists for selecting categories.