The ZX Ecosystem v5.1.0;_GUI_v3.1.0
Loading...
Searching...
No Matches
ZXWidgetFileBrowser.h
Go to the documentation of this file.
1
2/* **************************************************************************/
19#ifndef ZXWIDGET_FILEBROWSER
20#define ZXWIDGET_FILEBROWSER
21
22#include <filesystem>
25
26
27namespace zxeco
28{
29
30namespace gui
31{
32
33
34/*******************************************************************************
35*
36* Class: FileBrowserWidget
37*
38*******************************************************************************/
39
41
44{
45 public:
46
48
50 enum : uint8_t {
53 WITH_EDIT = 4
54 };
55
56 FileBrowserWidget(ID id, const std::string & name,
57 uint8_t elements = WITH_TREE | WITH_PATH | WITH_EDIT,
58 const std::filesystem::path & initpath =
59 std::filesystem::path{},
60 const std::string & initedit = "",
61 char markingsinfiles = 'N',
62 const std::string & tooltiptext = "",
63 HorAlign hal = HorAlign::LEFT,
64 VertAlign val = VertAlign::TOP);
66
73 bool changeDir(const std::filesystem::path & path);
75
78 void reload(void)
79
80 { pwfiles_->list().fillWithFiles(curpath_,'T',
81 pwtree_ != nullptr,&fileentries_); }
82
83 const std::string & editedText(void) const;
85
87 const std::filesystem::path & browserPath(void) const noexcept
89 { return(curpath_); }
90
91 bool eventProcessedByTree(const CallbackParms & cbp) const noexcept
93
97 { return((pwtree_ != nullptr) && cbp.isAfterWithData() &&
98 (cbp.whoprocessed != nullptr) &&
99 cbp.whoprocessed->isDescendantOf(*pwtree_)); }
100
101 bool eventProcessedByFiles(const CallbackParms & cbp) const noexcept
103
107 { return(cbp.isAfterWithData() && (cbp.whoprocessed != nullptr) &&
108 cbp.whoprocessed->isDescendantOf(*pwfiles_)); }
109
110
111 const char * className(void) const noexcept { return("FileBrowserWidget"); }
112 std::pair<bool,const CharRect *> hasFocusZone(void) const noexcept override;
113
114 private:
115
116 enum Subwidgs {
117 PATH = 0,
118 TOP_CONT,
119 BACK_BUTT,
120 CENTRAL_CONT,
121 CONT_FILES,
122 FILES,
123 CONT_TREE,
124 TREE,
125 EDIT,
126 NUMSUBWIDGETS
127 };
128
129 static const ID kIDsSubs[NUMSUBWIDGETS];
130
131 static bool checkDir(const std::filesystem::path & pa);
132
133 LineInputWidget * pwpath_;
134 ListWidget * pwfiles_;
135 ListWidget * pwtree_;
136 LineInputWidget * pwedit_;
137 std::vector<std::string> fileentries_;
138 Widget * pfocused_;
139 int oldmark_;
140 std::filesystem::path curpath_;
141
142 int treeMarked(void) const;
143 void setDir(const std::filesystem::path & path);
144 bool followTreeDir(void);
145 int processEvent(const EventData & evdata, Widget * who) override;
146};
147
148
149
150} // end namespace gui
151} // end namespace zxeco
152
153#endif
154 // ZXWidgetFileBrowser
156
157
158
void fillWithFiles(const std::filesystem::path &path={}, char mode='T', bool onlyfiles=false, std::vector< std::string > *entries=nullptr)
Clear the list and fill it with the files and folders in PATH.
HorAlign
Horizontal alignment of widgets within the areas of their containers.
VertAlign
Vertical alignment of widgets within the areas of their containers.
A container of other widgets.
All widgets must inherit from this.
Definition: ZXWidgetsBase.h:56
int ID
A numeric ID associated to the widget.
Definition: ZXWidgetsBase.h:67
A class to contain the parameters received by a callback routine.
A widget that shows a line for user typing.
FileBrowserWidget(ID id, const std::string &name, uint8_t elements=WITH_TREE|WITH_PATH|WITH_EDIT, const std::filesystem::path &initpath=std::filesystem::path{}, const std::string &initedit="", char markingsinfiles='N', const std::string &tooltiptext="", HorAlign hal=HorAlign::LEFT, VertAlign val=VertAlign::TOP)
Constructor.
LabelList & list(void) noexcept
Return the current list of elements.
Definition: ZXWidgetList.h:102
const std::string & editedText(void) const
Return the currently text in the editing line.
const std::filesystem::path & browserPath(void) const noexcept
< Return a ref to the current path of the browser (empty after creation).
bool eventProcessedByTree(const CallbackParms &cbp) const noexcept
< Return TRUE if the callback is for an event already processed by tree.
@ WITH_EDIT
To show currently selected filename.
@ WITH_TREE
A tree for browsing directories.
@ WITH_PATH
To show current path.
bool changeDir(const std::filesystem::path &path)
Change the current path to the given one.
bool eventProcessedByFiles(const CallbackParms &cbp) const noexcept
< Return TRUE if the callback is for an event already processed by files.
std::pair< bool, const CharRect * > hasFocusZone(void) const noexcept override
< Must return TRUE and the zone if the widget contains a focus-able zone.
const char * className(void) const noexcept
Must return a text with the name of the class.
A widget that allows the user to browse files in the filesystem.
A sequence of text lines with possibly scroll bars and selection of elements.
Definition: ZXWidgetList.h:64
The main namespace of the library, that spans across all the zx modules.
Definition: ZXChars.h:31