Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Minor annoyance: Allow an escape key binding on popups #14

Open
davidrenne opened this issue May 29, 2022 · 10 comments
Open

[feature] Minor annoyance: Allow an escape key binding on popups #14

davidrenne opened this issue May 29, 2022 · 10 comments
Labels
enhancement New feature or request

Comments

@davidrenne
Copy link

Instead of having to click the red close button, allow for an escape key to do the same thing.

@frank-weindel frank-weindel added the enhancement New feature or request label Dec 7, 2022
@willbr
Copy link

willbr commented Aug 5, 2023

hotkeys are defined in utest.rc

acidMain ACCELERATORS DISCARDABLE
BEGIN
"C", cidCopy, VIRTKEY, CONTROL, NOINVERT
"C", cidShiftCopy, VIRTKEY, SHIFT, CONTROL,
NOINVERT
"I", cidInfo, VIRTKEY, SHIFT, CONTROL,
NOINVERT
"M", cidMap, VIRTKEY, CONTROL, NOINVERT
"N", cidNew, VIRTKEY, CONTROL, NOINVERT
"O", cidOpen, VIRTKEY, CONTROL, NOINVERT
"Q", cidQuit, VIRTKEY, CONTROL, NOINVERT
"S", cidSave, VIRTKEY, CONTROL, NOINVERT
"V", cidPaste, VIRTKEY, CONTROL, NOINVERT
VK_F1, cidHelpBook, VIRTKEY, NOINVERT
VK_F9, cidToggleXY, VIRTKEY, NOINVERT
VK_F10, cidWriteBmps, VIRTKEY, CONTROL, NOINVERT
"X", cidCut, VIRTKEY, CONTROL, NOINVERT
"X", cidShiftCut, VIRTKEY, SHIFT, CONTROL,
NOINVERT
"Y", cidRedo, VIRTKEY, CONTROL, NOINVERT
"Z", cidUndo, VIRTKEY, CONTROL, NOINVERT
END

@willbr
Copy link

willbr commented Aug 18, 2023

Browsers and Easels are implimented in Chunky Script. This could prove a tad complicated.

We might need to create a new event that we can add a handler for in the Chunky Script.

@jayrod246
Copy link

jayrod246 commented Aug 18, 2023

You might also get away with just handling it with the command handler ESL and the various browser classes. I believe there is a base browser class? And they are what get instantiated by those scripts I think.

Edit: Or have the escape key send a cancel button command.

@willbr
Copy link

willbr commented Aug 19, 2023

I'm not sure how to find which Browser to dispatch the message to.

If I hardcode it to just one kidCameraGlass it works.

/***************************************************************************
    Escape Key
***************************************************************************/
bool Studio::FCmdEscapeKey(PCMD pcmd)
{
    PKidspaceGraphicObject pgok = pvNil;

    AssertThis(0);
    AssertVarMem(pcmd);

    printf("Studio::FCmdEscapeKey\n");

    pgok = (PKidspaceGraphicObject)((APP *)vpappb)->Pkwa()->PgobFromHid(kidCameraGlass);

    if (pgok != pvNil)
    {
        vpcex->EnqueueCid(cidBrowserCancel, pgok, pvNil, kidBrowserCancel, 0,0,0);
    }

    return fTrue;
}

@willbr
Copy link

willbr commented Aug 19, 2023

The same works for Easels.

It feels like a bit of a bodge, but we could iterate over the handler id's.

And, if it has a graphic object, post the cancel message.

/***************************************************************************
    Escape Key
***************************************************************************/
bool Studio::FCmdEscapeKey(PCMD pcmd)
{
    PKidspaceGraphicObject pgok = pvNil;

    AssertThis(0);
    AssertVarMem(pcmd);

    printf("Studio::FCmdEscapeKey\n");

    pgok = (PKidspaceGraphicObject)((APP *)vpappb)->Pkwa()->PgobFromHid(kidCostGlass);

    if (pgok != pvNil)
    {
        // vpcex->EnqueueCid(cidBrowserCancel, pgok, pvNil, kidBrowserCancel, 0,0,0);
        vpcex->EnqueueCid(cidEaselCancel, pgok, pvNil, 0, 0,0,0);
    }

    return fTrue;
}

@willbr
Copy link

willbr commented Aug 19, 2023

One edge case I've seen noted in the Chunky scripts is the Sound Recorder.

You've got an Easel open over a Browser.

@jayrod246
Copy link

jayrod246 commented Aug 19, 2023

Have it send without a target, pvNil. The browser/easel should pick it up since the command accepts fcmmNobody.

But still need to figure out edge cases where there would be multiple browsers or easels open at a time.

@willbr
Copy link

willbr commented Aug 20, 2023

Do you mean like this?

    vpcex->EnqueueCid(cidClicked, pvNil, pvNil, 0,0,0,0);
    vpcex->EnqueueCid(cidBrowserCancel, pvNil,pvNil, kidBrowserCancel, 0,0,0);

That didn't work for me.

I assumed it was because I had to pass the GOK object.

browser.cht

CLICK_SCRIPT("Browser cancel clicked")
	EnqueueCid(cidBrowserCancel, GidParGob(GidParThis()), GidThis(), 0, 0, 0);
ENDCHUNK

Is fcmmNobody for Handlers that handle all events?

@jayrod246
Copy link

jayrod246 commented Aug 20, 2023

Ah, so the browsers never receive the commands because they are never being added the Command Execution list. So the only way currently they are able to handle them is if you pass the GOK object.

So you need to do something similar like this in the browser constructor/init:

if (!vpcex->FAddCmh(this, kcmhlStudio))
goto LFail;

And the browsers have their own Command Handler Level. This constant is defined but never used:

const long kcmhlBrowser = 0x11000; // nice medium level for the Browser

I got an opportunity to play around here and was able to get them to handle the command, but it turns out you can "cancel" those roll call views (the actor/prop selection views on the sides) 😂

So a little more work to be done but definitely getting somewhere lol.

@jayrod246
Copy link

Is fcmmNobody for Handlers that handle all events?

It means it handles those events that have no target, specifically pvNil.
And fcmmOthers means it handles those that do have a target, but it isn't us.

enum
{
fcmmNil = 0,
fcmmThis = 1,
fcmmNobody = 2,
fcmmOthers = 4,
};
const ulong kgrfcmmAll = fcmmThis | fcmmNobody | fcmmOthers;

To handle all events you can use kgrfcmmAll, which is what the helper ON_CID_ALL does:

3DMMForever/kauai/src/cmd.h

Lines 116 to 119 in 79b3010

#define ON_CID(cid, pfncmd, pfneds, grfcmm) {cid, (PFNCMD)pfncmd, (PFNEDS)pfneds, grfcmm},
#define ON_CID_ME(cid, pfncmd, pfneds) {cid, (PFNCMD)pfncmd, (PFNEDS)pfneds, fcmmThis},
#define ON_CID_GEN(cid, pfncmd, pfneds) {cid, (PFNCMD)pfncmd, (PFNEDS)pfneds, fcmmThis | fcmmNobody},
#define ON_CID_ALL(cid, pfncmd, pfneds) {cid, (PFNCMD)pfncmd, (PFNEDS)pfneds, kgrfcmmAll},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants