User forums > Using Code::Blocks

Bug in 'swap header / source'

<< < (9/9)

p2rkw:
Hmm... No. Only windows isn't case sensitive.

Btw. Newly opened file tab (via F11) might be placed next to current file, not at end.

MortenMacFly:

--- Quote from: p2rkw on December 11, 2012, 11:12:03 pm ---Hmm... No. Only windows isn't case sensitive.

--- End quote ---
That's not correct, too.

The right way is to first look for a case sensitive and then as backup for a case non-sensitive on Linux platforms. On Windows, you can start with case-insensitive directly. So - these are two cases that cannot be handled together.

Alpha:

--- Quote from: MortenMacFly on December 12, 2012, 08:49:24 am ---The right way is to first look for a case sensitive and then as backup for a case non-sensitive on Linux platforms. On Windows, you can start with case-insensitive directly. So - these are two cases that cannot be handled together.

--- End quote ---
Unless someone already has begun work on this, I will see if I can pull something together.

Alpha:

--- Quote from: Alpha on December 15, 2012, 11:16:43 pm ---I will see if I can pull something together.

--- End quote ---
I believe this meets the criteria, and it passes my test cases.  oBFusCATed, does it work on your project?

--- Code: ---Index: src/sdk/editormanager.cpp
===================================================================
--- src/sdk/editormanager.cpp (revision 8669)
+++ src/sdk/editormanager.cpp (working copy)
@@ -1012,11 +1012,14 @@
     m_isCheckingForExternallyModifiedFiles = false;
 }
 
-bool EditorManager::IsHeaderSource(const wxFileName& candidateFile, const wxFileName& activeFile, FileType ftActive)
+bool EditorManager::IsHeaderSource(const wxFileName& candidateFile, const wxFileName& activeFile, FileType ftActive, bool& isCandidate)
 {
-    // Verify the base name mathes
-    if (candidateFile.GetName() == activeFile.GetName())
+    // Verify the base name matches
+    if (candidateFile.GetName().CmpNoCase(activeFile.GetName()) == 0)
     {
+        // non-Windows platforms: case-insensitive match -> isCandidate
+        isCandidate = !( platform::windows || (candidateFile.GetName() == activeFile.GetName()) );
+
         // Verify:
         // If looking for a header we have a source OR
         // If looking for a source we have a header
@@ -1056,13 +1059,12 @@
     {
         wxFileName currentCandidateFile(candidateFilesArray[i]);
 
-        if (IsHeaderSource(currentCandidateFile, activeFile, ftActive))
+        if (IsHeaderSource(currentCandidateFile, activeFile, ftActive, isCandidate))
         {
             bool isUpper = wxIsupper(currentCandidateFile.GetExt()[0]);
-            if (isUpper == extStartsWithCapital)
+            if (isUpper == extStartsWithCapital && !isCandidate)
             {
                 // we definitely found the header/source we were searching for
-                isCandidate = false;
                 return currentCandidateFile;
             }
             else
Index: src/include/editormanager.h
===================================================================
--- src/include/editormanager.h (revision 8669)
+++ src/include/editormanager.h (working copy)
@@ -194,7 +194,7 @@
         int FindInFiles(cbFindReplaceData* data);
         int Replace(cbStyledTextCtrl* control, cbFindReplaceData* data);
         int ReplaceInFiles(cbFindReplaceData* data);
-        bool IsHeaderSource(const wxFileName& candidateFile, const wxFileName& activeFile, FileType ftActive);
+        bool IsHeaderSource(const wxFileName& candidateFile, const wxFileName& activeFile, FileType ftActive, bool& isCandidate);
         wxFileName FindHeaderSource(const wxArrayString& candidateFilesArray, const wxFileName& activeFile, bool& isCandidate);
 
         cbAuiNotebook*             m_pNotebook;

--- End code ---

Navigation

[0] Message Index

[*] Previous page

Go to full version