| 55 | } |
| 56 | |
| 57 | void SaveFile(const char* path){ |
| 58 | struct stat sResult; |
| 59 | int ret = stat(path, &sResult); |
| 60 | if(ret && ret != ENOENT){ |
| 61 | Lemon::GUI::DisplayMessageBox("Text Editor", strerror(ret), Lemon::GUI::MsgButtonsOK); |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | if(S_ISDIR(sResult.st_mode)){ |
| 66 | Lemon::GUI::DisplayMessageBox("Text Editor", "File is a directory!", Lemon::GUI::MsgButtonsOK); |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | FILE* textFile = fopen(path, "w"); |
| 71 | |
| 72 | if(!textFile){ |
| 73 | Lemon::GUI::DisplayMessageBox("Text Editor", "Failed to open file for writing!", Lemon::GUI::MsgButtonsOK); |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | fseek(textFile, 0, SEEK_SET); |
| 78 | |
| 79 | for(std::string& str : textBox->contents){ |
| 80 | fwrite(str.c_str(), 1, str.length(), textFile); |
| 81 | fwrite("\n", 1, 1, textFile); // Line ending |
| 82 | } |
| 83 | |
| 84 | fclose(textFile); |
| 85 | |
| 86 | openPath = path; |
| 87 | } |
| 88 | |
| 89 | void OpenFile(){ |
| 90 |
no test coverage detected