Kitlist
A list manager for maintaining kit lists
Loading...
Searching...
No Matches
fdsd::ftxui::KitListFtxui Class Reference

Implements an FTXUI text based user interface. More...

#include "kitlist_base_app.hpp"

Inheritance diagram for fdsd::ftxui::KitListFtxui:
KitListBaseApp

Public Member Functions

 KitListFtxui ()
 Default constructor.
int run (const std::string filename)
 The main run loop.
Public Member Functions inherited from KitListBaseApp
 KitListBaseApp ()
 Default constructor.
virtual ~KitListBaseApp ()
 Destructor.
bool is_dirty () const
void set_dirty (bool dirty=true) const
auto get_current_checked_item_count () const
void new_file ()
 Create a new Model and sets the associated filename to be empty.
virtual void load_file (const std::string &filename)
 Loads the specified file.
virtual bool save ()
 Saves the current Model using the current filename.
virtual bool save (std::string filename)
const std::shared_ptr< Categoryset_category_name (const int32_t id, const std::string &name)
 Updates the name of passed Category.
const std::shared_ptr< Itemset_item_name (const int32_t id, const std::string &name)
 Updates the name of the passed Item.
const std::shared_ptr< Itemset_item_checked (const int32_t id, const bool state)
 Updates the checked state of the passed Item.
virtual const std::shared_ptr< Itemchange_checked_state (int32_t id, Model::check_action action)
 Switches the checked state of the Item referenced by the specified ID according to the specified action.
void change_all_current_items_checked_states (Model::check_action action) const
 Switches the checked state of all items in the currently selected Category.
void set_filename (const std::string &filename)
 Sets a new filename to associate with the Model.
const std::string get_filename () const
virtual void initialization_complete ()
 Sets initialized to true.
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 assigning it to the Item.
void delete_category (int32_t id) const
 Deletes the Category having the passed ID.
void delete_item (int32_t id) const
 Deletes the Item having the passed ID.
void remove_items (const std::vector< std::shared_ptr< Item > > &items) const
 Removes references to each of the Item instances in the list from the currently selected Category.
void remove_item (int32_t id) const
 Removes references to the item from the currently selected Category.
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 and assigning it to the Category.
const std::shared_ptr< Itemget_item (int32_t id) const
 Gets an Item by ID.
const std::shared_ptr< Categoryget_category (int32_t id) const
 Gets a Category by ID.
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::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) and checked status (Model::filter).
auto count_filter_items_for_current_selected_category () const
 Returns a count of the filtered items in the currently selected category.
void remove_all_current_checked_items ()
 Removes all checked items from the current category.
void delete_all_current_checked_items ()
 Deletes all checked items.
void associate_item_with_category (int32_t item_id, std::shared_ptr< Category > category)
 Updates the relationships between an Item and a Category that are already in the model, but using only the item's ID as a reference.
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 copy_checked_items_to_categories (std::vector< int32_t > cids) const
 Copies all currently checked items for the currently selected Category to the list of categories.
void copy_item_to_categories (int32_t item_id, std::vector< int32_t > cids)
 Copies the specified item to the list of categories.
void select_category (int32_t id)
 Sets the selected Category to that of the passed ID.
int32_t get_selected_category () const
 Gets the ID of the currently selected Category.
const std::vector< std::shared_ptr< Category > > get_categories () const
 Gets the list of categories.
const std::vector< std::shared_ptr< Item > > get_all_items () const
 Gets all items, without filtering.
void set_filter (Model::state_filter state) const
 Sets filtering of checked items.
Model::state_filter get_filter () const
 The current filter.
void sort_categories () const
 Sorts all the model's categories.
void sort () const
 Sorts everything within the model.

Protected Member Functions

virtual void category_entry_changed (const std::shared_ptr< Category > category) override
 Called when a Category name has changed.
virtual void item_entry_changed (const std::shared_ptr< Item > item) override
 Called when a Item instance's state has changed.
Protected Member Functions inherited from KitListBaseApp
virtual void update_menu_state (bool is_dirty)
 Called whenever there is a change to the Model state.
virtual void category_name_changed (const std::shared_ptr< Category > category)
virtual void item_name_changed (const std::shared_ptr< Item > item)
virtual void item_checked_changed (const std::shared_ptr< Item > item)
virtual void model_state_changed (bool is_dirty)
 Called whenever the Model state is changed.

Private Types

enum struct  Layer : int {
  default_layer = 0 , new_item_layer , new_category_layer , item_action_layer ,
  copy_category_layer
}
 Indicates the different layers of the application. More...

Private Member Functions

void do_refresh_select_category_list ()
 refreshes the select category list.
::ftxui::Component select_category_list ()
 Component displaying a list of all categories with a checkbox.
::ftxui::Component copy_items_dialog ()
 Modal dialog for selecting target categories.
::ftxui::Component item_action_dialog ()
 Component to display options for removing or deleting checked items.
::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.
::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.

Private Attributes

::ftxui::Component copy_category_container = ::ftxui::Container::Vertical({})
 Component for modal dialog for copying items to categories.
std::vector< SelectCategoryselected_categories
::ftxui::Component item_action_container = ::ftxui::Container::Horizontal({})
 Component for modal dialog for delete or removing items.
std::vector< std::shared_ptr< Category > > current_categories
 The current list of Category instances.
int menu_selected_category = 0
 The index position in the list of category menu items.
int layer = static_cast<int>(Layer::default_layer)
bool show_save = false
 Whether the Save button is shown.
int selected_filter = 0
 Maintained by dropdown giving choices of Model::state_filter.
std::string category_name
 Updated by new_category_component.
std::string item_name
 Updated by new_item_component.
bool item_checked = false
 Updated by new_item_component.
bool refresh_category_container = true
 When true, the category container needs to be refreshed.
bool refresh_copy_item_category_container = true
 When true, the copy items to category container needs to be refreshed.
bool refresh_select_category_list = true
 When true, the select category list needs to be refreshed.
std::vector< std::string > category_menu_entries
 The menu entries for the catalog list.

Additional Inherited Members

Public Attributes inherited from KitListBaseApp
const std::string all_items_text = "-- Show all items --"
 Constant string indicating the option to select no category and therefor display all items.
Static Public Attributes inherited from KitListBaseApp
static const std::string DEFAULT_FILE_EXTENSION = ".kit"
 The application's default filename extension. .kit.

Detailed Description

Implements an FTXUI text based user interface.

Definition at line 57 of file kitlist_ftxui.hpp.

Member Enumeration Documentation

◆ Layer

enum struct fdsd::ftxui::KitListFtxui::Layer : int
strongprivate

Indicates the different layers of the application.

Enumerator
default_layer 

The default base layer of the app.

new_item_layer 

Shows the dialog for creating a new item.

new_category_layer 

Shows the dialog for create a new category.

item_action_layer 

Shows the dialog for deleting or removing items.

copy_category_layer 

Shows the dialog for copying items to categories.

Definition at line 102 of file kitlist_ftxui.hpp.

Constructor & Destructor Documentation

◆ KitListFtxui()

fdsd::ftxui::KitListFtxui::KitListFtxui ( )
inline

Default constructor.

Definition at line 61 of file kitlist_ftxui.hpp.

Member Function Documentation

◆ category_entry_changed()

virtual void fdsd::ftxui::KitListFtxui::category_entry_changed ( const std::shared_ptr< Category > category)
inlineoverrideprotectedvirtual

Called when a Category name has changed.

This allows the front-end implementation to update the category list view. The value will be a nullptr if there is no selected Category.

Not used in this FTXUI front-end implementation.

Reimplemented from KitListBaseApp.

Definition at line 80 of file kitlist_ftxui.hpp.

◆ copy_items_dialog()

Component KitListFtxui::copy_items_dialog ( )
private

Modal dialog for selecting target categories.

Definition at line 82 of file kitlist_ftxui.cpp.

◆ do_refresh_select_category_list()

void KitListFtxui::do_refresh_select_category_list ( )
private

refreshes the select category list.

The list is only refreshed if refresh_select_category_list is true.

Definition at line 40 of file kitlist_ftxui.cpp.

◆ item_action_dialog()

Component KitListFtxui::item_action_dialog ( )
private

Component to display options for removing or deleting checked items.

Definition at line 135 of file kitlist_ftxui.cpp.

◆ item_entry_changed()

virtual void fdsd::ftxui::KitListFtxui::item_entry_changed ( const std::shared_ptr< Item > item)
inlineoverrideprotectedvirtual

Called when a Item instance's state has changed.

This allows the front-end implementation to update the item list view. The value will be a nullptr if there is no selected Item.

Not used in this FTXUI front-end implementation.

Reimplemented from KitListBaseApp.

Definition at line 92 of file kitlist_ftxui.hpp.

◆ new_category_component()

Component KitListFtxui::new_category_component ( std::function< void()> cancel,
std::function< void()> create_item )
private

Component for modal dialog for the user to create a new Category.

Definition at line 167 of file kitlist_ftxui.cpp.

◆ new_item_component()

Component KitListFtxui::new_item_component ( std::function< void()> cancel,
std::function< void()> create_item )
private

Component for modal dialog for the user to create a new Item.

Definition at line 211 of file kitlist_ftxui.cpp.

◆ run()

int KitListFtxui::run ( const std::string filename)

The main run loop.

Definition at line 256 of file kitlist_ftxui.cpp.

◆ select_category_list()

Component KitListFtxui::select_category_list ( )
private

Component displaying a list of all categories with a checkbox.

Definition at line 53 of file kitlist_ftxui.cpp.

Member Data Documentation

◆ category_menu_entries

std::vector<std::string> fdsd::ftxui::KitListFtxui::category_menu_entries
private

The menu entries for the catalog list.

Definition at line 195 of file kitlist_ftxui.hpp.

◆ category_name

std::string fdsd::ftxui::KitListFtxui::category_name
private

Updated by new_category_component.

Definition at line 177 of file kitlist_ftxui.hpp.

◆ copy_category_container

::ftxui::Component fdsd::ftxui::KitListFtxui::copy_category_container = ::ftxui::Container::Vertical({})
private

Component for modal dialog for copying items to categories.

Definition at line 111 of file kitlist_ftxui.hpp.

◆ current_categories

std::vector<std::shared_ptr<Category> > fdsd::ftxui::KitListFtxui::current_categories
private

The current list of Category instances.

Each category's position in the vector corresponds with its name's position within a vector of menu items, such that the index of a selected menu item can be used to retrieve which category it corresponds to.

See also
menu_selected_category

Definition at line 151 of file kitlist_ftxui.hpp.

◆ item_action_container

::ftxui::Component fdsd::ftxui::KitListFtxui::item_action_container = ::ftxui::Container::Horizontal({})
private

Component for modal dialog for delete or removing items.

Definition at line 116 of file kitlist_ftxui.hpp.

◆ item_checked

bool fdsd::ftxui::KitListFtxui::item_checked = false
private

Updated by new_item_component.

Definition at line 183 of file kitlist_ftxui.hpp.

◆ item_name

std::string fdsd::ftxui::KitListFtxui::item_name
private

Updated by new_item_component.

Definition at line 180 of file kitlist_ftxui.hpp.

◆ layer

int fdsd::ftxui::KitListFtxui::layer = static_cast<int>(Layer::default_layer)
private

/brief The currently active layer.

Each model dialog occupies a separate layer.

Definition at line 168 of file kitlist_ftxui.hpp.

◆ menu_selected_category

int fdsd::ftxui::KitListFtxui::menu_selected_category = 0
private

The index position in the list of category menu items.

When zero it indicates that no category is selected.

Incrementing this value by one, corresponds with the list of Category references in current_categories.

Definition at line 161 of file kitlist_ftxui.hpp.

◆ refresh_category_container

bool fdsd::ftxui::KitListFtxui::refresh_category_container = true
private

When true, the category container needs to be refreshed.

Definition at line 186 of file kitlist_ftxui.hpp.

◆ refresh_copy_item_category_container

bool fdsd::ftxui::KitListFtxui::refresh_copy_item_category_container = true
private

When true, the copy items to category container needs to be refreshed.

Definition at line 189 of file kitlist_ftxui.hpp.

◆ refresh_select_category_list

bool fdsd::ftxui::KitListFtxui::refresh_select_category_list = true
private

When true, the select category list needs to be refreshed.

Definition at line 192 of file kitlist_ftxui.hpp.

◆ selected_categories

std::vector<SelectCategory> fdsd::ftxui::KitListFtxui::selected_categories
private

Definition at line 113 of file kitlist_ftxui.hpp.

◆ selected_filter

int fdsd::ftxui::KitListFtxui::selected_filter = 0
private

Maintained by dropdown giving choices of Model::state_filter.

Definition at line 174 of file kitlist_ftxui.hpp.

◆ show_save

bool fdsd::ftxui::KitListFtxui::show_save = false
private

Whether the Save button is shown.

Definition at line 171 of file kitlist_ftxui.hpp.


The documentation for this class was generated from the following files:
Copyright 2008-2025 Frank Dean