Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: arthurzmj on May 07, 2014, 05:16:38 pm

Title: Take over the event handler
Post by: arthurzmj on May 07, 2014, 05:16:38 pm
Hello guys,

I'm developing a vim-like key shortcut plugin for C::B.
I want to take over the control of the editor, so I created a wxEvtHandler and use window.PushEventHandler() to add my handler to the top of the handler chain.
But when I press CTRL+A or CTRL+F or some other key shortcuts that I configured in "keybinder", the standard key shortcut plugin in C::B, the handler I pushed can not receive the event.
I guess the event handler of "keybinder" is above my handler in the handler chain which may mean the initialization of "keybinder" is later than my plugin because if I disable the "keybinder", my plugin can work well.

Does someone have suggestion for my problem?
Title: Re: Take over the event handler
Post by: stahta01 on May 07, 2014, 07:26:07 pm
I suggest reading this thread it might have answers.
I really do NOT know enough C++ to judge if it has answers; so, I did NOT read the thread.

http://forums.codeblocks.org/index.php?topic=6214.10 (http://forums.codeblocks.org/index.php?topic=6214.10)

Edit: I saw that you posted in that thread, sorry about the noise.

Tim S.
Title: Re: Take over the event handler
Post by: Alpha on May 07, 2014, 07:50:47 pm
Catching key events globally (http://wiki.wxwidgets.org/Catching_key_events_globally) might be helpful (I have not looked in depth though).
Title: Re: Take over the event handler
Post by: Pecan on May 07, 2014, 08:04:35 pm
Keybinder loads the key definitions after all plugins have finished initializing, This is in order to catch key defs defined by plugins.

Keybinder binds it's event handler to each created editor at the create window event. It catches a defined key and passes it on to a menu event.

What editor event did you bind CTRL+A and CTRL+F to? Did you define command events to catch the menu events?

See: cbkeybinder.cpp line 955
// ----------------------------------------------------------------------------
void cbKeyBinder::OnWindowCreateEvent(wxEvent& event)
// ----------------------------------------------------------------------------
{...

keybinder.cpp 1223
// ----------------------------------------------------------------------------
//  wxKeyBinder Attach
// ----------------------------------------------------------------------------
void wxKeyBinder::Attach(wxWindow *p)
{..


Title: Re: Take over the event handler
Post by: arthurzmj on May 08, 2014, 06:35:27 am
Keybinder loads the key definitions after all plugins have finished initializing, This is in order to catch key defs defined by plugins.

Keybinder binds it's event handler to each created editor at the create window event. It catches a defined key and passes it on to a menu event.

What editor event did you bind CTRL+A and CTRL+F to? Did you define command events to catch the menu events?

See: cbkeybinder.cpp line 955
// ----------------------------------------------------------------------------
void cbKeyBinder::OnWindowCreateEvent(wxEvent& event)
// ----------------------------------------------------------------------------
{...

keybinder.cpp 1223
// ----------------------------------------------------------------------------
//  wxKeyBinder Attach
// ----------------------------------------------------------------------------
void wxKeyBinder::Attach(wxWindow *p)
{..




I bind CTRL+A to EVT_KEY_PRESS.
Did you mean I need to define some menu items and set the key shortcuts via keybinder? But in fact these key shortcuts are not menu events.
I think maybe I can provide a script to append a new profile to keybinder configuration file. I found the file and had a look at it. I wonder whether I can copy the default profile and delete the key shortcuts I used. Is it protable? I mean with the version of C::B changing, do I need to change my script in this way?
Title: Re: Take over the event handler
Post by: arthurzmj on May 08, 2014, 06:37:27 am
Catching key events globally (http://wiki.wxwidgets.org/Catching_key_events_globally) might be helpful (I have not looked in depth though).

Thanks. But it can not cancel the default action of the key shortcuts, is it?