SmallSense__DialogBox.st
author Jan Vrany <jan.vrany@labware.com>
Thu, 01 Jun 2023 20:20:33 +0100
changeset 1149 33f8a8571e92
parent 1144 93164087c56a
permissions -rw-r--r--
Fix class selection drop-in dialog Commit 93164087c56a added class selection dialog to SmallSense's `DialogBox`. This commit selever bugs in the implementation.

"
COPYRIGHT (c) 2022-2023 LabWare

stx:goodies/smallsense - A productivity plugin for Smalltalk/X IDE

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
"
"{ Package: 'stx:goodies/smallsense' }"

"{ NameSpace: SmallSense }"

Smalltalk::DialogBox subclass:#DialogBox
	instanceVariableNames:''
	classVariableNames:'PreviousDialog'
	poolDictionaries:''
	category:'SmallSense-Core-Interface'
!

!DialogBox class methodsFor:'documentation'!

copyright
"
COPYRIGHT (c) 2022-2023 LabWare

stx:goodies/smallsense - A productivity plugin for Smalltalk/X IDE

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
"
!

documentation
"
    This is a drop-in replacement for stock DialogBox replacing old
    'smalltalk' dialogs with Smallsense ones.

    [author:]
        Jan Vrany <jan.vrany@labware.com>

    [instance variables:]

    [class variables:]

    [see also:]
        DialogBox class, protocol 'smalltalk dialogs'

"
! !

!DialogBox class methodsFor:'installing'!

install
    | currentDialog |

    currentDialog := Smalltalk at: #Dialog.
    (currentDialog isNil or: [ currentDialog ~~ self ]) ifTrue: [ 
        PreviousDialog := currentDialog.
        Smalltalk at: #Dialog put: self.
    ].

    "Created: / 02-09-2022 / 20:10:15 / Jan Vrany <jan.vrany@labware.com>"
!

uninstall
    | currentDialog |

    currentDialog := Smalltalk at: #Dialog.
    currentDialog == self ifTrue: [ 
        Smalltalk at: #Dialog put: PreviousDialog.
    ].

    "Created: / 02-09-2022 / 20:10:59 / Jan Vrany <jan.vrany@labware.com>"
! !

!DialogBox class methodsFor:'smalltalk dialogs'!

requestClassName:title list: classesOrNil okLabel:okLabel initialAnswer:initialTextOrNil
    "launch a Dialog, which allows user to enter a class name.
     Return the entered string (may be empty string) or nil (if cancel was pressed).
     The entryField does classNameCompletion on TAB."

    | dialog class |

    UserPreferences current smallSenseNewDialogsEnabled ifFalse:[ 
        ^ super requestClassName:title list: classesOrNil okLabel:okLabel initialAnswer:initialTextOrNil
    ].
    dialog := SmallSense::ClassSelectDialog new.
    dialog title: title.
    dialog filter: [ :cls | classesOrNil isNil or:[classesOrNil includes: cls ] ].
    initialTextOrNil notNil ifTrue: [
        dialog pattern: initialTextOrNil.
        dialog selection: initialTextOrNil.
    ].
    class := dialog open.
    ^ class name

    "Created: / 24-08-2022 / 14:45:09 / Jan Vrany <jan.vrany@labware.com>"
    "Modified: / 01-06-2023 / 19:42:27 / Jan Vrany <jan.vrany@labware.com>"
!

requestProject:title from:listOfProjects initialAnswer:initialTextOrNil suggestions:suggestions
    "Ask for a project (package-id)"
    | dialog |

    UserPreferences current smallSenseNewDialogsEnabled ifFalse:[ 
        ^ super requestProject:title from:listOfProjects initialAnswer:initialTextOrNil suggestions:suggestions.
    ].
    dialog := SmallSense::PackageSelectDialog new.
    dialog title: title.
    dialog filter: [ :pkg | listOfProjects includes: pkg ].
    (initialTextOrNil notNil and:[initialTextOrNil ~~ PackageId noProjectID]) ifTrue:[
        initialTextOrNil isEmpty ifTrue:[
            suggestions size == 1 ifTrue:[
                dialog pattern:   suggestions anElement. 
                dialog selection: suggestions anElement. 
            ].
        ] ifFalse:[ 
            dialog pattern: initialTextOrNil.
            dialog selection: initialTextOrNil.
        ]
    ].
    ^ dialog open.

    "Created: / 24-08-2022 / 14:40:04 / Jan Vrany <jan.vrany@labware.com>"
! !

!DialogBox class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
! !