CodeCompletionHelpView.st
author Claus Gittinger <cg@exept.de>
Mon, 20 Jan 2020 21:02:47 +0100
changeset 19422 c6ca1c3e0fd7
parent 19304 1304be6172f7
permissions -rw-r--r--
#REFACTORING by exept class: MultiViewToolApplication added: #askForFile:default:forSave:thenDo: changed: #askForFile:default:thenDo: #askForFile:thenDo: #menuSaveAllAs #menuSaveAs

"
 COPYRIGHT (c) 2013 by Claus Gittinger
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
"{ Package: 'stx:libtool' }"

"{ NameSpace: Smalltalk }"

View subclass:#CodeCompletionHelpView
	instanceVariableNames:'myView editView delayedCloseAction checkAction
		closeOnPointerLeave pointerEntered'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-Help'
!

!CodeCompletionHelpView class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2013 by Claus Gittinger
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    used with code completion suggestions

    [author:]
        Claus Gittinger

    [See also:]
        ActiveHelp Workspace::CodeCompletionService
"
! !

!CodeCompletionHelpView class methodsFor:'instance creation'!

with:aView
    "create a talking-view wrapping some other view"

    ^ self new withView:aView

    "
     (ActiveHelpView with:(TextView new)) realize
     (ActiveHelpView with:(TextView new)) open
     (ActiveHelpView with:(Button label:'ok')) open
    "

    "Modified: 27.4.1996 / 15:14:18 / cg"
! !

!CodeCompletionHelpView methodsFor:'accessing'!

closeOnPointerLeave:aBoolean
    closeOnPointerLeave := aBoolean.
!

editView:aView
    "my code editor view"

    editView := aView
!

withView:aView
    "set the component view"

    |fg|

    (aView isKindOf:Label) ifTrue:[
        aView viewBackground:viewBackground.
        aView backgroundColor:viewBackground.
        (fg := styleSheet colorAt:#'activeHelp.foregroundColor' default:nil) notNil ifTrue:[
            aView foregroundColor:fg.    
        ].
    ].
    self addSubView:aView.
    myView := aView.
    myView borderWidth:0.
    myView origin:(0.0@0.0) corner:(1.0@1.0).

    self enableDelegation.

    "Modified: 27.4.1996 / 15:16:46 / cg"
! !

!CodeCompletionHelpView methodsFor:'event handling'!

delayedClose
    self delayedUnmap

    "Created: / 05-08-2018 / 03:16:26 / Claus Gittinger"
!

delayedDestroy
    (subViews notEmptyOrNil) ifTrue:[
        self topView destroy
    ].
    ^ true

    "Created: / 04-08-2018 / 21:25:48 / Claus Gittinger"
!

delayedUnmap
    (subViews notEmptyOrNil) ifTrue:[
        self topView unmap
    ].
    ^ true

    "Created: / 05-08-2018 / 03:12:39 / Claus Gittinger"
!

focusIn
    self uninstallDelayedClose.

    "Created: / 04-08-2018 / 10:41:59 / Claus Gittinger"
    "Modified: / 05-08-2018 / 03:12:58 / Claus Gittinger"
!

focusOut
    self installDelayedClose.

    "Created: / 04-08-2018 / 10:41:59 / Claus Gittinger"
    "Modified: / 05-08-2018 / 03:12:58 / Claus Gittinger"
!

handlesButtonMotion:state inView:aView
    ^ false

    "Created: / 04-08-2018 / 16:55:09 / Claus Gittinger"
!

handlesButtonPress:state inView:aView
    ^ false

    "Created: / 04-08-2018 / 16:55:20 / Claus Gittinger"
!

handlesButtonRelease:state inView:aView
    ^ false

    "Created: / 04-08-2018 / 16:55:24 / Claus Gittinger"
!

handlesKeyPress:key inView:aView
    ^ self realized

    "Created: / 04-08-2018 / 16:54:44 / Claus Gittinger"
!

handlesKeyRelease:key inView:aView
    ^ false

    "Created: / 04-08-2018 / 16:54:54 / Claus Gittinger"
!

handlesPointerEnter:state inView:aView
    ^ self realized
    "/ ^ true

    "Created: / 04-08-2018 / 16:55:49 / Claus Gittinger"
!

handlesPointerLeave:state inView:aView
    ^ self realized
    "/ ^ true

    "Created: / 04-08-2018 / 16:55:53 / Claus Gittinger"
!

installDelayedClose
    self uninstallDelayedClose.
    delayedCloseAction isNil ifTrue:[
        delayedCloseAction := [ self delayedClose ]. 
    ].
    Processor addTimedBlock:delayedCloseAction for:nil afterMilliseconds:750.

    "Created: / 05-08-2018 / 03:13:23 / Claus Gittinger"
    "Modified: / 14-02-2019 / 02:16:10 / Claus Gittinger"
!

keyPress:key x:x y:y view:aView
    key == #Escape ifTrue:[
        "/ close now
        self delayedClose.
        ^ true.
    ].
    ( #( CursorUp CursorDown Return ) includes:key) ifFalse:[
        "/ close soon
        self installDelayedClose.
        ^ false.
    ].
    self uninstallDelayedClose.

"/    (subViews notNil and:[aView == (subViews firstIfEmpty:nil)]) ifTrue:[
"/        self topView destroy
"/    ].
    ^ false

    "Created: / 04-08-2018 / 17:00:33 / Claus Gittinger"
    "Modified: / 08-10-2018 / 08:36:52 / Claus Gittinger"
!

pointerEnter:state x:x y:y view:view
    (view isComponentOf:myView) ifTrue:[
        self uninstallDelayedClose.
        pointerEntered := true.
    ].
    ^ false

    "Created: / 04-08-2018 / 17:01:39 / Claus Gittinger"
!

pointerLeave:state view:view
    (view isComponentOf:myView) ifTrue:[
        closeOnPointerLeave ifTrue:[
            pointerEntered == true ifTrue:[
                pointerEntered := false.
                self installDelayedClose.
                ^ false
            ].
        ].
    ].
    ^ false

    "Created: / 04-08-2018 / 16:57:18 / Claus Gittinger"
    "Modified: / 05-08-2018 / 03:13:46 / Claus Gittinger"
!

uninstallDelayedClose
    closeOnPointerLeave := true.
    delayedCloseAction notNil ifTrue:[
        Processor removeTimedBlock:delayedCloseAction.
    ].    

    "Created: / 05-08-2018 / 03:13:23 / Claus Gittinger"
    "Modified: / 14-02-2019 / 02:16:10 / Claus Gittinger"
! !

!CodeCompletionHelpView methodsFor:'initialization'!

checkForClosedOrRaisedEditor
    |a p wg|
    
    (a := checkAction) notNil ifTrue:[
        "/ Transcript showCR:editView.
        "/ Transcript showCR:editView topView.
        (editView isNil
          or:[editView realized not
          or:[editView isReallyShown not
          or:[editView topView shown not
          or:[(wg := editView windowGroup) isNil
          or:[(p := wg process) isNil
          or:[p isDead
          or:[wg anyViewHasFocus not
        ]]]]]]]) ifTrue:[
            self pushEvent:#closeRequest.
            checkAction := nil.
        ] ifFalse:[
            "/ Transcript showCR:'raising...'.
            "/ self inspect.
            self raise.
            Processor addTimedBlock:a for:nil afterSeconds:5.
        ]
    ]

    "Created: / 14-02-2019 / 15:33:26 / Claus Gittinger"
!

enableDelegation
    |helpMenuView|

    myView notNil ifTrue:[
        myView isScrollWrapper ifTrue:[
            helpMenuView := myView scrolledView
        ] ifFalse:[
            helpMenuView := myView
        ].
        helpMenuView notNil ifTrue:[
            helpMenuView delegate:self.
            helpMenuView enableEnterLeaveEvents.
            helpMenuView enableMotionEvents.
            helpMenuView enableButtonMotionEvents.
            helpMenuView enableFocusEvents.
        ].
    ].
!

initStyle
    "setup viewStyle specifics"

    <resource: #style (
                       "/ #'activeHelp.backgroundColor'
                       #'activeHelp.borderWidth'
                       "/ #'activeHelp.font'
                       )>

    |defaultFont|

    super initStyle.

"/    defaultFont := styleSheet fontAt:#'activeHelp.font' default:nil.
"/    defaultFont notNil ifTrue:[
"/        self font:defaultFont
"/    ].

    self borderWidth:(styleSheet at:#'activeHelp.borderWidth' default:1).

    "Modified: / 26.10.1997 / 17:02:09 / cg"
!

initialize
    super initialize.
    closeOnPointerLeave := true.
    pointerEntered := false.
!

mapped
    super mapped.

    "/ install a watcher to check for the editView being still present
    "/ from time to time.
    "/ this prevents leftover completion views in case the editView is destroyed
    "/ and forgets to tell me...
    checkAction := [self checkForClosedOrRaisedEditor].
    Processor addTimedBlock:checkAction for:nil afterSeconds:2.
!

raise
    super raise

    "Modified: / 14-02-2019 / 15:34:17 / Claus Gittinger"
!

realize
    self create.
    "/ self computeShape.
    self enableDelegation.

    super realize

    "Modified: / 14-02-2019 / 15:34:17 / Claus Gittinger"
!

release
    |a|
    
    (a := checkAction) notNil ifTrue:[
        checkAction := nil.
        Processor removeTimedBlock:a.
    ].
    super release.

    "Created: / 14-02-2019 / 15:35:32 / Claus Gittinger"
!

unmapped
    Processor removeTimedBlock:checkAction.
    super unmapped.


! !

!CodeCompletionHelpView methodsFor:'private'!

resizeToFit
    "resize myself to make the component view fit"

    |pref bw|

    pref := myView preferredExtent.
    myView extent:pref.
    bw := self borderWidth.
    self extent:(pref + (bw * 2)).
    myView origin:(bw asPoint).

    "Modified: 28.6.1997 / 14:23:49 / cg"
! !

!CodeCompletionHelpView methodsFor:'queries'!

isPopUpView
    "return true - I am a popUp type of view (no decoration, pop-to-top)"

    ^ true

    "Modified: 12.5.1996 / 21:58:12 / cg"
!

wantsFocusWithButtonPress
    "DEFINITELY not, because if we do so,
     the editView looses focus on click, and sends me to hell in its lost focus handling!!
     So I will be terminated by a buttonPress, before I get a chance to handle the buttonRelease
     (in which I fire my action)"

    ^ false
!

wantsFocusWithPointerEnter
    "DEFINITELY not, because if we do so,
     the editView looses focus on entry, and sends me to hell in its lost focus handling!!
     So I will be terminated by a motion"

    ^ false
! !

!CodeCompletionHelpView class methodsFor:'documentation'!

version
    ^ '$Header$'
!

version_CVS
    ^ '$Header$'
! !