Skip to content

Commit 092a2fc

Browse files
committed
FLTK: added live editing menu
1 parent 9c0366f commit 092a2fc

File tree

9 files changed

+85
-27
lines changed

9 files changed

+85
-27
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2020-02-08 (0.12.18)
2+
SDL: fix issue #81 - numlock handling
3+
FLTK: added live editing menu item
4+
COMMON: increase stack size to 1024
5+
16
2019-12-21 (0.12.17)
27
SDL: fix issue #81 - numlock handling
38

src/common/sys.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ extern "C" {
7878
#define SB_KEYWORD_SIZE 128
7979
#define SB_SOURCELINE_SIZE 65536 // compiler
8080
#define SB_TEXTLINE_SIZE 8192 // RTL
81-
#define SB_EXEC_STACK_SIZE 512 // executor's stack size
81+
#define SB_EXEC_STACK_SIZE 1024 // executor's stack size
8282
#define SB_EVAL_STACK_SIZE 16 // evaluation stack size
8383
#define SB_KW_NONE_STR "Nil"
8484

src/platform/fltk/MainWindow.cxx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of SmallBASIC
22
//
3-
// Copyright(C) 2001-2019 Chris Warren-Smith.
3+
// Copyright(C) 2001-2020 Chris Warren-Smith.
44
//
55
// This program is distributed under the terms of the GPL v2.0 or later
66
// Download the GNU Public License (GPL) from www.gnu.org
@@ -9,6 +9,7 @@
99
#include <config.h>
1010
#include <FL/fl_ask.H>
1111
#include <FL/Fl_PNG_Image.H>
12+
#include <FL/fl_utf8.h>
1213
#include "platform/fltk/MainWindow.h"
1314
#include "platform/fltk/EditorWidget.h"
1415
#include "platform/fltk/HelpView.h"
@@ -524,6 +525,16 @@ void MainWindow::run_selection(Fl_Widget *w, void *eventData) {
524525
}
525526
}
526527

528+
/**
529+
* run the active program in sbasicg
530+
*/
531+
void MainWindow::run_live(Fl_Widget *w, void *eventData) {
532+
EditorWidget *editWidget = getEditor();
533+
if (editWidget) {
534+
launchExec(editWidget->getFilename());
535+
}
536+
}
537+
527538
/**
528539
* callback for editor-plug-in plug-ins. we assume the target
529540
* program will be changing the contents of the editor buffer
@@ -978,7 +989,8 @@ MainWindow::MainWindow(int w, int h) :
978989
scanPlugIns(m);
979990

980991
m->add("&Program/&Run", FL_F+9, run_cb);
981-
m->add("&Program/_&Run Selection", FL_F+8, run_selection_cb);
992+
m->add("&Program/Run &Live Editing", FL_F+8, run_live_cb);
993+
m->add("&Program/_Run &Selection", FL_F+7, run_selection_cb);
982994
m->add("&Program/&Break", FL_CTRL + 'b', run_break_cb);
983995
m->add("&Program/_&Restart", FL_CTRL + 'r', restart_run_cb);
984996
m->add("&Program/&Command", FL_F+10, set_options_cb);

src/platform/fltk/MainWindow.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of SmallBASIC
22
//
3-
// Copyright(C) 2001-2019 Chris Warren-Smith.
3+
// Copyright(C) 2001-2020 Chris Warren-Smith.
44
//
55
// This program is distributed under the terms of the GPL v2.0 or later
66
// Download the GNU Public License (GPL) from www.gnu.org
@@ -138,6 +138,7 @@ struct MainWindow : public BaseWindow {
138138
CALLBACK_METHOD(run_samples);
139139
CALLBACK_METHOD(run_break);
140140
CALLBACK_METHOD(run_selection);
141+
CALLBACK_METHOD(run_live);
141142
CALLBACK_METHOD(save_file_as);
142143
CALLBACK_METHOD(set_options);
143144
CALLBACK_METHOD(set_theme);

src/platform/fltk/utils.cxx

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
// This file is part of SmallBASIC
22
//
3-
// Copyright(C) 2001-2019 Chris Warren-Smith.
3+
// Copyright(C) 2001-2020 Chris Warren-Smith.
44
//
55
// This program is distributed under the terms of the GPL v2.0 or later
66
// Download the GNU Public License (GPL) from www.gnu.org
77
//
88

99
#include <config.h>
10-
#if !defined(_Win32)
10+
#if defined(_Win32)
11+
#include <shellapi.h>
12+
#else
1113
#include <sys/socket.h>
14+
#include <unistd.h>
15+
#include <errno.h>
1216
#endif
1317
#include <stdint.h>
1418
#include "lib/str.h"
@@ -232,3 +236,38 @@ void vsncat(char *buffer, size_t size, ...) {
232236
}
233237
va_end(args);
234238
}
239+
240+
241+
#if defined(_Win32)
242+
void launchExec(const char *file) {
243+
STARTUPINFO info = {sizeof(info)};
244+
PROCESS_INFORMATION processInfo;
245+
char cmd[1024];
246+
auto app = "./sbasicg.exe";
247+
sprintf(cmd, "%s -x %s", app, file);
248+
if (!CreateProcess(app, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo)) {
249+
appLog("failed to start %d %s %s\n", GetLastError(), app, cmd);
250+
}
251+
}
252+
#else
253+
void launchExec(const char *file) {
254+
pid_t pid = fork();
255+
auto app = "/usr/bin/sbasicg";
256+
257+
switch (pid) {
258+
case -1:
259+
// failed
260+
break;
261+
case 0:
262+
// child process
263+
if (execl(app, app, "-x", file, (char *)0) == -1) {
264+
fprintf(stderr, "exec failed [%s] %s\n", strerror(errno), app);
265+
exit(1);
266+
}
267+
break;
268+
default:
269+
// parent process - continue
270+
break;
271+
}
272+
}
273+
#endif

src/platform/fltk/utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@ Fl_Font get_font(const char *name);
5656
void getHomeDir(char *fileName, size_t size, bool appendSlash = true);
5757
bool cacheLink(dev_file_t *df, char *localFile, size_t size);
5858
void vsncat(char *buffer, size_t size, ...);
59+
void launchExec(const char *file);
5960

6061
#endif

src/platform/sdl/editor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct StatusMessage {
6363
.append(editor->getCol())
6464
.append(") ");
6565
if (!_insert) {
66-
message.append(" Ovwrt ");
66+
message.append("Ovwrt");
6767
}
6868
int digits = snprintf(NULL, 0, "%d%d",
6969
editor->getRow(), editor->getCol());

src/platform/sdl/keymap.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
const int keymap[][2] = {
1313
{SDLK_RETURN, SB_KEY_ENTER},
1414
{SDLK_ESCAPE, SB_KEY_ESCAPE},
15-
{SDLK_KP_PERIOD, '.'},
1615
{SDLK_KP_ENTER, SB_KEY_ENTER},
1716
{SDLK_TAB, SB_KEY_TAB},
1817
{SDLK_BACKSPACE, SB_KEY_BACKSPACE},

src/platform/sdl/runtime.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ MAEvent *getMotionEvent(int type, SDL_Event *event) {
6565
return result;
6666
}
6767

68+
MAEvent *getKeyPressedEvent(int keycode, int nativeKey) {
69+
MAEvent *result = new MAEvent();
70+
result->type = EVENT_TYPE_KEY_PRESSED;
71+
result->key = keycode;
72+
result->nativeKey = nativeKey;
73+
return result;
74+
}
75+
6876
Runtime::Runtime(SDL_Window *window) :
6977
System(),
7078
_menuX(0),
@@ -450,19 +458,10 @@ void Runtime::pollEvents(bool blocking) {
450458
if (ev.text.text[0] < 0) {
451459
wchar_t keycode;
452460
mbstowcs(&keycode, ev.text.text, 1);
453-
454-
MAEvent *keyEvent = new MAEvent();
455-
keyEvent->type = EVENT_TYPE_KEY_PRESSED;
456-
keyEvent->key = (int)keycode;
457-
keyEvent->nativeKey = 0;
458-
pushEvent(keyEvent);
461+
pushEvent(getKeyPressedEvent((int)keycode, 0));
459462
} else {
460463
for (int i = 0; ev.text.text[i] != 0; i++) {
461-
MAEvent *keyEvent = new MAEvent();
462-
keyEvent->type = EVENT_TYPE_KEY_PRESSED;
463-
keyEvent->key = ev.text.text[i];
464-
keyEvent->nativeKey = 0;
465-
pushEvent(keyEvent);
464+
pushEvent(getKeyPressedEvent(ev.text.text[i], 0));
466465
}
467466
}
468467
}
@@ -502,12 +501,17 @@ void Runtime::pollEvents(bool blocking) {
502501
}
503502
} else {
504503
int lenMap = sizeof(keymap) / sizeof(keymap[0]);
504+
if (ev.key.keysym.sym == SDLK_KP_PERIOD) {
505+
if (ev.key.keysym.mod == KMOD_NUM) {
506+
// '.' character sent as SDL_TEXTINPUT
507+
} else {
508+
pushEvent(getKeyPressedEvent(SB_KEY_DELETE, 0));
509+
}
510+
lenMap = 0;
511+
}
505512
for (int i = 0; i < lenMap; i++) {
506513
if (ev.key.keysym.sym == keymap[i][0]) {
507-
maEvent = new MAEvent();
508-
maEvent->type = EVENT_TYPE_KEY_PRESSED;
509-
maEvent->key = keymap[i][1];
510-
maEvent->nativeKey = ev.key.keysym.mod;
514+
pushEvent(getKeyPressedEvent(keymap[i][1], ev.key.keysym.mod));
511515
break;
512516
}
513517
}
@@ -521,10 +525,7 @@ void Runtime::pollEvents(bool blocking) {
521525
ev.key.keysym.sym != SDLK_LCTRL &&
522526
ev.key.keysym.sym != SDLK_RCTRL) ||
523527
(ev.key.keysym.mod & KMOD_ALT))) {
524-
maEvent = new MAEvent();
525-
maEvent->type = EVENT_TYPE_KEY_PRESSED;
526-
maEvent->key = ev.key.keysym.sym;
527-
maEvent->nativeKey = ev.key.keysym.mod;
528+
maEvent = getKeyPressedEvent(ev.key.keysym.sym, ev.key.keysym.mod);
528529
}
529530
}
530531
break;

0 commit comments

Comments
 (0)