View unanswered posts | View active topics



Reply to topic  [ 3 posts ] 
Please add this code folding functionality into the codebase 
Author Message
Member

Joined: Thu Apr 29, 2010 9:39 pm
Posts: 133
Reply with quote
Hi Philippe/Mika,

This is about the code folding, I had contributed the CollapseFunctions method before, and I want to add another similar method - CollapseRegions.

I have been using this privately for the last 7 months and it is very stable.

Can you please add this into the "FlashDevelop\Core\ScintillaNet\ScintillaControl.cs" file?
If you could also add a shortcut to it from the main menu it would be great.

You can test it with code like this:

Code:

//{ display

private function a1():void {

}
private function a2():void {

}
private function a3():void {

}

//}

//{ data management

private function b1():void {

}
private function b2():void {

}
private function b3():void {

}

//}



Code:
        /// <summary>
        /// Only folds functions keeping the blocks within it open
        /// </summary>
        public void CollapseFunctions()
        {
            for (int i = 0; i < LineCount; i++){
            
                // Determine if function block
                string line = GetLine(i);
                if ((line.Contains("function") && line.Contains("(") && line.Contains(")"))){
               
                    // Get the function closing brace
                    int maxSubOrd = LastChild(i, -1);
               
                    // Get brace if on the next line
                    if (maxSubOrd == i){
                        i++;
                        maxSubOrd = LastChild(i, -1);
                    }
               
                    FoldExpanded(i, false);
               
                    HideLines(i + 1, maxSubOrd);
                    i = maxSubOrd;
                }
                else
                {
                    FoldExpanded(i, true);
                    ShowLines(i + 1, i + 1);
                }
            }
        }
      
      /// <summary>
      /// Only folds regions and functions keeping the blocks within it open
      /// </summary>
      public void CollapseRegions()
      {
         
         // hide all lines inside some blocks, show lines outside
         for (int i = 0; i < LineCount; i++){
            
            // if region/function block
            string line = GetLine(i);
                if (line.Contains("//{") || (line.Contains("function") && line.Contains("(") && line.Contains(")"))){
               
                    // Get the function closing brace
                    int maxSubOrd = LastChild(i, -1);
               
                    // Get brace if on the next line
                    if (maxSubOrd == i){
                        i++;
                        maxSubOrd = LastChild(i, -1);
                    }
               
               // hide all lines inside
                    HideLines(i + 1, maxSubOrd);
                    i = maxSubOrd;
               
                }else{
               
               // show lines outside
                    ShowLines(i + 1, i + 1);
                }
         }
         
         // collapse some block lines, expand all other type of lines
         for (int i = 0; i < LineCount; i++){
            
            // if region/function block
            string line = GetLine(i);
                if (line.Contains("//{") || (line.Contains("function") && line.Contains("(") && line.Contains(")"))){
               
                    // Get the function closing brace
                    int maxSubOrd = LastChild(i, -1);
               
                    // Get brace if on the next line
                    if (maxSubOrd == i){
                        i++;
                        maxSubOrd = LastChild(i, -1);
                    }
               
               // collapse some block lines
                    FoldExpanded(i, false);
               
                }else{
               
               // expand all other type of lines
                    FoldExpanded(i, true);
                }
         }
         
      }


Thanks,
fd1


Thu Oct 18, 2012 5:32 am
Profile
Admin

Joined: Tue Aug 30, 2005 6:14 pm
Posts: 3046
Location: Finland
Reply with quote
Added to trunk, thanks.


Tue Oct 23, 2012 10:53 am
Profile WWW
Admin

Joined: Tue Aug 30, 2005 6:14 pm
Posts: 3046
Location: Finland
Reply with quote
Could you please fix this so that if a function spans on multiple lines it works too?


Tue Nov 20, 2012 10:24 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.