Workspace.st
changeset 6016 3362754911e4
parent 5990 31f05a6924f2
child 6020 79c1a6bb497a
equal deleted inserted replaced
6015:9984d88f5e98 6016:3362754911e4
  1302     "convenient function to comment out a block.
  1302     "convenient function to comment out a block.
  1303      All lines from line1 to line2 get an end-of-line comment
  1303      All lines from line1 to line2 get an end-of-line comment
  1304      in the first col
  1304      in the first col
  1305      (if no eol comment is available, a bracketing comment is used)."
  1305      (if no eol comment is available, a bracketing comment is used)."
  1306 
  1306 
  1307     |eolComment opening closing|
  1307     self commentFrom:line1 to:line2 commentStrings:commentStrings.
  1308 
       
  1309     eolComment := commentStrings at:1.
       
  1310     eolComment isNil ifTrue:[
       
  1311 	opening := (commentStrings at:2) at:1.
       
  1312 	closing := (commentStrings at:2) at:2.
       
  1313 	(opening isNil or:[closing isNil]) ifTrue:[^ self].
       
  1314     ].
       
  1315 
       
  1316     line1 to:line2 do:[:lineNr |
       
  1317 	|l|
       
  1318 
       
  1319 	l := self listAt:lineNr.
       
  1320 	l isNil ifTrue:[l := ''].
       
  1321 	eolComment notNil ifTrue:[
       
  1322 	    l := eolComment , l
       
  1323 	] ifFalse:[
       
  1324 	    l := opening , l , closing
       
  1325 	].
       
  1326 	self replaceLine:lineNr with:l.
       
  1327 	widthOfWidestLine notNil ifTrue:[
       
  1328 	    widthOfWidestLine := widthOfWidestLine max:(self widthOfLineString:l).
       
  1329 	].
       
  1330     ].
       
  1331     self textChanged.
       
  1332 
  1308 
  1333     "Created: / 09-11-1997 / 01:05:35 / cg"
  1309     "Created: / 09-11-1997 / 01:05:35 / cg"
  1334     "Modified: / 09-10-2006 / 10:46:44 / cg"
  1310     "Modified: / 09-10-2006 / 10:46:44 / cg"
  1335 !
  1311 !
  1336 
  1312 
  1337 commentSelection
  1313 commentSelection
  1338     "convenient function to comment out a block.
  1314     "convenient function to comment out a block.
  1339      All lines from line1 to line2 get an end-of-line comment
  1315      All lines from line1 to line2 get an end-of-line comment
  1340      in the first col."
  1316      in the first col."
  1341 
  1317 
  1342     |e commentPair opening closing|
  1318     self commentSelection:commentStrings
  1343 
       
  1344     (self checkModificationsAllowed) ifFalse:[ ^ self].
       
  1345     commentStrings isNil ifTrue:[ self beep. ^ self].
       
  1346 
       
  1347     selectionStartLine isNil ifTrue:[
       
  1348 	self
       
  1349 	    undoableDo:[ self commentFrom:cursorLine to:cursorLine ]
       
  1350 	    info:'Comment'.
       
  1351 	^ self
       
  1352     ].
       
  1353 
       
  1354     self
       
  1355 	undoableDo:
       
  1356 	    [
       
  1357 		(selectionStartCol == 1 and:[selectionEndCol == 0]) ifTrue:[
       
  1358 		    self commentFrom:selectionStartLine to:selectionEndLine-1
       
  1359 		] ifFalse:[
       
  1360 		    commentPair := commentStrings at:2 ifAbsent:nil.
       
  1361 		    commentPair isNil ifTrue:[
       
  1362 			self beep.
       
  1363 		    ] ifFalse:[
       
  1364 			opening := commentPair at:1.
       
  1365 			closing := commentPair at:2.
       
  1366 			(opening isNil or:[closing isNil]) ifTrue:[^ self].
       
  1367 
       
  1368 			e := selectionEndCol.
       
  1369 
       
  1370 			self insertString:closing atLine:selectionEndLine col:e+1.
       
  1371 			self insertString:opening atLine:selectionStartLine col:selectionStartCol.
       
  1372 
       
  1373 			selectionStartLine == selectionEndLine ifTrue:[e := e + opening size].
       
  1374 			self selectFromLine:selectionStartLine col:selectionStartCol
       
  1375 				     toLine:selectionEndLine col:e+closing size.
       
  1376 		    ]
       
  1377 		]
       
  1378 	    ]
       
  1379 	info:'comment'
       
  1380 
  1319 
  1381     "Created: / 9.11.1997 / 01:05:40 / cg"
  1320     "Created: / 9.11.1997 / 01:05:40 / cg"
  1382     "Modified: / 5.4.1998 / 16:52:23 / cg"
  1321     "Modified: / 5.4.1998 / 16:52:23 / cg"
  1383 !
  1322 !
  1384 
  1323 
  1386     "convenient function to comment out a block.
  1325     "convenient function to comment out a block.
  1387      All lines from line1 to line2 get an end-of-line comment
  1326      All lines from line1 to line2 get an end-of-line comment
  1388      in the first col.
  1327      in the first col.
  1389      (if no eol comment is available, a bracketing comment is removed)"
  1328      (if no eol comment is available, a bracketing comment is removed)"
  1390 
  1329 
  1391     |eolComment opening closing rest|
  1330     self uncommentFrom:line1 to:line2 commentStrings:commentStrings.
  1392 
       
  1393     eolComment := commentStrings at:1.
       
  1394     eolComment isNil ifTrue:[
       
  1395 	opening := (commentStrings at:2) at:1.
       
  1396 	closing := (commentStrings at:2) at:2.
       
  1397 	(opening isNil or:[closing isNil]) ifTrue:[^ self].
       
  1398     ] ifFalse:[
       
  1399 	rest := eolComment size + 1.
       
  1400     ].
       
  1401 
       
  1402     line1 to:line2 do:[:lineNr |
       
  1403 	|l|
       
  1404 
       
  1405 	l := self listAt:lineNr.
       
  1406 	l notNil ifTrue:[
       
  1407 	    eolComment notNil ifTrue:[
       
  1408 		(l startsWith:eolComment) ifTrue:[
       
  1409 		    l := l copyFrom:rest
       
  1410 		]
       
  1411 	    ] ifFalse:[
       
  1412 		((l startsWith:opening)
       
  1413 		and:[l endsWith:closing]) ifTrue:[
       
  1414 		    l := l copyFrom:opening size + 1.
       
  1415 		    l := l copyButLast:closing size.
       
  1416 		]
       
  1417 	    ].
       
  1418 	    self replaceLine:lineNr with:l.
       
  1419 	]
       
  1420     ].
       
  1421     widthOfWidestLine := nil.
       
  1422     self textChanged.
       
  1423 
  1331 
  1424     "Created: / 09-11-1997 / 01:05:43 / cg"
  1332     "Created: / 09-11-1997 / 01:05:43 / cg"
  1425     "Modified: / 09-10-2006 / 10:46:59 / cg"
  1333     "Modified: / 09-10-2006 / 10:46:59 / cg"
  1426 !
  1334 !
  1427 
  1335 
  1428 uncommentSelection
  1336 uncommentSelection
  1429     "convenient function to comment out a block.
  1337     "convenient function to comment out a block.
  1430      All lines from line1 to line2 get an end-of-line comment
  1338      All lines from line1 to line2 get an end-of-line comment
  1431      in the first col."
  1339      in the first col."
  1432 
  1340 
  1433     |e commentPair opening closing sz1 sz2 l1 l2 c1 c2|
  1341     self uncommentSelection:commentStrings
  1434 
       
  1435     (self checkModificationsAllowed) ifFalse:[ ^ self].
       
  1436     selectionStartLine isNil ifTrue:[
       
  1437 	self
       
  1438 	    undoableDo:[
       
  1439 		self uncommentFrom:cursorLine to:cursorLine
       
  1440 	    ]
       
  1441 	    info:'Uncomment'.
       
  1442 	^ self
       
  1443     ].
       
  1444 
       
  1445     self
       
  1446 	undoableDo:
       
  1447 	    [
       
  1448 		(selectionStartCol == 1 and:[selectionEndCol == 0]) ifTrue:[
       
  1449 		    self uncommentFrom:selectionStartLine to:selectionEndLine-1
       
  1450 		] ifFalse:[
       
  1451 		    commentPair := commentStrings at:2.
       
  1452 		    opening := commentPair at:1.
       
  1453 		    closing := commentPair at:2.
       
  1454 		    (opening isNil or:[closing isNil]) ifTrue:[^ self].
       
  1455 
       
  1456 		    sz1 := opening size.
       
  1457 		    sz2 := closing size.
       
  1458 
       
  1459 		    ((self
       
  1460 			stringAtLine:selectionStartLine
       
  1461 			from:selectionStartCol
       
  1462 			to:selectionStartCol+sz1 - 1) = opening
       
  1463 		    and:[(self
       
  1464 			stringAtLine:selectionEndLine
       
  1465 			from:selectionEndCol - sz2 + 1
       
  1466 			to:selectionEndCol) = closing ]) ifTrue:[
       
  1467 
       
  1468 			l2 := selectionEndLine.   c2 := selectionEndCol.
       
  1469 			l1 := selectionStartLine. c1 := selectionStartCol.
       
  1470 			self deleteCharsAtLine:l2 fromCol:c2-sz2+1 toCol:c2.
       
  1471 			self deleteCharsAtLine:l1 fromCol:c1 toCol:c1+sz1-1.
       
  1472 
       
  1473 			e := c2 - sz2.
       
  1474 			l1 == l2 ifTrue:[e := e - sz1].
       
  1475 			self selectFromLine:l1 col:c1 toLine:l2 col:e.
       
  1476 		    ]
       
  1477 		]
       
  1478 	    ]
       
  1479 	info:'uncomment'
       
  1480 
  1342 
  1481     "Modified: / 7.1.1997 / 20:13:32 / cg"
  1343     "Modified: / 7.1.1997 / 20:13:32 / cg"
  1482     "Created: / 9.11.1997 / 01:05:46 / cg"
  1344     "Created: / 9.11.1997 / 01:05:46 / cg"
  1483 ! !
  1345 ! !
  1484 
  1346