| 23 | std::string openPath; |
| 24 | |
| 25 | void LoadFile(const char* path){ |
| 26 | textBox->contents.clear(); |
| 27 | |
| 28 | FILE* textFile = fopen(path, "r"); |
| 29 | |
| 30 | if(!textFile){ |
| 31 | Lemon::GUI::DisplayMessageBox("Text Editor", "Failed to open file!", Lemon::GUI::MsgButtonsOK); |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | fseek(textFile, 0, SEEK_END); |
| 36 | long textFileSize = ftell(textFile); |
| 37 | fseek(textFile, 0, SEEK_SET); |
| 38 | |
| 39 | char* textBuffer = (char*)malloc(textFileSize + 1); |
| 40 | |
| 41 | fread(textBuffer, textFileSize, 1, textFile); |
| 42 | for(int i = 0; i < textFileSize; i++){ if(textBuffer[i] == 0) textBuffer[i] = ' ';} |
| 43 | textBuffer[textFileSize] = 0; |
| 44 | |
| 45 | textBox->LoadText(textBuffer); |
| 46 | |
| 47 | free(textBuffer); |
| 48 | |
| 49 | openPath = path; |
| 50 | |
| 51 | char title[32 + openPath.length()]; |
| 52 | sprintf(title, "Text Editor: %s", openPath.c_str()); |
| 53 | |
| 54 | window->SetTitle(title); |
| 55 | } |
| 56 | |
| 57 | void SaveFile(const char* path){ |
| 58 | struct stat sResult; |