Skip to content

Commit 56d1d10

Browse files
committed
FLTK: add online samples command
1 parent e54aa34 commit 56d1d10

File tree

5 files changed

+52
-7
lines changed

5 files changed

+52
-7
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2019-12-13 (0.12.17)
2+
FLTK: add online samples command
3+
14
2019-12-07 (0.12.17)
25
FLTK: fix memory leaks
36
FLTK: implement audio

src/platform/fltk/MainWindow.cxx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,19 @@ void MainWindow::run_break(Fl_Widget *w, void *eventData) {
509509
}
510510
}
511511

512+
/**
513+
* run the online samples program
514+
*/
515+
void MainWindow::run_samples(Fl_Widget *w, void *eventData) {
516+
if (runMode == edit_state) {
517+
runMode = run_state;
518+
_runtime->runSamples();
519+
runMode = edit_state;
520+
} else {
521+
busyMessage();
522+
}
523+
}
524+
512525
/**
513526
* run the selected text as the main program
514527
*/
@@ -981,6 +994,7 @@ MainWindow::MainWindow(int w, int h) :
981994
m->add("&Program/&Break", FL_CTRL + 'b', run_break_cb);
982995
m->add("&Program/_&Restart", FL_CTRL + 'r', restart_run_cb);
983996
m->add("&Program/&Command", FL_F+10, set_options_cb);
997+
m->add("&Program/Online Samples", 0, run_samples_cb);
984998
m->add("&Help/&Help Contents", FL_F+1, help_contents_cb);
985999
m->add("&Help/_&Context Help", FL_F+2, help_contents_brief_cb);
9861000
m->add("&Help/&Program Help", FL_F+11, help_app_cb);

src/platform/fltk/MainWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ struct MainWindow : public BaseWindow {
134134
CALLBACK_METHOD(quit);
135135
CALLBACK_METHOD(restart_run);
136136
CALLBACK_METHOD(run);
137+
CALLBACK_METHOD(run_samples);
137138
CALLBACK_METHOD(run_break);
138139
CALLBACK_METHOD(run_selection);
139140
CALLBACK_METHOD(save_file_as);

src/platform/fltk/runtime.cxx

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
extern MainWindow *wnd;
1919
extern System *g_system;
20+
static auto *onlineUrl = "http://smallbasic.github.io/samples/index.bas";
2021

2122
#define MIN_WINDOW_SIZE 10
2223
#define OPTIONS_BOX_WIDTH_EXTRA 4
@@ -60,9 +61,9 @@ void Runtime::alert(const char *title, const char *message) {
6061
int Runtime::ask(const char *title, const char *prompt, bool cancel) {
6162
int result;
6263
if (cancel) {
63-
result = fl_choice(prompt, "Yes", "No", "Cancel", NULL);
64+
result = fl_choice(prompt, "Yes", "No", "Cancel", nullptr);
6465
} else {
65-
result = fl_choice(prompt, "Yes", "No", 0, NULL);
66+
result = fl_choice(prompt, "Yes", "No", 0, nullptr);
6667
}
6768
return result;
6869
}
@@ -76,7 +77,7 @@ void Runtime::enableCursor(bool enabled) {
7677
}
7778

7879
char *Runtime::getClipboardText() {
79-
return NULL;
80+
return nullptr;
8081
}
8182

8283
int Runtime::handle(int e) {
@@ -126,7 +127,7 @@ void Runtime::optionsBox(StringList *items) {
126127
menu[index].labelfont_ = FL_HELVETICA;
127128
menu[index].labelsize_ = FL_NORMAL_SIZE;
128129
menu[index].labelcolor_ = FL_FOREGROUND_COLOR;
129-
menu[index].measure(&h, NULL);
130+
menu[index].measure(&h, nullptr);
130131

131132
height += h + 1;
132133
w = (strlen(str) * charWidth);
@@ -137,7 +138,7 @@ void Runtime::optionsBox(StringList *items) {
137138
}
138139

139140
menu[index].flags = 0;
140-
menu[index].text = NULL;
141+
menu[index].text = nullptr;
141142
width += (charWidth * OPTIONS_BOX_WIDTH_EXTRA);
142143

143144
int menuX = event_x();
@@ -201,8 +202,33 @@ void Runtime::resize(int w, int h) {
201202
}
202203
}
203204

205+
void Runtime::runSamples() {
206+
logEntered();
207+
_loadPath = onlineUrl;
208+
_mainBas = true;
209+
210+
String activePath = _loadPath;
211+
bool started = execute(onlineUrl);
212+
213+
while (started && !wnd->isBreakExec()) {
214+
if (isBreak() && (activePath.equals(onlineUrl) || activePath.equals(_loadPath))) {
215+
// break from index page OR break with same _loadPath
216+
break;
217+
}
218+
if (_loadPath.empty()) {
219+
// return to index page
220+
_loadPath = onlineUrl;
221+
}
222+
activePath = _loadPath;
223+
started = execute(_loadPath);
224+
}
225+
_mainBas = false;
226+
showCompletion(started);
227+
_output->redraw();
228+
}
229+
204230
void Runtime::setClipboardText(const char *text) {
205-
Fl::copy(text, strlen(text), true);
231+
Fl::copy(text, strlen(text), 1);
206232
}
207233

208234
void Runtime::setFontSize(int size) {
@@ -347,7 +373,7 @@ int osd_devrestore() {
347373
void appLog(const char *format, ...) {
348374
va_list args;
349375
va_start(args, format);
350-
unsigned size = vsnprintf(NULL, 0, format, args);
376+
unsigned size = vsnprintf(nullptr, 0, format, args);
351377
va_end(args);
352378

353379
if (size) {

src/platform/fltk/runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct Runtime : public System {
2626
void optionsBox(StringList *items);
2727
MAEvent processEvents(int waitFlag);
2828
bool run(const char *bas) { return execute(bas); }
29+
void runSamples();
2930
void resize(int w, int h);
3031
void setClipboardText(const char *text);
3132
void setFontSize(int size);

0 commit comments

Comments
 (0)