@@ -45,7 +45,8 @@ void setup() {
4545 }, NO_REPEAT);
4646
4747 // and initialise the list menu item with the number of rows, see the list callback function below
48- menuRootList.setNumberOfRows (FILE_NAME_SIZE);
48+ // we set the number of items to all the files plus the refresh item
49+ menuRootList.setNumberOfRows (FILE_NAME_SIZE + 1 );
4950}
5051
5152void loop () {
@@ -154,16 +155,32 @@ void CALLBACK_FUNCTION onShowDialogs(int) {
154155int CALLBACK_FUNCTION fnRootListRtCall (RuntimeMenuItem* item, uint8_t row, RenderFnMode mode, char * buffer, int bufferSize) {
155156 switch (mode) {
156157 case RENDERFN_INVOKE:
157- serlogF2 (SER_DEBUG, " List invoke: " , row);
158- menuMgr.resetMenu (false ); // drop back one level dismissing the list
159- reinterpret_cast <ListRuntimeMenuItem*>(item)->asParent ();
158+ // we have a list of files and a refresh option at the end.
159+ if (row < FILE_NAME_SIZE) {
160+ // a file has been selected, dismiss list.
161+ serlogF2 (SER_DEBUG, " List invoke: " , row);
162+ menuMgr.resetMenu (false ); // drop back one level dismissing the list
163+ reinterpret_cast <ListRuntimeMenuItem *>(item)->asParent ();
164+ } else {
165+ // refresh was selected, refresh and force recalc.
166+ item->setNumberOfRows (item->getNumberOfRows () + 1 );
167+ menuMgr.recalculateListIfOnDisplay (item);
168+ }
160169 return true ;
161170 case RENDERFN_NAME:
162171 strncpy (buffer, " Choose File" , bufferSize);
163172 return true ;
164173 case RENDERFN_VALUE:
165- if (row < FILE_NAME_SIZE) {
174+ if (row == LIST_PARENT_ITEM_POS) {
175+ // no value on the parent item, IE when this list is displayed in a parent menu.
176+ buffer[0 ]=0 ;
177+ } else if (row < FILE_NAME_SIZE) {
178+ // copy the file name into the buffer
166179 strncpy (buffer, fileNames[row], bufferSize);
180+ } else if (row == FILE_NAME_SIZE) {
181+ strcpy (buffer, " Add more" );
182+ } else {
183+ ltoaClrBuff (buffer, row, 4 , ' 0' , bufferSize);
167184 }
168185 return true ;
169186 case RENDERFN_EEPROM_POS: return 0xffff ; // lists are generally not saved to EEPROM
0 commit comments