Wednesday, March 2, 2016

PowerShell ISE add-on to toggle collapsible sections in all files

UPDATE 03/03/2016: It's amazing how quickly this went from a simple script to within an hour yesterday becoming a Module and now released on PowerShellGallery and GitHub. Check out the instructions here to install this.
---------------

One feature I am hoping to see in the PowerShell ISE is the state of collapsed sections to be maintained for "recent" files. It is just annoying when you have a very large file that you are regularly working on to have to collapse all the sections you had previously collapsed each time you open it up..... anyway you can vote on that idea here.

If you didn't know there is a keyboard shortcut CTRL+M which will toggle the collapsed sections for the current file. Handy little gem that one. We can also programmatically invoke this method with:

$psISE.CurrentFile.Editor.ToggleOutliningExpansion()

This got me thinking, I can easily write an function that itterates through each open Tab/File and collapses it. Even better I can wrap that up into an add-on for the ISE.

I've added a menu item and also the keyboard shortcut CTRL+SHIFT+M to implement this.

Save the following code into your Profile script and enjoy!

#requires -Version 4
<#
    Script:     ISEColapseAllFiles.ps1
    Author:     Matt Lavery
    Created:    02/03/2016
    Version:    0.0.1
    
    Change History
    Version    Who          When           What
    --------------------------------------------------------------------------------------------------
    0.0.1      MLavery      02/03/2016     Initial Coding
    
#>

<#  
    .SYNOPSIS
        Toggles the state of all expandable sections in all open files within the ISE

    .DESCRIPTION
        Toggles the state of all expandable sections in all open files within the ISE
        Works across PowerShell Tabs.
        Implements the keyboard shortcut CTRL+SHIFT+M and a menu item in the Add-ons menu.
#>
function Set-ISECollapseAllFiles
{
    [CmdletBinding()]
    Param()

    Foreach ($psISETab in $psISE.PowerShellTabs)
    {
        Write-Verbose "PS Tab: $($psISETab.DisplayName)";
        foreach ($psISEFile in $psISETab.Files)
        {
            Write-Verbose "PS File: $($psISEFile.DisplayName)";
            $psISEFile.Editor.ToggleOutliningExpansion()
        }
    }
}

# remove the existing menu item if it exists
if ($psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.DisplayName.Contains('Toggle Colapse All Files'))
{
    $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Remove(($psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.GetEnumerator() | Where-Object DisplayName -EQ 'Toggle Colapse All Files'));
}
# add the add-on menu
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add('Toggle Colapse All Files',{Set-ISECollapseAllFiles},"CTRL+SHIFT+M");



Legal Stuff: As always the contents of this blog is provided “as-is”. The information, opinions and views expressed are those of the author and do not necessarily state or reflect those of any other company with affiliation to the products discussed. This includes any URLs or Tools. The author does not accept any responsibility from the use of the information or tools mentioned within this blog, and recommends adequate evaluation against your own requirements to measure suitability.

6 comments:

  1. Kup hublot fałszywy zegarek, najlepsza replika breitling, u-boat italo fontana, repliki cartier , zegarki hublot replica, fałszywe zegarki breitling, replika montblanc, chodź tu kupić repliki zegarków uk, zegarki rolex fałszywe, repliki zegarków repliki, zegarki repliki tag heuer, zegarek omega, najtańsze fałszywe rolex, omega.
    repliki zegarków Rolex
    repliki zegarków Rolex

    ReplyDelete
  2. Fake Cartier watches come in all the fake watches prominent Cartier styles: Tortue, Tank, Santos, Ballon, and replica cartier watchesBaignore to mention a few. These come in a wonderful number of gorgeous gents and womens designs. Our fake Swiss Cartier watches are exact forgeries of the genuine ones, down to the detailing that includes coloured knobs, diamonds encrusting, and stainless-steel cases. These specific replications . are great for showing your love for quality whether at the workplace or perhaps in a social setting.

    ReplyDelete
  3. The Royal Oak Offshore draws from Audemars Piguet’s signature Royal Oak model and pushes it to the limits.fake watches The replica royal oak offshore watchesbrand takes their iconic Royal Oak to the next level by employing a fearless and boundless spirit of innovation. Only available in limited editions, the Royal Oak Offshore collection is big, bold, and brash. Its commanding presence is certainly anything but understated. Still, it packs the same refined finishes and superior functionality of the Audemars Piguet brand.

    ReplyDelete
  4. The Audemars Piguet Jules Audemarsfake watches collection commemorates one of the brand’s founders. The line is characterized by its traditional and timeless round cases and overall minimalist design. replica jules audemars watchesHowever, behind the simplicity of these watches is an array of impressive functions, such as tourbillons, moon phases, and chronographs. Designed with both men and women in mind, the Jules Audemars collection fully embodies both the range and restraint of the brand.

    ReplyDelete
  5. The Longines, replica watches saleLa Grande Classique series features a stainless steel 24mm case, with a fixed bezel, replica Longines Conquest watchesa blue dial and a scratch resistant sapphire crystal.This beautiful wristwatch, powered by a Longines Calibre 209, Swiss quartz movement, supporting: hour, minute functions.This watch has a water resistance of up to 100 feet/30 meters, suitable for short periods of recreational swimming.This stylish Swiss-made timepiece is sure to complete any man's collection.

    ReplyDelete
  6. The Longines, replica watches saleLa Grande Classique series features a stainless steel 24mm case, with a fixed bezel, replica Longines Conquest watchesa blue dial and a scratch resistant sapphire crystal.This beautiful wristwatch, powered by a Longines Calibre 209, Swiss quartz movement, supporting: hour, minute functions.This watch has a water resistance of up to 100 feet/30 meters, suitable for short periods of recreational swimming.This stylish Swiss-made timepiece is sure to complete any man's collection.

    ReplyDelete