diff --git a/MarkdigWrapper/Properties/AssemblyInfo.cs b/MarkdigWrapper/Properties/AssemblyInfo.cs index fff7e0c..6e6558b 100644 --- a/MarkdigWrapper/Properties/AssemblyInfo.cs +++ b/MarkdigWrapper/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.7.4.1")] -[assembly: AssemblyFileVersion("0.7.4.1")] +[assembly: AssemblyVersion("0.7.4.2")] +[assembly: AssemblyFileVersion("0.7.4.2")] diff --git a/NppMarkdownPanel/Entities/Settings.cs b/NppMarkdownPanel/Entities/Settings.cs index e59a19c..ebcba0e 100644 --- a/NppMarkdownPanel/Entities/Settings.cs +++ b/NppMarkdownPanel/Entities/Settings.cs @@ -22,6 +22,7 @@ public class Settings public bool IsDarkModeEnabled { get; set; } public bool ShowToolbar { get; set; } public bool ShowStatusbar { get; set; } + public bool SuppressScriptErrors { get; set; } public bool AutoShowPanel { get; set; } public const int FILTERS = 10; diff --git a/NppMarkdownPanel/Forms/AboutForm.Designer.cs b/NppMarkdownPanel/Forms/AboutForm.Designer.cs index fdfa05c..fe488f4 100644 --- a/NppMarkdownPanel/Forms/AboutForm.Designer.cs +++ b/NppMarkdownPanel/Forms/AboutForm.Designer.cs @@ -99,6 +99,8 @@ private void InitializeComponent() // AboutForm // this.AcceptButton = this.btnOk; + this.KeyPreview = true; + this.KeyDown += this.cancelButton_Click; this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(621, 503); diff --git a/NppMarkdownPanel/Forms/AboutForm.cs b/NppMarkdownPanel/Forms/AboutForm.cs index 0f68acd..2671cc1 100644 --- a/NppMarkdownPanel/Forms/AboutForm.cs +++ b/NppMarkdownPanel/Forms/AboutForm.cs @@ -32,5 +32,13 @@ public AboutForm() this.ActiveControl = btnOk; } + private void cancelButton_Click(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Escape) + { + this.Close(); + } + } + } } diff --git a/NppMarkdownPanel/Forms/MarkdownPreviewForm.Designer.cs b/NppMarkdownPanel/Forms/MarkdownPreviewForm.Designer.cs index bfb175a..5bbe2b1 100644 --- a/NppMarkdownPanel/Forms/MarkdownPreviewForm.Designer.cs +++ b/NppMarkdownPanel/Forms/MarkdownPreviewForm.Designer.cs @@ -92,6 +92,7 @@ private void InitializeComponent() // webBrowserPreview // this.webBrowserPreview.AllowWebBrowserDrop = false; + this.webBrowserPreview.ScriptErrorsSuppressed = true; this.webBrowserPreview.Dock = System.Windows.Forms.DockStyle.Fill; this.webBrowserPreview.Location = new System.Drawing.Point(0, 0); this.webBrowserPreview.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); diff --git a/NppMarkdownPanel/Forms/MarkdownPreviewForm.cs b/NppMarkdownPanel/Forms/MarkdownPreviewForm.cs index 81772a9..cbc6eac 100644 --- a/NppMarkdownPanel/Forms/MarkdownPreviewForm.cs +++ b/NppMarkdownPanel/Forms/MarkdownPreviewForm.cs @@ -66,6 +66,7 @@ public void UpdateSettings(Settings settings) tbPreview.Visible = settings.ShowToolbar; statusStrip2.Visible = settings.ShowStatusbar; + webBrowserPreview.ScriptErrorsSuppressed = settings.SuppressScriptErrors; } private MarkdownService markdownService; diff --git a/NppMarkdownPanel/Forms/SettingsForm.Designer.cs b/NppMarkdownPanel/Forms/SettingsForm.Designer.cs index 660a7e7..00d03a5 100644 --- a/NppMarkdownPanel/Forms/SettingsForm.Designer.cs +++ b/NppMarkdownPanel/Forms/SettingsForm.Designer.cs @@ -60,6 +60,7 @@ private void InitializeComponent() this.tbMkdnExts = new System.Windows.Forms.TextBox(); this.tbHtmlExts = new System.Windows.Forms.TextBox(); this.cbShowStatusbar = new System.Windows.Forms.CheckBox(); + this.cbSuppressScriptErrors = new System.Windows.Forms.CheckBox(); this.panel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit(); @@ -390,12 +391,26 @@ private void InitializeComponent() this.cbShowStatusbar.UseVisualStyleBackColor = true; this.cbShowStatusbar.CheckedChanged += new System.EventHandler(this.cbShowStatusbar_CheckedChanged); // + // cbSuppressScriptErrors + // + this.cbSuppressScriptErrors.AutoSize = true; + this.cbSuppressScriptErrors.Location = new System.Drawing.Point(442, 384); + this.cbSuppressScriptErrors.Name = "cbSuppressScriptErrors"; + this.cbSuppressScriptErrors.Size = new System.Drawing.Size(286, 17); + this.cbSuppressScriptErrors.TabIndex = 29; + this.cbSuppressScriptErrors.Text = "Suppress Script Errors"; + this.cbSuppressScriptErrors.UseVisualStyleBackColor = true; + this.cbSuppressScriptErrors.CheckedChanged += new System.EventHandler(this.cbSuppressScriptErrors_CheckedChanged); + // // SettingsForm // + this.KeyPreview = true; + this.KeyDown += this.cancelEsc_Click; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(700, 582); this.Controls.Add(this.cbShowStatusbar); + this.Controls.Add(this.cbSuppressScriptErrors); this.Controls.Add(this.cbAutoShowPanel); this.Controls.Add(this.btnDefaultDarkmodeCss); this.Controls.Add(this.btnChooseDarkmodeCss); @@ -473,5 +488,6 @@ private void InitializeComponent() private System.Windows.Forms.Button btnDefaultHtmlExts; private System.Windows.Forms.CheckBox cbAutoShowPanel; private System.Windows.Forms.CheckBox cbShowStatusbar; + private System.Windows.Forms.CheckBox cbSuppressScriptErrors; } } \ No newline at end of file diff --git a/NppMarkdownPanel/Forms/SettingsForm.cs b/NppMarkdownPanel/Forms/SettingsForm.cs index 3e328a4..1f849e2 100644 --- a/NppMarkdownPanel/Forms/SettingsForm.cs +++ b/NppMarkdownPanel/Forms/SettingsForm.cs @@ -15,6 +15,7 @@ public partial class SettingsForm : Form public string HtmlExtensions { get; set; } public bool AutoShowPanel { get; set; } public bool ShowStatusbar { get; set; } + public bool SuppressScriptErrors { get; set; } public SettingsForm(Settings settings) { @@ -27,6 +28,7 @@ public SettingsForm(Settings settings) HtmlExtensions = settings.HtmlExtensions; AutoShowPanel = settings.AutoShowPanel; ShowStatusbar = settings.ShowStatusbar; + SuppressScriptErrors = settings.SuppressScriptErrors; InitializeComponent(); @@ -40,6 +42,7 @@ public SettingsForm(Settings settings) tbHtmlExts.Text = HtmlExtensions; cbAutoShowPanel.Checked = AutoShowPanel; cbShowStatusbar.Checked = ShowStatusbar; + cbSuppressScriptErrors.Checked = SuppressScriptErrors; } private void trackBar1_ValueChanged(object sender, EventArgs e) @@ -74,6 +77,14 @@ private void btnSave_Click(object sender, EventArgs e) } } + private void cancelEsc_Click(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Escape) + { + this.DialogResult = DialogResult.Cancel; + } + } + private void btnCancel_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; @@ -196,5 +207,10 @@ private void cbShowStatusbar_CheckedChanged(object sender, EventArgs e) { ShowStatusbar = cbShowStatusbar.Checked; } + + private void cbSuppressScriptErrors_CheckedChanged(object sender, EventArgs e) + { + SuppressScriptErrors = cbSuppressScriptErrors.Checked; + } } } diff --git a/NppMarkdownPanel/MarkdownPanelController.cs b/NppMarkdownPanel/MarkdownPanelController.cs index bf922b3..f7e5180 100644 --- a/NppMarkdownPanel/MarkdownPanelController.cs +++ b/NppMarkdownPanel/MarkdownPanelController.cs @@ -43,6 +43,8 @@ public class MarkdownPanelController private Settings settings; + private IntPtr _ptrNppTbData; + public MarkdownPanelController() { scintillaGatewayFactory = PluginBase.GetGatewayFactory(); @@ -68,6 +70,7 @@ private Settings LoadSettingsFromIni() settings.HtmlFileName = Win32.ReadIniValue("Options", "HtmlFileName", iniFilePath); settings.ShowToolbar = PluginUtils.ReadIniBool("Options", "ShowToolbar", iniFilePath); settings.ShowStatusbar = PluginUtils.ReadIniBool("Options", "ShowStatusbar", iniFilePath); + settings.SuppressScriptErrors = PluginUtils.ReadIniBool("Options", "SuppressScriptErrors", iniFilePath); settings.MkdnExtensions = Win32.ReadIniValue("Options", "MkdnExtensions", iniFilePath, Settings.DEFAULT_SUPPORTED_MKDN_EXT); settings.HtmlExtensions = Win32.ReadIniValue("Options", "HtmlExtensions", iniFilePath, Settings.DEFAULT_SUPPORTED_HTML_EXT); settings.IsDarkModeEnabled = IsDarkModeEnabled(); @@ -204,7 +207,34 @@ private void OnRenderTimerElapsed(object source, EventArgs e) private void RenderMarkdownDirect(bool preserveVerticalScrollPosition = true) { - viewerInterface.RenderMarkdown(GetCurrentEditorText(), notepadPPGateway.GetCurrentFilePath(), preserveVerticalScrollPosition); + string filepath = notepadPPGateway.GetCurrentFilePath(); + if (_ptrNppTbData != IntPtr.Zero) + { + string caption = Main.PluginTitle; + caption += " - "; + caption += Path.GetFileName(filepath); + IntPtr pCaption = Marshal.ReadIntPtr(_ptrNppTbData, IntPtr.Size); + byte[] newCaption = new System.Text.UnicodeEncoding().GetBytes(caption); + int p = 0; + // We only have 48 characters to use (see line 379) + // But each character is 2 bytes (TCHAR / Unicode), so 96 + // Copy as much and bail if still going to write the last 2 NULLs + for (; p < newCaption.Length; p++) + { + if (p >= 94) + break; + Marshal.WriteByte((pCaption + p), newCaption[p]); + } + Marshal.WriteInt16((pCaption + p), 0); + Marshal.WriteInt16((pCaption + (p+1)), 0); + Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_DMMUPDATEDISPINFO, 0, viewerInterface.Handle); + } + + viewerInterface.RenderMarkdown(GetCurrentEditorText(), filepath, preserveVerticalScrollPosition); + + // Set focus back to Notepad++ editor buffer + var scintillaGateway = scintillaGatewayFactory(); + scintillaGateway.GrabFocus(); } private string GetCurrentEditorText() @@ -257,6 +287,7 @@ private void EditSettings() settings.MkdnExtensions = settingsForm.MkdnExtensions; settings.HtmlExtensions = settingsForm.HtmlExtensions; settings.ShowStatusbar = settingsForm.ShowStatusbar; + settings.SuppressScriptErrors = settingsForm.SuppressScriptErrors; settings.AutoShowPanel = settingsForm.AutoShowPanel; settings.IsDarkModeEnabled = IsDarkModeEnabled(); @@ -332,6 +363,7 @@ private void SaveSettings() Win32.WriteIniValue("Options", "HtmlFileName", settings.HtmlFileName, iniFilePath); Win32.WriteIniValue("Options", "ShowToolbar", settings.ShowToolbar.ToString(), iniFilePath); Win32.WriteIniValue("Options", "ShowStatusbar", settings.ShowStatusbar.ToString(), iniFilePath); + Win32.WriteIniValue("Options", "SuppressScriptErrors", settings.SuppressScriptErrors.ToString(), iniFilePath); Win32.WriteIniValue("Options", "MkdnExtensions", settings.MkdnExtensions, iniFilePath); Win32.WriteIniValue("Options", "HtmlExtensions", settings.HtmlExtensions, iniFilePath); Win32.WriteIniValue("Options", "AutoShowPanel", settings.AutoShowPanel.ToString(), iniFilePath); @@ -350,12 +382,15 @@ private void TogglePanelVisible() { NppTbData _nppTbData = new NppTbData(); _nppTbData.hClient = viewerInterface.Handle; - _nppTbData.pszName = Main.PluginTitle; + // Main.PluginTitle ("Markdown Panel") = 14 + 34 spaces = 48 + string caption = Main.PluginTitle; + caption += " "; + _nppTbData.pszName = caption; _nppTbData.dlgID = idMyDlg; _nppTbData.uMask = NppTbMsg.DWS_DF_CONT_RIGHT | NppTbMsg.DWS_ICONTAB | NppTbMsg.DWS_ICONBAR; _nppTbData.hIconTab = (uint)ConvertBitmapToIcon(Properties.Resources.markdown_16x16_solid_bmp).Handle; _nppTbData.pszModuleName = Main.ModuleName; - IntPtr _ptrNppTbData = Marshal.AllocHGlobal(Marshal.SizeOf(_nppTbData)); + _ptrNppTbData = Marshal.AllocHGlobal(Marshal.SizeOf(_nppTbData)); Marshal.StructureToPtr(_nppTbData, _ptrNppTbData, false); Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_DMMREGASDCKDLG, 0, _ptrNppTbData); diff --git a/NppMarkdownPanel/Properties/AssemblyInfo.cs b/NppMarkdownPanel/Properties/AssemblyInfo.cs index 38a99bd..20e10f9 100644 --- a/NppMarkdownPanel/Properties/AssemblyInfo.cs +++ b/NppMarkdownPanel/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.7.4.1")] -[assembly: AssemblyFileVersion("0.7.4.1")] +[assembly: AssemblyVersion("0.7.4.2")] +[assembly: AssemblyFileVersion("0.7.4.2")] diff --git a/README.md b/README.md index 7884685..088866e 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,9 @@ To open the settings for this plugin: Plugins -> Markdown Panel -> Settings * #### Show Toolbar in Preview Window Checking this box will enable the toolbar in the preview window. By default, this is unchecked. +* #### Suppress Script Errors + Suppress the annoying popups about script errors when this is really meant to be just a viewer, not a full-blown Browser. **HINT:** To see scripts "run properly", open in a real browser. + ### Preview Window Toolbar * #### Save As... (![save-btn](help/save-btn.png "Picture of the Save button on the preview panel toolbar"))