Patch #1740 2006-12-19 08:01

mcdave

Code Fold at Marked Line Bug Fix
Download
1740-Code_Fold_at_M.patch (3.3 KB)
Category
Application::Bugfix
Status
Closed
Close date
2007-04-06 14:25
Assigned to
killerbot
Index: src/sdk/cbeditor.cpp
===================================================================
--- src/sdk/cbeditor.cpp    (revision 3455)
+++ src/sdk/cbeditor.cpp    (working copy)
@@ -1467,13 +1467,37 @@
 
 void cbEditor::DoFoldBlockFromLine(int line, int fold)
 {
-    m_pControl->Colourise(0, -1); // the *most* important part!
+    /*m_pControl->Colourise(0, -1); // the *most* important part!
     int i = line;
     while (i != 0)
     {
         if (DoFoldLine(i, fold))
             return;
         --i;
+    }*/
+    
+    ConfigManager* mgr = Manager::Get()->GetConfigManager(_T("editor"));
+    if (mgr->ReadBool(_T("/folding/show_folds"), true)) //Only unfold the marked line if the folds are enabled ... duh
+    {
+        m_pControl->Colourise(0, -1); // the *most* important part!
+        int level = m_pControl->GetFoldLevel(line);
+        int parent = m_pControl->GetFoldParent(line);
+        
+        //Check for fold headers
+        if ((level & wxSCI_FOLDLEVELHEADERFLAG) && (wxSCI_FOLDLEVELBASE <= (level & wxSCI_FOLDLEVELNUMBERMASK)))
+           parent = line;
+        if (parent != -1)
+        {
+            if (m_pControl->GetFoldExpanded(parent) == false && fold == 0)
+                m_pControl->ToggleFold(parent);
+            else
+            {
+                if (m_pControl->GetFoldExpanded(parent) == true && fold == 1)
+                    m_pControl->ToggleFold(parent);
+                else if (fold == 2)
+                    m_pControl->ToggleFold(parent);
+            }
+        }
     }
 }
 
@@ -1569,8 +1593,23 @@
         control->GotoLine(line - onScreen);
         control->GotoLine(line + onScreen);
     }
+    
+    ConfigManager* mgr = Manager::Get()->GetConfigManager(_T("editor"));
+    if (mgr->ReadBool(_T("/folding/show_folds"), true)) //Only unfold the marked line if the folds are enabled ... duh
+    {
+        m_pControl->Colourise(0, -1); // the *most* important part!
+        
+        int parent = m_pControl->GetFoldParent(line);
+        while (parent != -1) //Unfold all the parent folds to ensure that the line is visible correctly
+        {
+            if (m_pControl->GetFoldExpanded(parent) == false)
+                m_pControl->ToggleFold(parent);
+            
+            parent = m_pControl->GetFoldParent(parent);
+        }
+    }
+    
     control->GotoLine(line);
-    UnfoldBlockFromLine(line); // make sure it's visible (not folded)
 }
 
 bool cbEditor::AddBreakpoint(int line, bool notifyDebugger)
@@ -1804,7 +1843,23 @@
     if (line == -1)
         m_pControl->MarkerDeleteAll(marker);
     else
+    {
+        ConfigManager* mgr = Manager::Get()->GetConfigManager(_T("editor"));
+        if (mgr->ReadBool(_T("/folding/show_folds"), true)) //Only unfold the marked line if the folds are enabled ... duh
+        {
+            m_pControl->Colourise(0, -1); // the *most* important part!
+            int parent = m_pControl->GetFoldParent(line);
+            while (parent != -1) //Unfold all the parent folds to ensure that the line is visible correctly
+            {
+                if (m_pControl->GetFoldExpanded(parent) == false)
+                    m_pControl->ToggleFold(parent);
+                
+                parent = m_pControl->GetFoldParent(parent);
+            }
+        }
+        
         m_pControl->MarkerAdd(line, marker);
+    }
 }
 
 void cbEditor::GotoMatchingBrace()
mcdave 2006-12-19 09:36

This patch ensures the when the compiler marks a line as error/warning, or when it searches for something, that it will first unfold all of the parent fold then mark the line.

mcdave 2006-12-19 11:47

A nasty search and goto bug occured, this new patch fixes that issue. This patch also fixes the issue mentioned in that forum post killerbot. The issue was regarding the fold and unfold of blocks. This currently works correctly.

mcdave 2006-12-19 11:57

Hey killerbot... what do you think about that request that a user should be able to select which levels should be folded and which ones not (The depth part of it)

Makes sense... but hell... will you ever satisfy everybody?

We all have different coding styles...

kkez 2006-12-30 16:30
Here's the patch before astyle was used.

Index: cbeditor.cpp
===================================================================
--- cbeditor.cpp	(revision 3434)
+++ cbeditor.cpp	(working copy)
@@ -1467,13 +1467,37 @@

 void cbEditor::DoFoldBlockFromLine(int line, int fold)
 {
-    m_pControl->Colourise(0, -1); // the *most* important part!
+    /*m_pControl->Colourise(0, -1); // the *most* important part!
     int i = line;
     while (i != 0)
     {
         if (DoFoldLine(i, fold))
             return;
         --i;
+    }*/
+
+    ConfigManager* mgr = Manager::Get()->GetConfigManager(_T("editor"));
+    if (mgr->ReadBool(_T("/folding/show_folds"), true)) //Only unfold the marked line if the folds are enabled ... duh
+    {
+        m_pControl->Colourise(0, -1); // the *most* important part!
+        int level = m_pControl->GetFoldLevel(line);
+        int parent = m_pControl->GetFoldParent(line);
+
+        //Check for fold headers
+        if ((level & wxSCI_FOLDLEVELHEADERFLAG) && (wxSCI_FOLDLEVELBASE <= (level & wxSCI_FOLDLEVELNUMBERMASK)))
+           parent = line;
+        if (parent != -1)
+        {
+            if (m_pControl->GetFoldExpanded(parent) == false && fold == 0)
+                m_pControl->ToggleFold(parent);
+            else
+            {
+                if (m_pControl->GetFoldExpanded(parent) == true && fold == 1)
+                    m_pControl->ToggleFold(parent);
+                else if (fold == 2)
+                    m_pControl->ToggleFold(parent);
+            }
+        }
     }
 }

@@ -1569,8 +1593,23 @@
         control->GotoLine(line - onScreen);
         control->GotoLine(line + onScreen);
     }
+
+    ConfigManager* mgr = Manager::Get()->GetConfigManager(_T("editor"));
+    if (mgr->ReadBool(_T("/folding/show_folds"), true)) //Only unfold the marked line if the folds are enabled ... duh
+    {
+        m_pControl->Colourise(0, -1); // the *most* important part!
+
+        int parent = m_pControl->GetFoldParent(line);
+        while (parent != -1) //Unfold all the parent folds to ensure that the line is visible correctly
+        {
+            if (m_pControl->GetFoldExpanded(parent) == false)
+                m_pControl->ToggleFold(parent);
+
+            parent = m_pControl->GetFoldParent(parent);
+        }
+    }
+
     control->GotoLine(line);
-    UnfoldBlockFromLine(line); // make sure it's visible (not folded)
 }

 bool cbEditor::AddBreakpoint(int line, bool notifyDebugger)
@@ -1804,7 +1843,23 @@
     if (line == -1)
         m_pControl->MarkerDeleteAll(marker);
     else
+    {
+        ConfigManager* mgr = Manager::Get()->GetConfigManager(_T("editor"));
+        if (mgr->ReadBool(_T("/folding/show_folds"), true)) //Only unfold the marked line if the folds are enabled ... duh
+        {
+            m_pControl->Colourise(0, -1); // the *most* important part!
+            int parent = m_pControl->GetFoldParent(line);
+            while (parent != -1) //Unfold all the parent folds to ensure that the line is visible correctly
+            {
+                if (m_pControl->GetFoldExpanded(parent) == false)
+                    m_pControl->ToggleFold(parent);
+
+                parent = m_pControl->GetFoldParent(parent);
+            }
+        }
+
         m_pControl->MarkerAdd(line, marker);
+    }
 }

 void cbEditor::GotoMatchingBrace()
kkez 2006-12-30 16:32
mcdave 2007-01-04 06:41

kkez's Version uploaded. Thanks

mcdave 2007-01-15 05:48

Testing?

biplab 2007-03-10 16:57

First 2/3 of patch has been applied in modified form.

I could not understand the third part [bool cbEditor::AddBreakpoint(int line, bool notifyDebugger)]. In which situation it's useful?

biplab 2007-04-06 14:25

@killerbot

I wrote previously that this patch has been reworked and applied. Thus I'm closing this patch report.