From 5a590512bda77ba701c7bb958f1e9cb3c886352e Mon Sep 17 00:00:00 2001 From: "C. Augusto Proiete" Date: Wed, 15 Jul 2020 14:23:59 -0300 Subject: [PATCH] Rename `MarkDown` -> `Markdown` to resolve differences for non-Windows machines (#3758) --- PowerToys.sln | 2 +- .../HTMLParsingExtension.cs | 206 +++++----- .../MarkdownPreviewHandler.cs | 72 ++-- .../MarkdownPreviewHandler.csproj} | 320 +++++++-------- .../MarkdownPreviewHandlerControl.cs | 384 +++++++++--------- .../Properties/Resources.Designer.cs | 162 ++++---- .../Properties/Resources.resx | 254 ++++++------ .../Properties/Settings.Designer.cs | 0 .../Properties/Settings.settings | 0 .../Events/MarkdownFileHandlerLoaded.cs | 0 .../Events/MarkdownFilePreviewError.cs | 46 +-- .../Telemetry/Events/MarkdownFilePreviewed.cs | 40 +- .../UnitTests-MarkdownPreviewHandler.csproj | 2 +- 13 files changed, 744 insertions(+), 744 deletions(-) rename src/modules/previewpane/{MarkDownPreviewHandler => MarkdownPreviewHandler}/HTMLParsingExtension.cs (97%) rename src/modules/previewpane/{MarkDownPreviewHandler/MarkDownPreviewHandler.csproj => MarkdownPreviewHandler/MarkdownPreviewHandler.csproj} (98%) rename src/modules/previewpane/{MarkDownPreviewHandler => MarkdownPreviewHandler}/Properties/Settings.Designer.cs (100%) rename src/modules/previewpane/{MarkDownPreviewHandler => MarkdownPreviewHandler}/Properties/Settings.settings (100%) rename src/modules/previewpane/{MarkDownPreviewHandler => MarkdownPreviewHandler}/Telemetry/Events/MarkdownFileHandlerLoaded.cs (100%) rename src/modules/previewpane/{MarkDownPreviewHandler => MarkdownPreviewHandler}/Telemetry/Events/MarkdownFilePreviewError.cs (97%) rename src/modules/previewpane/{MarkDownPreviewHandler => MarkdownPreviewHandler}/Telemetry/Events/MarkdownFilePreviewed.cs (97%) diff --git a/PowerToys.sln b/PowerToys.sln index 52175309c5..f93926f436 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -207,7 +207,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "previewpane", "previewpane" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PreviewHandlerCommon", "src\modules\previewpane\Common\PreviewHandlerCommon.csproj", "{AF2349B8-E5B6-4004-9502-687C1C7730B1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MarkdownPreviewHandler", "src\modules\previewpane\MarkDownPreviewHandler\MarkdownPreviewHandler.csproj", "{6A71162E-FC4C-4A2C-B90F-3CF94F59A9BB}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MarkdownPreviewHandler", "src\modules\previewpane\MarkdownPreviewHandler\MarkdownPreviewHandler.csproj", "{6A71162E-FC4C-4A2C-B90F-3CF94F59A9BB}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests-MarkdownPreviewHandler", "src\modules\previewpane\PreviewPaneUnitTests\UnitTests-MarkdownPreviewHandler.csproj", "{A2B51B8B-8F90-424E-BC97-F9AB7D76CA1A}" EndProject diff --git a/src/modules/previewpane/MarkDownPreviewHandler/HTMLParsingExtension.cs b/src/modules/previewpane/MarkdownPreviewHandler/HTMLParsingExtension.cs similarity index 97% rename from src/modules/previewpane/MarkDownPreviewHandler/HTMLParsingExtension.cs rename to src/modules/previewpane/MarkdownPreviewHandler/HTMLParsingExtension.cs index 5ba5387c50..8c0c622e9e 100644 --- a/src/modules/previewpane/MarkDownPreviewHandler/HTMLParsingExtension.cs +++ b/src/modules/previewpane/MarkdownPreviewHandler/HTMLParsingExtension.cs @@ -1,103 +1,103 @@ -// Copyright (c) Microsoft Corporation -// The Microsoft Corporation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.IO; -using Markdig; -using Markdig.Extensions.Figures; -using Markdig.Extensions.Tables; -using Markdig.Renderers; -using Markdig.Renderers.Html; -using Markdig.Syntax; -using Markdig.Syntax.Inlines; - -namespace MarkdownPreviewHandler -{ - /// - /// Callback if extension blocks external images. - /// - public delegate void ImagesBlockedCallBack(); - - /// - /// Markdig Extension to process html nodes in markdown AST. - /// - public class HTMLParsingExtension : IMarkdownExtension - { - /// - /// Callback if extension blocks external images. - /// - private readonly ImagesBlockedCallBack imagesBlockedCallBack; - - /// - /// Initializes a new instance of the class. - /// - /// Callback function if image is blocked by extension. - /// Absolute path of markdown file. - public HTMLParsingExtension(ImagesBlockedCallBack imagesBlockedCallBack, string baseUrl = "") - { - this.imagesBlockedCallBack = imagesBlockedCallBack; - this.BaseUrl = baseUrl; - } - - /// - /// Gets or sets path to directory containing markdown file. - /// - public string BaseUrl { get; set; } - - /// - public void Setup(MarkdownPipelineBuilder pipeline) - { - // Make sure we don't have a delegate twice - pipeline.DocumentProcessed -= this.PipelineOnDocumentProcessed; - pipeline.DocumentProcessed += this.PipelineOnDocumentProcessed; - } - - /// - public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) - { - } - - /// - /// Process nodes in markdown AST. - /// - /// Markdown Document. - public void PipelineOnDocumentProcessed(MarkdownDocument document) - { - foreach (var node in document.Descendants()) - { - if (node is Block) - { - if (node is Table) - { - node.GetAttributes().AddClass("table table-striped table-bordered"); - } - else if (node is QuoteBlock) - { - node.GetAttributes().AddClass("blockquote"); - } - else if (node is Figure) - { - node.GetAttributes().AddClass("figure"); - } - else if (node is FigureCaption) - { - node.GetAttributes().AddClass("figure-caption"); - } - } - else if (node is Inline) - { - if (node is LinkInline link) - { - if (link.IsImage) - { - link.Url = "#"; - link.GetAttributes().AddClass("img-fluid"); - this.imagesBlockedCallBack(); - } - } - } - } - } - } -} +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.IO; +using Markdig; +using Markdig.Extensions.Figures; +using Markdig.Extensions.Tables; +using Markdig.Renderers; +using Markdig.Renderers.Html; +using Markdig.Syntax; +using Markdig.Syntax.Inlines; + +namespace MarkdownPreviewHandler +{ + /// + /// Callback if extension blocks external images. + /// + public delegate void ImagesBlockedCallBack(); + + /// + /// Markdig Extension to process html nodes in markdown AST. + /// + public class HTMLParsingExtension : IMarkdownExtension + { + /// + /// Callback if extension blocks external images. + /// + private readonly ImagesBlockedCallBack imagesBlockedCallBack; + + /// + /// Initializes a new instance of the class. + /// + /// Callback function if image is blocked by extension. + /// Absolute path of markdown file. + public HTMLParsingExtension(ImagesBlockedCallBack imagesBlockedCallBack, string baseUrl = "") + { + this.imagesBlockedCallBack = imagesBlockedCallBack; + this.BaseUrl = baseUrl; + } + + /// + /// Gets or sets path to directory containing markdown file. + /// + public string BaseUrl { get; set; } + + /// + public void Setup(MarkdownPipelineBuilder pipeline) + { + // Make sure we don't have a delegate twice + pipeline.DocumentProcessed -= this.PipelineOnDocumentProcessed; + pipeline.DocumentProcessed += this.PipelineOnDocumentProcessed; + } + + /// + public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) + { + } + + /// + /// Process nodes in markdown AST. + /// + /// Markdown Document. + public void PipelineOnDocumentProcessed(MarkdownDocument document) + { + foreach (var node in document.Descendants()) + { + if (node is Block) + { + if (node is Table) + { + node.GetAttributes().AddClass("table table-striped table-bordered"); + } + else if (node is QuoteBlock) + { + node.GetAttributes().AddClass("blockquote"); + } + else if (node is Figure) + { + node.GetAttributes().AddClass("figure"); + } + else if (node is FigureCaption) + { + node.GetAttributes().AddClass("figure-caption"); + } + } + else if (node is Inline) + { + if (node is LinkInline link) + { + if (link.IsImage) + { + link.Url = "#"; + link.GetAttributes().AddClass("img-fluid"); + this.imagesBlockedCallBack(); + } + } + } + } + } + } +} diff --git a/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandler.cs b/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandler.cs index 053c41845b..488203102e 100644 --- a/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandler.cs +++ b/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandler.cs @@ -1,36 +1,36 @@ -// Copyright (c) Microsoft Corporation -// The Microsoft Corporation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Runtime.InteropServices; -using Common; -using Microsoft.PowerToys.Telemetry; - -namespace MarkdownPreviewHandler -{ - /// - /// Implementation of preview handler for markdown files. - /// - [Guid("45769bcc-e8fd-42d0-947e-02beef77a1f5")] - [ClassInterface(ClassInterfaceType.None)] - [ComVisible(true)] - public class MarkdownPreviewHandler : FileBasedPreviewHandler - { - private MarkdownPreviewHandlerControl markdownPreviewHandlerControl; - - /// - public override void DoPreview() - { - this.markdownPreviewHandlerControl.DoPreview(this.FilePath); - } - - /// - protected override IPreviewHandlerControl CreatePreviewHandlerControl() - { - PowerToysTelemetry.Log.WriteEvent(new Telemetry.Events.MarkdownFileHandlerLoaded()); - this.markdownPreviewHandlerControl = new MarkdownPreviewHandlerControl(); - return this.markdownPreviewHandlerControl; - } - } -} +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using Common; +using Microsoft.PowerToys.Telemetry; + +namespace MarkdownPreviewHandler +{ + /// + /// Implementation of preview handler for markdown files. + /// + [Guid("45769bcc-e8fd-42d0-947e-02beef77a1f5")] + [ClassInterface(ClassInterfaceType.None)] + [ComVisible(true)] + public class MarkdownPreviewHandler : FileBasedPreviewHandler + { + private MarkdownPreviewHandlerControl markdownPreviewHandlerControl; + + /// + public override void DoPreview() + { + this.markdownPreviewHandlerControl.DoPreview(this.FilePath); + } + + /// + protected override IPreviewHandlerControl CreatePreviewHandlerControl() + { + PowerToysTelemetry.Log.WriteEvent(new Telemetry.Events.MarkdownFileHandlerLoaded()); + this.markdownPreviewHandlerControl = new MarkdownPreviewHandlerControl(); + return this.markdownPreviewHandlerControl; + } + } +} diff --git a/src/modules/previewpane/MarkDownPreviewHandler/MarkDownPreviewHandler.csproj b/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandler.csproj similarity index 98% rename from src/modules/previewpane/MarkDownPreviewHandler/MarkDownPreviewHandler.csproj rename to src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandler.csproj index 5d95e47546..20585f30be 100644 --- a/src/modules/previewpane/MarkDownPreviewHandler/MarkDownPreviewHandler.csproj +++ b/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandler.csproj @@ -1,161 +1,161 @@ - - - - - - - MarkdownPreviewHandler - PowerToys MarkdownPreviewHandler - Microsoft Corp. - Copyright (C) 2020 Microsoft Corporation - PowerToys - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Debug - AnyCPU - {6A71162E-FC4C-4A2C-B90F-3CF94F59A9BB} - Library - Properties - MarkdownPreviewHandler - MarkdownPreviewHandler - v4.7.2 - 512 - true - - $(SolutionDir)$(Platform)\$(Configuration)\obj\$(AssemblyName)\ - - - true - full - false - $(SolutionDir)$(Platform)\$(Configuration)\modules\FileExplorerPreview\ - DEBUG;TRACE - prompt - 4 - true - $(SolutionDir)$(Platform)\$(Configuration)\modules\FileExplorerPreview\MarkdownPreviewPaneDocumentation.xml - x64 - - - pdbonly - true - $(SolutionDir)$(Platform)\$(Configuration)\modules\FileExplorerPreview\ - TRACE - prompt - 4 - true - $(SolutionDir)$(Platform)\$(Configuration)\modules\FileExplorerPreview\MarkdownPreviewPaneDocumentation.xml - x64 - - - false - - - - - - - - - - - - - - - - - - - - - - Form - - - Code - - - True - True - Resources.resx - - - True - True - Settings.settings - - - - - - - - 1.11.23 - - - 0.20.0 - - - 1.1.118 - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - StyleCop.json - - - - - {5D00D290-4016-4CFE-9E41-1E7C724509BA} - Telemetry - - - {af2349b8-e5b6-4004-9502-687c1c7730b1} - PreviewHandlerCommon - - - - - ResXFileCodeGenerator - Resources.Designer.cs - - - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - + + + + + + + MarkdownPreviewHandler + PowerToys MarkdownPreviewHandler + Microsoft Corp. + Copyright (C) 2020 Microsoft Corporation + PowerToys + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Debug + AnyCPU + {6A71162E-FC4C-4A2C-B90F-3CF94F59A9BB} + Library + Properties + MarkdownPreviewHandler + MarkdownPreviewHandler + v4.7.2 + 512 + true + + $(SolutionDir)$(Platform)\$(Configuration)\obj\$(AssemblyName)\ + + + true + full + false + $(SolutionDir)$(Platform)\$(Configuration)\modules\FileExplorerPreview\ + DEBUG;TRACE + prompt + 4 + true + $(SolutionDir)$(Platform)\$(Configuration)\modules\FileExplorerPreview\MarkdownPreviewPaneDocumentation.xml + x64 + + + pdbonly + true + $(SolutionDir)$(Platform)\$(Configuration)\modules\FileExplorerPreview\ + TRACE + prompt + 4 + true + $(SolutionDir)$(Platform)\$(Configuration)\modules\FileExplorerPreview\MarkdownPreviewPaneDocumentation.xml + x64 + + + false + + + + + + + + + + + + + + + + + + + + + + Form + + + Code + + + True + True + Resources.resx + + + True + True + Settings.settings + + + + + + + + 1.11.23 + + + 0.20.0 + + + 1.1.118 + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + StyleCop.json + + + + + {5D00D290-4016-4CFE-9E41-1E7C724509BA} + Telemetry + + + {af2349b8-e5b6-4004-9502-687c1c7730b1} + PreviewHandlerCommon + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + \ No newline at end of file diff --git a/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandlerControl.cs b/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandlerControl.cs index cd6581cd60..7eac866096 100644 --- a/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandlerControl.cs +++ b/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandlerControl.cs @@ -1,192 +1,192 @@ -// Copyright (c) Microsoft Corporation -// The Microsoft Corporation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Drawing; -using System.IO; -using System.Text.RegularExpressions; -using System.Windows.Forms; -using Common; -using Markdig; -using MarkdownPreviewHandler.Properties; -using MarkdownPreviewHandler.Telemetry.Events; -using Microsoft.PowerToys.Telemetry; -using PreviewHandlerCommon; - -namespace MarkdownPreviewHandler -{ - /// - /// Win Form Implementation for Markdown Preview Handler. - /// - public class MarkdownPreviewHandlerControl : FormHandlerControl - { - /// - /// Extension to modify markdown AST. - /// - private readonly HTMLParsingExtension extension; - - /// - /// Markdig Pipeline builder. - /// - private readonly MarkdownPipelineBuilder pipelineBuilder; - - /// - /// Markdown HTML header. - /// - private readonly string htmlHeader = "
"; - - /// - /// Markdown HTML footer. - /// - private readonly string htmlFooter = "
"; - - /// - /// RichTextBox control to display if external images are blocked. - /// - private RichTextBox infoBar; - - /// - /// Extended Browser Control to display markdown html. - /// - private WebBrowserExt browser; - - /// - /// True if external image is blocked, false otherwise. - /// - private bool infoBarDisplayed = false; - - /// - /// Initializes a new instance of the class. - /// - public MarkdownPreviewHandlerControl() - { - this.extension = new HTMLParsingExtension(this.ImagesBlockedCallBack); - this.pipelineBuilder = new MarkdownPipelineBuilder().UseAdvancedExtensions().UseEmojiAndSmiley(); - this.pipelineBuilder.Extensions.Add(this.extension); - } - - /// - /// Start the preview on the Control. - /// - /// Path to the file. - public override void DoPreview(T dataSource) - { - this.infoBarDisplayed = false; - - try - { - if (!(dataSource is string filePath)) - { - throw new ArgumentException($"{nameof(dataSource)} for {nameof(MarkdownPreviewHandler)} must be a string but was a '{typeof(T)}'"); - } - - string fileText = File.ReadAllText(filePath); - Regex imageTagRegex = new Regex(@"<[ ]*img.*>"); - if (imageTagRegex.IsMatch(fileText)) - { - this.infoBarDisplayed = true; - } - - this.extension.BaseUrl = Path.GetDirectoryName(filePath); - MarkdownPipeline pipeline = this.pipelineBuilder.Build(); - string parsedMarkdown = Markdown.ToHtml(fileText, pipeline); - string markdownHTML = $"{this.htmlHeader}{parsedMarkdown}{this.htmlFooter}"; - - this.InvokeOnControlThread(() => - { - this.browser = new WebBrowserExt - { - DocumentText = markdownHTML, - Dock = DockStyle.Fill, - IsWebBrowserContextMenuEnabled = false, - ScriptErrorsSuppressed = true, - ScrollBarsEnabled = true, - AllowNavigation = false, - }; - this.Controls.Add(this.browser); - - if (this.infoBarDisplayed) - { - this.infoBar = this.GetTextBoxControl(Resources.BlockedImageInfoText); - this.Resize += this.FormResized; - this.Controls.Add(this.infoBar); - } - }); - - PowerToysTelemetry.Log.WriteEvent(new MarkdownFilePreviewed()); - } - catch (Exception e) - { - PowerToysTelemetry.Log.WriteEvent(new MarkdownFilePreviewError { Message = e.Message }); - - this.InvokeOnControlThread(() => - { - this.Controls.Clear(); - this.infoBarDisplayed = true; - this.infoBar = this.GetTextBoxControl(Resources.MarkdownNotPreviewedError); - this.Resize += this.FormResized; - this.Controls.Add(this.infoBar); - }); - } - finally - { - base.DoPreview(dataSource); - } - } - - /// - /// Gets a textbox control. - /// - /// Message to be displayed in textbox. - /// An object of type . - private RichTextBox GetTextBoxControl(string message) - { - RichTextBox richTextBox = new RichTextBox - { - Text = message, - BackColor = Color.LightYellow, - Multiline = true, - Dock = DockStyle.Top, - ReadOnly = true, - }; - richTextBox.ContentsResized += this.RTBContentsResized; - richTextBox.ScrollBars = RichTextBoxScrollBars.None; - richTextBox.BorderStyle = BorderStyle.None; - - return richTextBox; - } - - /// - /// Callback when RichTextBox is resized. - /// - /// Reference to resized control. - /// Provides data for the resize event. - private void RTBContentsResized(object sender, ContentsResizedEventArgs e) - { - RichTextBox richTextBox = (RichTextBox)sender; - richTextBox.Height = e.NewRectangle.Height + 5; - } - - /// - /// Callback when form is resized. - /// - /// Reference to resized control. - /// Provides data for the event. - private void FormResized(object sender, EventArgs e) - { - if (this.infoBarDisplayed) - { - this.infoBar.Width = this.Width; - } - } - - /// - /// Callback when image is blocked by extension. - /// - private void ImagesBlockedCallBack() - { - this.infoBarDisplayed = true; - } - } -} +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Drawing; +using System.IO; +using System.Text.RegularExpressions; +using System.Windows.Forms; +using Common; +using Markdig; +using MarkdownPreviewHandler.Properties; +using MarkdownPreviewHandler.Telemetry.Events; +using Microsoft.PowerToys.Telemetry; +using PreviewHandlerCommon; + +namespace MarkdownPreviewHandler +{ + /// + /// Win Form Implementation for Markdown Preview Handler. + /// + public class MarkdownPreviewHandlerControl : FormHandlerControl + { + /// + /// Extension to modify markdown AST. + /// + private readonly HTMLParsingExtension extension; + + /// + /// Markdig Pipeline builder. + /// + private readonly MarkdownPipelineBuilder pipelineBuilder; + + /// + /// Markdown HTML header. + /// + private readonly string htmlHeader = "
"; + + /// + /// Markdown HTML footer. + /// + private readonly string htmlFooter = "
"; + + /// + /// RichTextBox control to display if external images are blocked. + /// + private RichTextBox infoBar; + + /// + /// Extended Browser Control to display markdown html. + /// + private WebBrowserExt browser; + + /// + /// True if external image is blocked, false otherwise. + /// + private bool infoBarDisplayed = false; + + /// + /// Initializes a new instance of the class. + /// + public MarkdownPreviewHandlerControl() + { + this.extension = new HTMLParsingExtension(this.ImagesBlockedCallBack); + this.pipelineBuilder = new MarkdownPipelineBuilder().UseAdvancedExtensions().UseEmojiAndSmiley(); + this.pipelineBuilder.Extensions.Add(this.extension); + } + + /// + /// Start the preview on the Control. + /// + /// Path to the file. + public override void DoPreview(T dataSource) + { + this.infoBarDisplayed = false; + + try + { + if (!(dataSource is string filePath)) + { + throw new ArgumentException($"{nameof(dataSource)} for {nameof(MarkdownPreviewHandler)} must be a string but was a '{typeof(T)}'"); + } + + string fileText = File.ReadAllText(filePath); + Regex imageTagRegex = new Regex(@"<[ ]*img.*>"); + if (imageTagRegex.IsMatch(fileText)) + { + this.infoBarDisplayed = true; + } + + this.extension.BaseUrl = Path.GetDirectoryName(filePath); + MarkdownPipeline pipeline = this.pipelineBuilder.Build(); + string parsedMarkdown = Markdown.ToHtml(fileText, pipeline); + string markdownHTML = $"{this.htmlHeader}{parsedMarkdown}{this.htmlFooter}"; + + this.InvokeOnControlThread(() => + { + this.browser = new WebBrowserExt + { + DocumentText = markdownHTML, + Dock = DockStyle.Fill, + IsWebBrowserContextMenuEnabled = false, + ScriptErrorsSuppressed = true, + ScrollBarsEnabled = true, + AllowNavigation = false, + }; + this.Controls.Add(this.browser); + + if (this.infoBarDisplayed) + { + this.infoBar = this.GetTextBoxControl(Resources.BlockedImageInfoText); + this.Resize += this.FormResized; + this.Controls.Add(this.infoBar); + } + }); + + PowerToysTelemetry.Log.WriteEvent(new MarkdownFilePreviewed()); + } + catch (Exception e) + { + PowerToysTelemetry.Log.WriteEvent(new MarkdownFilePreviewError { Message = e.Message }); + + this.InvokeOnControlThread(() => + { + this.Controls.Clear(); + this.infoBarDisplayed = true; + this.infoBar = this.GetTextBoxControl(Resources.MarkdownNotPreviewedError); + this.Resize += this.FormResized; + this.Controls.Add(this.infoBar); + }); + } + finally + { + base.DoPreview(dataSource); + } + } + + /// + /// Gets a textbox control. + /// + /// Message to be displayed in textbox. + /// An object of type . + private RichTextBox GetTextBoxControl(string message) + { + RichTextBox richTextBox = new RichTextBox + { + Text = message, + BackColor = Color.LightYellow, + Multiline = true, + Dock = DockStyle.Top, + ReadOnly = true, + }; + richTextBox.ContentsResized += this.RTBContentsResized; + richTextBox.ScrollBars = RichTextBoxScrollBars.None; + richTextBox.BorderStyle = BorderStyle.None; + + return richTextBox; + } + + /// + /// Callback when RichTextBox is resized. + /// + /// Reference to resized control. + /// Provides data for the resize event. + private void RTBContentsResized(object sender, ContentsResizedEventArgs e) + { + RichTextBox richTextBox = (RichTextBox)sender; + richTextBox.Height = e.NewRectangle.Height + 5; + } + + /// + /// Callback when form is resized. + /// + /// Reference to resized control. + /// Provides data for the event. + private void FormResized(object sender, EventArgs e) + { + if (this.infoBarDisplayed) + { + this.infoBar.Width = this.Width; + } + } + + /// + /// Callback when image is blocked by extension. + /// + private void ImagesBlockedCallBack() + { + this.infoBarDisplayed = true; + } + } +} diff --git a/src/modules/previewpane/MarkdownPreviewHandler/Properties/Resources.Designer.cs b/src/modules/previewpane/MarkdownPreviewHandler/Properties/Resources.Designer.cs index ea7599efd6..73587e08de 100644 --- a/src/modules/previewpane/MarkdownPreviewHandler/Properties/Resources.Designer.cs +++ b/src/modules/previewpane/MarkdownPreviewHandler/Properties/Resources.Designer.cs @@ -1,81 +1,81 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace MarkdownPreviewHandler.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MarkdownPreviewHandler.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to Some pictures have been blocked to help prevent the sender from identifying this computer. Open this item to view pictures.. - /// - internal static string BlockedImageInfoText { - get { - return ResourceManager.GetString("BlockedImageInfoText", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The markdown could not be preview due to an internal error.. - /// - internal static string MarkdownNotPreviewedError { - get { - return ResourceManager.GetString("MarkdownNotPreviewedError", resourceCulture); - } - } - } -} +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace MarkdownPreviewHandler.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MarkdownPreviewHandler.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Some pictures have been blocked to help prevent the sender from identifying this computer. Open this item to view pictures.. + /// + internal static string BlockedImageInfoText { + get { + return ResourceManager.GetString("BlockedImageInfoText", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The markdown could not be preview due to an internal error.. + /// + internal static string MarkdownNotPreviewedError { + get { + return ResourceManager.GetString("MarkdownNotPreviewedError", resourceCulture); + } + } + } +} diff --git a/src/modules/previewpane/MarkdownPreviewHandler/Properties/Resources.resx b/src/modules/previewpane/MarkdownPreviewHandler/Properties/Resources.resx index 9beb635bd9..e97ed33cad 100644 --- a/src/modules/previewpane/MarkdownPreviewHandler/Properties/Resources.resx +++ b/src/modules/previewpane/MarkdownPreviewHandler/Properties/Resources.resx @@ -1,128 +1,128 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Some pictures have been blocked to help prevent the sender from identifying this computer. Open this item to view pictures. - This text is displayed if image is blocked from being displayed. - - - The markdown could not be preview due to an internal error. - This text is displayed if markdown fails to preview - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Some pictures have been blocked to help prevent the sender from identifying this computer. Open this item to view pictures. + This text is displayed if image is blocked from being displayed. + + + The markdown could not be preview due to an internal error. + This text is displayed if markdown fails to preview + \ No newline at end of file diff --git a/src/modules/previewpane/MarkDownPreviewHandler/Properties/Settings.Designer.cs b/src/modules/previewpane/MarkdownPreviewHandler/Properties/Settings.Designer.cs similarity index 100% rename from src/modules/previewpane/MarkDownPreviewHandler/Properties/Settings.Designer.cs rename to src/modules/previewpane/MarkdownPreviewHandler/Properties/Settings.Designer.cs diff --git a/src/modules/previewpane/MarkDownPreviewHandler/Properties/Settings.settings b/src/modules/previewpane/MarkdownPreviewHandler/Properties/Settings.settings similarity index 100% rename from src/modules/previewpane/MarkDownPreviewHandler/Properties/Settings.settings rename to src/modules/previewpane/MarkdownPreviewHandler/Properties/Settings.settings diff --git a/src/modules/previewpane/MarkDownPreviewHandler/Telemetry/Events/MarkdownFileHandlerLoaded.cs b/src/modules/previewpane/MarkdownPreviewHandler/Telemetry/Events/MarkdownFileHandlerLoaded.cs similarity index 100% rename from src/modules/previewpane/MarkDownPreviewHandler/Telemetry/Events/MarkdownFileHandlerLoaded.cs rename to src/modules/previewpane/MarkdownPreviewHandler/Telemetry/Events/MarkdownFileHandlerLoaded.cs diff --git a/src/modules/previewpane/MarkDownPreviewHandler/Telemetry/Events/MarkdownFilePreviewError.cs b/src/modules/previewpane/MarkdownPreviewHandler/Telemetry/Events/MarkdownFilePreviewError.cs similarity index 97% rename from src/modules/previewpane/MarkDownPreviewHandler/Telemetry/Events/MarkdownFilePreviewError.cs rename to src/modules/previewpane/MarkdownPreviewHandler/Telemetry/Events/MarkdownFilePreviewError.cs index 95b10a90d9..37da4df0a9 100644 --- a/src/modules/previewpane/MarkDownPreviewHandler/Telemetry/Events/MarkdownFilePreviewError.cs +++ b/src/modules/previewpane/MarkdownPreviewHandler/Telemetry/Events/MarkdownFilePreviewError.cs @@ -1,23 +1,23 @@ -// Copyright (c) Microsoft Corporation -// The Microsoft Corporation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using Microsoft.PowerToys.Telemetry; -using Microsoft.PowerToys.Telemetry.Events; - -namespace MarkdownPreviewHandler.Telemetry.Events -{ - /// - /// A telemetry event that is triggered when an error occurs while attempting to view a markdown file in the preview pane. - /// - public class MarkdownFilePreviewError : EventBase, IEvent - { - /// - /// Gets or sets the error message. - /// - public string Message { get; set; } - - /// - public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServicePerformance; - } -} +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Microsoft.PowerToys.Telemetry; +using Microsoft.PowerToys.Telemetry.Events; + +namespace MarkdownPreviewHandler.Telemetry.Events +{ + /// + /// A telemetry event that is triggered when an error occurs while attempting to view a markdown file in the preview pane. + /// + public class MarkdownFilePreviewError : EventBase, IEvent + { + /// + /// Gets or sets the error message. + /// + public string Message { get; set; } + + /// + public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServicePerformance; + } +} diff --git a/src/modules/previewpane/MarkDownPreviewHandler/Telemetry/Events/MarkdownFilePreviewed.cs b/src/modules/previewpane/MarkdownPreviewHandler/Telemetry/Events/MarkdownFilePreviewed.cs similarity index 97% rename from src/modules/previewpane/MarkDownPreviewHandler/Telemetry/Events/MarkdownFilePreviewed.cs rename to src/modules/previewpane/MarkdownPreviewHandler/Telemetry/Events/MarkdownFilePreviewed.cs index f3334c0f6e..b946c3d263 100644 --- a/src/modules/previewpane/MarkDownPreviewHandler/Telemetry/Events/MarkdownFilePreviewed.cs +++ b/src/modules/previewpane/MarkdownPreviewHandler/Telemetry/Events/MarkdownFilePreviewed.cs @@ -1,20 +1,20 @@ -// Copyright (c) Microsoft Corporation -// The Microsoft Corporation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Diagnostics.Tracing; -using Microsoft.PowerToys.Telemetry; -using Microsoft.PowerToys.Telemetry.Events; - -namespace MarkdownPreviewHandler.Telemetry.Events -{ - /// - /// A telemetry event that is triggered when a markdown file is viewed in the preview pane. - /// - [EventData] - public class MarkdownFilePreviewed : EventBase, IEvent - { - /// - public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage; - } -} +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Diagnostics.Tracing; +using Microsoft.PowerToys.Telemetry; +using Microsoft.PowerToys.Telemetry.Events; + +namespace MarkdownPreviewHandler.Telemetry.Events +{ + /// + /// A telemetry event that is triggered when a markdown file is viewed in the preview pane. + /// + [EventData] + public class MarkdownFilePreviewed : EventBase, IEvent + { + /// + public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage; + } +} diff --git a/src/modules/previewpane/PreviewPaneUnitTests/UnitTests-MarkdownPreviewHandler.csproj b/src/modules/previewpane/PreviewPaneUnitTests/UnitTests-MarkdownPreviewHandler.csproj index 080400f76b..92d60c6cc1 100644 --- a/src/modules/previewpane/PreviewPaneUnitTests/UnitTests-MarkdownPreviewHandler.csproj +++ b/src/modules/previewpane/PreviewPaneUnitTests/UnitTests-MarkdownPreviewHandler.csproj @@ -108,7 +108,7 @@ {AF2349B8-E5B6-4004-9502-687C1C7730B1} PreviewHandlerCommon - + {6a71162e-fc4c-4a2c-b90f-3cf94f59a9bb} MarkdownPreviewHandler