Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

button disable?

66 views
Skip to first unread message

john c

unread,
Sep 14, 2021, 2:58:01 PM9/14/21
to
hi all,

i've had a problem for quite a while. i have a dialog where one button should be enabled/disabled based the values of some instance variables. i have included what i think are the relevant methods. the enable/disable is not working.

i'm running on v7.1.20 but have had the same problem with 7.0.57.

any thoughts will be appreciated.

john


queryCommand: aCommandQuery

super queryCommand: aCommandQuery.
(self canEnableLoad)
ifTrue:[(#(#onLoadEnabled) includes: aCommandQuery command) ifTrue: [ aCommandQuery beEnabled ]]
ifFalse:[(#(#onLoadEnabled) includes: aCommandQuery command) ifTrue: [ aCommandQuery beDisabled ]].

canEnableLoad

(hasRegion)
ifFalse:[^false].
(hasFilePath )
ifFalse:[^false].
(hasFileType )
ifFalse:[^false].
canEnablePresenter value: true.
^true


openOn: aJCModel

(aJCModel isNil)
ifTrue:[self model: self class defaultModel]
ifFalse:[self model: aJCModel ].

self preOpenProcess.
self halt. <== hasRegion, hasFilePath, hasFileType are all false here
^self showModal. <== load button enabled (it is assoc with method onLoadEnabled)

vin...@gmail.com

unread,
Sep 15, 2021, 12:03:13 AM9/15/21
to
Hi John

Does the button have a command connected to it? If it does it should be enabled by default.

It is difficult to tell from you snippet the exact problem, but can you mock the call to the code in the body of the #queryCommand: method? I.e., if you call
(self canEnableLoad)
ifTrue:[(true) ifTrue: [ aCommandQuery beEnabled ]]
ifFalse:[(true) ifTrue: [ aCommandQuery beDisabled ]].
does anything different happen?

Vince

john c

unread,
Sep 15, 2021, 2:07:14 PM9/15/21
to
hi vince,

i took your suggestions (code below). bottom line is that method which sets variables and the boolean method which queryCommand reference, are working correctly. beyond that i setup queryCommand to "false" and button is still enabled.

john

queryCommand: aCommandQuery

super queryCommand: aCommandQuery.
(false "self canEnableLoad") <== should disable the button assoc with (#onLoadEnabled) ... doesn't
ifTrue:[(#(#onLoadEnabled) includes: aCommandQuery command) ifTrue: [ aCommandQuery beEnabled ]]
ifFalse:[(#(#onLoadEnabled) includes: aCommandQuery command) ifTrue: [ aCommandQuery beDisabled ]].

updateUI: aParser <== method which sets instance vars which queryCommand cares about

| bool |

bool := self canEnableLoad. <== method in #queryCommand: first time in false here
self halt.
wpRegionPresenter model: (aParser fileRegion).
hasRegion := true.
wpFileTypePresenter model: (aParser fileType).
hasFileType := true.
wpFullPathPresenter model: (aParser filePath).
hasFilePath := true.
bool := self canEnableLoad. <== bool is true, so #canEnableLoad is working
self halt.
fileType := (aParser fileType).
fileName := (aParser filePath).
regionName := (aParser fileRegion).

john.a...@gmail.com

unread,
Sep 16, 2021, 3:41:20 AM9/16/21
to
Hi John - I haven't looked in detail at this but I think you should be checking the commandSymbol of aCommandQuery, i.e.

(#(#onLoadEnabled) includes: aCommandQuery commandSymbol) ifTrue: [ aCommandQuery beDisabled ]

Hope this helps.

John Aspinall

john c

unread,
Sep 16, 2021, 9:05:04 AM9/16/21
to
hi john,

unfortunately this didn't fix it.

john

vin...@gmail.com

unread,
Sep 16, 2021, 8:00:51 PM9/16/21
to
Hi John

Are you able to test this and tell us what you get in the Transcript?

queryCommand: aCommandQuery
| comm |

comm := aCommandQuery command.
Transcript nextPutAll: comm printString; cr

Vince

john c

unread,
Sep 16, 2021, 8:42:01 PM9/16/21
to
hi vince,

i've attached queryCommand from my problem dialog, but it doesn't produce any output.

as a side note i created a new test dialog outside of the hierarchy of my base dialog and it worked fine. so i created a completely new dialog as a sub class of my base dialog and it doesn't work. so i have to assume there is something funky in my dialog hierarchy but i have no clue where to start. i attached the queryCommand from my base dialog.




queryCommand: aCommandQuery <== queryCommand from problem dialog

| comm |

super queryCommand: aCommandQuery.

comm := aCommandQuery command.
Transcript nextPutAll: 'Cmd ', comm printString, Character cr.
(false "self canEnableLoad")
ifTrue:[(#(#onLoadEnabled) includes: aCommandQuery commandSymbol) ifTrue: [ aCommandQuery beEnabled ]]
ifFalse:[(#(#onLoadEnabled) includes: aCommandQuery commandSymbol) ifTrue: [ aCommandQuery beDisabled ]].

queryCommand: aCommandQuery <== from my base dialog class

super queryCommand: aCommandQuery.

(#(#cancel) includes: aCommandQuery command) ifTrue: [ aCommandQuery beEnabled ].

(self isDirty)
ifTrue:[(#(#ok) includes: aCommandQuery command) ifTrue: [ aCommandQuery beEnabled ]]
ifFalse:[(#(#ok) includes: aCommandQuery command) ifTrue: [ aCommandQuery beDisabled ]].

vin...@gmail.com

unread,
Sep 16, 2021, 9:02:43 PM9/16/21
to
On Friday, 17 September 2021 at 10:42:01 UTC+10, john c wrote:
> hi vince,
>
> i've attached queryCommand from my problem dialog, but it doesn't produce any output.
...
> queryCommand: aCommandQuery <== queryCommand from problem dialog
>
> | comm |
>
> super queryCommand: aCommandQuery.
>
> comm := aCommandQuery command.
> Transcript nextPutAll: 'Cmd ', comm printString, Character cr.

This won't print anything out as you need to send the message #cr to the Transcript to flush the line. You will need to do this:
Transcript nextPutAll: 'Cmd ', comm printString; cr.

Vince

john c

unread,
Sep 17, 2021, 8:26:33 AM9/17/21
to
hi vince,

sorry, missed the semi-colon.

here is transcript

Cmd #ok
Cmd #cancel
Cmd #openFindFile
Cmd #onLoadEnabled
Cmd #ok
Cmd #cancel
Cmd #openFindFile
Cmd #onLoadEnabled

john c

unread,
Sep 17, 2021, 9:20:16 AM9/17/21
to
it strikes me that the problem must be the includes: is failing.
Message has been deleted

vin...@gmail.com

unread,
Sep 17, 2021, 9:23:25 PM9/17/21
to
On Friday, 17 September 2021 at 23:20:16 UTC+10, john c wrote:
> it strikes me that the problem must be the includes: is failing.

You should now try substituting the #beEnabled: message send with a Transcript output:

(self canEnableLoad)
ifTrue:[(#(#onLoadEnabled) includes: aCommandQuery command) ifTrue: [ Transcript nextPutAll: 'Enabled'; cr ]]
ifFalse:[(#(#onLoadEnabled) includes: aCommandQuery command) ifTrue: [ Transcript nextPutAll: 'Disabled'; cr ]].

By the way is the button in a Presenter or in a Shell?

Vince

john c

unread,
Sep 18, 2021, 9:37:28 AM9/18/21
to
hi vince,

transcript shows Disabled

button is still enabled

button is in a shell(dialog) at the same level as the cancel/ok

john

john c

unread,
Sep 18, 2021, 12:13:11 PM9/18/21
to
did some experimenting.

created a new shell with only menu option to open the problem dialog. it worked!

i went to the "real" shell and just selected the menu to open the problem dialog. it worked!

i then went back and went thru the same sequence except for opening the db before opening the dialog. it failed.

i went and opened the dialog (good result), then open the db, and then opened the dialog again. it failed.

so it has something to do with what is going on in my shell/openDb. any suggestions on what i should be looking for in my main shell which would cause queryCommand to not work in a dialog?

btw, thanks for all your help.


john

john c

unread,
Sep 18, 2021, 2:55:39 PM9/18/21
to
On Saturday, September 18, 2021 at 12:13:11 PM UTC-4, john c wrote:

i think i figured it out.

in my main shell i had the method name the same as the method name in the dialog. i enabled/disabled the method in the main shell queryCommand based on whether the db was open or not. subsequently i changed the name of the main shell message but forgot to change the name in the main shell queryCommand. so it appears the queryCommand of the main shell overrides the queryCommand in the dialog if there is a method name clash. i assume this is the result of symbols being globally unique.
0 new messages