@@ -149,16 +149,17 @@ class CachedFSO:public FSO<SDC> {
149149// instead of allocating options for each file we will instead customize a menu
150150// to print the files list, we can opt to use objects for each file for a
151151// faster reopening.. but its working quite fast
152- // avr's will be limited to 127 file (not a good idea)
153- // this can be changed without breaking compatibility thou, but wasting more memory.
154152// On this example we assume the existence of an esc button as we are not drawing
155153// an exit option (or [..] as would be appropriate for a file system)
156154// not the mennu presents it self as the menu and as the options
157155// ands does all drawing navigation.
156+ #define USE_BACKDOTS 1
157+
158158template <typename FS>
159159class SDMenuT :public menuNode ,public FS {
160160public:
161161 String folderName=" /" ;// set this to other folder when needed
162+ String selectedFolder=" /" ;
162163 String selectedFile=" " ;
163164 // using menuNode::menuNode;//do not use default constructors as we wont allocate for data
164165 SDMenuT (typename FS::Type& sd,constText* title,const char * at,Menu::action act=doNothing,Menu::eventMask mask=noEvent)
@@ -175,16 +176,16 @@ class SDMenuT:public menuNode,public FS {
175176 switch (event) {
176177 case enterEvent:
177178 if (nav.root ->navFocus !=nav.target ) {// on sd card entry
178- nav.sel =((SDMenuT<FS>*)(&item))->entryIdx (((SDMenuT<FS>*)(&item))->selectedFile );// restore context
179+ nav.sel =((SDMenuT<FS>*)(&item))->entryIdx (((SDMenuT<FS>*)(&item))->selectedFile )+USE_BACKDOTS ;// restore context
179180 }
180181 }
181182 return proceed;
182183 }
183184
184185 void doNav (navNode& nav,navCmd cmd) {
185186 switch (cmd.cmd ) {
186- case enterCmd: {
187- String selFile=SDMenuT<FS>::entry (nav.sel );
187+ case enterCmd: if (nav. sel >=USE_BACKDOTS) {
188+ String selFile=SDMenuT<FS>::entry (nav.sel -USE_BACKDOTS );
188189 if (selFile.endsWith (" /" )) {
189190 // Serial.print("\nOpen folder...");
190191 // open folder (reusing the menu)
@@ -196,6 +197,7 @@ class SDMenuT:public menuNode,public FS {
196197 // Serial.print("\nFile selected:");
197198 // select a file and return
198199 selectedFile=selFile;
200+ selectedFolder=folderName;
199201 nav.root ->node ().event (enterEvent);
200202 menuNode::doNav (nav,escCmd);
201203 }
@@ -210,7 +212,7 @@ class SDMenuT:public menuNode,public FS {
210212 folderName.remove (folderName.lastIndexOf (" /" ,folderName.length ()-2 )+1 );
211213 SDMenuT<FS>::goFolder (folderName);
212214 dirty=true ;// redraw menu
213- nav.sel =SDMenuT<FS>::entryIdx (fn);
215+ nav.sel =SDMenuT<FS>::entryIdx (fn)+USE_BACKDOTS ;
214216 }
215217 return ;
216218 }
@@ -224,11 +226,17 @@ class SDMenuT:public menuNode,public FS {
224226 menuNode::printTo (root,sel,out,idx,len,pn):
225227 out.printRaw (selectedFile.c_str (),len);
226228 } else if (idx==-1 ) {// when menu open (show folder name)
227- ((menuNodeShadow*)shadow)->sz =SDMenuT<FS>::count ();
228- return out.printRaw (folderName.c_str (),len);
229+ ((menuNodeShadow*)shadow)->sz =SDMenuT<FS>::count ()+USE_BACKDOTS;
230+ idx_t at=folderName.lastIndexOf (" /" ,folderName.length ()-2 )+1 ;
231+ String fn=folderName.substring (at,folderName.length ()-1 );
232+ return out.printRaw (fn.c_str (),len);
233+ // return out.printRaw(folderName.c_str(),len);
234+ // return out.printRaw(SDMenuT<FS>::dir.name(),len);
229235 }
230236 // drawing options
231- len-=out.printRaw (SDMenuT<FS>::entry (out.tops [root.level ]+idx).c_str (),len);
237+ idx_t i=out.tops [root.level ]+idx;
238+ if (i<USE_BACKDOTS) len-=out.printRaw (" [..]" ,len);
239+ else len-=out.printRaw (SDMenuT<FS>::entry (out.tops [root.level ]+idx-USE_BACKDOTS).c_str (),len);
232240 return len;
233241 }
234242};
0 commit comments