11// This file is part of SmallBASIC
22//
3- // Copyright(C) 2001-2014 Chris Warren-Smith.
3+ // Copyright(C) 2001-2015 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
@@ -111,6 +111,7 @@ void System::editSource(strlib::String &loadPath) {
111111 TextEditInput *editWidget = new TextEditInput (_programSrc, charWidth, charHeight, 0 , 0 , w, h);
112112 TextEditHelpWidget *helpWidget = new TextEditHelpWidget (editWidget, charWidth, charHeight);
113113 TextEditInput *widget = editWidget;
114+ _modifiedTime = getModifiedTime ();
114115
115116 editWidget->updateUI (NULL , NULL );
116117 editWidget->setLineNumbers ();
@@ -144,6 +145,17 @@ void System::editSource(strlib::String &loadPath) {
144145 bool dirty = editWidget->isDirty ();
145146 char *text;
146147
148+ if (_modifiedTime != 0 && _modifiedTime != getModifiedTime ()) {
149+ const char *msg = " Do you want to reload the file?" ;
150+ if (ask (" File has changed on disk" , msg, false ) == 0 ) {
151+ loadSource (loadPath.c_str ());
152+ editWidget->reload (_programSrc);
153+ dirty = !editWidget->isDirty ();
154+ }
155+ _modifiedTime = getModifiedTime ();
156+ event.key = 0 ;
157+ }
158+
147159 switch (event.key ) {
148160 case SB_KEY_F (2 ):
149161 case SB_KEY_F (3 ):
@@ -170,6 +182,7 @@ void System::editSource(strlib::String &loadPath) {
170182 if (!editWidget->save (loadPath)) {
171183 alert (" " , " Failed to save file" );
172184 }
185+ _modifiedTime = getModifiedTime ();
173186 break ;
174187 case SB_KEY_CTRL (' c' ):
175188 case SB_KEY_CTRL (' x' ):
@@ -186,9 +199,14 @@ void System::editSource(strlib::String &loadPath) {
186199 helpWidget->show ();
187200 break ;
188201 case SB_KEY_CTRL (' h' ):
189- _output->setStatus (" Keystroke help. Esc=Close" );
190- widget = helpWidget;
191- helpWidget->createHelp ();
202+ if (widget == helpWidget) {
203+ _output->setStatus (" Keyword Help. Esc=Close" );
204+ helpWidget->createKeywordIndex ();
205+ } else {
206+ _output->setStatus (" Keystroke help. Esc=Close" );
207+ widget = helpWidget;
208+ helpWidget->createHelp ();
209+ }
192210 helpWidget->show ();
193211 break ;
194212 case SB_KEY_CTRL (' l' ):
@@ -954,7 +972,11 @@ void System::showSystemScreen(bool showSrc) {
954972
955973void System::waitForBack () {
956974 while (!isBack () && !isClosing () && !isRestart ()) {
957- getNextEvent ();
975+ MAEvent event = getNextEvent ();
976+ if (event.type == EVENT_TYPE_KEY_PRESSED &&
977+ event.key == SB_KEY_BACKSPACE) {
978+ break ;
979+ }
958980 }
959981}
960982
0 commit comments