Author Topic: Code snippet plugin  (Read 48728 times)

Offline artoj

  • Almost regular
  • **
  • Posts: 206
  • Location: Supporting my team
    • http://ajonsson.kapsi.fi/
Re: Code snippet plugin
« Reply #15 on: August 14, 2006, 02:35:11 pm »
OK, first public version is now ready and you can download it from here: http://ajonsson.kapsi.fi/files/codesnippets.zip.

It uses external XML file called codesnippets.xml to save the snippets. This file is saved to Code::Blocks' config directory.

Now, the most important thing, I'm unable to build this plugin on Windows. The reason is beoynd my knowledge. You can read the issue from this topic: http://forums.codeblocks.org/index.php?topic=3804.0. *nix building works fine.

The zip file has a readme in it, it should answer most of your questions.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Code snippet plugin
« Reply #16 on: August 14, 2006, 03:30:30 pm »
Now, the most important thing, I'm unable to build this plugin on Windows.
Nice work! And I can tell you: I can compile this nicely under Windows. However, I had to make some adjustments to the project file. Please find my variant attached to this post for your inspection. I'm not sure if this will fix your issue, too - but it's worth a try... ;-)

[attachment deleted by admin]
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5490
Re: Code snippet plugin
« Reply #17 on: August 14, 2006, 03:35:15 pm »
I could build it too, first had some linker ?warnings?
with Morton's adjustment (place the plug-in in a subdir of the contrib dir !!), those warnings are gone , this is my output (the update.bat is not present yet, therefor the little error at the end) :
Quote
-------------- Build: Debug - Win32 in Code Snippets Plugin ---------------
Compiling: codesnippetstreectrl.cpp
Compiling: codesnippetswindow.cpp
Compiling: snippetitemdata.cpp
Compiling: codesnippets.cpp
In file included from codesnippetswindow.h:24,
                 from codesnippets.cpp:32:
C:/Projects/wxWidgets-2.6.3/include/wx/dnd.h:53: warning: inline function `bool wxIsDragResultOk(wxDragResult)' declared as dllimport: attribute ignored
Linking dynamic library: ..\..\..\devel\share\CodeBlocks\plugins\codesnippets.dll
Running project post-build steps
update.bat
Execution of 'update.bat' in 'C:\Projects\CodeBlocks\src\plugins\contrib\codesnippets' failed.
Nothing to be done.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Code snippet plugin
« Reply #18 on: August 14, 2006, 03:42:50 pm »
Execution of 'update.bat' in 'C:\Projects\CodeBlocks\src\plugins\contrib\codesnippets' failed.
Nothing to be done.
Ah yes - I've forgotten this. I've added a batch file that copies the images for me, here is the content of update.bat (to be placed in the plugin's directory):
Code
@echo off
cls
md ..\..\..\devel\share\CodeBlocks\images\codesnippets > nul 2>&1
md ..\..\..\output\share\CodeBlocks\images\codesnippets > nul 2>&1
copy resources\*.png ..\..\..\devel\share\CodeBlocks\images\codesnippets\ > nul 2>&1
copy resources\*.png ..\..\..\output\share\CodeBlocks\images\codesnippets\ > nul 2>&1
BTW: What I've also done is the re-order how the libs are linked to the plugin and (!) to add the tixml lib into linkage. Thus the warnings were gone and everything is fine.
With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5490
Re: Code snippet plugin
« Reply #19 on: August 14, 2006, 03:45:10 pm »
Both Morton and I have put the plug-in in our source tree at the level on contributed plug-ins. Hint hint ;-)


Offline artoj

  • Almost regular
  • **
  • Posts: 206
  • Location: Supporting my team
    • http://ajonsson.kapsi.fi/
Re: Code snippet plugin
« Reply #20 on: August 14, 2006, 03:57:58 pm »
Both Morton and I have put the plug-in in our source tree at the level on contributed plug-ins. Hint hint ;-)

You can add it to the trunk, if you really want to :)

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5490
Re: Code snippet plugin
« Reply #21 on: August 14, 2006, 04:06:21 pm »
If I get the approval of the Don, I will add it tomorrow ;-)

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2750
Re: Code snippet plugin
« Reply #22 on: August 14, 2006, 10:01:00 pm »
Import from file... is appending the file to the current tree.

Is there a way to clear the previous xml file/tree before importing?

I'd rather not keep all the snippets in memory at the same time. If Import from file.. would clear the tree then we could separate large snippets into individual xml files and load only when needed.
 

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Code snippet plugin
« Reply #23 on: August 15, 2006, 07:24:32 am »
Is there a way to clear the previous xml file/tree before importing?
Nice would be a question like: Press "Append" to append the file or "New" to import. (Click "Cancel" to abort.). I think both can be interesting: To append to an existing code snippet list or to "create" a new one when importing. Oh - and by the way: I truly vote for adding this to SVN. It's great!
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline artoj

  • Almost regular
  • **
  • Posts: 206
  • Location: Supporting my team
    • http://ajonsson.kapsi.fi/
Re: Code snippet plugin
« Reply #24 on: August 15, 2006, 10:10:38 am »
The import / export functionality doesn't actually make sense anymore because it's same type of file that gets saved and loaded. In the first version the snippets were saved to the main C::B config file so that's why the Import / Export.

The import/export should be changed to "Load from file" and "Save to file" or something like that. I think another menu item "Load from file (append)" should added too + "remove all".

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5490
Re: Code snippet plugin
« Reply #25 on: August 15, 2006, 12:17:27 pm »
I'll add it to svn this afternoon ...

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2750
Re: Code snippet plugin
« Reply #26 on: August 15, 2006, 02:29:56 pm »
Once this is under SVN, If you are accepting patches, I'd like to offer the following which I've already coded in another app. It might save you some time, and avoid duplicated effort.

* clipboard copy/paste to/from tree  via toolbar (I'll adapt it to your code)

* drag/drop/copy/paste multiple formats (ie filename or text format) useful to record workspace/project/filenames when they run off the "recent" list; the user just drags/copies the workspace/project/file name into the management window and it opens as if it had been on the recent list.

* drag/drop text from/to external apps (scite and StEdit are very useful).

thanks for this nice plugin,
pecan
« Last Edit: August 15, 2006, 02:32:06 pm by Pecan »

Offline artoj

  • Almost regular
  • **
  • Posts: 206
  • Location: Supporting my team
    • http://ajonsson.kapsi.fi/
Re: Code snippet plugin
« Reply #27 on: August 15, 2006, 02:58:52 pm »
Once this is under SVN, If you are accepting patches, I'd like to offer the following which I've already coded in another app. It might save you some time, and avoid duplicated effort.

Sure, thanks :)

Quote
* drag/drop text from/to external apps (scite and StEdit are very useful).

You do this already but you can't drag and drop to external apps. The problem is that I want to able to drag and drop within the tree also, I don't know how this and the drag and drop to external apps can be archieved (or more importantly, will it work).

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2750
Re: Code snippet plugin
« Reply #28 on: August 15, 2006, 03:46:02 pm »
Quote
The problem is that I want to able to drag and drop within the tree also, I don't know how this and the drag and drop to external apps can be archieved (or more importantly, will it work).

Yes, it works, I already have the code.

I've also seen code that allows drag/drop within the tree by creating an xml doc of the selected source and children then inserting it in the target position. It allowed copy/moving an item up/down and in/out.

It copied the source xml to the clipboard, then inserted at the drop target.
I can't seem to find it now, but I'll keep looking. If I don't find it, and you don't get to it first, I'll try to recreate it from memory.

I also meant to say that I already had code that dragged/dropped from/to copy/pasted to/from external apps from a wxTreeCtrl. It uses another xml other than tinyXml, but it can be adapted.

I see that codesnippet can drag text "into" the tree item from an external app, but not "out" of the tree. Thats where the clipboard/dragdrop code that I have already written comes in. I'll rework it for CodeSnippets.

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.)
« Last Edit: August 15, 2006, 04:08:04 pm by Pecan »

Offline artoj

  • Almost regular
  • **
  • Posts: 206
  • Location: Supporting my team
    • http://ajonsson.kapsi.fi/
Re: Code snippet plugin
« Reply #29 on: August 15, 2006, 04:42:43 pm »
Yes, it works, I already have the code.

I've also seen code that allows drag/drop within the tree by creating an xml doc of the selected source and children then inserting it in the target position. It allowed copy/moving an item up/down and in/out.

It copied the source xml to the clipboard, then inserted at the drop target.
I can't seem to find it now, but I'll keep looking. If I don't find it, and you don't get to it first, I'll try to recreate it from memory.

Wow, that's really cool way to do it, I never tought of that. :shock:

Quote
I also meant to say that I already had code that dragged/dropped from/to copy/pasted to/from external apps from a wxTreeCtrl. It uses another xml other than tinyXml, but it can be adapted.

I see that codesnippet can drag text "into" the tree item from an external app, but not "out" of the tree. Thats where the clipboard/dragdrop code that I have already written comes in. I'll rework it for CodeSnippets.

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.

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.