Skip to content

Add custom HTML views to VSCode module #523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,122 +1,126 @@
#
# Module manifest for module 'PowerShellEditorServices.VSCode'
#
# Generated by: daviwil
#
# Generated on: 6/16/2017
#

@{

# Script module or binary module file associated with this manifest.
RootModule = 'PowerShellEditorServices.VSCode.psm1'

# Version number of this module.
ModuleVersion = '0.1.0'

# Supported PSEditions
# CompatiblePSEditions = @()

# ID used to uniquely identify this module
GUID = '8794484f-cfc3-40f1-b88f-a934f403e679'

# Author of this module
Author = 'Microsoft'

# Company or vendor of this module
CompanyName = 'Microsoft'

# Copyright statement for this module
Copyright = '(c) 2017 Microsoft. All rights reserved.'

# Description of the functionality provided by this module
Description = 'Provides added functionality to PowerShell Editor Services for the Visual Studio Code editor.'

# Minimum version of the Windows PowerShell engine required by this module
# PowerShellVersion = ''

# Name of the Windows PowerShell host required by this module
# PowerShellHostName = ''

# Minimum version of the Windows PowerShell host required by this module
# PowerShellHostVersion = ''

# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# DotNetFrameworkVersion = ''

# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# CLRVersion = ''

# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @()

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
# NestedModules = @()

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = @()

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()

# Variables to export from this module
VariablesToExport = '*'

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = @()

# DSC resources to export from this module
# DscResourcesToExport = @()

# List of all modules packaged with this module
# ModuleList = @()

# List of all files packaged with this module
# FileList = @()

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{

PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
# Tags = @()

# A URL to the license for this module.
LicenseUri = 'https://github.com/PowerShell/PowerShellEditorServices/blob/master/LICENSE'

# A URL to the main website for this project.
ProjectUri = 'https://github.com/PowerShell/PowerShellEditorServices'

# A URL to an icon representing this module.
# IconUri = ''

# ReleaseNotes of this module
# ReleaseNotes = ''

} # End of PSData hashtable

} # End of PrivateData hashtable

# HelpInfo URI of this module
# HelpInfoURI = ''

# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''

}
#
# Module manifest for module 'PowerShellEditorServices.VSCode'
#
# Generated by: daviwil
#
# Generated on: 6/16/2017
#

@{

# Script module or binary module file associated with this manifest.
RootModule = 'PowerShellEditorServices.VSCode.psm1'

# Version number of this module.
ModuleVersion = '0.1.0'

# Supported PSEditions
# CompatiblePSEditions = @()

# ID used to uniquely identify this module
GUID = '8794484f-cfc3-40f1-b88f-a934f403e679'

# Author of this module
Author = 'Microsoft'

# Company or vendor of this module
CompanyName = 'Microsoft'

# Copyright statement for this module
Copyright = '(c) 2017 Microsoft. All rights reserved.'

# Description of the functionality provided by this module
Description = 'Provides added functionality to PowerShell Editor Services for the Visual Studio Code editor.'

# Minimum version of the Windows PowerShell engine required by this module
# PowerShellVersion = ''

# Name of the Windows PowerShell host required by this module
# PowerShellHostName = ''

# Minimum version of the Windows PowerShell host required by this module
# PowerShellHostVersion = ''

# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# DotNetFrameworkVersion = ''

# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# CLRVersion = ''

# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @()

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
# NestedModules = @()

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = @('New-VSCodeHtmlContentView',
'Show-VSCodeHtmlContentView',
'Close-VSCodeHtmlContentView',
'Set-VSCodeHtmlContentView',
'Write-VSCodeHtmlContentView')

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()

# Variables to export from this module
VariablesToExport = '*'

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = @()

# DSC resources to export from this module
# DscResourcesToExport = @()

# List of all modules packaged with this module
# ModuleList = @()

# List of all files packaged with this module
# FileList = @()

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{

PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
# Tags = @()

# A URL to the license for this module.
LicenseUri = 'https://github.com/PowerShell/PowerShellEditorServices/blob/master/LICENSE'

# A URL to the main website for this project.
ProjectUri = 'https://github.com/PowerShell/PowerShellEditorServices'

# A URL to an icon representing this module.
# IconUri = ''

# ReleaseNotes of this module
# ReleaseNotes = ''

} # End of PSData hashtable

} # End of PrivateData hashtable

# HelpInfo URI of this module
# HelpInfoURI = ''

# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''

}
Original file line number Diff line number Diff line change
@@ -16,3 +16,7 @@ if ($psEditor -is [Microsoft.PowerShell.EditorServices.Extensions.EditorObject])
else {
Write-Verbose '$psEditor object not found in the session, components will not be registered.'
}

Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -Recurse | ForEach-Object {
. $PSItem.FullName
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

function Close-VSCodeHtmlContentView {
<#
.SYNOPSIS
Closes an HtmlContentView.

.DESCRIPTION
Closes an HtmlContentView inside of Visual Studio Code if
it is displayed.

.PARAMETER HtmlContentView
The HtmlContentView to be closed.

.EXAMPLE
Close-VSCodeHtmlContentView -HtmlContentView $htmlContentView
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[Alias("View")]
[ValidateNotNull()]
[Microsoft.PowerShell.EditorServices.VSCode.CustomViews.IHtmlContentView]
$HtmlContentView
)

process {
$HtmlContentView.Close().Wait();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

function New-VSCodeHtmlContentView {
<#
.SYNOPSIS
Creates a custom view in Visual Studio Code which displays HTML content.

.DESCRIPTION
Creates a custom view in Visual Studio Code which displays HTML content.

.PARAMETER Title
The title of the view.

.PARAMETER ShowInColumn
If specified, causes the new view to be displayed in the specified column.
If unspecified, the Show-VSCodeHtmlContentView cmdlet will need to be used
to display the view.

.EXAMPLE
# Create a new view called "My Custom View"
$htmlContentView = New-VSCodeHtmlContentView -Title "My Custom View"

.EXAMPLE
# Create a new view and show it in the second view column
$htmlContentView = New-VSCodeHtmlContentView -Title "My Custom View" -ShowInColumn Two
#>
[CmdletBinding()]
[OutputType([Microsoft.PowerShell.EditorServices.VSCode.CustomViews.IHtmlContentView])]
param (
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$Title,

[Parameter(Mandatory = $false)]
[Microsoft.PowerShell.EditorServices.VSCode.CustomViews.ViewColumn]
$ShowInColumn
)

process {
if ($psEditor -is [Microsoft.PowerShell.EditorServices.Extensions.EditorObject]) {
$viewFeature = $psEditor.Components.Get([Microsoft.PowerShell.EditorServices.VSCode.CustomViews.IHtmlContentViews])
$view = $viewFeature.CreateHtmlContentView($Title).Result

if ($ShowInColumn) {
$view.Show($ShowInColumn).Wait();
}

return $view
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

function Set-VSCodeHtmlContentView {
<#
.SYNOPSIS
Sets the content of an HtmlContentView.

.DESCRIPTION
Sets the content of an HtmlContentView. If an empty string
is passed, it causes the view's content to be cleared.

.PARAMETER HtmlContentView
The HtmlContentView where content will be set.

.PARAMETER HtmlBodyContent
The HTML content that will be placed inside the <body> tag
of the view.

.EXAMPLE
# Set the view content with an h1 header
Set-VSCodeHtmlContentView -HtmlContentView $htmlContentView -HtmlBodyContent "<h1>Hello world!</h1>"

.EXAMPLE
# Clear the view
Set-VSCodeHtmlContentView -View $htmlContentView -Content ""
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[Alias("View")]
[ValidateNotNull()]
[Microsoft.PowerShell.EditorServices.VSCode.CustomViews.IHtmlContentView]
$HtmlContentView,

[Parameter(Mandatory = $true)]
[Alias("Content")]
[AllowEmptyString()]
[string]
$HtmlBodyContent
)

process {
$HtmlContentView.SetContent($HtmlBodyContent).Wait();
}
}
Loading