EditTextView.st
changeset 1300 be8b356b2e59
parent 1296 d834c8210a01
child 1304 173d00c195f9
equal deleted inserted replaced
1299:27f3fc6dee3d 1300:be8b356b2e59
    18 		replacing showMatchingParenthesis hasKeyboardFocus acceptAction
    18 		replacing showMatchingParenthesis hasKeyboardFocus acceptAction
    19 		lockUpdates tabMeansNextField autoIndent insertMode
    19 		lockUpdates tabMeansNextField autoIndent insertMode
    20 		trimBlankLines wordWrap replacementWordSelectStyle acceptChannel
    20 		trimBlankLines wordWrap replacementWordSelectStyle acceptChannel
    21 		acceptEnabled'
    21 		acceptEnabled'
    22 	classVariableNames:'DefaultCursorForegroundColor DefaultCursorBackgroundColor
    22 	classVariableNames:'DefaultCursorForegroundColor DefaultCursorBackgroundColor
    23 		DefaultCursorType DefaultCursorNoFocusForegroundColor'
    23 		DefaultCursorType DefaultCursorNoFocusForegroundColor ST80Mode'
    24 	poolDictionaries:''
    24 	poolDictionaries:''
    25 	category:'Views-Text'
    25 	category:'Views-Text'
    26 !
    26 !
    27 
    27 
    28 !EditTextView class methodsFor:'documentation'!
    28 !EditTextView class methodsFor:'documentation'!
   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
   731 !
   740 !
   732 
   741 
   733 cursorLeft
   742 cursorLeft
   734     "move cursor to left"
   743     "move cursor to left"
   735 
   744 
   736     (cursorCol ~~ 1) ifTrue: [
   745     (cursorCol ~~ 1) ifTrue:[
   737 	self cursorCol:(cursorCol - 1)
   746         self cursorCol:(cursorCol - 1)
   738     ].
   747     ] ifFalse:[
       
   748         ST80Mode == true ifTrue:[
       
   749             self cursorUp.
       
   750             self cursorToEndOfLine.
       
   751         ]
       
   752     ]
       
   753 
       
   754     "Modified: 12.8.1997 / 13:57:14 / cg"
   739 !
   755 !
   740 
   756 
   741 cursorLine:line col:col
   757 cursorLine:line col:col
   742     "this positions onto physical - not visible - line"
   758     "this positions onto physical - not visible - line"
   743 
   759 
   779 !
   795 !
   780 
   796 
   781 cursorRight
   797 cursorRight
   782     "move cursor to right"
   798     "move cursor to right"
   783 
   799 
       
   800     |l|
       
   801 
       
   802     ST80Mode == true ifTrue:[
       
   803         l := (self listAt:cursorLine).
       
   804         cursorCol >= (l size + 1) ifTrue:[
       
   805             self cursorReturn.
       
   806             ^ self    
       
   807         ]
       
   808     ].    
   784     self cursorCol:(cursorCol + 1)
   809     self cursorCol:(cursorCol + 1)
       
   810 
       
   811     "Modified: 13.8.1997 / 15:33:48 / cg"
   785 !
   812 !
   786 
   813 
   787 cursorTab
   814 cursorTab
   788     "move cursor to next tabstop"
   815     "move cursor to next tabstop"
   789 
   816 
   849 !
   876 !
   850 
   877 
   851 cursorToEndOfLine
   878 cursorToEndOfLine
   852     "move cursor to end of current line"
   879     "move cursor to end of current line"
   853 
   880 
   854     |line newCol|
   881     |line|
   855 
   882 
   856     list isNil ifTrue:[
   883     line := (self listAt:cursorLine).
   857 	newCol := 1
   884     self cursorCol:(line size + 1)
   858     ] ifFalse:[
   885 
   859 	line := list at:cursorLine.
   886     "Modified: 13.8.1997 / 15:34:02 / cg"
   860 	newCol := line size + 1
       
   861     ].
       
   862     self cursorCol:newCol
       
   863 !
   887 !
   864 
   888 
   865 cursorToFirstVisibleLine
   889 cursorToFirstVisibleLine
   866     "place cursor into the first visible line; do not scroll."
   890     "place cursor into the first visible line; do not scroll."
   867 
   891 
  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
  2146         ] ifFalse:[
  2022         ] ifFalse:[
  2147             self redrawLine:lineNr from:colNr
  2023             self redrawLine:lineNr from:colNr
  2148         ]
  2024         ]
  2149     ]
  2025     ]
  2150 
  2026 
  2151     "Modified: 22.5.1996 / 15:35:12 / cg"
  2027     "Modified: 13.8.1997 / 15:37:21 / cg"
  2152 
       
  2153 
       
  2154 
       
  2155 !
  2028 !
  2156 
  2029 
  2157 insertLines:someText from:start to:end before:lineNr
  2030 insertLines:someText from:start to:end before:lineNr
  2158     "insert a bunch of lines before line lineNr"
  2031     "insert a bunch of lines before line lineNr"
  2159 
  2032 
  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
  4062 ! !
  3942 ! !
  4063 
  3943 
  4064 !EditTextView class methodsFor:'documentation'!
  3944 !EditTextView class methodsFor:'documentation'!
  4065 
  3945 
  4066 version
  3946 version
  4067     ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.130 1997-08-11 11:58:13 cg Exp $'
  3947     ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.131 1997-08-13 13:40:07 cg Exp $'
  4068 ! !
  3948 ! !