3#include "DatabaseIdentifiers.hpp"
4#include "FileManager.hpp"
5#include "Primitives.hpp"
12#include <unordered_set>
19struct ElementSelectorState
21 ElementSelectorState(
size_t firstVisible,
size_t selected);
23 size_t firstVisibleElementIndx;
24 size_t selectedElementIndx;
27template <
typename Element>
31 } -> std::same_as<std::string>;
33template <
typename Element>
34concept NameIsString = std::is_same<
decltype(Element::name), std::string>::value;
36template <
typename Element>
39template <
typename Element>
52template <
typename ElementPtr>
57 template <
typename Element>
62 ElementSelector(
const Recti& bounds);
64 void Load(std::vector<ElementPtr> element,
bool overwrite);
65 void Load(ElementPtr element,
bool overwrite);
68 void HandleResize(
const Recti& bounds);
72 void SelectByIndx(std::size_t indx);
73 void SelectByName(
const std::string& filename);
75 void ClearAllLastingSelections();
76 void LastingSelectOnCurrent();
81 std::vector<std::size_t> GetLastingSelectedElementsIndices()
const;
82 std::vector<ElementPtr> GetLastingSelectedElements()
const;
83 std::vector<ElementPtr> GetElements()
const;
85 const std::optional<ElementPtr> GetSelected()
const;
86 std::size_t GetSelectedPosition()
const;
87 std::size_t GetElementsSize()
const;
93 template <
typename U = ElementPtr>
97 int x = mBounds.left + 1;
99 int xSpace = mBounds.width - 1;
102 std::min((
int) mFirstVisibleIndx + mBounds.height, (
int) mFiles.size());
103 for (
int i = mFirstVisibleIndx; i < iBound; ++i)
105 if (i == mSelectedIndx)
109 if (mLastingSelectIndxs.contains(i))
111 attron(COLOR_PAIR(3));
115 attroff(A_REVERSE | COLOR_PAIR(0));
118 attroff(COLOR_PAIR(2));
124 "Wow such empty, Can you pleeeeease open another directory?", mBounds);
132 template <
typename U = ElementPtr>
136 int x = mBounds.left + 1;
138 int xSpace = mBounds.width - 1;
141 std::min((
int) mFirstVisibleIndx + mBounds.height, (
int) mFiles.size());
142 for (
int i = mFirstVisibleIndx; i < iBound; ++i)
144 if (i == mSelectedIndx)
148 if (mFiles[i]->type == File::Type::Directory)
150 attron(COLOR_PAIR(2));
152 if (mLastingSelectIndxs.contains(i))
154 attron(COLOR_PAIR(3));
158 attroff(A_REVERSE | COLOR_PAIR(0));
161 attroff(COLOR_PAIR(2));
167 "Wow such empty, Can you pleeeeease open another directory?", mBounds);
171 void ShuffleElements();
176 template <
typename U = ElementPtr,
177 std::enable_if_t<std::is_same<U, File_Ptr>::value,
bool> =
true>
183 bool parentDirExist =
false;
184 File_Ptr parent_dir =
nullptr;
185 for (
auto iter{begin(mFiles)}; iter != end(mFiles); ++iter)
187 if ((*iter)->name ==
"..")
190 parentDirExist =
true;
196 std::vector<File_Ptr> sortedFiles;
198 sortedFiles.push_back(parent_dir);
200 for (
auto& file : mFiles)
202 if (file->type == File::Type::Directory)
204 sortedFiles.push_back(file);
208 for (
auto& file : mFiles)
210 if (file->type == File::Type::Directory)
213 sortedFiles.push_back(std::move(file));
215 mFiles = std::move(sortedFiles);
220 std::size_t mSelectedIndx;
221 std::size_t mFirstVisibleIndx;
222 std::vector<ElementPtr> mFiles;
223 std::unordered_set<size_t> mLastingSelectIndxs;
224 std::default_random_engine mShuffleRandomEngine;
227#include "ElementSelector.tpp"
void printwMsgBox(const std::string &msg, const Recti &availableSpace)
Definition Utility.cpp:106
bool PrintwInLimitedX(const Vector2i &startPos, const std::string &text, int xLimit, int startIndx=0, bool truncIfNotFit=true)
Printw line in specified x boundary. if line is larger than x boundary. then truncate the line.
Definition Utility.cpp:23
The ElementSelector class - class to select & draw list of elements.
Definition ElementSelector.hpp:55
void Load(std::vector< ElementPtr > element, bool overwrite)
Definition ElementSelector.tpp:70
void Load(ElementPtr element, bool overwrite)
Definition ElementSelector.tpp:50
void SortDirsFirst()
SortDirsFirst - defined for File_Ptr to sort dirs first.
Definition ElementSelector.hpp:178
static std::vector< ElementPtr > CrutchConverter(std::vector< Element > elements)
ElementSelector::CrutchConverter - convert vector of Element to vector of Element_Ptr;.
Definition ElementSelector.tpp:29
void Draw() const
Draw method defined twice: this one is for DBPlaylistPtr. Required in NewElementsDialogBundle,...
Definition ElementSelector.hpp:95
void Draw() const
Draw method defined twice: this one is for all other elements (File_Ptr for now all the other elemenr...
Definition ElementSelector.hpp:134
Definition ElementSelector.hpp:37
Definition ElementSelector.hpp:40
Definition ElementSelector.hpp:34
Definition ElementSelector.hpp:28
The ElementSelectorState - struct to store element selector state .
Definition ElementSelector.hpp:20