none
Powershell Code Folding

    Question

  • Hi all! I have a general question regarding the code folding feature in the Powershell 3.0 ISE.

    Code folding is a great addition to the ISE, but I have one major issue with it - when I fold portions of code in a script and then save the script, the next time I open it the sections are expanded again! Is it possible that there is a way to manipulate the ISE properties in any way that would either remember the folding state on save or if not, is there anything that may provide auto-folding? It would even be acceptable to me to have all scripts open with sections folded rather than expanded. I could then just expand the portions I need to work on. I have poked around in the $PSISE variable to see if there is anything I can modify but haven't found anything yet. 

    At the very least I think it would be great if more folding options like this could be included in the 4.0 version of the ISE. 

    Thanks!

    Wednesday, July 31, 2013 2:47 PM

Answers

  • I just press control-M to toggle all folding when I want to get the bird's eye view.
    • Marked as answer by Matt McNabb Thursday, August 01, 2013 11:47 AM
    Wednesday, July 31, 2013 9:39 PM

All replies

  • I just press control-M to toggle all folding when I want to get the bird's eye view.
    • Marked as answer by Matt McNabb Thursday, August 01, 2013 11:47 AM
    Wednesday, July 31, 2013 9:39 PM
  • Thanks this is exactly what I needed! I haven't been able to find a list of keyboard shortcuts anywhere for the ISE. I guess I should just monkey around with them and figure out what they do. 

    It's funny that a table of shortcuts isn't easier to find. 

    Thursday, August 01, 2013 11:47 AM
  • Anyway, while we are on the subject of undocumented ISE features, does anyone know a way of disabling the region highlighting? When you mouse over the outlines just to the right of the line numbers it will highlight the selected region in white. Normally this is not an issue because the default background color is white but I modified the defaults so my background is black.  This is a bit annoying since it whites everything out in that region and I would love to either turn it off or modify the highlight color.

    Thursday, August 01, 2013 11:57 AM
  • You might be able to configure the background colour used for highlight to black. Don't know how myself, but you already know more about changing background colours than I do, so it should be a breeze for you ;-)


    Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.

    Thursday, August 01, 2013 1:43 PM
  • Anyway, while we are on the subject of undocumented ISE features, does anyone know a way of disabling the region highlighting? When you mouse over the outlines just to the right of the line numbers it will highlight the selected region in white. Normally this is not an issue because the default background color is white but I modified the defaults so my background is black.  This is a bit annoying since it whites everything out in that region and I would love to either turn it off or modify the highlight color.

    Not that I've been able to find. I dug around a bit with Reflection, and I think I've found where those settings are stored, but haven't had any success with getting them to change.

    #region test
    
    $editor = $psise.CurrentFile.Editor
    $gPowerShellAssembly = $editor.GetType().Assembly
    $editorImportsType = $gPowerShellAssembly.GetType('Microsoft.Windows.PowerShell.Gui.Internal.EditorImports')
    
    $iBindingFlags = [System.Reflection.BindingFlags]'Instance,NonPublic'
    $sBindingFlags = [System.Reflection.BindingFlags]'Static,NonPublic'
    
    $methodInfo = $editor.GetType().GetMethod('get_TextView', $iBindingFlags)
    $textView = $methodInfo.Invoke($editor, $null)
    
    $methodInfo = $editorImportsType.GetMethod('get_EditorFormatMapService', $sBindingFlags)
    $editorFormatMapService = $methodInfo.Invoke($null, $null)
    
    $editorFormatMap = $editorFormatMapService.GetEditorFormatMap($textView)
    
    $map = $editorFormatMap.GetType().GetMember('_editorFormatMap', $iBindingFlags).GetValue(0).GetValue($editorformatMap)
    $dictionary = $map.GetType().GetMember('_storedResourceDictionaries', $iBindingFlags).GetValue(0).GetValue($map)
    
    # This seems to be where the colors are stored, but making changes in this object doesn't have any effect on the ISE's execution,
    # and when I tried to access them through the same calls that the ISE makes ($editorFormatMap.SetProperties method), I got an error
    # saying "The calling thread cannot access this object because a different thread owns it."
    
    $dictionary
    $dictionary['outlining.collapsehintadornment']
    
    # If these reference aren't cleared, and you close / re-open the file, outlining (and who knows what else) stops working
    # until you close and restart the ISE.
    
    $dictionary = $null
    $map = $null
    $editorFormatMap = $null
    $editorFormatMapService = $null
    $textView = $null
    
    [System.GC]::Collect(2, [System.GCCollectionMode]::Forced, $true)
    
    #endregion

    Thursday, August 01, 2013 6:00 PM
  • It doesn't appear that there is a token for the highlight so there is no way to configure that color. Seems like an oversight on the developer's part. Oh well, you can't have it all can you?

    Regardless, the ISE in version 3 is a great tool and I use it every day, so I guess I should stop complaining!

    Thanks for your responses everyone!

    Monday, August 05, 2013 5:44 PM