1313#include " common/device.h"
1414#include " ui/keypad.h"
1515
16- void showHelpLineInput (TextEditHelpWidget *helpWidget, int width = 35 ) {
17- helpWidget->showPopup (width, 1 );
18- }
16+ struct StatusMessage {
17+ explicit StatusMessage (const TextEditInput *editor) :
18+ _dirty(editor->isDirty ()),
19+ _row(editor->getRow ()),
20+ _col(editor->getCol ()) {
21+ }
1922
20- void Runtime::editSource (strlib::String loadPath, bool restoreOnExit) {
21- logEntered ();
23+ void setFilename (const String &loadPath) {
24+ int i = loadPath.lastIndexOf (' /' , 0 );
25+ if (i != -1 ) {
26+ _fileName = loadPath.substring (i + 1 );
27+ } else {
28+ _fileName = loadPath;
29+ }
30+ }
2231
23- strlib::String fileName;
24- int i = loadPath.lastIndexOf (' /' , 0 );
25- if (i != -1 ) {
26- fileName = loadPath.substring (i + 1 );
27- } else {
28- fileName = loadPath;
32+ bool update (TextEditInput *editor, const AnsiWidget *out, const bool force=false ) {
33+ bool result;
34+ bool dirty = editor->isDirty ();
35+ if (force
36+ || _dirty != dirty
37+ || _row != editor->getRow ()
38+ || _col != editor->getCol ()) {
39+ String message;
40+ result = true ;
41+ if (dirty) {
42+ message.append (" * " );
43+ } else {
44+ message.append (" - " );
45+ }
46+ message.append (_fileName)
47+ .append (" (" )
48+ .append (editor->getRow ())
49+ .append (" ," )
50+ .append (editor->getCol ())
51+ .append (" ) " );
52+ if (!editor->getScroll ()) {
53+ message.append (" Top" );
54+ } else if (editor->getLines () - editor->getScroll () < editor->getPageRows ()) {
55+ message.append (" Bot" );
56+ } else {
57+ const int pos = editor->getRow () * 100 / editor->getLines ();
58+ message.append (pos).append (" %" );
59+ }
60+ out->setStatus (message);
61+ _dirty = dirty;
62+ resetCursor (editor);
63+ } else {
64+ result = false ;
65+ }
66+ return result;
2967 }
3068
31- strlib::String dirtyFile;
32- dirtyFile.append (" * " );
33- dirtyFile.append (fileName);
34- strlib::String cleanFile;
35- cleanFile.append (" - " );
36- cleanFile.append (fileName);
69+ void resetCursor (const TextEditInput *editor) {
70+ _row = editor->getRow ();
71+ _col = editor->getCol ();
72+ }
73+
74+ void setDirty (const TextEditInput *editor) {
75+ _dirty = !editor->isDirty ();
76+ }
77+
78+ bool _dirty;
79+ int _row;
80+ int _col;
81+ String _fileName;
82+ };
83+
84+ void showFind (TextEditHelpWidget *helpWidget) {
85+ helpWidget->showPopup (35 , 1 );
86+ helpWidget->createSearch (false );
87+ helpWidget->setFocus (true );
88+ }
89+
90+ void showHelp (TextEditHelpWidget *helpWidget) {
91+ helpWidget->showPopup (-4 , -2 );
92+ helpWidget->createKeywordIndex ();
93+ helpWidget->setFocus (true );
94+ }
95+
96+ void Runtime::editSource (strlib::String loadPath, bool restoreOnExit) {
97+ logEntered ();
3798
3899 int w = _output->getWidth ();
39100 int h = _output->getHeight ();
@@ -50,6 +111,9 @@ void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
50111 }
51112 auto *helpWidget = new TextEditHelpWidget (editWidget, charWidth, charHeight, false );
52113 auto *widget = editWidget;
114+ StatusMessage statusMessage (editWidget);
115+ statusMessage.setFilename (loadPath);
116+
53117 _modifiedTime = getModifiedTime ();
54118 editWidget->updateUI (nullptr , nullptr );
55119 editWidget->setLineNumbers ();
@@ -79,9 +143,9 @@ void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
79143 alert (gsb_last_errmsg);
80144 }
81145
146+ statusMessage.update (editWidget, _output, true );
82147 bool showStatus = !editWidget->getScroll ();
83148 _srcRendered = false ;
84- _output->setStatus (showStatus ? cleanFile : " " );
85149 _output->redraw ();
86150 _state = kEditState ;
87151
@@ -91,28 +155,31 @@ void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
91155 switch (event.type ) {
92156 case EVENT_TYPE_POINTER_PRESSED:
93157 if (!showStatus && widget == editWidget && event.point .x < editWidget->getMarginWidth ()) {
94- _output-> setStatus (editWidget-> isDirty () ? dirtyFile : cleanFile );
158+ statusMessage. update (editWidget, _output, true );
95159 _output->redraw ();
96160 showStatus = true ;
97161 }
98162 break ;
163+ case EVENT_TYPE_POINTER_DRAGGED:
164+ statusMessage.update (editWidget, _output);
165+ break ;
99166 case EVENT_TYPE_POINTER_RELEASED:
100167 if (showStatus && event.point .x < editWidget->getMarginWidth () && editWidget->getScroll ()) {
168+ statusMessage.update (editWidget, _output);
101169 _output->setStatus (" " );
102170 _output->redraw ();
103171 showStatus = false ;
104172 }
105173 break ;
106174 case EVENT_TYPE_OPTIONS_BOX_BUTTON_CLICKED:
107175 if (editWidget->isDirty () && !editWidget->getScroll ()) {
108- _output-> setStatus (dirtyFile );
176+ statusMessage. update (editWidget, _output, true );
109177 _output->redraw ();
110178 }
111179 break ;
112180 case EVENT_TYPE_KEY_PRESSED:
113181 if (_userScreenId == -1 ) {
114182 dev_clrkb ();
115- int sw = _output->getScreenWidth ();
116183 bool redraw = true ;
117184 bool dirty = editWidget->isDirty ();
118185 char *text;
@@ -139,9 +206,7 @@ void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
139206 exitHelp = true ;
140207 } else {
141208 widget = helpWidget;
142- helpWidget->showPopup (-4 , -2 );
143- helpWidget->createKeywordIndex ();
144- helpWidget->setFocus (true );
209+ showHelp (helpWidget);
145210 }
146211 break ;
147212 case SB_KEY_F (9 ):
@@ -153,11 +218,12 @@ void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
153218 break ;
154219 case SB_KEY_CTRL (' f' ):
155220 if (widget == helpWidget) {
221+ _output->setStatus (" " );
156222 exitHelp = true ;
157223 } else {
224+ _output->setStatus (" Search..." );
158225 widget = helpWidget;
159- helpWidget->createSearch (false );
160- showHelpLineInput (helpWidget);
226+ showFind (helpWidget);
161227 }
162228 break ;
163229 case SB_KEY_CTRL (' s' ):
@@ -186,11 +252,11 @@ void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
186252 _state = kEditState ;
187253 break ;
188254 default :
189- redraw = widget->edit (event.key , sw , charWidth);
255+ redraw = widget->edit (event.key , _output-> getScreenWidth () , charWidth);
190256 break ;
191257 }
192258 if (editWidget->isDirty () != dirty && !editWidget->getScroll ()) {
193- _output-> setStatus (editWidget-> isDirty () ? dirtyFile : cleanFile );
259+ redraw |= statusMessage. update (editWidget, _output, true );
194260 }
195261 if (redraw) {
196262 _output->redraw ();
0 commit comments