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

Plugin scripts - accessing local context data

(1/4) > >>

beldaz:
Hi, I'm new to the forums and to the internals of C::B, so please forgive my ignorance...

I'm read through the wiki pages on writing plugin scripts, and this appears to be a very powerful tool. The wiki explains enough for me to modify the menus and add context menus. Could anyone help me go further by giving a demonstration of how to do the following within a script?

Say I have some code in the currently open editor panel:

--- Code: ---// ...
a= foo(data);
//...

--- End code ---

I'd like to be able to right-click within the word "foo" and get a context menu entry "change foo to bar", and if I select this entry the code would change to:

--- Code: ---// ...
a= bar(data);
//...

--- End code ---

Can the above be done, and if so, how. Clearly the work should be done from GetModuleMenu(who, data), but I don't know how to access the string located under the cursor.

I've many more questions, but this would be a great start.

oBFusCATed:
See the cbDebuggerPlugin::GetEditorWordAtCaret c++ function in http://svn.berlios.de/wsvn/codeblocks/branches/wxpropgrid_debugger/src/sdk/cbplugin.cpp?peg=7625
And then try to implement it in the script, if some of the methods/functions are missing we can expose them to the scripts.
This is the most clever version of the function and it does more than what you want.

Looking here wiki.codeblocks.org/index.php?title=Scripting_commands it seems that the cbStyleTextCtrl is missing from the binding.
I guess you can try to add the bindings yourself and then send us a patch, because I think I don't have time to do it now. It should be pretty easy, look at the wiki for the documentation of the process.

http://wiki.codeblocks.org/index.php?title=Script_bindings

If you have problems don't hesitate to ask.

zabzonk:
Where would the context menu get "bar" from so it can say "change foo to bar"? Also, this feature kind of exists already in the Code Refactoring context menu.

oBFusCATed:
Neil: The function I've posted does this - it is used in debugger's branch to get a string for the watches and why do you think he wants to implement refactoring tool in script?

beldaz:
oBFusCATed: Thanks, I'll look into that. I've just been using the 10.05 binary, but I shall have to be brave and start looking at the source. Looks like the more that can be exposed to scripting the better. Experience has taught me not to jump straight to C++ each time, fun though it is, and the scripting functionality has the potential to be very powerful.

Neil: My example wasn't for refactoring. I'm currently playing around with different approaches to unit testing and I was thinking about how to adding some tools for this. However, at present I'm just trying to understand what can be done. The point was to be able to get the content at the cursor position and change it, without a specific application intended. For this example bar could be hard-coded, foo should not.

However, taking things further, any idea how much harder would it be to identify which namespace/class/method I was currently in? The code completion toolbar appears to be able to do this...

Thank again.

Navigation

[0] Message Index

[#] Next page

Go to full version