Author Topic: PATCH: File extension handling improvement  (Read 6128 times)

Offline DrewBoo

  • Multiple posting newcomer
  • *
  • Posts: 110
PATCH: File extension handling improvement
« on: April 01, 2008, 06:43:07 am »
I have submitted a patch to BerliOS for your consideration.

http://developer.berlios.de/patch/?func=detailpatch&patch_id=2425&group_id=5358

Currently, Code::Blocks has inconsistent concepts of what a "source file" and "header file" are, which prevents some functionality from working.  See discussion here: http://forums.codeblocks.org/index.php/topic,8098.msg60489.html and here: http://forums.codeblocks.org/index.php/topic,7905.0.html

The Project Manager has predefined file masks to define "Source Files" and "Header Files".  ".C" (capital letter) is a valid extension, for example.  You can also add you own extensions, such as ".inl" for inline code.

Elsewhere in Code::Blocks, functionality that requires knowing header and source files ignore extensions defined in the Project Manager - even many of the default ones - and use a hard coded list.

This patch will retain the existing hard-coded extensions, but before returning failure also check whatever extensions are known by the Project Manager.

If you use non-standard file extensions such as .C or .H or .inl or any other extensions you teach the Project Manager, the following functionality will now work with those files:

  • Source Code Formatter (AStyle) will format these files
  • Code completion will always consider these files
  • GCC compiler will support "Build file" on right-click
  • GCC compiler will support building a single file outside of a project
  • GDB Debugger will always show the file in the editor when appropriate
  • Swap header/source (F11) works
  • Code::Blocks will always assume that the file should be viewed in the editor
  • File name can be used as command-line parameter to Code::Blocks to open it immediately.


Files affected:

src/sdk/globals.cpp
    Modified FileTypeOf() so that, before giving up and returning ftOther, check the Project Manager to see if it would consider the file a source or header
src/sdk/filegroupsandmasks.cpp
    Improved const-correctness
src/sdk/editormanager.cpp
    Changed swap header/source code to consider file extensions known by the project manager
src/include/projectmanager.h
    Provided an accessor to a const FileGroupsAndMasks object
src/include/filegroupsandmasks.h
    Improved const-correctness

Offline joubertdj

  • Multiple posting newcomer
  • *
  • Posts: 120
Re: PATCH: File extension handling improvement
« Reply #1 on: April 01, 2008, 08:09:37 am »
 :) Nice ... I hope all the tests succeed for your sake, so that it can be included in SVN!

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: PATCH: File extension handling improvement
« Reply #2 on: April 01, 2008, 08:30:34 am »
Quote
src/include/projectmanager.h
    Provided an accessor to a const FileGroupsAndMasks object
src/include/filegroupsandmasks.h
    Improved const-correctness

Without having looked at the patch yet, I can safely say it's probably not going to be accepted for the time being. That is because touching those files I quoted is going to break binary compatibility with the 8.02 release. And that is something that hasn't been yet decided by the devs how to handle.

Still, thanks for providing patches to improve C::B :).
Be patient!
This bug will be fixed soon...

Offline DrewBoo

  • Multiple posting newcomer
  • *
  • Posts: 110
Re: PATCH: File extension handling improvement
« Reply #3 on: April 01, 2008, 08:43:43 am »
Without having looked at the patch yet, I can safely say it's probably not going to be accepted for the time being. That is because touching those files I quoted is going to break binary compatibility with the 8.02 release. And that is something that hasn't been yet decided by the devs how to handle.

Hmm...I don't have to change filegroupsandmasks.h...I made it more const correct because it seemed like the right thing to do.

As for projectmanager.h...it's holding on to that FileGroupsAndMasks object really tight.  I could get my hands on it by doing some OFFSETOF voodoo instead of changing the interface in the header.  You know, just while the devs are deciding how this should usually be handled.

What do you think?

Still, thanks for providing patches to improve C::B :).

Bah...it's fun.   :lol:

Offline DrewBoo

  • Multiple posting newcomer
  • *
  • Posts: 110
Re: PATCH: File extension handling improvement
« Reply #4 on: April 01, 2008, 08:45:53 am »
Still, thanks for providing patches to improve C::B :).

Oh, and congratulations on your 212th post.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: PATCH: File extension handling improvement
« Reply #5 on: April 01, 2008, 10:00:03 am »
Doesn't look so bad all in all, except my TortoiseDiff doesn't seem to like the patch (some error about line 12... I'm too lazy to figure it out  8)), so only been reading out of context.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline DrewBoo

  • Multiple posting newcomer
  • *
  • Posts: 110
Re: PATCH: File extension handling improvement
« Reply #6 on: April 01, 2008, 03:47:03 pm »
Doesn't look so bad all in all, except my TortoiseDiff doesn't seem to like the patch (some error about line 12... I'm too lazy to figure it out  8)), so only been reading out of context.

If you think it could get in, I'll go see what Tortoise doesn't like about the patch.

[Edit]
...Ah, Tortoise is Windows-only.  I won't be able to check that right away.  For what it's worth, I tested that patch in my Ubuntu environment against a clean svn checkout using

Code
 patch -p0 < filetypes.patch

And it worked.  Perhaps it's just not happy about line endings?
« Last Edit: April 01, 2008, 04:13:54 pm by DrewBoo »