Skip to content

Commit 6d0a583

Browse files
committed
Merge pull request #34 from chrisws/0_11_20
0 12 2
2 parents aa44aa9 + 595f275 commit 6d0a583

File tree

11 files changed

+177
-36
lines changed

11 files changed

+177
-36
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2015-12-05
2+
Implemented loading recent files via ALT+1 .. ALT+9
3+
Fix potential editor crash with empty support widget
4+
Fix potential crash with debug target
5+
Fix restore path to only function when no other arguments supplied
6+
17
2015-11-01
28
Fix debugger launch in linux build
39
Fix editor display issue with keyword completion

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dnl This program is distributed under the terms of the GPL v2.0
77
dnl Download the GNU Public License (GPL) from www.gnu.org
88
dnl
99

10-
AC_INIT([smallbasic], [0.12.1])
10+
AC_INIT([smallbasic], [0.12.2])
1111
AC_CONFIG_SRCDIR([configure.ac])
1212

1313
AC_CANONICAL_TARGET

debian/changelog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
smallbasic (0.12.2) unstable; urgency=low
2+
* Various - see web site
3+
4+
-- Chris Warren-Smith <cwarrensmith@gmail.com> Sat, 5 Dec 2015 09:45:25 +1000
5+
16
smallbasic (0.12.1) unstable; urgency=low
27
* Various - see web site
38

documentation/sbasic_ref.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,4 @@ Graphics,command,SHOWPAGE,0,"SHOWPAGE","This command is used to display pending
304304
Data,function,ISMAP,0,"ISMAP (x)","Returns true if x is an MAP variable type. A MAP provides value-key pair access along with array or dotted notation. The MAP can be initialized from a String variable using the ARRAY command"
305305
Data,function,ISREF,0,"ISREF (x)","Returns true if x is a reference variable type. The REF variable type is a ""reference"" to another variable (like a pointer in c). You create a reference by assigning a variable with the BYREF keyword (or @ symbol)."
306306
Data,function,ARRAY,0,"ARRAY [var | expr]","Creates a ARRAY or MAP variable from the given string or expression"
307-
Console,command,FORM,0,"FORM","Create a form widget. "
307+
Console,command,FORM,0,"FORM","Creates a form object from a MAP variable. This provides access to the following sub-commands: doEvents, close, refresh. The form MAP may contain the following properties: value, inputs, focusColor. Inputs is an array of MAP, each may contain the following properties: x, y, width, height, value, label, name, type, backgroundColor, color, visible, isExit, selectedIndex, length, noFocus, onclick"

ide/android/assets/main.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ sub do_about()
5555
print "(_ ._ _ _.|||_) /\ (_ |/ "
5656
print "__)| | |(_||||_)/--\__)|\_"
5757
print
58-
print "Version 0.12.1"
58+
print "Version 0.12.2"
5959
print
6060
print "Copyright (c) 2002-2015 Chris Warren-Smith"
6161
print "Copyright (c) 1999-2006 Nic Christopoulos" + chr(10)

src/platform/sdl/editor.cpp

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#include "common/sbapp.h"
1212
#include "ui/textedit.h"
1313
#include "platform/sdl/runtime.h"
14+
#include "platform/sdl/settings.h"
15+
16+
using namespace strlib;
1417

1518
void onlineHelp(Runtime *runtime, TextEditInput *widget) {
1619
char path[100];
@@ -29,26 +32,36 @@ void onlineHelp(Runtime *runtime, TextEditInput *widget) {
2932
runtime->browseFile(path);
3033
}
3134

32-
void System::editSource(strlib::String &loadPath) {
33-
logEntered();
34-
35-
strlib::String fileName;
35+
void setupStatus(String &dirtyFile, String &cleanFile, String &loadPath) {
36+
const char *help = " Ctrl+h (C-h)=Help";
37+
String fileName;
3638
int i = loadPath.lastIndexOf('/', 0);
3739
if (i != -1) {
3840
fileName = loadPath.substring(i + 1);
3941
} else {
4042
fileName = loadPath;
4143
}
42-
43-
const char *help = " Ctrl+h (C-h)=Help";
44-
strlib::String dirtyFile;
44+
dirtyFile.empty();
4545
dirtyFile.append(" * ");
4646
dirtyFile.append(fileName);
4747
dirtyFile.append(help);
48-
strlib::String cleanFile;
48+
cleanFile.empty();
4949
cleanFile.append(" - ");
5050
cleanFile.append(fileName);
5151
cleanFile.append(help);
52+
}
53+
54+
void showRecentFiles(TextEditHelpWidget *helpWidget) {
55+
helpWidget->createMessage();
56+
helpWidget->show();
57+
helpWidget->reload(NULL);
58+
String fileList;
59+
getRecentFileList(fileList);
60+
helpWidget->setText(fileList);
61+
}
62+
63+
void System::editSource(String &loadPath) {
64+
logEntered();
5265

5366
int w = _output->getWidth();
5467
int h = _output->getHeight();
@@ -58,8 +71,11 @@ void System::editSource(strlib::String &loadPath) {
5871
TextEditInput *editWidget = new TextEditInput(_programSrc, charWidth, charHeight, 0, 0, w, h);
5972
TextEditHelpWidget *helpWidget = new TextEditHelpWidget(editWidget, charWidth, charHeight);
6073
TextEditInput *widget = editWidget;
61-
_modifiedTime = getModifiedTime();
74+
String dirtyFile;
75+
String cleanFile;
6276

77+
setupStatus(dirtyFile, cleanFile, loadPath);
78+
_modifiedTime = getModifiedTime();
6379
editWidget->updateUI(NULL, NULL);
6480
editWidget->setLineNumbers();
6581
editWidget->setFocus(true);
@@ -85,6 +101,7 @@ void System::editSource(strlib::String &loadPath) {
85101
_state = kEditState;
86102

87103
showCursor(kIBeam);
104+
setRecentFile(loadPath.c_str());
88105

89106
while (_state == kEditState) {
90107
MAEvent event = getNextEvent();
@@ -216,6 +233,31 @@ void System::editSource(strlib::String &loadPath) {
216233
_output->selectScreen(SOURCE_SCREEN);
217234
_state = kEditState;
218235
break;
236+
case SB_KEY_ALT('0'):
237+
_output->setStatus("Recent files. Esc=Close");
238+
widget = helpWidget;
239+
showRecentFiles(helpWidget);
240+
break;
241+
case SB_KEY_ALT('1'):
242+
case SB_KEY_ALT('2'):
243+
case SB_KEY_ALT('3'):
244+
case SB_KEY_ALT('4'):
245+
case SB_KEY_ALT('5'):
246+
case SB_KEY_ALT('6'):
247+
case SB_KEY_ALT('7'):
248+
case SB_KEY_ALT('8'):
249+
case SB_KEY_ALT('9'):
250+
if (editWidget->isDirty()) {
251+
saveFile(editWidget, loadPath);
252+
}
253+
if (getRecentFile(loadPath, event.key - SB_KEY_ALT('1'))) {
254+
loadSource(loadPath.c_str());
255+
editWidget->reload(_programSrc);
256+
dirty = !editWidget->isDirty();
257+
setupStatus(dirtyFile, cleanFile, loadPath);
258+
_modifiedTime = getModifiedTime();
259+
}
260+
break;
219261
default:
220262
redraw = widget->edit(event.key, sw, charWidth);
221263
break;

src/platform/sdl/main.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ int main(int argc, char* argv[]) {
263263
char *fontFamily = NULL;
264264
char *runFile = NULL;
265265
bool debug = false;
266-
bool restoreDir = true;
267266
int fontScale;
268267
int ide_option = -1;
269268
SDL_Rect rect;
@@ -281,9 +280,7 @@ int main(int argc, char* argv[]) {
281280
&& ((strcasecmp(s + len - 4, ".bas") == 0 && access(s, 0) == 0)
282281
|| (strstr(s, "://") != NULL))) {
283282
runFile = strdup(s);
284-
} else if (chdir(s) == 0) {
285-
restoreDir = false;
286-
} else {
283+
} else if (chdir(s) != 0) {
287284
strcpy(opt_command, s);
288285
}
289286
}
@@ -347,7 +344,7 @@ int main(int argc, char* argv[]) {
347344
}
348345
}
349346

350-
restoreSettings(rect, fontScale, debug, restoreDir);
347+
restoreSettings(rect, fontScale, debug, argc == 1);
351348
if (ide_option != -1) {
352349
opt_ide = ide_option;
353350
}

src/platform/sdl/runtime.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -906,16 +906,22 @@ int debugThread(void *data) {
906906
break;
907907
case 'v':
908908
// variables
909-
net_print(socket, "Variables:\n");
910-
for (unsigned i = SYSVAR_COUNT; i < prog_varcount; i++) {
911-
if (!v_isempty(tvar[i])) {
912-
pv_writevar(tvar[i], PV_NET, socket);
913-
net_print(socket, "\n");
909+
SDL_LockMutex(g_lock);
910+
if (!runtime->isRunning()) {
911+
net_printf(socket, "\n");
912+
} else {
913+
net_print(socket, "Variables:\n");
914+
for (unsigned i = SYSVAR_COUNT; i < prog_varcount; i++) {
915+
if (!v_isempty(tvar[i])) {
916+
pv_writevar(tvar[i], PV_NET, socket);
917+
net_print(socket, "\n");
918+
}
914919
}
920+
net_print(socket, "Stack:\n");
921+
dumpStack(socket);
922+
net_print(socket, "\1");
915923
}
916-
net_print(socket, "Stack:\n");
917-
dumpStack(socket);
918-
net_print(socket, "\1");
924+
SDL_UnlockMutex(g_lock);
919925
break;
920926
case 'b':
921927
// set breakpoint

src/platform/sdl/settings.cpp

Lines changed: 91 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
#include <ctype.h>
1414
#include <sys/stat.h>
1515

16-
#include "platform/sdl/settings.h"
1716
#include "ui/utils.h"
1817
#include "ui/textedit.h"
1918
#include "common/smbas.h"
19+
#include "platform/sdl/settings.h"
20+
21+
using namespace strlib;
2022

2123
static const char *ENV_VARS[] = {
2224
"APPDATA", "HOME", "TMP", "TEMP", "TMPDIR"
@@ -29,13 +31,17 @@ static const char *ENV_VARS[] = {
2931
#define DEFAULT_WIDTH 640
3032
#define DEFAULT_HEIGHT 480
3133
#define DEFAULT_SCALE 100
34+
#define NUM_RECENT_ITEMS 9
3235

3336
#if defined(__MINGW32__)
3437
#define makedir(f) mkdir(f)
3538
#else
3639
#define makedir(f) mkdir(f, 0700)
3740
#endif
3841

42+
String recentPath[NUM_RECENT_ITEMS];
43+
int recentPosition[NUM_RECENT_ITEMS];
44+
3945
FILE *openConfig(const char *flags, bool debug) {
4046
FILE *result = NULL;
4147
char path[FILENAME_MAX];
@@ -94,19 +100,39 @@ int nextHex(FILE *fp, int def) {
94100
}
95101

96102
//
97-
// sets the next string in the file as the current working directory
103+
// returns the length of the next string
98104
//
99-
void restorePath(FILE *fp) {
105+
int nextString(FILE *fp) {
100106
int pos = ftell(fp);
101107
int len = 0;
102-
for (int c = fgetc(fp); c != EOF && c != ',' && c != '\n'; c = fgetc(fp)) {
108+
for (int c = fgetc(fp); c != EOF; c = fgetc(fp)) {
109+
if (c == '\n') {
110+
if (len > 0) {
111+
// string terminator
112+
break;
113+
} else {
114+
// skip previous terminator
115+
pos++;
116+
continue;
117+
}
118+
}
103119
len++;
104120
}
105121
fseek(fp, pos, SEEK_SET);
122+
return len;
123+
}
124+
125+
//
126+
// sets the next string in the file as the current working directory
127+
//
128+
void restorePath(FILE *fp, bool restoreDir) {
129+
int len = nextString(fp);
106130
if (len > 0) {
107131
String path;
108132
path.append(fp, len);
109-
chdir(path.c_str());
133+
if (restoreDir) {
134+
chdir(path.c_str());
135+
}
110136
}
111137
}
112138

@@ -127,8 +153,17 @@ void restoreSettings(SDL_Rect &rect, int &fontScale, bool debug, bool restoreDir
127153
for (int i = 0; i < THEME_COLOURS; i++) {
128154
g_user_theme[i] = nextHex(fp, g_user_theme[i]);
129155
}
130-
if (restoreDir) {
131-
restorePath(fp);
156+
restorePath(fp, restoreDir);
157+
158+
// restore recent paths
159+
for (int i = 0; i < NUM_RECENT_ITEMS; i++) {
160+
int len = nextString(fp);
161+
if (len > 1) {
162+
recentPath[i].empty();
163+
recentPath[i].append(fp, len);
164+
} else {
165+
break;
166+
}
132167
}
133168
fclose(fp);
134169
} else {
@@ -158,6 +193,7 @@ void saveSettings(SDL_Window *window, int fontScale, bool debug) {
158193
for (int i = 0; i < THEME_COLOURS; i++) {
159194
fprintf(fp, (i + 1 < THEME_COLOURS ? "%06x," : "%06x"), g_user_theme[i]);
160195
}
196+
fprintf(fp, "\n");
161197

162198
// save the current working directory
163199
char path[FILENAME_MAX + 1];
@@ -168,11 +204,56 @@ void saveSettings(SDL_Window *window, int fontScale, bool debug) {
168204
path[i] = '/';
169205
}
170206
}
171-
fprintf(fp, "\n%s\n", path);
172-
} else {
173-
fprintf(fp, "\n%s\n", path);
174207
}
208+
fprintf(fp, "%s\n", path);
209+
210+
// save the recent editor paths
211+
for (int i = 0; i < NUM_RECENT_ITEMS; i++) {
212+
if (recentPath[i].length() > 0) {
213+
fprintf(fp, "%s\n", recentPath[i].c_str());
214+
}
215+
}
216+
175217
fclose(fp);
176218
}
177219
}
178220

221+
bool getRecentFile(String &path, unsigned position) {
222+
bool result = false;
223+
if (position < NUM_RECENT_ITEMS && recentPath[position].length() > 0 &&
224+
!recentPath[position].equals(path)) {
225+
path.empty();
226+
path.append(recentPath[position]);
227+
result = true;
228+
}
229+
return result;
230+
}
231+
232+
void getRecentFileList(String &fileList) {
233+
for (int i = 0; i < NUM_RECENT_ITEMS; i++) {
234+
if (recentPath[i].length() > 0) {
235+
fileList.append(i + 1).append(" ");
236+
fileList.append(recentPath[i]).append("\n\n");
237+
}
238+
}
239+
}
240+
241+
void setRecentFile(const char *filename) {
242+
bool found = false;
243+
for (int i = 0; i < NUM_RECENT_ITEMS && !found; i++) {
244+
if (recentPath[i].equals(filename, false)) {
245+
found = true;
246+
}
247+
}
248+
if (!found) {
249+
// shift items downwards
250+
for (int i = NUM_RECENT_ITEMS - 1; i > 0; i--) {
251+
recentPath[i].empty();
252+
recentPath[i].append(recentPath[i - 1]);
253+
}
254+
255+
// create new item in first position
256+
recentPath[0].empty();
257+
recentPath[0].append(filename);
258+
}
259+
}

src/platform/sdl/settings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
void restoreSettings(SDL_Rect &rect, int &fontScale, bool debug, bool restoreDir);
1515
void saveSettings(SDL_Window *window, int fontScale, bool debug);
16+
void setRecentFile(const char *path);
17+
bool getRecentFile(strlib::String &path, unsigned position);
18+
void getRecentFileList(strlib::String &fileList);
1619

1720
#endif
1821

0 commit comments

Comments
 (0)