Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development

Help for a plugin newbie - reading keypresses inside the editor

<< < (2/3) > >>

dmoore:

--- Quote from: Turbo on December 07, 2009, 07:10:06 am ---If I leave the "if(event.GetControl())" line, i get an "undefined reference to `_imp___ZNK16wxScintillaEvent10GetControlEv' in keys.cpp :|
In the same way, if i leave the "wxEVT_SCI_KEY" check, i get another unexpected linker error...

--- End quote ---

you need to link against the wxscintilla .dll or .so (again see how its done in codecompletion)


--- Quote ---The code looks nicely organized, but it's a bit overwhelming to the newbie, lots of different libraries mixed together and not many comments in the code make it a bit hard to follow.

--- End quote ---

agree, but not easy to fix. suggetions?

Turbo:

--- Quote from: dmoore on December 07, 2009, 02:26:17 pm ---did you try looking at void CodeCompletion::EditorEventHook(cbEditor* editor, wxScintillaEvent& event) in src/plugins/codecompletion/codecompletion.cpp (approx line 1850)?

--- End quote ---
Yes, it's been my main source of reference. But it doesn't handle extended keys. From the wxScintilla events I'm printing, I don't think the Ctrl/Alt/Shift keys generate wxScintillaEvents, unless it's in combination with. My guess is Scintilla is too high level for a Ctrl key event, and i have to go lower level. I'll now try your first suggestion, using Connect() and associating it with the currently selected Editor.
Your help has helped me learn a lot from the inner workings of CodeBlocks, thank you.


--- Quote from: dmoore on December 07, 2009, 02:47:25 pm ---you need to link against the wxscintilla .dll or .so (again see how its done in codecompletion)

--- End quote ---
Thanks, i was a bit tired and did not realize wxscintilla.dll was not being linked.


--- Quote ---
--- Quote ---The code looks nicely organized, but it's a bit overwhelming to the newbie, lots of different libraries mixed together and not many comments in the code make it a bit hard to follow.

--- End quote ---

agree, but not easy to fix. suggetions?

--- End quote ---
I'm not too confident with the code to suggest a proper solution yet (or to realize that this is in fact a real problem), but i just tend to leave lots of comments everywhere on my code. Some people have called me on that, saying that code looks dirty :)
I guess most of my doubts can be resolved with source code digging and checking out what each 3rd party library inner workings are, but it takes a lot longer than simply looking at the wiki's tutorials :)

dmoore:

--- Quote ---I guess most of my doubts can be resolved with source code digging and checking out what each 3rd party library inner workings are,

--- End quote ---

that's the way I work. html docs for 3rd party libs + right click -> find declaration/implementation work a charm :) Currently, the source of the various plugins are the best tutorials we have.


--- Quote ---but it takes a lot longer than simply looking at the wiki's tutorials

--- End quote ---

Improving the wiki tutorials would probably be one of the the most valuable things we can do, but it does take quite a bit of work to put tutorials together and keep them up to date.

Turbo:

--- Quote ---what you are doing with your event table is telling wxWidgets you want to capture key events from your plugin and any of its children. one problem: your plugin is not the parent of the editors.
--- End quote ---

Which is the editor's plugin's parent? The wxWindow from which the editor inherits, or the EditorManager, or some other class?

I've tried using the Connect as mentioned in the post, but keys::OnKeyUp is never called. It now looks like:

--- Code: ---void keys::OnAttach()
{
    this->Connect(wxID_ANY, wxEVT_KEY_UP, wxKeyEventHandler(keys::OnKeyUp), NULL, this); // does nothing
    //Connect(wxID_ANY, wxEVT_KEY_UP, wxKeyEventHandler(keys::OnKeyUp), NULL, this); // this does nothing as well
    //Connect(wxEVT_KEY_UP, wxKeyEventHandler(keys::OnKeyUp)); // neither does this
}

--- End code ---


--- Quote ---Improving the wiki tutorials would probably be one of the the most valuable things we can do, but it does take quite a bit of work to put tutorials together and keep them up to date.

--- End quote ---
I'd contribute, if i can ever get this thing off the ground. Maybe i should go play with event catching in wxWidgets first to make sure i can make it work and then try in CodeBlocks.
I also need a new computer, 2 minutes to compile this barebones plugin is too much :)

dmoore:

--- Quote from: Turbo on December 08, 2009, 12:29:32 am ---
--- Quote ---what you are doing with your event table is telling wxWidgets you want to capture key events from your plugin and any of its children. one problem: your plugin is not the parent of the editors.
--- End quote ---

Which is the editor's plugin's parent? The wxWindow from which the editor inherits, or the EditorManager, or some other class?

--- End quote ---

I think the editor manager owns the editors, but C::B also uses a general event sink that traps many of the events so that they can be redirected to plugins.


--- Quote ---I've tried using the Connect as mentioned in the post, but keys::OnKeyUp is never called. It now looks like:

--- Code: ---void keys::OnAttach()
{
    this->Connect(wxID_ANY, wxEVT_KEY_UP, wxKeyEventHandler(keys::OnKeyUp), NULL, this); // does nothing
    //Connect(wxID_ANY, wxEVT_KEY_UP, wxKeyEventHandler(keys::OnKeyUp), NULL, this); // this does nothing as well
    //Connect(wxEVT_KEY_UP, wxKeyEventHandler(keys::OnKeyUp)); // neither does this
}

--- End code ---

--- End quote ---

replace


--- Code: ---this->Connect(...);
--- End code ---

with


--- Code: ---target_window->Connect(wxEVT_KEY_UP, wxKeyEventHandler(keys::OnKeyUp), NULL, this);
--- End code ---

where target window is some window that will receive keystrokes (editor/editormanager?). Also don't forget that scintilla also generates wxEVT_SCI_KEY events (I don't know what impact that has, if any, on regular key events)

btw, the Keybinder plugin uses a slightly different strategy to trap key events. It adds an entire event handler to relevant windows:


--- Code: ---target_window->PushEventHandler(this);
--- End code ---

You could then use a regular event table in your plugin (or whatever handler object you choose)


--- Quote ---I'd contribute, if i can ever get this thing off the ground. Maybe i should go play with event catching in wxWidgets first to make sure i can make it work and then try in CodeBlocks.

--- End quote ---

If you plan to hack on C::B, the more comfortable you are with wxWidgets the better.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version