Author Topic: Code Alignment Tool  (Read 20898 times)

Offline DarrenClark

  • Single posting newcomer
  • *
  • Posts: 3
Code Alignment Tool
« on: October 04, 2009, 04:08:59 am »
Hi.

I've just picked up Code::Blocks today and I thought I'd have a wee play with the plugin system to get me using the IDE in anger.  I've made a little plugin that aligns equals characters and C++ comments.  For example:

Before
Code: [Select]
somevar1 = 1;
foo = 223;
barfoo = 12;

wibble = flibble;

squid = ferret;

/* lots of comments, doesn't matter as long as it doesn't
contain the string that's being
aligned
on
*/

After (assuming you select the lines with variables on)
Code: [Select]
somevar1 = 1;
foo      = 223;
barfoo   = 12;

wibble   = flibble;

squid    = ferret;

/* lots of comments, doesn't matter as long as it doesn't
contain the string that's being
aligned
on
*/

Not the world's greatest plugin by far but it keeps my code aligned as I want it.

The plugin creates a new menu option "Aligner" in the context menu for an editor.  There are two options in it, align = and align //.  As soon as I can figure out how to spawn an input window then you should be able to align on any string.

I'm not sure on what needs distributing but the .cbplugin file has been renamed to .zip to get past the upload filter on the forum.

Hope somebody finds this of use.  I'm off to go and make a game now :)

All the best.



[attachment deleted by admin]
--
Cheers,
Darren Clark

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5226
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code Alignment Tool
« Reply #1 on: October 04, 2009, 04:36:59 am »
I would like to download and try it!!
Thanks!!

Edit

How to use it ...???

I upzip this file, and find a .so file :(
« Last Edit: October 04, 2009, 05:35:20 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline blueshake

  • Regular
  • ***
  • Posts: 459
Re: Code Alignment Tool
« Reply #2 on: October 04, 2009, 07:08:09 am »
I remove the extend .zip,and install from the plugin managerment,it said the *.dll is available not *.so.
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5226
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code Alignment Tool
« Reply #3 on: October 04, 2009, 09:00:05 am »
I remove the extend .zip,and install from the plugin managerment,it said the *.dll is available not *.so.
It seems this add-in can only works under Linux system. Because .so file is just like .dll file under windows.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9496
Re: Code Alignment Tool
« Reply #4 on: October 04, 2009, 08:10:42 pm »
It seems this add-in can only works under Linux system. Because .so file is just like .dll file under windows.
Yes, linux only :-(

BTW: If you rename it to *.cbplugin it should install just fine using C::B.

Any change to publish the sources, too? Sounds interesting to me...?!
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline DarrenClark

  • Single posting newcomer
  • *
  • Posts: 3
Re: Code Alignment Tool
« Reply #5 on: October 04, 2009, 10:17:18 pm »
Hi.

I don't usually code C++ on Windows but I've knocked a build of this plugin up.  It's compiled in CB 8.02 stable and is linked against WX 2.8.10.  It's all in the attached 7z file.

I've been getting some problems with the version of the SDK I'm linking to.  As I understand there's not a stable version to go by I've put the source code in the 7z file as well; that way you can compile against SVN if you so desire. :)

All the best.



[attachment deleted by admin]
--
Cheers,
Darren Clark

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5226
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code Alignment Tool
« Reply #6 on: October 05, 2009, 03:13:13 am »
Hi.

I don't usually code C++ on Windows but I've knocked a build of this plugin up.  It's compiled in CB 8.02 stable and is linked against WX 2.8.10.  It's all in the attached 7z file.

I've been getting some problems with the version of the SDK I'm linking to.  As I understand there's not a stable version to go by I've put the source code in the 7z file as well; that way you can compile against SVN if you so desire. :)

All the best.


Thanks for sharing!!!
I can build against the Trunk code, and it works ok under Windows! :D
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 202
Re: Code Alignment Tool
« Reply #7 on: October 07, 2009, 06:37:23 pm »
Thank you for your work. I was able to build on Windows... but it crashes on c::b exit (I assume it also crashes during uninstall of the plugin).

The reason is that you store the pointer to your submenu in m_menu_root and delete it in the dtor.
You must not delet it yourself because it gets deleted when the whole popupmenu gets deleted (I am not 100% sure about this).
« Last Edit: October 07, 2009, 07:01:20 pm by danselmi »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9496
Re: Code Alignment Tool
« Reply #8 on: October 07, 2009, 08:22:09 pm »
You must not delet it yourself because it gets deleted when the whole popupmenu gets deleted (I am not 100% sure about this).
That's right. Basically you can remove the whole code in the dtor. I was able to build it under Windows, too hence I did not find the time yet to try. First thing I've noticed: Where exactly is the button/function I am supposed to be offered? I found out after fixing the bug... ;-)

BTW:  This should actually crash on Linux, too...?!
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline DarrenClark

  • Single posting newcomer
  • *
  • Posts: 3
Re: Code Alignment Tool
« Reply #9 on: October 07, 2009, 10:02:16 pm »
Hmm, oddly enough it didn't, guess I shouldn't be such a neat boy...

Thanks for that one Morten, the destructor is now like my head, all empty :D  I've uploaded the changes in a 7z file.

The tool is accessed through the context popup in the editor, I've attached a wee screeny to this post.

All the best.

[attachment deleted by admin]
--
Cheers,
Darren Clark

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11939
    • Travis build status
Re: Code Alignment Tool
« Reply #10 on: October 07, 2009, 10:54:39 pm »
To make it easier for use/find, you can add it to the main menu edit -> aligner or plugins -> aligner.
Some dev, should point the correct place...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Code Alignment Tool
« Reply #11 on: October 07, 2009, 11:22:52 pm »
I attach a patch that contains a linux-project-file, that's created to be used from inside contrib-plugins subfolder of trunk.

I removed OnAttach, OnRelease, m_menu_root and some virtual declarations, because we do not need them, and I also removed the this-pointers, because they are also not needed and I really don't like them.

It's not a svn patch and therefore has to be used with patch -p1 < path/to/the/patch/aligner_linux_20091007-1.patch from inside the ALigner sub-directory.

[attachment deleted by admin]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9496
Re: Code Alignment Tool
« Reply #12 on: October 08, 2009, 07:20:36 am »
I attach a patch that contains a linux-project-file, that's created to be used from inside contrib-plugins subfolder of trunk.
I am using the patch tool.
First trial:
can't find file to patch at input line 4
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff -Nrub Aligner.orig/Aligner.cpp Aligner.work/Aligner.cpp
|--- Aligner.orig/Aligner.cpp   2009-10-07 21:44:26.000000000 +0200
|+++ Aligner.work/Aligner.cpp   2009-10-07 22:57:27.000000000 +0200
--------------------------
File to patch:
Skip this patch? [y]
Skipping patch.
4 out of 4 hunks ignored
can't find file to patch at input line 72
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff -Nrub Aligner.orig/Aligner.h Aligner.work/Aligner.h
|--- Aligner.orig/Aligner.h   2009-10-07 21:41:50.000000000 +0200
|+++ Aligner.work/Aligner.h   2009-10-07 22:57:07.000000000 +0200
--------------------------
File to patch:
Skip this patch? [y]
Skipping patch.
2 out of 2 hunks ignored
patching file "Aligner.orig/Aligner-unix.cbp"

...then after cleaning up the patch (removing "Aligner.orig/" and "Aligner.work/"):
patching file "Aligner.cpp"
Hunk #1 FAILED at 29.
Hunk #2 succeeded at 58 (offset 12 lines).
Hunk #4 succeeded at 129 (offset 12 lines).
1 out of 4 hunks FAILED -- saving rejects to file "Aligner.cpp.rej"
patching file "Aligner.h"
Hunk #1 FAILED at 22.
Hunk #2 succeeded at 91 (offset 53 lines).
1 out of 2 hunks FAILED -- saving rejects to file "Aligner.h.rej"
patching file "Aligner-unix.cbp"

...what are the base sources you used? The file "plugin_aligner_windows.7z" attached in this thread?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Code Alignment Tool
« Reply #13 on: October 08, 2009, 07:46:21 am »
The second attachement (the one in reply #9).

You have to be in the same directory where the sources are and use patch with -p1.
Works fine here.

Neither the 1.1-sources nor my patch include the windows project-file.

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 202
Re: Code Alignment Tool
« Reply #14 on: December 08, 2009, 10:55:58 pm »
A friend of mine changed the Aligner plugin:
  • don't add a newline at the end of a "new aligned" block
  • possibility to add other chars/strings to align to
  • store/load the most used chars/strings in the config.


[attachment deleted by admin]