Author Topic: Take over the event handler  (Read 5455 times)

Offline arthurzmj

  • Multiple posting newcomer
  • *
  • Posts: 13
Take over the event handler
« 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?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6489
    • My Best Post
Re: Take over the event handler
« Reply #1 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

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

Tim S.
« Last Edit: May 07, 2014, 07:28:14 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Take over the event handler
« Reply #2 on: May 07, 2014, 07:50:47 pm »
Catching key events globally might be helpful (I have not looked in depth though).

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2119
Re: Take over the event handler
« Reply #3 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)
{..



Offline arthurzmj

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Take over the event handler
« Reply #4 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?

Offline arthurzmj

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Take over the event handler
« Reply #5 on: May 08, 2014, 06:37:27 am »
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?