Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/platform/sdl/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ void setupStatus(String &dirtyFile, String &cleanFile, String &loadPath) {
cleanFile.append(help);
}

void showRecentFiles(TextEditHelpWidget *helpWidget) {
void showRecentFiles(TextEditHelpWidget *helpWidget, String &loadPath) {
helpWidget->createMessage();
helpWidget->show();
helpWidget->reload(NULL);
String fileList;
getRecentFileList(fileList);
getRecentFileList(fileList, loadPath);
helpWidget->setText(fileList);
}

Expand Down Expand Up @@ -236,7 +236,7 @@ void System::editSource(String &loadPath) {
case SB_KEY_ALT('0'):
_output->setStatus("Recent files. Esc=Close");
widget = helpWidget;
showRecentFiles(helpWidget);
showRecentFiles(helpWidget, loadPath);
break;
case SB_KEY_ALT('1'):
case SB_KEY_ALT('2'):
Expand All @@ -256,6 +256,9 @@ void System::editSource(String &loadPath) {
dirty = !editWidget->isDirty();
setupStatus(dirtyFile, cleanFile, loadPath);
_modifiedTime = getModifiedTime();
if (helpWidget->messageMode() && helpWidget->isVisible()) {
showRecentFiles(helpWidget, loadPath);
}
}
break;
default:
Expand Down
21 changes: 14 additions & 7 deletions src/platform/sdl/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ FILE *openConfig(const char *flags, bool debug) {
int nextInteger(FILE *fp, int def) {
int result = 0;
for (int c = fgetc(fp); c != EOF && c != ',' && c != '\n'; c = fgetc(fp)) {
result = (result * 10) + (c - '0');
if (c != '\r') {
result = (result * 10) + (c - '0');
}
}
if (!result) {
result = def;
Expand All @@ -90,8 +92,10 @@ int nextInteger(FILE *fp, int def) {
int nextHex(FILE *fp, int def) {
int result = 0;
for (int c = fgetc(fp); c != EOF && c != ',' && c != '\n'; c = fgetc(fp)) {
int val = (c >= 'a') ? (10 + (c - 'a')) : (c - '0');
result = (result * 16) + val;
if (c != '\r') {
int val = (c >= 'a') ? (10 + (c - 'a')) : (c - '0');
result = (result * 16) + val;
}
}
if (!result) {
result = def;
Expand All @@ -106,7 +110,7 @@ int nextString(FILE *fp) {
int pos = ftell(fp);
int len = 0;
for (int c = fgetc(fp); c != EOF; c = fgetc(fp)) {
if (c == '\n') {
if (c == '\n' || c == '\r') {
if (len > 0) {
// string terminator
break;
Expand Down Expand Up @@ -140,7 +144,7 @@ void restorePath(FILE *fp, bool restoreDir) {
// restore window position
//
void restoreSettings(SDL_Rect &rect, int &fontScale, bool debug, bool restoreDir) {
FILE *fp = openConfig("r", debug);
FILE *fp = openConfig("rb", debug);
if (fp) {
rect.x = nextInteger(fp, SDL_WINDOWPOS_UNDEFINED);
rect.y = nextInteger(fp, SDL_WINDOWPOS_UNDEFINED);
Expand Down Expand Up @@ -182,7 +186,7 @@ void restoreSettings(SDL_Rect &rect, int &fontScale, bool debug, bool restoreDir
// save the window position
//
void saveSettings(SDL_Window *window, int fontScale, bool debug) {
FILE *fp = openConfig("w", debug);
FILE *fp = openConfig("wb", debug);
if (fp) {
int x, y, w, h;
SDL_GetWindowPosition(window, &x, &y);
Expand Down Expand Up @@ -229,9 +233,12 @@ bool getRecentFile(String &path, unsigned position) {
return result;
}

void getRecentFileList(String &fileList) {
void getRecentFileList(String &fileList, String &current) {
for (int i = 0; i < NUM_RECENT_ITEMS; i++) {
if (recentPath[i].length() > 0) {
if (recentPath[i].equals(current)) {
fileList.append(">> ");
}
fileList.append(i + 1).append(" ");
fileList.append(recentPath[i]).append("\n\n");
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/sdl/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void restoreSettings(SDL_Rect &rect, int &fontScale, bool debug, bool restoreDir
void saveSettings(SDL_Window *window, int fontScale, bool debug);
void setRecentFile(const char *path);
bool getRecentFile(strlib::String &path, unsigned position);
void getRecentFileList(strlib::String &fileList);
void getRecentFileList(strlib::String &fileList, strlib::String &current);

#endif

5 changes: 4 additions & 1 deletion src/ui/textedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#define strcasestr StrStrI
#endif

int g_themeId = 0;
unsigned g_themeId = 0;
int g_lineMarker[MAX_MARKERS] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1
};
Expand Down Expand Up @@ -136,6 +136,9 @@ int compareIntegers(const void *p1, const void *p2) {
// EditTheme
//
EditTheme::EditTheme() {
if (g_themeId >= (sizeof(themes) / sizeof(themes[0]))) {
g_themeId = 0;
}
selectTheme(themes[g_themeId]);
}

Expand Down
3 changes: 2 additions & 1 deletion src/ui/textedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "common/smbas.h"
#include "common/keymap.h"

extern int g_themeId;
extern unsigned g_themeId;
extern int g_user_theme[];
#define THEME_COLOURS 17

Expand Down Expand Up @@ -198,6 +198,7 @@ struct TextEditHelpWidget : public TextEditInput {
void resize(int w, int h) { _x = w - _width; _height = h; }
void reset(HelpMode mode);
bool closeOnEnter() const;
bool messageMode() const { return _mode == kMessage; }
bool replaceMode() const { return _mode == kReplace; }
bool replaceDoneMode() const { return _mode == kReplaceDone; }
bool selected(MAPoint2d pt, int scrollX, int scrollY, bool &redraw);
Expand Down