13
13
#include " common/device.h"
14
14
#include " ui/keypad.h"
15
15
16
+ // whether to hide the status message
17
+ bool statusEnabled = true ;
18
+
16
19
struct StatusMessage {
17
- explicit StatusMessage (const TextEditInput *editor) :
20
+ explicit StatusMessage (const TextEditInput *editor, String &loadPath ) :
18
21
_dirty(!editor->isDirty ()),
19
- _enabled(true ),
20
22
_find(false ),
21
23
_scroll(-1 ),
22
24
_row(editor->getRow ()),
23
25
_col(editor->getCol ()) {
24
- }
25
-
26
- void setFilename (const String &loadPath) {
27
26
int i = loadPath.lastIndexOf (' /' , 0 );
28
27
if (i != -1 ) {
29
28
_fileName = loadPath.substring (i + 1 );
@@ -38,66 +37,73 @@ struct StatusMessage {
38
37
_scroll = editor->getScroll ();
39
38
}
40
39
41
- bool toggleEnabled () {
42
- _enabled = !_enabled;
43
- _dirty = true ;
44
- return _enabled;
40
+ void toggleEnabled (const TextEditInput *editor) {
41
+ statusEnabled = !statusEnabled;
42
+ setDirty (editor);
45
43
}
46
44
47
45
void setDirty (const TextEditInput *editor) {
48
46
_dirty = !editor->isDirty ();
49
47
}
50
48
51
- void setFind (bool find) {
52
- _find = find;
53
- _dirty = true ;
49
+ void setFind (bool find, const TextEditInput *editor) {
50
+ if (_find != find) {
51
+ _find = find;
52
+ setDirty (editor);
53
+ }
54
54
}
55
55
56
56
bool update (TextEditInput *editor, const AnsiWidget *out) {
57
57
bool result;
58
58
bool dirty = editor->isDirty ();
59
- if (_enabled &&
60
- (_dirty != dirty
61
- || _scroll != editor->getScroll ()
62
- || _row != editor->getRow ()
63
- || _col != editor->getCol ())) {
64
- String message;
65
- result = true ;
66
- if (_find) {
67
- message.append (" Search " );
59
+ if (_dirty != dirty
60
+ || _scroll != editor->getScroll ()
61
+ || _row != editor->getRow ()
62
+ || _col != editor->getCol ()) {
63
+ if (statusEnabled) {
64
+ setMessage (editor, out, dirty);
68
65
} else {
69
- if (dirty) {
70
- message.append (" * " );
71
- } else {
72
- message.append (" - " );
73
- }
74
- message.append (_fileName);
75
- }
76
- message.append (" (" )
77
- .append (editor->getRow ())
78
- .append (" ," )
79
- .append (editor->getCol ())
80
- .append (" ) " );
81
- if (!editor->getScroll ()) {
82
- message.append (" Top" );
83
- } else if (editor->getLines () - editor->getScroll () < editor->getPageRows ()) {
84
- message.append (" Bot" );
85
- } else {
86
- const int pos = editor->getRow () * 100 / editor->getLines ();
87
- message.append (pos).append (" %" );
66
+ out->setStatus (" " );
88
67
}
89
- out->setStatus (message);
90
- _dirty = dirty;
91
68
resetCursor (editor);
69
+ result = true ;
92
70
} else {
93
71
result = false ;
94
72
}
73
+ _dirty = dirty;
95
74
return result;
96
75
}
97
76
77
+ void setMessage (TextEditInput *editor, const AnsiWidget *out, bool dirty) const {
78
+ String message;
79
+ if (_find) {
80
+ message.append (" Search " );
81
+ } else {
82
+ if (dirty) {
83
+ message.append (" * " );
84
+ } else {
85
+ message.append (" - " );
86
+ }
87
+ message.append (_fileName);
88
+ }
89
+ message.append (" (" )
90
+ .append (editor->getRow ())
91
+ .append (" ," )
92
+ .append (editor->getCol ())
93
+ .append (" ) " );
94
+ if (!editor->getScroll ()) {
95
+ message.append (" Top" );
96
+ } else if (editor->getLines () - editor->getScroll () < editor->getPageRows ()) {
97
+ message.append (" Bot" );
98
+ } else {
99
+ const int pos = editor->getRow () * 100 / editor->getLines ();
100
+ message.append (pos).append (" %" );
101
+ }
102
+ out->setStatus (message);
103
+ }
104
+
98
105
private:
99
106
bool _dirty;
100
- bool _enabled;
101
107
bool _find;
102
108
int _scroll;
103
109
int _row;
@@ -135,8 +141,7 @@ void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
135
141
}
136
142
auto *helpWidget = new TextEditHelpWidget (editWidget, charWidth, charHeight, false );
137
143
auto *widget = editWidget;
138
- StatusMessage statusMessage (editWidget);
139
- statusMessage.setFilename (loadPath);
144
+ StatusMessage statusMessage (editWidget, loadPath);
140
145
141
146
_modifiedTime = getModifiedTime ();
142
147
editWidget->updateUI (nullptr , nullptr );
@@ -213,11 +218,11 @@ void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
213
218
case SB_KEY_CTRL (' f' ):
214
219
if (widget == helpWidget) {
215
220
exitHelp = true ;
216
- statusMessage.setFind (false );
221
+ statusMessage.setFind (false , editWidget );
217
222
} else {
218
223
widget = helpWidget;
219
224
showFind (helpWidget);
220
- statusMessage.setFind (true );
225
+ statusMessage.setFind (true , editWidget );
221
226
}
222
227
redraw = true ;
223
228
break ;
@@ -247,9 +252,7 @@ void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
247
252
_state = kEditState ;
248
253
break ;
249
254
case SB_KEY_CTRL (' t' ):
250
- if (!statusMessage.toggleEnabled ()) {
251
- _output->setStatus (" " );
252
- }
255
+ statusMessage.toggleEnabled (editWidget);
253
256
redraw = true ;
254
257
break ;
255
258
default :
@@ -267,6 +270,7 @@ void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
267
270
widget = editWidget;
268
271
helpWidget->hide ();
269
272
editWidget->setFocus (true );
273
+ statusMessage.setFind (false , editWidget);
270
274
_state = kEditState ;
271
275
_output->redraw ();
272
276
}
0 commit comments