ListView.st
changeset 403 ee8f6d080077
parent 394 795f293f8520
child 407 998d3f5c4690
equal deleted inserted replaced
402:ed4a635f43c6 403:ee8f6d080077
  2514 searchBackwardFor:pattern startingAtLine:startLine col:startCol ifFound:block1 ifAbsent:block2
  2514 searchBackwardFor:pattern startingAtLine:startLine col:startCol ifFound:block1 ifAbsent:block2
  2515     "search for a pattern, if found evaluate block1 with row/col as arguments, if not
  2515     "search for a pattern, if found evaluate block1 with row/col as arguments, if not
  2516      found evaluate block2.
  2516      found evaluate block2.
  2517      Sorry, but pattern is no regular expression pattern (yet)"
  2517      Sorry, but pattern is no regular expression pattern (yet)"
  2518 
  2518 
  2519     |lineString col cc found firstChar savedCursor patternSize 
  2519     |lineString col cc found firstChar patternSize 
  2520      line1 "{Class: SmallInteger}"|
  2520      line1 "{Class: SmallInteger}"|
  2521 
  2521 
  2522     patternSize := pattern size.
  2522     patternSize := pattern size.
  2523     (list notNil and:[patternSize ~~ 0]) ifTrue:[
  2523     (list notNil and:[patternSize ~~ 0]) ifTrue:[
  2524         savedCursor := cursor.
  2524         self withCursor:Cursor questionMark do:[
  2525         self cursor:(Cursor questionMark).
  2525 "/            searchPattern := pattern.
  2526 "/        searchPattern := pattern.
  2526             col := startCol - 1.
  2527         col := startCol - 1.
  2527             firstChar := pattern at:1.
  2528         firstChar := pattern at:1.
  2528             col > (list at:startLine) size ifTrue:[
  2529         col > (list at:startLine) size ifTrue:[
  2529                 col := nil
  2530             col := nil
  2530             ].
  2531         ].
  2531             line1 := startLine.
  2532         line1 := startLine.
  2532             line1 to:1 by:-1 do:[:lnr |
  2533         line1 to:1 by:-1 do:[:lnr |
  2533                 lineString := list at:lnr.
  2534             lineString := list at:lnr.
  2534                 lineString notNil ifTrue:[
  2535             lineString notNil ifTrue:[
  2535                     col isNil ifTrue:[col := lineString size - patternSize + 1].
  2536                 col isNil ifTrue:[col := lineString size - patternSize + 1].
       
  2537                 [(col > 0) and:[(lineString at:col) ~= firstChar]] whileTrue:[
       
  2538                     col := col - 1
       
  2539                 ].
       
  2540                 [col > 0] whileTrue:[
       
  2541                     cc := col.
       
  2542                     found := true.
       
  2543                     1 to:patternSize do:[:cnr |
       
  2544                         cc > lineString size ifTrue:[
       
  2545                             found := false
       
  2546                         ] ifFalse:[
       
  2547                             (pattern at:cnr) ~= (lineString at:cc) ifTrue:[
       
  2548                                 found := false
       
  2549                             ]
       
  2550                         ].
       
  2551                         cc := cc + 1
       
  2552                     ].
       
  2553                     found ifTrue:[
       
  2554                         self cursor:savedCursor.
       
  2555                         ^ block1 value:lnr value:col.
       
  2556                     ].
       
  2557                     col := col - 1.
       
  2558                     [(col > 0) and:[(lineString at:col) ~= firstChar]] whileTrue:[
  2536                     [(col > 0) and:[(lineString at:col) ~= firstChar]] whileTrue:[
  2559                         col := col - 1
  2537                         col := col - 1
       
  2538                     ].
       
  2539                     [col > 0] whileTrue:[
       
  2540                         cc := col.
       
  2541                         found := true.
       
  2542                         1 to:patternSize do:[:cnr |
       
  2543                             cc > lineString size ifTrue:[
       
  2544                                 found := false
       
  2545                             ] ifFalse:[
       
  2546                                 (pattern at:cnr) ~= (lineString at:cc) ifTrue:[
       
  2547                                     found := false
       
  2548                                 ]
       
  2549                             ].
       
  2550                             cc := cc + 1
       
  2551                         ].
       
  2552                         found ifTrue:[
       
  2553                             ^ block1 value:lnr value:col.
       
  2554                         ].
       
  2555                         col := col - 1.
       
  2556                         [(col > 0) and:[(lineString at:col) ~= firstChar]] whileTrue:[
       
  2557                             col := col - 1
       
  2558                         ]
  2560                     ]
  2559                     ]
  2561                 ]
  2560                 ].
  2562             ].
  2561                 col := nil
  2563             col := nil
  2562             ]
  2564         ]
  2563         ]
  2565     ].
  2564     ].
  2566     "not found"
  2565     "not found"
  2567 
  2566 
  2568     self cursor:savedCursor.
       
  2569     ^ block2 value
  2567     ^ block2 value
  2570 
  2568 
  2571     "Modified: 23.2.1996 / 19:12:40 / cg"
  2569     "Modified: 26.2.1996 / 22:40:29 / cg"
  2572 !
  2570 !
  2573 
  2571 
  2574 searchForwardFor:pattern startingAtLine:startLine col:startCol ifFound:block1 ifAbsent:block2
  2572 searchForwardFor:pattern startingAtLine:startLine col:startCol ifFound:block1 ifAbsent:block2
  2575     "search for a pattern, if found evaluate block1 with row/col as arguments, if not
  2573     "search for a pattern, if found evaluate block1 with row/col as arguments, if not
  2576      found evaluate block2.
  2574      found evaluate block2.
  2577      Sorry, but pattern is no regular expression pattern (yet)"
  2575      Sorry, but pattern is no regular expression pattern (yet)"
  2578 
  2576 
  2579     |lineString col savedCursor patternSize 
  2577     |lineString col patternSize 
  2580      line1 "{Class: SmallInteger}"
  2578      line1 "{Class: SmallInteger}"
  2581      line2 "{Class: SmallInteger}"
  2579      line2 "{Class: SmallInteger}"
  2582      p realPattern|
  2580      p realPattern|
  2583 
  2581 
  2584     patternSize := pattern size.
  2582     patternSize := pattern size.
  2585     (list notNil and:[patternSize ~~ 0]) ifTrue:[
  2583     (list notNil and:[patternSize ~~ 0]) ifTrue:[
  2586 	savedCursor := cursor.
  2584         self withCursor:Cursor questionMark do:[
  2587 	self cursor:(Cursor questionMark).
  2585 
  2588 
  2586             col := startCol + 1.
  2589 	col := startCol + 1.
  2587             line1 := startLine.
  2590 	line1 := startLine.
  2588             line2 := list size.
  2591 	line2 := list size.
  2589 
  2592 
  2590             pattern includesMatchCharacters ifTrue:[
  2593 	pattern includesMatchCharacters ifTrue:[
  2591                 p := pattern species new:0.
  2594 	    p := ''.
  2592                 (pattern startsWith:$*) ifFalse:[
  2595 	    (pattern startsWith:$*) ifFalse:[
  2593                     p := p , '*'
  2596 		p := p , '*'
  2594                 ].
  2597 	    ].
  2595                 p := p , pattern.
  2598 	    p := p , pattern.
  2596                 (pattern endsWith:$*) ifFalse:[
  2599 	    (pattern endsWith:$*) ifFalse:[
  2597                     p := p , '*'
  2600 		p := p , '*'
  2598                 ].
  2601 	    ].
  2599                 realPattern := pattern.
  2602 	    realPattern := pattern.
  2600                 (realPattern startsWith:$*) ifTrue:[
  2603 	    (realPattern startsWith:$*) ifTrue:[
  2601                     realPattern := realPattern copyFrom:2
  2604 		realPattern := realPattern copyFrom:2
  2602                 ].
  2605 	    ].
  2603                 line1 to:line2 do:[:lnr |
  2606 	    line1 to:line2 do:[:lnr |
  2604                     lineString := list at:lnr.
  2607 		lineString := list at:lnr.
  2605                     lineString notNil ifTrue:[
  2608 		lineString notNil ifTrue:[
  2606                         "/ first a crude check ...
  2609 		    "/ first a crude check ...
  2607                         (p match:lineString) ifTrue:[
  2610 		    (p match:lineString) ifTrue:[
  2608                             "/ ok, there it is; look at which position
  2611 			"/ ok, there it is; look at which position
  2609                             col := lineString findMatchString:realPattern startingAt:col ignoreCase:false ifAbsent:[0].
  2612 			col := lineString findMatchString:realPattern startingAt:col ignoreCase:false ifAbsent:[0].
  2610                             col ~~ 0 ifTrue:[
  2613 			col ~~ 0 ifTrue:[
  2611                                 ^ block1 value:lnr value:col.
  2614 			    self cursor:savedCursor.
  2612                             ]
  2615 			    ^ block1 value:lnr value:col.
  2613                         ].
  2616 			]
  2614                     ].
  2617 		    ].
  2615                     col := 1
  2618 		].
  2616                 ]
  2619 		col := 1
  2617             ] ifFalse:[
  2620 	    ]
  2618                 line1 to:line2 do:[:lnr |
  2621 	] ifFalse:[
  2619                     lineString := list at:lnr.
  2622 	    line1 to:line2 do:[:lnr |
  2620                     lineString isString ifTrue:[
  2623 		lineString := list at:lnr.
  2621                         col := lineString findString:pattern startingAt:col ifAbsent:[0].
  2624 		lineString isString ifTrue:[
  2622                         col ~~ 0 ifTrue:[
  2625 		    col := lineString findString:pattern startingAt:col ifAbsent:[0].
  2623                             ^ block1 value:lnr value:col.
  2626 		    col ~~ 0 ifTrue:[
  2624                         ]
  2627 			self cursor:savedCursor.
  2625                     ].
  2628 			^ block1 value:lnr value:col.
  2626                     col := 1
  2629 		    ]
  2627                 ]
  2630 		].
  2628             ].
  2631 		col := 1
  2629         ]
  2632 	    ]
       
  2633 	]
       
  2634     ].
  2630     ].
  2635     "not found"
  2631     "not found"
  2636 
  2632 
  2637     self cursor:savedCursor.
       
  2638     ^ block2 value
  2633     ^ block2 value
       
  2634 
       
  2635     "Modified: 26.2.1996 / 22:39:59 / cg"
  2639 ! !
  2636 ! !
  2640 
  2637 
  2641 !ListView methodsFor:'tabulators'!
  2638 !ListView methodsFor:'tabulators'!
  2642 
  2639 
  2643 expandTabs
  2640 expandTabs
  2829 ! !
  2826 ! !
  2830 
  2827 
  2831 !ListView class methodsFor:'documentation'!
  2828 !ListView class methodsFor:'documentation'!
  2832 
  2829 
  2833 version
  2830 version
  2834     ^ '$Header: /cvs/stx/stx/libwidg/ListView.st,v 1.67 1996-02-24 17:19:17 cg Exp $'
  2831     ^ '$Header: /cvs/stx/stx/libwidg/ListView.st,v 1.68 1996-02-26 21:42:02 cg Exp $'
  2835 ! !
  2832 ! !