Author Topic: Code snippet plugin  (Read 32698 times)

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2178
Re: Code snippet plugin
« Reply #30 on: August 15, 2006, 05:32:44 pm »
OK, thanks, but could you wait untill I get my first patch integrated in to the source tree. Some of the code needs to moved, mainly the XML saving etc. to the main tree ctrl subclass. Currently the code is floating in the CodeSnippetsWindow class.

Of course. I'm not being pushy I hope.

Quote
It would also be nice to see a "peek" of the snippet when the tree item is selected. (This is either a feature request or a "pecan todo" if you dont have time.)

Yes, I agree, killerbot mentioned about this too. I thinked about tooltips first but after reading the wxWidgets docs it seems that they are only supported on Windows (or I'm reading the docs incorrectly). Another way would be to add some text control under the tree control, while I am not fundamentally against this, I don't think this is a good solution.

You might want to look at a "timed" wxMiniFrame. Something like a CB popUpWindow as used in infoWindow.cpp, but using a miniFram. It's cross-platform and the CB code is practically clonable.


Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2178
Re: Code snippet plugin
« Reply #31 on: September 16, 2006, 11:03:22 pm »
Arto,

Included in the attached file (see URL below) is a standalone version of your CodeSnippets plugin.

I've included the code I promised except for the internal drag/dropping of tree item. I tried it, but the sort just put 'em back in place. I'll work on that though.

I've include the following features:
  • drag and drop out of a tree item
  • support for the clipboard
  • saving a snippet to a file
  • editing a snippet as a file (snippet file)
  • editing a snippet as a tree item(snippet text)
  • specifying an external editor to use on snippets
  • addition of a description field to the snippet
  • addition of properties viewer with editing

Please see the Help->About text for additional information.

You are welcome to use any of the code that you find to be a good addition to CodeSnippets.
You might find the program as a useful utility to prototype additions to the CodeSnippet plugin. It's so much easier to debug.





SnipList011.zip
http://savefile.com/files/77784

Direct download
http://dl1u.savefile.com/52c868ef5691ba18226eb86bbd4f9147-4af2299f6f5f8bed86bf10f1b2f39cb0/SnipList011.zip

Thank you for such a nice plugin.

pecan
« Last Edit: September 17, 2006, 03:29:42 am by Pecan »

Offline artoj

  • Almost regular
  • **
  • Posts: 206
  • Location: Supporting my team
    • http://ajonsson.kapsi.fi/
Re: Code snippet plugin
« Reply #32 on: September 17, 2006, 11:13:24 am »
Thank you very much Pecan! :)

I'll try to integrate the features to the next version of Code Snippets.

I've created a patch which I mentioned earlier; it cleans up the code / UI.

Changes:

Code: [Select]

* Added visual feedback to the searchbox: if no items can be found, the
   background is painted light red and the root item is selected

* Changed menu functionality / structure:

      - "Import from file" is now called "Load from file", it first
         deletes all the current items and then loads the file

      - "Export to XML" is now called "Save to file", with no
         functionality changed

      - To append items from file, hold down Shift while right clicking the root item,
         you should then see a "Load from file (append)" item in the menu

      - Added "Remove all" menu item

* Removed some parts of the documentation which are now obsolete

* Some code refactoring

* Removed some of the debug messages


The append menu system might change in the future; however I don't like to stack the pop up menu full of items.

Full source

Patch (against latest SVN version)

« Last Edit: September 17, 2006, 04:15:56 pm by artoj »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2178
Re: Code snippet plugin
« Reply #33 on: September 17, 2006, 02:54:52 pm »

I'll try to integrate the features to the next version of Code Snippets.

I've created a patch which I mentioned earlier; it cleans up the code the UI.
...<snip>...

Full source

Patch (against latest SVN version)


Arto,

You should be able to apply your patches directly to the CodeBlocks svn sources at berlios.

If he hasn't already, in a Personal Message, ask Mandrav for permission to update your own sources.

Offline szczepan

  • Multiple posting newcomer
  • *
  • Posts: 42
Re: Code snippet plugin
« Reply #34 on: September 21, 2006, 10:20:02 pm »
I don't seem to be able to figure out how to actually edit code snippets. When I right-click on a snippet node there are only two menu items, "Apply" and "Remove".

Is editing the XML file really the only way?

Does this plugin do variable substitutions? If so, what is the markup for a variable placeholder in snippet body?

Thanks in advance

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Code snippet plugin
« Reply #35 on: September 21, 2006, 10:36:09 pm »
Quote
I don't seem to be able to figure out how to actually edit code snippets. When I right-click on a snippet node there are only two menu items, "Apply" and "Remove"

couldn't you just insert the snippet into the editor by double clicking, edit the text, then select and drag the text back into your snippet?

Offline artoj

  • Almost regular
  • **
  • Posts: 206
  • Location: Supporting my team
    • http://ajonsson.kapsi.fi/
Re: Code snippet plugin
« Reply #36 on: September 22, 2006, 09:36:45 am »
Does this plugin do variable substitutions?

No, it's in the TODO list.

Offline szczepan

  • Multiple posting newcomer
  • *
  • Posts: 42
Re: Code snippet plugin
« Reply #37 on: September 22, 2006, 04:31:09 pm »
Does this plugin do variable substitutions?

No, it's in the TODO list.

OK. Perhaps you could reuse the built-in abbreviations code?

Offline artoj

  • Almost regular
  • **
  • Posts: 206
  • Location: Supporting my team
    • http://ajonsson.kapsi.fi/
Re: Code snippet plugin
« Reply #38 on: September 22, 2006, 04:52:13 pm »
OK. Perhaps you could reuse the built-in abbreviations code?

Yeah, I was actually browsing the abbreviations code.

However I will implement the editing of the snippets first which probably requires writing the configuration dialog so it might take a while.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2178
Re: Code snippet plugin
« Reply #39 on: September 22, 2006, 07:32:12 pm »
OK. Perhaps you could reuse the built-in abbreviations code?

Yeah, I was actually browsing the abbreviations code.

However I will implement the editing of the snippets first which probably requires writing the configuration dialog so it might take a while.

You might implement that properties box I sent you, but make the textCtrl a wxTE_MULTILINE editor. That'd take the pressure off implementing an editor for awhile.

Code: [Select]
m_SnippetTextCtrl = new wxTextCtrl( this, ID_DEFAULT, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
bSizer1->Add( m_SnippetTextCtrl, 1, wxALL|wxEXPAND, 5 );


« Last Edit: September 22, 2006, 07:33:49 pm by Pecan »

Offline artoj

  • Almost regular
  • **
  • Posts: 206
  • Location: Supporting my team
    • http://ajonsson.kapsi.fi/
Re: Code snippet plugin
« Reply #40 on: September 22, 2006, 09:00:24 pm »
You might implement that properties box I sent you, but make the textCtrl a wxTE_MULTILINE editor. That'd take the pressure off implementing an editor for awhile.

I've started implementing it a bit other way, through Code::Blocks' internal editor. It works similar to your implementation of the external editor:

- Hook to EVT_EDITOR_SAVE and EVT_EDITOR_CLOSE events
- When user clicks Edit, create a temporary file and put the snippet to it, record the file name
- Use C::B API to open the file
- On EVT_EDITOR_SAVE check if the file name is recorded, if it is, transfer the text from the file to the snippet
- On EVT_EDITOR_CLOSE check if the file name is recorded, if it is, remove it

This is how it works in general, although I need EVT_EDITOR_OPEN to check if the current tree item id has already a file open etc.
« Last Edit: September 22, 2006, 09:03:52 pm by artoj »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2178
Re: Code snippet plugin
« Reply #41 on: September 22, 2006, 10:16:23 pm »
I've started implementing it a bit other way, through Code::Blocks' internal editor. It works similar to your implementation of the external editor:

Wonderful !!

Speaking of implementations...

Please find attached the Catagory/snippet dragging code. It allows the user to drag snippets into and out of another Catagory or drag Catagories into and out of other Catagories.

I implemented it as an xml document that simply extracts and inserts the tree items using your Load/Save snippet xml routines.

I believe that finishes my promised code.



[attachment deleted by admin]

Offline artoj

  • Almost regular
  • **
  • Posts: 206
  • Location: Supporting my team
    • http://ajonsson.kapsi.fi/
Re: Code snippet plugin
« Reply #42 on: September 22, 2006, 11:23:56 pm »
Wonderful !!

Speaking of implementations...

Please find attached the Catagory/snippet dragging code. It allows the user to drag snippets into and out of another Catagory or drag Catagories into and out of other Catagories.

I implemented it as an xml document that simply extracts and inserts the tree items using your Load/Save snippet xml routines.

I believe that finishes my promised code.

Thanks! :)

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2178
Re: Code snippet plugin
« Reply #43 on: September 28, 2006, 03:29:32 pm »
Arto,

I've just discovered something great about CodeSnippets.

I can drag a forum url out of Firefox to a snippets category and it will create a snippet containing that url.

With the dragndrop additions I sent you, I can then drag the snippet back to Firefox, returning to that forum thread.

I was shocked!

I always wanted something like this. It's better than a bookmark because I can put the url along with/under the associated working code snippet category. Later, when I look back at the code snippet/file, the url discussion is right there.

Not only that, I can drag a bugReport/patch url to the relavent snippet category.
It's great!

I've made come changes to the dragndrop, specifically, 1) ability to automatically create an enclosing category when dragging a snippet to a snippet, 2) use of ctrl key to "copy" a snippet when dragging.

Have a look at the bottom of app.h to see the change log.
Maybe there's something there that you will find useful.
http://savefile.com/files/114566
Thanks
pecan

ps, Your code taught me to correctly spell category.

Edit: 2006/09/28 9:35
I've just discovered that a snippet catagory will *always* be created when dragging a snippet out of the tree. I'll fix this today. Just a heads up in case you find this problem in my code.
« Last Edit: September 28, 2006, 07:27:58 pm by Pecan »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2178
Re: Code snippet plugin
« Reply #44 on: September 28, 2006, 07:32:31 pm »
I've just discovered that a snippet catagory will *always* be created when dragging a snippet out of the tree. I'll fix this today. Just a heads up in case you find this problem in my code.

Arto,

The problem was in CodeSnippetsWindow::OnEndDrag(). The very code I've hoped you'd check out. I'm embarrased.
 
Below is a corrected version.

http://savefile.com/files/115267

Direct link:
http://dl1u.savefile.com/59d423f987ffe01b56b777f3145577f5/cbSnipList3.zip

FileFactory:http://www.filefactory.com/file/957265/

Thanks
pecan
« Last Edit: September 30, 2006, 01:12:23 am by Pecan »