Bug 59002 - Switch Header/Implementation does not work
Summary: Switch Header/Implementation does not work
Status: CLOSED INTENTIONAL
Alias: None
Product: kdevelop
Classification: Applications
Component: Language Support: CPP (old) (show other bugs)
Version: git master
Platform: unspecified Linux
: NOR wishlist
Target Milestone: ---
Assignee: KDevelop Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-05-26 22:48 UTC by Christian
Modified: 2006-04-06 10:46 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
This patch looks for matching files within all files in the project. (2.76 KB, patch)
2006-02-23 20:46 UTC, Florian Hackenberger
Details
Improved patch (2.53 KB, patch)
2006-04-02 18:05 UTC, Florian Hackenberger
Details
Even more improved patch (3.56 KB, patch)
2006-04-02 20:26 UTC, Florian Hackenberger
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Christian 2003-05-26 22:48:02 UTC
Version:           alpha4 (using KDE KDE 3.1)
Installed from:    Not specified
Compiler:          gcc 3.2.2 
OS:          Linux

I am not able to switch between header and source files in my qmake-based project (e.g. headers in /include and sources in /src). Neither F12 nor the menu entry 'Switch Header/Implementation' seem to work. My files are named like mymainwindow.h, mymainwindow.cpp..
Comment 1 Amilcar do Carmo Lucas 2003-08-21 15:45:07 UTC
This only works if the .h and .cpp files are on the same dir.  
Comment 2 Sascha Cunz 2004-06-04 02:34:29 UTC
Hmm, this is not a bug. This is the intended behaviour of kdevelop; and it is not planned on implementing it.

Since, there is no way, that we could know how to map a source file in /src to a header in /include? This kind of project is actually very seldom.

Making it a wish and closing as WONTFIX.
Comment 3 Andreas Schallenberg 2004-06-04 18:43:55 UTC
I have a similar project at work with separate header and
source directories. And I'd like to have a working
switch-command, too.
Comment 4 Sascha Herrmann 2004-06-06 21:42:36 UTC
Hi, 

sorry for reopening the discussion. As i suggested  here:

http://bugs.kde.org/show_bug.cgi?id=79406#c3

it should be posible to implement a feature like this when the new classparser is ready. 
bye fox
Comment 5 Jordi Blasi 2005-04-28 13:03:16 UTC
I am working also with custom projects where might happen that some headers are not placed in same directory than source code implementation is. Not so rare. For those files, this functionality is not working. 

If kdevelop does not find header/source to switch because not placed in same directory, should find all project files which match FileName (all FileName.h or all FileName.cpp). If more than one just open a dialog and let the user to pick one of them.
Comment 6 Florian Hackenberger 2006-02-23 20:43:40 UTC
I propose the attached patch as a fix for 3.4. I will post the patch to the mailing list for applying.

Regards,
        Florian Hackenberger
Comment 7 Florian Hackenberger 2006-02-23 20:46:34 UTC
Created attachment 14832 [details]
This patch looks for matching files within all files in the project.

Could someone please check if using iterating (pluginIt) over
QValueList<KDevPlugin*> pluginList = pluginController()->loadedPlugins(); and
then checking all files in the list obtained with fileList = (*pluginIt)
->codeModel() ->fileList();?
Comment 8 Florian Hackenberger 2006-02-23 20:47:43 UTC
...is ok (forgot to type that *gg*)?
Comment 9 Jens Dagerbo 2006-04-02 13:54:20 UTC
No.. I don't think that patch makes sense. I can see no reason to check the codemodel more than once, and you don't need to jump through hoops to find it to begin with. 

Furthermore, the codemodel works on the project files, and you can get the list of project files simply through KDevProject::allFiles().

Seeing how you're already in the plugin part class, all you need is:
QStringList files = project()->allFiles();

Once you have a few files that look like possible candidates, you can try to find out if one of them is a likelier match than another.
Comment 10 Florian Hackenberger 2006-04-02 18:04:50 UTC
Thank you for pointing out that iterating over all plugins is uneccessary. Attached you can find a second try. I'm not sure if I really get your point, but as far as I see the case, this bug is about finding header/source files in another directory as the directory where the source/header code is located. Although I agree that it would be nice to choose the best header/source files if several options are available, the patch solves the bug. But we should file another bug (wish) for the feature you mention. Could you (Jens) please have another look at the patch? Thanks, Flo
Comment 11 Florian Hackenberger 2006-04-02 18:05:47 UTC
Created attachment 15422 [details]
Improved patch
Comment 12 Jens Dagerbo 2006-04-02 18:52:15 UTC
Yeah, that looks much better to me.

I'd avoid running QStringList::split( ',', possibleExts ) over and over, that's a list you know will not change. I'd also avoid going through the projectFiles at all until you know that the naive check-this-directory has in fact failed to produce a hit.

Assume that the list of project files *could* be 5000+ files. You don't want to hang the UI for several seconds if you manage to hit "switch" when in a file that has no corresponding header/source file, forcing you to traverse the entire project file list.
Comment 13 Florian Hackenberger 2006-04-02 20:25:22 UTC
I should have spent 10 seconds more on actually looking at my code before posting it. Find the improved patch attached and thank again for looking at it!
Comment 14 Florian Hackenberger 2006-04-02 20:26:16 UTC
Created attachment 15426 [details]
Even more improved patch
Comment 15 Jens Dagerbo 2006-04-02 20:38:37 UTC
Looks nice. I'll try to test it later tonight. I'll commit it if it works. :)
Comment 16 Jens Dagerbo 2006-04-05 22:21:15 UTC
Committed as 526869. Thanks for the patch! :)
Comment 17 Florian Hackenberger 2006-04-06 10:46:25 UTC
You'r welcome!