From 723d7968a8ad15ed1f10ea6a10f8cd09f7384175 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Mon, 7 Dec 2015 06:21:29 +1000 Subject: [PATCH 1/3] SDL: save settings in binary mode --- src/platform/sdl/settings.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platform/sdl/settings.cpp b/src/platform/sdl/settings.cpp index 0d9c3ba9..3d7fba85 100644 --- a/src/platform/sdl/settings.cpp +++ b/src/platform/sdl/settings.cpp @@ -140,7 +140,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); @@ -182,7 +182,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); From 021c75b4dd2e86b5675176bc94909e9209070882 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Mon, 7 Dec 2015 06:47:07 +1000 Subject: [PATCH 2/3] SDL: display current in recent file list --- src/platform/sdl/editor.cpp | 9 ++++++--- src/platform/sdl/settings.cpp | 5 ++++- src/platform/sdl/settings.h | 2 +- src/ui/textedit.h | 1 + 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/platform/sdl/editor.cpp b/src/platform/sdl/editor.cpp index bb66de8e..31f83dd7 100644 --- a/src/platform/sdl/editor.cpp +++ b/src/platform/sdl/editor.cpp @@ -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); } @@ -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'): @@ -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: diff --git a/src/platform/sdl/settings.cpp b/src/platform/sdl/settings.cpp index 3d7fba85..741fb6ec 100644 --- a/src/platform/sdl/settings.cpp +++ b/src/platform/sdl/settings.cpp @@ -229,9 +229,12 @@ bool getRecentFile(String &path, unsigned position) { return result; } -void getRecentFileList(String &fileList) { +void getRecentFileList(String &fileList, String ¤t) { 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"); } diff --git a/src/platform/sdl/settings.h b/src/platform/sdl/settings.h index 928d9815..f538692e 100644 --- a/src/platform/sdl/settings.h +++ b/src/platform/sdl/settings.h @@ -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 ¤t); #endif diff --git a/src/ui/textedit.h b/src/ui/textedit.h index b982cde4..616cb440 100644 --- a/src/ui/textedit.h +++ b/src/ui/textedit.h @@ -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); From 11f49fbad0b1555bd06b9b32c63d2bb41713f60d Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Thu, 10 Dec 2015 05:34:59 +1000 Subject: [PATCH 3/3] SDL: handle DOS mode settings.txt --- src/platform/sdl/settings.cpp | 12 ++++++++---- src/ui/textedit.cpp | 5 ++++- src/ui/textedit.h | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/platform/sdl/settings.cpp b/src/platform/sdl/settings.cpp index 741fb6ec..452fe298 100644 --- a/src/platform/sdl/settings.cpp +++ b/src/platform/sdl/settings.cpp @@ -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; @@ -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; @@ -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; diff --git a/src/ui/textedit.cpp b/src/ui/textedit.cpp index 0418262c..5ed76699 100644 --- a/src/ui/textedit.cpp +++ b/src/ui/textedit.cpp @@ -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 }; @@ -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]); } diff --git a/src/ui/textedit.h b/src/ui/textedit.h index 616cb440..29c01072 100644 --- a/src/ui/textedit.h +++ b/src/ui/textedit.h @@ -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