119 lockUpdates <Boolean> internal, private |
119 lockUpdates <Boolean> internal, private |
120 |
120 |
121 prevCursorState <Boolean> temporary, private |
121 prevCursorState <Boolean> temporary, private |
122 |
122 |
123 |
123 |
|
124 class variables: |
|
125 ST80Mode <Boolean> if true, cursor positioning is |
|
126 done as in vi or ST80; i.e. |
|
127 wysiwyg mode is somewhat relaxed, |
|
128 in that the cursor cannot be |
|
129 positioned behind a lines end. |
|
130 This is not yet completely implemented. |
124 used globals: |
131 used globals: |
125 |
132 |
126 DeleteHistory <Text> last 1000 lines of deleted text |
133 DeleteHistory <Text> last 1000 lines of deleted text |
127 (but only if this variable exists already) |
134 (but only if this variable exists already) |
128 |
135 |
333 DefaultCursorForegroundColor := StyleSheet colorAt:'textCursorForegroundColor'. |
340 DefaultCursorForegroundColor := StyleSheet colorAt:'textCursorForegroundColor'. |
334 DefaultCursorBackgroundColor := StyleSheet colorAt:'textCursorBackgroundColor'. |
341 DefaultCursorBackgroundColor := StyleSheet colorAt:'textCursorBackgroundColor'. |
335 DefaultCursorNoFocusForegroundColor := StyleSheet colorAt:'textCursorNoFocusForegroundColor'. |
342 DefaultCursorNoFocusForegroundColor := StyleSheet colorAt:'textCursorNoFocusForegroundColor'. |
336 DefaultCursorType := StyleSheet at:'textCursorType' default:#block. |
343 DefaultCursorType := StyleSheet at:'textCursorType' default:#block. |
337 |
344 |
338 "Modified: 18.2.1997 / 15:00:01 / cg" |
345 ST80Mode := false. |
|
346 |
|
347 "Modified: 13.8.1997 / 15:38:16 / cg" |
339 ! ! |
348 ! ! |
340 |
349 |
341 !EditTextView methodsFor:'ST-80 compatibility editing'! |
350 !EditTextView methodsFor:'ST-80 compatibility editing'! |
342 |
351 |
343 insert:aString at:aCharacterPosition |
352 insert:aString at:aCharacterPosition |
1273 "check of col is a valid cursor position; return a new col-nr if not. |
1297 "check of col is a valid cursor position; return a new col-nr if not. |
1274 Here, no limits are enforced (and col is returned), |
1298 Here, no limits are enforced (and col is returned), |
1275 but it may be redefined in EditFields or views which dont like the |
1299 but it may be redefined in EditFields or views which dont like the |
1276 cursor to be positioned behind the end of a textLine (vi/st-80 behavior)" |
1300 cursor to be positioned behind the end of a textLine (vi/st-80 behavior)" |
1277 |
1301 |
|
1302 |l max| |
|
1303 |
|
1304 ST80Mode == true ifTrue:[ |
|
1305 l := (self listAt:line). |
|
1306 max := l size + 1. |
|
1307 col > max ifTrue:[ |
|
1308 ^ max |
|
1309 ] |
|
1310 ]. |
1278 ^ col |
1311 ^ col |
1279 |
1312 |
1280 "Created: 22.5.1996 / 14:25:30 / cg" |
1313 "Created: 22.5.1996 / 14:25:30 / cg" |
1281 "Modified: 22.5.1996 / 18:29:21 / cg" |
1314 "Modified: 13.8.1997 / 15:34:13 / cg" |
1282 ! |
1315 ! |
1283 |
1316 |
1284 validateCursorLine:line |
1317 validateCursorLine:line |
1285 "check of line is a valid cursor line; return a fixed line-nr if not. |
1318 "check of line is a valid cursor line; return a fixed line-nr if not. |
1286 Here, no limits are enforced (and line is returned), but it may be |
1319 Here, no limits are enforced (and line is returned), but it may be |
1302 ]. |
1335 ]. |
1303 self hideCursor. |
1336 self hideCursor. |
1304 aBlock valueNowOrOnUnwindDo:[ |
1337 aBlock valueNowOrOnUnwindDo:[ |
1305 self showCursor |
1338 self showCursor |
1306 ] |
1339 ] |
1307 ! ! |
|
1308 |
|
1309 !EditTextView methodsFor:'documentation'! |
|
1310 |
|
1311 examples |
|
1312 " |
|
1313 non MVC operation: |
|
1314 |
|
1315 basic setup: |
|
1316 [exBegin] |
|
1317 |top textView| |
|
1318 |
|
1319 top := StandardSystemView new. |
|
1320 top extent:300@200. |
|
1321 |
|
1322 textView := EditTextView new. |
|
1323 textView origin:0.0 @ 0.0 corner:1.0 @ 1.0. |
|
1324 top addSubView:textView. |
|
1325 |
|
1326 textView contents:('/etc/hosts' asFilename contentsOfEntireFile). |
|
1327 |
|
1328 top open. |
|
1329 [exEnd] |
|
1330 |
|
1331 |
|
1332 with vertical scrollbar: |
|
1333 [exBegin] |
|
1334 |top scrollView textView| |
|
1335 |
|
1336 top := StandardSystemView new. |
|
1337 top extent:300@200. |
|
1338 |
|
1339 scrollView := ScrollableView for:EditTextView. |
|
1340 textView := scrollView scrolledView. |
|
1341 scrollView origin:0.0 @ 0.0 corner:1.0 @ 1.0. |
|
1342 top addSubView:scrollView. |
|
1343 |
|
1344 textView contents:('/etc/hosts' asFilename contentsOfEntireFile). |
|
1345 |
|
1346 top open. |
|
1347 [exEnd] |
|
1348 |
|
1349 |
|
1350 with horizontal & vertical scrollbars: |
|
1351 [exBegin] |
|
1352 |top scrollView textView| |
|
1353 |
|
1354 top := StandardSystemView new. |
|
1355 top extent:300@200. |
|
1356 |
|
1357 scrollView := HVScrollableView for:EditTextView. |
|
1358 textView := scrollView scrolledView. |
|
1359 scrollView origin:0.0 @ 0.0 corner:1.0 @ 1.0. |
|
1360 top addSubView:scrollView. |
|
1361 |
|
1362 textView contents:('/etc/hosts' asFilename contentsOfEntireFile). |
|
1363 |
|
1364 top open. |
|
1365 [exEnd] |
|
1366 |
|
1367 |
|
1368 set the action for accept: |
|
1369 [exBegin] |
|
1370 |top textView| |
|
1371 |
|
1372 top := StandardSystemView new. |
|
1373 top extent:300@200. |
|
1374 |
|
1375 textView := EditTextView new. |
|
1376 textView origin:0.0 @ 0.0 corner:1.0 @ 1.0. |
|
1377 top addSubView:textView. |
|
1378 |
|
1379 textView contents:('/etc/hosts' asFilename contentsOfEntireFile). |
|
1380 textView acceptAction:[:contents | |
|
1381 Transcript showCR:'will not overwrite the file with:'. |
|
1382 Transcript showCR:contents asString |
|
1383 ]. |
|
1384 top open. |
|
1385 [exEnd] |
|
1386 |
|
1387 |
|
1388 |
|
1389 MVC operation: |
|
1390 (the examples model here is a plug simulating a real model; |
|
1391 real world applications would not use a plug ..) |
|
1392 [exBegin] |
|
1393 |top textView model| |
|
1394 |
|
1395 model := Plug new. |
|
1396 model respondTo:#accepted: |
|
1397 with:[:newContents | |
|
1398 Transcript showCR:'will not overwrite the file with:'. |
|
1399 Transcript showCR:newContents asString |
|
1400 ]. |
|
1401 model respondTo:#getList |
|
1402 with:['/etc/hosts' asFilename contentsOfEntireFile]. |
|
1403 |
|
1404 |
|
1405 top := StandardSystemView new. |
|
1406 top extent:300@200. |
|
1407 |
|
1408 textView := EditTextView new. |
|
1409 textView origin:0.0 @ 0.0 corner:1.0 @ 1.0. |
|
1410 top addSubView:textView. |
|
1411 |
|
1412 textView model:model; |
|
1413 changeMessage:#accepted:; |
|
1414 listMessage:#getList; |
|
1415 aspect:#list. |
|
1416 top open. |
|
1417 [exEnd] |
|
1418 |
|
1419 |
|
1420 two textViews on the same model: |
|
1421 [exBegin] |
|
1422 |top1 textView1 top2 textView2 model currentContents| |
|
1423 |
|
1424 model := Plug new. |
|
1425 model respondTo:#accepted: |
|
1426 with:[:newContents | |
|
1427 Transcript showCR:'accepted:'. |
|
1428 Transcript showCR:newContents asString. |
|
1429 currentContents := newContents. |
|
1430 model changed:#contents |
|
1431 ]. |
|
1432 model respondTo:#getList |
|
1433 with:[Transcript showCR:'query'. |
|
1434 currentContents]. |
|
1435 |
|
1436 |
|
1437 top1 := StandardSystemView new. |
|
1438 top1 extent:300@200. |
|
1439 |
|
1440 textView1 := EditTextView new. |
|
1441 textView1 origin:0.0 @ 0.0 corner:1.0 @ 1.0. |
|
1442 top1 addSubView:textView1. |
|
1443 |
|
1444 textView1 model:model; |
|
1445 aspect:#contents; |
|
1446 changeMessage:#accepted:; |
|
1447 listMessage:#getList. |
|
1448 top1 open. |
|
1449 |
|
1450 top2 := StandardSystemView new. |
|
1451 top2 extent:300@200. |
|
1452 |
|
1453 textView2 := EditTextView new. |
|
1454 textView2 origin:0.0 @ 0.0 corner:1.0 @ 1.0. |
|
1455 top2 addSubView:textView2. |
|
1456 |
|
1457 textView2 model:model; |
|
1458 aspect:#contents; |
|
1459 changeMessage:#accepted:; |
|
1460 listMessage:#getList. |
|
1461 top2 open. |
|
1462 [exEnd] |
|
1463 " |
|
1464 |
|
1465 "Modified: 27.4.1996 / 16:29:43 / cg" |
|
1466 ! ! |
1340 ! ! |
1467 |
1341 |
1468 !EditTextView methodsFor:'editing'! |
1342 !EditTextView methodsFor:'editing'! |
1469 |
1343 |
1470 copyAndDeleteSelection |
1344 copyAndDeleteSelection |
2093 drawCharacterOnly := false. |
1967 drawCharacterOnly := false. |
2094 self checkForExistingLine:lineNr. |
1968 self checkForExistingLine:lineNr. |
2095 line := list at:lineNr. |
1969 line := list at:lineNr. |
2096 lineSize := line size. |
1970 lineSize := line size. |
2097 |
1971 |
2098 (trimBlankLines |
1972 ST80Mode ~~ true ifTrue:[ |
2099 and:[colNr > lineSize |
1973 (trimBlankLines |
2100 and:[aCharacter == Character space]]) ifTrue:[ |
1974 and:[colNr > lineSize |
2101 ^ self |
1975 and:[aCharacter == Character space]]) ifTrue:[ |
|
1976 ^ self |
|
1977 ] |
2102 ]. |
1978 ]. |
2103 |
1979 |
2104 (lineSize == 0) ifTrue:[ |
1980 (lineSize == 0) ifTrue:[ |
2105 newLine := aCharacter asString species new:colNr. |
1981 newLine := aCharacter asString species new:colNr. |
2106 drawCharacterOnly := true |
1982 drawCharacterOnly := true |
3554 ! ! |
3427 ! ! |
3555 |
3428 |
3556 !EditTextView methodsFor:'private'! |
3429 !EditTextView methodsFor:'private'! |
3557 |
3430 |
3558 checkModificationsAllowed |
3431 checkModificationsAllowed |
|
3432 "check if the text can be modified (i.e. is not readOnly). |
|
3433 evaluate the exceptionBlock if not. |
|
3434 This block should be provided by the application or user of the textView, |
|
3435 and may show a warnBox or whatever." |
|
3436 |
3559 readOnly ifTrue: [ |
3437 readOnly ifTrue: [ |
3560 exceptionBlock isNil ifTrue:[ |
3438 exceptionBlock isNil ifTrue:[ |
3561 ^ false |
3439 ^ false |
3562 ]. |
3440 ]. |
3563 |
3441 |
3564 (exceptionBlock value:'Text may not be modified') ~~ true ifTrue:[ |
3442 (exceptionBlock value:'Text may not be modified') ~~ true ifTrue:[ |
3565 ^ false |
3443 ^ false |
3566 ] |
3444 ] |
3567 ]. |
3445 ]. |
3568 ^ true |
3446 ^ true |
|
3447 |
|
3448 "Modified: 13.8.1997 / 15:36:07 / cg" |
3569 ! |
3449 ! |
3570 |
3450 |
3571 textChanged |
3451 textChanged |
3572 "my text was modified (internally). |
3452 "my text was modified (internally). |
3573 Sent whenever text has been edited (not to confuse with |
3453 Sent whenever text has been edited (not to confuse with |