SmallSense__CompletionView.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 04 Apr 2014 15:12:18 +0200
changeset 190 c4dbecf1d9a7
parent 185 75738108cc3f
child 194 67f1d06c1b88
permissions -rw-r--r--
Added a little help text to completion view. Currently it shows some help text what to do and inferred receiver type when completing message selector.

"{ Encoding: utf8 }"

"{ Package: 'jv:smallsense' }"

"{ NameSpace: SmallSense }"

SimpleView subclass:#CompletionView
	instanceVariableNames:'completionController completionContext list listHolder listView
		selectionHolder helpHolder helpView'
	classVariableNames:''
	poolDictionaries:''
	category:'SmallSense-Core-Interface'
!

!CompletionView methodsFor:'accessing'!

completionContext
    ^ completionContext
!

completionContext:aCompletionContext
    | node |

    completionContext := aCompletionContext.
    node := completionContext node.
    node isMessage ifTrue:[ 
        helpHolder value: 'Receiver type: ', node receiver inferedType displayString
    ] ifFalse:[ 
        helpHolder value: 'Up/Down to select, Enter to paste' asText.
    ].

    "Modified: / 04-04-2014 / 15:04:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

completionController
    ^ completionController
!

completionController:aCompletionController
    completionController := aCompletionController.

    "Modified: / 04-04-2014 / 14:53:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

font: aFont
    super font: aFont.
    listView font: aFont.

    "Created: / 27-09-2013 / 14:03:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

list
    ^ list
!

list: aCollection
    list :=  aCollection.
    listHolder value: aCollection.
    self completionContext: (aCollection notEmptyOrNil ifTrue:[aCollection anElement context] ifFalse:[ nil ]).

    "Created: / 27-09-2013 / 14:02:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 04-04-2014 / 14:56:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

selection
    ^ (listView value at: selectionHolder value).

    "Created: / 27-09-2013 / 15:41:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

selection: po
    selectionHolder value: (listHolder value identityIndexOf: po)

    "Created: / 27-09-2013 / 16:09:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CompletionView methodsFor:'actions'!

complete: index
    self assert: selectionHolder value == index.
    completionController complete.

    "Created: / 27-02-2014 / 10:09:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CompletionView methodsFor:'event handling'!

keyPress:key x:x y:y
    ^ listView keyPress:key x:x y:y

    "Created: / 27-09-2013 / 14:05:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 31-03-2014 / 22:53:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CompletionView methodsFor:'initialization & release'!

initialize
    | listViewScroller listViewScrollerLayout helpViewLayout |

    super initialize.
    listHolder := ValueHolder new.
    selectionHolder := ValueHolder new.
    helpHolder := ValueHolder new.

    listViewScrollerLayout := LayoutFrame origin: 0.0 @ 0.0  corner: 1.0 @ 1.0.
    listViewScrollerLayout bottomOffset: -20.
    listViewScroller := ScrollableView for: SelectionInListModelView.
    listViewScroller layout: listViewScrollerLayout.
    self addSubView: listViewScroller.

    listView := listViewScroller scrolledView.
    listView listHolder: listHolder.
    listView model: selectionHolder.
    listView highlightMode: #line.
    listView doubleClickAction:[:index | self complete: index ].

    helpViewLayout := LayoutFrame origin: 0.0 @ 1.0  corner: 1.0 @ 1.0.
    helpViewLayout topOffset: -20.
    helpView := Label new.
    helpView adjust: #left.
    helpView labelChannel: helpHolder.  
    helpView layout: helpViewLayout.
    self addSubView: helpView.  

    self extent: 400 @ 250

    "Created: / 27-09-2013 / 13:56:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 04-04-2014 / 15:03:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CompletionView methodsFor:'queries'!

hasSelection
    ^listView hasSelection

    "Created: / 27-09-2013 / 14:10:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

isPopUpView
    ^ true

    "Created: / 27-09-2013 / 13:56:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CompletionView methodsFor:'redrawing'!

flash
    listView flash.

    "Created: / 31-03-2014 / 22:56:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !