Correction menuBar::activateItem

This commit is contained in:
Jérôme Henry-Barnaudière - GeeHB 2024-01-05 14:30:47 +01:00
parent 45c7e4ad49
commit ffe553dc18
7 changed files with 92 additions and 82 deletions

View File

@ -28,8 +28,8 @@ extern "C" {
// App. infos
//
#define APP_NAME "sudoSolv"
#define APP_VERSION "0.1.9"
#define APP_NAME "sudoSolver"
#define APP_VERSION "0.1.11"
#define APP_AUTHOR "GeeHB"
// Grids folder

View File

@ -26,8 +26,6 @@ grids::grids(){
// this folder
strcpy(folder_, GRIDS_FOLDER);
strcat(folder_, PATH_SEPARATOR);
_browse();
}
// setPos() : Set current position index in list
@ -44,6 +42,62 @@ int grids::setPos(int index){
return index_;
}
// browse() : browse folder and fill list with file names
//
// @return : count of elements read or -1 if error
//
int grids::browse(){
bFile folder;
char szPattern[BFILE_MAX_PATH + 1];
#ifdef DEST_CASIO_CALC
uint16_t fName[BFILE_MAX_PATH + 1];
uint16_t FCPattern[BFILE_MAX_PATH + 1];
#else
char fName[BFILE_MAX_PATH + 1];
char FCPattern[BFILE_MAX_PATH + 1];
#endif // DEST_CASIO_CALC
// Ensure folder exist
strcpy(szPattern, GRIDS_FOLDER);
folder.FC_str2FC(szPattern, fName);
if (!folder.exist(fName)){
// create the folder
if (!folder.create(fName, BFile_Folder, NULL)){
return -1;
}
}
// Empty the list
if (capacity_){
__vector_clear();
}
// Browse folder
SEARCHHANDLE shandle;
struct BFile_FileInfo fileInfo;
#ifdef DEST_CASIO_CALC
strcat(szPattern, PATH_SEPARATOR);
strcat(szPattern, GRID_FILE_SEARCH_PATTERN);
#endif // DEST_CASIO_PATTERN
folder.FC_str2FC(szPattern, FCPattern);
if (folder.findFirst(FCPattern, &shandle, fName, &fileInfo)){
do{
// a file ?
if (BFile_Type_Archived == fileInfo.type){
_addFile(fName);
}
} while(folder.findNext(shandle, fName, &fileInfo));
folder.findClose(shandle);
}
return count_;
}
// addFileName() : Add a filename to the folder's content list
//
// @fName : filename to add
@ -164,58 +218,6 @@ bool grids::deleteFile(){
// Internal methods
//
// _browse() : browse folder and fill list with file names
//
void grids::_browse(){
bFile folder;
char szPattern[BFILE_MAX_PATH + 1];
#ifdef DEST_CASIO_CALC
uint16_t fName[BFILE_MAX_PATH + 1];
uint16_t FCPattern[BFILE_MAX_PATH + 1];
#else
char fName[BFILE_MAX_PATH + 1];
char FCPattern[BFILE_MAX_PATH + 1];
#endif // DEST_CASIO_CALC
// Ensure folder exist
strcpy(szPattern, GRIDS_FOLDER);
folder.FC_str2FC(szPattern, fName);
if (!folder.exist(fName)){
// create the folder
if (!folder.create(fName, BFile_Folder, NULL)){
return;
}
}
// Empty the list
if (capacity_){
__vector_clear();
}
// Browse folder
SEARCHHANDLE shandle;
struct BFile_FileInfo fileInfo;
#ifdef DEST_CASIO_CALC
strcat(szPattern, PATH_SEPARATOR);
strcat(szPattern, GRID_FILE_SEARCH_PATTERN);
#endif // DEST_CASIO_PATTERN
folder.FC_str2FC(szPattern, FCPattern);
if (folder.findFirst(FCPattern, &shandle, fName, &fileInfo)){
do{
// a file ?
if (BFile_Type_Archived == fileInfo.type){
_addFile(fName);
}
} while(folder.findNext(shandle, fName, &fileInfo));
folder.findClose(shandle);
}
}
// _addFile() - Add file to the list
//
// @fileName : file to add (with no folder)

View File

@ -51,6 +51,12 @@ public:
//
int setPos(int index);
// browse() : browse folder and fill list with file names
//
// @return : count of elements read or -1 if error
//
int browse();
// addFileName() : Add a filename to the folder's content list
//
// @fName : filename to add
@ -92,10 +98,6 @@ public:
// Internal methods
private:
// _browse() : browse folder and fill list with file names
//
void _browse();
// _addFile() - Add file to the list
//
// @fileName : file to add (with no folder)

View File

@ -65,12 +65,18 @@ void menuBar::update(){
_drawItem(&anchor, item);
#else
if (item){
cout << "|" << ((item->state == ITEM_STATE_SELECTED)?">" : " ");
cout << "|" << (_isBitSet(item->state, ITEM_STATE_SELECTED)?">" : " ");
if (_isBitSet(item->status, ITEM_STATUS_CHECKBOX)){
cout << (_isBitSet(item->state, ITEM_STATE_CHECKED)?"[x] ":"[ ] ");
}
cout << item->text;
cout << ((item->state == ITEM_STATE_SELECTED)?"<" : " ");
if (_isBitSet(item->state,ITEM_STATE_INACTIVE)){
cout << "_" << (item->text+1);
}
else {
cout << item->text;
}
cout << (_isBitSet(item->state,ITEM_STATE_SELECTED)?"<" : " ");
cout << "|";
}
else{
@ -114,8 +120,8 @@ bool menuBar::activateItem(int searchedID, int searchMode, bool activated){
PMENUITEM item(_findItem(&current_, searchedID, searchMode));
if (item){
// Found an item with this ID
bool inactive = _isBitSet(item->state, ITEM_STATE_INACTIVE);
if (inactive == activated){
bool active = !_isBitSet(item->state, ITEM_STATE_INACTIVE);
if (active != activated){
// change item's state
if (activated){
_removeBit(item->state, ITEM_STATE_INACTIVE);

View File

@ -43,7 +43,7 @@ int main(void)
// List of grid files
grids files;
if (files.size()){
if (files.browse() > 0){
menu.activate(IDM_FILE_NEXT, SEARCH_BY_ID, true);
menu.update();
}
@ -58,7 +58,7 @@ int main(void)
//
sudoku game(&mainRect);
bool end(false);
uint8_t error(FILE_NO_ERROR);
int error(FILE_NO_ERROR);
MENUACTION action;
while (!end){
// A menu action ?
@ -129,7 +129,9 @@ int main(void)
// Save the grid (using a new name)
case IDM_FILE_SAVE:
if (files.newFileName(fileName)){
if (game.save(fileName)){
bFile::FC_FC2str(fileName, sFileName);
dprint(TEXT_X, 1, C_RED, "File : %s", sFileName);
if (FILE_NO_ERROR == (error = game.save(fileName))){
if (files.addFileName(fileName)){
_setFileName(fileName, sFileName);
_displayStats(sFileName, -1, -1);
@ -141,7 +143,7 @@ int main(void)
}
}
else{
dprint(TEXT_X, TEXT_V_OFFSET, C_RED, "Error saving file");
dprint(TEXT_X, TEXT_V_OFFSET, C_RED, "Error saving file : %d", error);
}
menu.activate(IDM_FILE_SAVE, SEARCH_BY_ID, false);
menu.activate(IDM_FILE_DELETE, SEARCH_BY_ID, true);

View File

@ -163,28 +163,25 @@ uint8_t sudoku::load(const FONTCHARACTER fName){
//
// @return : 0 on success or an error code
//
uint8_t sudoku::save(const FONTCHARACTER fName){
int sudoku::save(const FONTCHARACTER fName){
if (!fName || !fName[0]){
return FILE_NO_FILENAME; // No valid file name
}
// Transfer content in a buffer
char buffer[FILE_SIZE+1];
element* pElement(NULL);
position pos(INDEX_MIN, false); // Begining of the matrix
memset(buffer, 0x00, FILE_SIZE); // ???
int index(0);
for (uint8_t lId(0); lId < LINE_COUNT; lId++){
for (uint8_t cId(0); cId < ROW_COUNT; cId++){
pElement = &elements_[pos];
// '0' means empty !
buffer[2*pos] = pElement->isOriginal()?('0' + pElement->value()):'0';
buffer[2*pos+1] = VALUE_SEPARATOR;
pos+=1; // next element
buffer[2*index] = (elements_[index].isOriginal()?('0' + elements_[index].value()):'0');
buffer[2*index+1] = VALUE_SEPARATOR;
index++;
}
// Replace separator by LF
buffer[2*pos-1] = '\n';
buffer[2*index-1] = '\n';
}
buffer[FILE_SIZE] = '\0'; // for trace purpose
@ -195,15 +192,16 @@ uint8_t sudoku::save(const FONTCHARACTER fName){
oFile.remove(fName); // Remove the file (if already exist)
if (!oFile.create(fName, BFile_File, &fSize)){
return FILE_IO_ERROR;
return oFile.getLastError();
}
// copy the buffer to the file
bool done = oFile.write(buffer, FILE_SIZE);
int error = oFile.getLastError();
oFile.close();
// Done ?
return (done?FILE_NO_ERROR:FILE_IO_ERROR);
return (done?FILE_NO_ERROR:error);
}
#ifdef DEST_CASIO_CALC

View File

@ -65,7 +65,7 @@ public:
//
// @return : 0 on success or an error code
//
uint8_t save(const FONTCHARACTER fName);
int save(const FONTCHARACTER fName);
#ifdef DEST_CASIO_CALC
// edit() : Edit / modify the current grid