Author Topic: Plug-In devlopment/documentation  (Read 3153 times)

Online killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5149
Plug-In devlopment/documentation
« on: October 19, 2005, 01:26:11 pm »
I posted this here and not in the Plug-in devlopment section since I am not (?yet?) a developer.

I am starting to develop/debug plug-ins. I successfully created the "Hello world" plug-in. So far, so good. In another post I read the suggestion for a plug-in that would allow to comment/uncomment a selected block of code lines.
I am thinking of giving this a try as learning project.

My current knowledge concerned in this matter :
 - CodeBlocks SDK : very very little
 - wxWidgets : none
Now that's a good starting point ;-) .

So while learning the tricks I am planning on writing the experiences along the road in a document, to make life easier for others who want to develop pug-ins.

I hope a lot of you can provide me with good pointers to maybe other parts of the forum (rather concrete pointers, searching is not always that productive) or can provide some answers.

Sticking to the Comment/Uncomment plug-in, if we look at it we might need several things :
1) what is the selection to comment/uncomment
    - the current line (default)
    - the actual result of selecting several lines by means of mouse/keyboard
2) accessibility of the feature
    - right click on the selection
    - a button on the toolbar, which toolbar
    - a menu entry in the ?edit? menu
    - shortcut acceleration

  --> it is obvious that for this subtask we need to be able to adjust the menus of CB, so
       Question 1 : what are the correct ways to accomplish this ?
        it is obvious that at startup of the plug-in (OnAttach) the menus should be modified
3) getting the 'data' to be modified to the plug-in
    - the plug-in should receive the selected text (to be adjusted to a number of lines : line x -> line y)
4) modify the data
    in this case it is pretty easy, insert at column 0 (== start of the line) //
5) send the data back to the 'editor'


Some first ideas :
  - after the feature was 'triggered' we should end up at the Execute() method, from here we have to retrieve the selected lines
  - Get hold of the current editor :
       + pEditorManager = Manager::Get()->GetEditorManager()
       + EditBase = pEditorManager->GetActiveEditor()
  - retrieve from this active Editor the selected text ? the complete text ? the visible part of the text ?
Questions :
  - How can the contents (the code text) be retrieved from an editor ?
  - How can we know which part is selected (if possible in lines and columns 'text' coordinates)
  - How can we replace ?
--> Anyone who can help me with this, please do.

Another open question is :
  - this little feature can be implemented as a plug-in, but at which stage can it become part of default CB behaviour, or do we get a CB with a whole buch of 'started' plug-ins. Should be able to keep the plug-ins manageable.

kind regards,
LIeven

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Plug-In devlopment/documentation
« Reply #1 on: October 19, 2005, 02:17:15 pm »
In another post I read the suggestion for a plug-in that would allow to comment/uncomment a selected block of code lines.
The editor has a similar funcitonality already. Try selecting a block and press Ctrl-Shift-C / Ctrl-Shift-X. Is that what you want? Or do you mean "block comment" in the sense of /* ... */ ?

My current knowledge concerned in this matter :
 - CodeBlocks SDK : very very little
 - wxWidgets : none
The first point is no problem at all, just look at the sdk headers. Big compliment to Yiannis - most everything can be figured from the sdk headers without actually knowing anything.
As far as plugins are concerned, there is a WiKi on how to build a plugin, or you can just look at an existing plugin (choose an easy one, such as class wizard, for example).
The second point is a huge problem. Without understanding wxWidgets (in particular event handling), you will get nowhere. And it is not very intuitive, either (I think).
Bookmark this: http://www.wxwidgets.org/manuals/2.6.2/wx_contents.html  -- you will need it a lot. And make sure you read "Topic overviews", in particular the one regarding event handling, before starting anything.

   - right click on the selection
This is a nasty one, I am just trying to get this to work, too. The problem is that you cannot just set an event table entry for a right button down event and hope for the best, because the event is not propagated. The obvious solution is to use PushEventHandler. Only one problem... it does not work properly. wxWidgets processes some events fine, but loses some others when I do that, even if my event handler immediately calls the original handler without changing one bit. If you come up with something that works, I would be very interested.

    - a menu entry in the ?edit? menu
    - shortcut acceleration
it is obvious that for this subtask we need to be able to adjust the menus of CB, so
       Question 1 : what are the correct ways to accomplish this ?

For the first one, look at codecompletion.cpp, line 137, the second one is trivial (done in the same line).
The way it is done in codecompletion.cpp is the correct way to do it (you are sent an event and get the chance to modify the menu before it opens).
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Online killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5149
Re: Plug-In devlopment/documentation
« Reply #2 on: October 23, 2005, 10:09:40 am »
Hi,

Stupid me, I nearly finished this comment/uncomment plug-in when I noticed in the edit menu .... Comment and Uncomment. ;-)
Browsing in the forum I don't seem to find the post where I was suggested to add this as a plug-in by Mandrav. I think it was an old post, at a time this functionality was not around yet ? Later on I have found another post from someone who did the implementation.
Nevertheless I was an interesting journey, I already made a first tutorial, and a second one is coming up. I just need to find out where's the best place for them. Somewhere in the forum or in the wiki. But first I'll send them to Yiannis for his judgement, so that I don't provide poor documentation.

Lieven

Offline takeshi miya

  • Lives here!
  • ****
  • Posts: 1487
Re: Plug-In devlopment/documentation
« Reply #3 on: October 23, 2005, 04:00:25 pm »
Submit it to the Wiki, it's changed by the users, so any error you could have it will be corrected by anyone.

And if it proves to be useful enogh, it can be copied later to the Handbook or FAQ in the home page (though most people read the Wiki more).

Online killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5149
Re: Plug-In devlopment/documentation
« Reply #4 on: October 29, 2005, 02:52:15 pm »
Finally my first tutorial made it to the wiki.
The screenshots are not in yet, having some problem in uploading them. :-(

direct url : http://wiki.codeblocks.org/index.php/Creating_a_Plug-in_which_modifies_CB%27s_Menus

Cheers,
Lieven

for now you can also see it (temporarely) with screenshots @ :
http://users.pandora.be/lieven.de.cock/CodeBlocks/CodeBlocksPlugInMenus.html