EditTextViewCompletionSupport.st
changeset 5939 c22f1eec3ffd
parent 5891 584219e0a322
child 5960 d5697b81bbe6
equal deleted inserted replaced
5938:075863332625 5939:c22f1eec3ffd
   294 !
   294 !
   295 
   295 
   296 openCompletionView: list
   296 openCompletionView: list
   297     "Makes sure the completion view is opened and with given `list`."
   297     "Makes sure the completion view is opened and with given `list`."
   298     
   298     
   299     | cursorPos movePos topView limit |
   299     | textCursorPosInTextView textCursorPosOnScreen movePos topView 
   300 
   300       screenBounds screenBoundsCorner 
   301     "/ move the window
   301       helpViewsExtent helpViewsWidth helpViewsHeight|
   302     cursorPos := editView device translatePoint:(editView xOfCursor @ editView yOfCursor) fromView:editView toView:nil.
   302 
   303     cursorPos := cursorPos - (editView viewOrigin x @ 0).
   303     "/ move the window away from the text cursor (to not cover what user types in)
       
   304     "/ get the screen-relative position of the text cursor
       
   305     textCursorPosInTextView := editView xOfCursor @ editView yOfCursor.
       
   306     
       
   307     "/ care for the scroll-offset (xOfCursor/yOFCursor gives me               
       
   308     textCursorPosInTextView := textCursorPosInTextView - (editView viewOrigin x @ 0).
       
   309     
       
   310     textCursorPosOnScreen := editView device 
       
   311                     translatePoint:textCursorPosInTextView 
       
   312                     fromView:editView toView:nil.
       
   313 
   304     "/ currently, we have to stay away a bit, to avoid getting the focus
   314     "/ currently, we have to stay away a bit, to avoid getting the focus
   305     movePos := cursorPos + (60 @ (editView font height)).
   315     "/ this will be somewhat to the down-right of the textCursor
       
   316     movePos := textCursorPosOnScreen + (60 @ (editView font height)).
   306 
   317 
   307     completionView isNil ifTrue:[
   318     completionView isNil ifTrue:[
   308         completionView := CodeCompletionHelpMenuView new.
   319         completionView := CodeCompletionHelpMenuView new.
   309         completionView name:'completion'.
   320         completionView name:'completion'.
   310         completionView level:0.
   321         completionView level:0.
   316         topView editView:editView.
   327         topView editView:editView.
   317     ] ifFalse:[
   328     ] ifFalse:[
   318         completionView list:list.
   329         completionView list:list.
   319         topView := completionView topView.
   330         topView := completionView topView.
   320     ].
   331     ].
       
   332     
   321     topView ~~ completionView ifTrue:[
   333     topView ~~ completionView ifTrue:[
   322         topView resizeToFit.
   334         topView resizeToFit.
   323 "/        movePos := editView device 
   335 
   324 "/                        translatePoint:((editView right - topView width) @ (editView top)) 
       
   325 "/                        fromView:editView toView:nil.
       
   326         "/ make sure, the window is visible
   336         "/ make sure, the window is visible
   327         limit := topView device monitorBoundsAt:topView origin.
   337         screenBounds := topView device monitorBoundsAt:topView origin.
   328         movePos x + topView extent x > limit corner x ifTrue:[
   338         screenBoundsCorner := screenBounds corner.
   329             movePos := (cursorPos x - 60 - (topView extent x)) @ movePos y.
   339 
   330         ].
   340         helpViewsExtent := topView extent.
   331         movePos y + topView extent y > limit corner y ifTrue:[
   341         helpViewsWidth := helpViewsExtent x.
   332             movePos := movePos x @ (cursorPos y - (topView extent y)).
   342         helpViewsHeight := helpViewsExtent y.
   333         ].
   343 
       
   344         "/ if it does not lie completely inside the screen, move it     
       
   345         (movePos x + helpViewsWidth) > screenBoundsCorner x ifTrue:[
       
   346             movePos := (textCursorPosOnScreen x - 60 - helpViewsWidth) @ movePos y.
       
   347         ].
       
   348         (movePos y + helpViewsHeight) > screenBoundsCorner y ifTrue:[
       
   349             movePos := movePos x @ (textCursorPosOnScreen y - helpViewsHeight).
       
   350         ].
       
   351         movePos y < 0 ifTrue:[
       
   352             movePos := movePos x @ 0
       
   353         ].    
   334         topView origin:movePos.
   354         topView origin:movePos.
   335     ].
   355     ].
   336 
   356 
   337     "Created: / 26-09-2013 / 17:07:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   357     "Created: / 26-09-2013 / 17:07:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   338 ! !
   358 ! !