From e6c8926cdbe45ae4105e0b02688cafaa8c77399a Mon Sep 17 00:00:00 2001 From: Hiromi Hayashi Date: Sun, 8 Dec 2013 12:10:48 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=E7=B7=A8=E9=9B=86=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92=E5=A4=89=E3=81=88?= =?UTF-8?q?=E3=81=9F=E3=81=A8=E3=81=8D=E4=B8=80=E6=99=82Html=E3=83=95?= =?UTF-8?q?=E3=82=A1=E3=82=A4=E3=83=AB=E3=81=8C=E6=B6=88=E3=81=88=E3=81=9A?= =?UTF-8?q?=E3=81=AB=E6=AE=8B=E3=81=A3=E3=81=A6=E3=81=97=E3=81=BE=E3=81=86?= =?UTF-8?q?=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Delete_TemporaryHtmlFilePath()でプレビュー用一時Htmlファイルを削除するときに、インスタンス変数の _TemporaryHtmlFilePath の中身も消す。でないと次もまた同じファイル名で一時Htmlファイルが作られてしまう。 Delete_TemporaryHtmlFilePath()は一時Htmlファイルの名前をGet_TemporaryHtmlFilePath()で取得するため消すHtmlファイルの名前を正しく取得できずHtmlファイルを消せなかった。 --- MarkDownSharpEditor/Form1.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MarkDownSharpEditor/Form1.cs b/MarkDownSharpEditor/Form1.cs index a112655..726fba3 100644 --- a/MarkDownSharpEditor/Form1.cs +++ b/MarkDownSharpEditor/Form1.cs @@ -1096,7 +1096,9 @@ private void Delete_TemporaryHtmlFilePath() { try { - File.Delete(TempHtmlFilePath); + File.Delete(TempHtmlFilePath); + _TemporaryHtmlFilePath = ""; + } catch { From 09f371e887bfcfdd9cd416dd177608350535b84b Mon Sep 17 00:00:00 2001 From: Hiromi Hayashi Date: Fri, 20 Dec 2013 12:38:59 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=E3=83=97=E3=83=AC=E3=81=AB=E3=83=93?= =?UTF-8?q?=E3=83=A5=E3=83=BC=E7=94=A8=E3=81=AEIE=E3=81=AE=E3=83=AC?= =?UTF-8?q?=E3=83=B3=E3=83=80=E3=83=AA=E3=83=B3=E3=82=B0=E3=83=A2=E3=83=BC?= =?UTF-8?q?=E3=83=89=E5=88=87=E3=82=8A=E6=9B=BF=E3=81=88=E6=A9=9F=E8=83=BD?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit プレにビュー用のIEのレンダリングモード切り替えできるようにオプションに機能追加 --- MarkDownSharpEditor/AppSettings.cs | 48 +++++ MarkDownSharpEditor/Form1.cs | 48 ++--- MarkDownSharpEditor/Form3.Designer.cs | 42 +++++ MarkDownSharpEditor/Form3.cs | 49 ++++++ MarkDownSharpEditor/Form3.resx | 242 +++++++++++++++----------- 5 files changed, 305 insertions(+), 124 deletions(-) diff --git a/MarkDownSharpEditor/AppSettings.cs b/MarkDownSharpEditor/AppSettings.cs index 1a34cd6..8d2b843 100644 --- a/MarkDownSharpEditor/AppSettings.cs +++ b/MarkDownSharpEditor/AppSettings.cs @@ -106,6 +106,10 @@ public class AppSettings private int _ListViewColumnHeader1Width; private int _ListViewColumnHeader2Width; + private int _FeatureBrowserEmulation; //UserAgentのレジストリ設定 + private int _FeatureDocumentCompatibuleMode; //IEレンダリングモードのレジストリ設定 + + #endregion //----------------------------------- @@ -514,6 +518,22 @@ public int ListViewColumnHeader2Width set { _ListViewColumnHeader2Width = value; } } + //UserAgentのレジストリ設定 + public int FeatureBrowserEmulation + { + get { return _FeatureBrowserEmulation; } + set { _FeatureBrowserEmulation = value; } + } + + //IEレンダリングモードのレジストリ設定 + public int FeatureDocumentCompatibuleMode + { + get { return _FeatureDocumentCompatibuleMode; } + set { _FeatureDocumentCompatibuleMode = value; } + } + + + #endregion //----------------------------------- @@ -654,6 +674,9 @@ public AppSettings() _ListViewColumnHeader1Width = 128; _ListViewColumnHeader2Width = 512; + _FeatureBrowserEmulation = 7000; + _FeatureDocumentCompatibuleMode = 70000; + } //---------------------------------------------------- @@ -908,6 +931,31 @@ public static string GetAppDataLocalPath() //return (Path.GetDirectoryName(Application.ExecutablePath)); } + + // BrowserControlのUserAgentとレンダリングモードを指定する + public static void SetBrowserRenderingMode(int featureBrowserEmulation, int featureDocumentCompatibleMode) + { + // ユーザーエージェントのレジストリキー + string FEATURE_BROWSER_EMULATION = @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION"; + // レンダリングモードのレジストリキー + string FEATURE_DOCUMENT_COMPATIBLE_MODE = @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_DOCUMENT_COMPATIBLE_MODE"; + +#if DEBUG + string exename = "MarkDownSharpEditor.vshost.exe"; +#else + string exename = "MarkDownSharpEditor.exe"; +#endif + using (var regkey1 = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(FEATURE_BROWSER_EMULATION)) + using (var regkey2 = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(FEATURE_DOCUMENT_COMPATIBLE_MODE)) + { + regkey1.SetValue(exename, featureBrowserEmulation, Microsoft.Win32.RegistryValueKind.DWord); + regkey2.SetValue(exename, featureDocumentCompatibleMode, Microsoft.Win32.RegistryValueKind.DWord); + regkey1.Close(); + regkey2.Close(); + } + + } + } } diff --git a/MarkDownSharpEditor/Form1.cs b/MarkDownSharpEditor/Form1.cs index 726fba3..40fac95 100644 --- a/MarkDownSharpEditor/Form1.cs +++ b/MarkDownSharpEditor/Form1.cs @@ -55,7 +55,9 @@ public partial class Form1 : Form // コンストラクタ ( Constructor ) //----------------------------------- public Form1() - { + { + + InitializeComponent(); //IME Handler On/Off @@ -77,7 +79,8 @@ public Form1() //MarkDownSharpEditor.AppSettings.Instance.ReadFromXMLFile(); //WebBrowserClickSoundOFF(); - CoInternetSetFeatureEnabled(FEATURE_DISABLE_NAVIGATION_SOUNDS, SET_FEATURE_ON_PROCESS, true); + CoInternetSetFeatureEnabled(FEATURE_DISABLE_NAVIGATION_SOUNDS, SET_FEATURE_ON_PROCESS, true); + } @@ -128,12 +131,12 @@ private void Form1_Load(object sender, EventArgs e) //言語 ( Language ) if (obj.Lang == "ja") { - menuViewJapanese.Checked = true; + menuViewJapanese.Checked = true; menuViewEnglish.Checked = false; } else { - menuViewJapanese.Checked = false; + menuViewJapanese.Checked = false; menuViewEnglish.Checked = true; } @@ -211,7 +214,9 @@ private void Form1_Load(object sender, EventArgs e) //----------------------------------- //検索フォーム・オプション //Search form options - chkOptionCase.Checked = obj.fSearchOptionIgnoreCase ? false : true; + chkOptionCase.Checked = obj.fSearchOptionIgnoreCase ? false : true; + + } @@ -330,7 +335,9 @@ private void Form1_Shown(object sender, EventArgs e) //フォームタイトル更新 / Refresh form caption FormTextChange(); } - } + } + + //---------------------------------------------------------------------- // フォームタイトルの表示(更新) @@ -1097,8 +1104,7 @@ private void Delete_TemporaryHtmlFilePath() try { File.Delete(TempHtmlFilePath); - _TemporaryHtmlFilePath = ""; - + _TemporaryHtmlFilePath = ""; } catch { @@ -1182,7 +1188,11 @@ private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEve // BackgroundWorker browser preview //---------------------------------------------------------------------- private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) - { + { + var obj = MarkDownSharpEditor.AppSettings.Instance; + // プレビューブラウザのレンダリングモード指定 + AppSettings.SetBrowserRenderingMode(obj.FeatureBrowserEmulation, obj.FeatureDocumentCompatibuleMode); + string ResultText = (string)e.Argument; string MkResultText = ""; @@ -1252,7 +1262,9 @@ private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) FileName); //タイトル(=ファイル名) ( title = file name ) //Footer - string footer = "\n"; + string footer = //"\n"; + // 書き換え中 + "\n"; //----------------------------------- //Markdown parse ( default ) @@ -1295,6 +1307,7 @@ private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) //Encode and convert it to 'byte' value ( richEditBox default encoding is utf-8 = 65001 ) byte[] bytesData = Encoding.GetEncoding(CodePageNum).GetBytes(MkResultText); + //----------------------------------- // Write to temporay file if (_fNoTitle == false) @@ -1309,7 +1322,7 @@ private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) //Open temporary file to allow references from other processes using (FileStream fs = new FileStream( _TemporaryHtmlFilePath, - FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read | FileShare.Delete)) + FileMode.Create, FileAccess.ReadWrite, FileShare.Read | FileShare.Delete)) { fs.Write(bytesData, 0, bytesData.Length); e.Result = _TemporaryHtmlFilePath; @@ -1376,13 +1389,6 @@ private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerComple //Restore scroll bar position if (doc != null) { -#if false - while (webBrowser1.ReadyState != WebBrowserReadyState.Complete) - { - Application.DoEvents(); - } - doc.Window.ScrollTo(scrollpos); -#endif waitTask.ContinueWith((arg1) => { this.BeginInvoke(new Action(() => @@ -1486,7 +1492,6 @@ void browserWaitTimer_Tick(object sender, EventArgs e) int timerCount = 0; Timer browserWaitTimer; - //---------------------------------------------------------------------- // BackgroundWorker Syntax hightlighter work //---------------------------------------------------------------------- @@ -2185,6 +2190,7 @@ private bool SaveToEditingFile(bool fSaveAs = false) { if (saveFileDialog1.ShowDialog() == DialogResult.OK) { + using (StreamWriter sw = new StreamWriter(saveFileDialog1.FileName, false, _EditingFileEncoding)) { sw.Write(richTextBox1.Text); @@ -2558,7 +2564,7 @@ private void menuViewJapanese_Click(object sender, EventArgs e) else if (result == DialogResult.No) { MarkDownSharpEditor.AppSettings.Instance.Lang = "ja"; - menuViewJapanese.Checked = true; + menuViewJapanese.Checked = true; menuViewEnglish.Checked = false; } else @@ -2589,7 +2595,7 @@ private void menuViewEnglish_Click(object sender, EventArgs e) { MarkDownSharpEditor.AppSettings.Instance.Lang = "en"; MarkDownSharpEditor.AppSettings.Instance.SaveToXMLFile(); - menuViewJapanese.Checked = false; + menuViewJapanese.Checked = false; menuViewEnglish.Checked = true; } else diff --git a/MarkDownSharpEditor/Form3.Designer.cs b/MarkDownSharpEditor/Form3.Designer.cs index 590eec7..1162807 100644 --- a/MarkDownSharpEditor/Form3.Designer.cs +++ b/MarkDownSharpEditor/Form3.Designer.cs @@ -164,12 +164,16 @@ private void InitializeComponent() this.comboBoxSelectEncoding = new System.Windows.Forms.ComboBox(); this.radioButtonChangeEncoding = new System.Windows.Forms.RadioButton(); this.radioButtonDefaultEncoding = new System.Windows.Forms.RadioButton(); + this.tabPageBrowser = new System.Windows.Forms.TabPage(); + this.groupBox4 = new System.Windows.Forms.GroupBox(); + this.comboBoxRenderingMode = new System.Windows.Forms.ComboBox(); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog(); this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog(); this.fontDialog1 = new System.Windows.Forms.FontDialog(); this.colorDialog1 = new System.Windows.Forms.ColorDialog(); + this.label8 = new System.Windows.Forms.Label(); this.panel1.SuspendLayout(); this.tabControl1.SuspendLayout(); this.tabPageMain.SuspendLayout(); @@ -187,6 +191,8 @@ private void InitializeComponent() this.groupBox3.SuspendLayout(); this.groupBoxCssOption.SuspendLayout(); this.groupBoxEncoding.SuspendLayout(); + this.tabPageBrowser.SuspendLayout(); + this.groupBox4.SuspendLayout(); this.SuspendLayout(); // // panel1 @@ -235,6 +241,7 @@ private void InitializeComponent() this.tabControl1.Controls.Add(this.tabPageEdit); this.tabControl1.Controls.Add(this.tabPageCSS); this.tabControl1.Controls.Add(this.tabPageHTML); + this.tabControl1.Controls.Add(this.tabPageBrowser); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; // @@ -1349,6 +1356,29 @@ private void InitializeComponent() this.radioButtonDefaultEncoding.UseVisualStyleBackColor = true; this.radioButtonDefaultEncoding.CheckedChanged += new System.EventHandler(this.radioButtonDefaultEncoding_CheckedChanged); // + // tabPageBrowser + // + this.tabPageBrowser.Controls.Add(this.groupBox4); + resources.ApplyResources(this.tabPageBrowser, "tabPageBrowser"); + this.tabPageBrowser.Name = "tabPageBrowser"; + this.tabPageBrowser.UseVisualStyleBackColor = true; + // + // groupBox4 + // + this.groupBox4.Controls.Add(this.label8); + this.groupBox4.Controls.Add(this.comboBoxRenderingMode); + resources.ApplyResources(this.groupBox4, "groupBox4"); + this.groupBox4.Name = "groupBox4"; + this.groupBox4.TabStop = false; + this.groupBox4.Enter += new System.EventHandler(this.groupBox4_Enter); + // + // comboBoxRenderingMode + // + this.comboBoxRenderingMode.FormattingEnabled = true; + resources.ApplyResources(this.comboBoxRenderingMode, "comboBoxRenderingMode"); + this.comboBoxRenderingMode.Name = "comboBoxRenderingMode"; + this.comboBoxRenderingMode.SelectedIndexChanged += new System.EventHandler(this.comboBoxRenderingMode_SelectedIndexChanged); + // // openFileDialog1 // this.openFileDialog1.DefaultExt = "css"; @@ -1374,6 +1404,11 @@ private void InitializeComponent() this.colorDialog1.AnyColor = true; this.colorDialog1.FullOpen = true; // + // label8 + // + resources.ApplyResources(this.label8, "label8"); + this.label8.Name = "label8"; + // // Form3 // resources.ApplyResources(this, "$this"); @@ -1413,6 +1448,9 @@ private void InitializeComponent() this.groupBoxCssOption.PerformLayout(); this.groupBoxEncoding.ResumeLayout(false); this.groupBoxEncoding.PerformLayout(); + this.tabPageBrowser.ResumeLayout(false); + this.groupBox4.ResumeLayout(false); + this.groupBox4.PerformLayout(); this.ResumeLayout(false); } @@ -1559,5 +1597,9 @@ private void InitializeComponent() private System.Windows.Forms.Label label12; private System.Windows.Forms.Label labelMarkdownExtraNotice; private System.Windows.Forms.Button cmdOpenAppData; + private System.Windows.Forms.TabPage tabPageBrowser; + private System.Windows.Forms.GroupBox groupBox4; + private System.Windows.Forms.ComboBox comboBoxRenderingMode; + private System.Windows.Forms.Label label8; } } \ No newline at end of file diff --git a/MarkDownSharpEditor/Form3.cs b/MarkDownSharpEditor/Form3.cs index a7986d3..49fd7cf 100644 --- a/MarkDownSharpEditor/Form3.cs +++ b/MarkDownSharpEditor/Form3.cs @@ -27,6 +27,17 @@ public partial class Form3 : Form public string SelectedCssFilePath; public ComboBox.ObjectCollection CombCol; + public List> IEVersionList = new List>() + { + Tuple.Create(5000, "Internet Explorer 5 mode (also known as \"quirks mode\")"), + Tuple.Create(7000, "Internet Explorer 7 Standards mode"), + Tuple.Create(8000, "Internet Explorer 8 Standards mode"), + Tuple.Create(9000, "Internet Explorer 9 Standards mode"), + Tuple.Create(10000, "Internet Explorer 10 Standards mode"), + Tuple.Create(11000, "Internet Explorer 11 Standards mode") + + }; + //----------------------------------- // コンストラクタ // Constructor @@ -392,6 +403,23 @@ private void Form3_Load(object sender, EventArgs e) radioButtonChangeEncoding.Checked = true; } cmdApply.Enabled = false; + + //----------------------------------- + //Preview Browser + //----------------------------------- + comboBoxRenderingMode.Items.Clear(); + int renderingModeSelectedIndex = 0; + for (i = 0; i < IEVersionList.Count; i++) + { + comboBoxRenderingMode.Items.Add(IEVersionList[i].Item2); + + if (obj.FeatureBrowserEmulation == IEVersionList[i].Item1) + { + renderingModeSelectedIndex = i; + } + } + + comboBoxRenderingMode.SelectedIndex = renderingModeSelectedIndex; } //----------------------------------- @@ -631,6 +659,14 @@ private void cmdApply_Click(object sender, EventArgs e) //選択されたエンコーディングのコードページを保存 //Save the code page of selected encoding obj.CodePageNumber = Convert.ToInt32(comboBoxSelectEncoding.SelectedValue); + + // プレビューのIEのRenderingMode + obj.FeatureBrowserEmulation = IEVersionList[comboBoxRenderingMode.SelectedIndex].Item1; + obj.FeatureDocumentCompatibuleMode = obj.FeatureBrowserEmulation * 10; + + + AppSettings.SetBrowserRenderingMode(obj.FeatureBrowserEmulation, obj.FeatureDocumentCompatibuleMode); + //ファイルに設定を保存 //Save settings to file obj.SaveToXMLFile(); @@ -1247,9 +1283,22 @@ private void radioButtonChangeEncoding_CheckedChanged(object sender, EventArgs e #endregion + private void groupBox4_Enter(object sender, EventArgs e) + { + } + private void comboBoxRenderingMode_SelectedIndexChanged(object sender, EventArgs e) + { + + cmdApply.Enabled = true; + } + private void comboBoxUserAgent_SelectedIndexChanged(object sender, EventArgs e) + { + + cmdApply.Enabled = true; + } } } diff --git a/MarkDownSharpEditor/Form3.resx b/MarkDownSharpEditor/Form3.resx index ce3f01e..1914c44 100644 --- a/MarkDownSharpEditor/Form3.resx +++ b/MarkDownSharpEditor/Form3.resx @@ -120,21 +120,21 @@ - iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAAC6ElEQVRIS51V0UvaURQOgsFg - EOxlg8FgT70O9tp/0OueBnuSFkY4CUWqB0OihbCYCNIiQpGQUCIklJQeEpEIfQiRIsKFERJRRIQUIWfn - O91bv+ataR98ee4993e+c88999ZFREKbzfaO+ekRvtLrOqX84QA/XS4X+Xw+I4eGhui5Igj+3u120/X1 - NY/NmJ6ehkAfm8YgTxEC/YFAgO3HoQS+tcle/qQzgXQ6TZFIpC2Oj48jmTsRo8DNzQ1tbGw8i6lUigYG - BiDSzaHMArVajex2uyw2BXmK2WyWPB4PBD5wKLPA5uYmzc7OqlHnQGIc9webZoFEIiF1fwq7u7tS81wu - p2bugXiIy6ZZIBgM0vb2thrdo1qtyi+C+/1+KUk4HL4TwTeXl5fkcDgg8JqnzAKo4enpqRoRHR8f0+Li - Ik1OTsrv+vo6RaNR8aGcc3NzMo84w8PDCP6HXeYuurq6kkVWLC0t0draGjWbTcl4YWGBjo6OxIeMl5eX - pVzw7+/v0+DgIEResLtV4ODggKamptToFggOkXaA8+OYYTbNOygUCpKNFXhGcJv39vbUDNHZ2RltbW3R - ycmJmiE6Pz/X2b/hoVkgHo9LL2vgAPHg4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oH8s4MDwhIQkhmkAefg/ + AwCjitjm4vqxIQAAAABJRU5ErkJggg== @@ -3914,6 +3854,102 @@ 3 + + True + + + 13, 68 + + + 95, 12 + + + 7 + + + 再起動が必要です + + + label8 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox4 + + + 0 + + + 15, 33 + + + 354, 20 + + + 6 + + + comboBoxRenderingMode + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox4 + + + 1 + + + 20, 28 + + + 384, 96 + + + 7 + + + Rendering Mode: + + + groupBox4 + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tabPageBrowser + + + 0 + + + 4, 22 + + + 432, 401 + + + 4 + + + Preview Browser + + + tabPageBrowser + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tabControl1 + + + 4 + 12, 12 From a86cade201fbc0a64676dfff09c007bc9f65e8fd Mon Sep 17 00:00:00 2001 From: Hiromi Hayashi Date: Fri, 20 Dec 2013 12:43:04 +0900 Subject: [PATCH 3/4] =?UTF-8?q?debug=E7=94=A8=E3=82=B3=E3=83=BC=E3=83=89?= =?UTF-8?q?=E3=82=92=E6=B6=88=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit IEレンダリングモード切り替えのためのdebug用コードを消去した。 --- MarkDownSharpEditor/Form1.cs | 7118 +++++++++++++++++----------------- 1 file changed, 3558 insertions(+), 3560 deletions(-) diff --git a/MarkDownSharpEditor/Form1.cs b/MarkDownSharpEditor/Form1.cs index 40fac95..928e745 100644 --- a/MarkDownSharpEditor/Form1.cs +++ b/MarkDownSharpEditor/Form1.cs @@ -1,3567 +1,3565 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Windows.Forms; -using System.IO; -using System.Collections; -using System.Security.Cryptography; -using System.Text.RegularExpressions; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Windows.Documents; -using MarkDownSharpEditor.Properties; -using mshtml; - -namespace MarkDownSharpEditor -{ - - public partial class Form1 : Form - { - //----------------------------------- - // WebBrowserコンポーネントプレビューの更新音(クリック音)をOFFにする - // Click sound off when webBrowser component preview - const int FEATURE_DISABLE_NAVIGATION_SOUNDS = 21; - const int SET_FEATURE_ON_PROCESS = 0x00000002; - [DllImport("urlmon.dll")] - [PreserveSig] - [return: MarshalAs(UnmanagedType.Error)] - static extern int CoInternetSetFeatureEnabled(int FeatureEntry, [MarshalAs(UnmanagedType.U4)] int dwFlags, bool fEnable); - - //----------------------------------- - int undoCounter = 0; // Undo buffer counter - List UndoBuffer = new List(); - private bool _fSearchStart = false; //検索を開始したか ( Start search flag ) - private int _richEditBoxInternalHeight; //richTextBox1の内部的な高さ ( internal height of richTextBox1 component ) - private int _WebBrowserInternalHeight; //webBrowser1の内部的な高さ(body)( internal height of webBrowser1 component ) - - private Point _preFormPos; //フォームサイズ変更前の位置を一時保存 ( Temporary form position before resizing form ) - private Size _preFormSize; //フォームサイズ変更前のサイズを一時保存 ( Temporay form size before resizing form ) - - private bool _fNoTitle = true; //無題のまま編集中かどうか ( no name of file flag ) - private string _MarkDownTextFilePath = ""; //編集中のMDファイルパス ( Editing .MD file path ) - private string _TemporaryHtmlFilePath = ""; //プレビュー用のテンポラリHTMLファイルパス ( Temporary HTML file path for preview ) - private string _SelectedCssFilePath = ""; //選択中のCSSファイルパス ( Applying CSS file path ) - private Encoding _EditingFileEncoding = Encoding.UTF8; //編集中MDファイルの文字エンコーディング ( Character encoding of MD file editing ) - - private bool _fConstraintChange = true; //更新状態の抑制 ( Constraint changing flag ) - private List _MarkdownSyntaxKeywordAarray = new List(); // Array of MarkdownSyntaxKeyword Class - private ArrayList _SyntaxArrayList = new ArrayList(); - - //----------------------------------- - // コンストラクタ ( Constructor ) - //----------------------------------- - public Form1() - { - - - InitializeComponent(); - - //IME Handler On/Off - if (MarkDownSharpEditor.AppSettings.Instance.Lang == "ja") - { - richTextBox1.IMEWorkaroundEnabled = true; - } - else - { - richTextBox1.IMEWorkaroundEnabled = false; - } - - this.richTextBox1.DragEnter += new System.Windows.Forms.DragEventHandler(this.richTextBox1_DragEnter); - this.richTextBox1.DragDrop += new System.Windows.Forms.DragEventHandler(this.richTextBox1_DragDrop); - richTextBox1.AllowDrop = true; - - //設定を読み込む ( Read options ) - //Program.csで読み込むようにした ( Load in "Program.cs" ) - //MarkDownSharpEditor.AppSettings.Instance.ReadFromXMLFile(); - - //WebBrowserClickSoundOFF(); +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.IO; +using System.Collections; +using System.Security.Cryptography; +using System.Text.RegularExpressions; +using System.Diagnostics; +using System.Runtime.InteropServices; +using System.Windows.Documents; +using MarkDownSharpEditor.Properties; +using mshtml; + +namespace MarkDownSharpEditor +{ + + public partial class Form1 : Form + { + //----------------------------------- + // WebBrowserコンポーネントプレビューの更新音(クリック音)をOFFにする + // Click sound off when webBrowser component preview + const int FEATURE_DISABLE_NAVIGATION_SOUNDS = 21; + const int SET_FEATURE_ON_PROCESS = 0x00000002; + [DllImport("urlmon.dll")] + [PreserveSig] + [return: MarshalAs(UnmanagedType.Error)] + static extern int CoInternetSetFeatureEnabled(int FeatureEntry, [MarshalAs(UnmanagedType.U4)] int dwFlags, bool fEnable); + + //----------------------------------- + int undoCounter = 0; // Undo buffer counter + List UndoBuffer = new List(); + private bool _fSearchStart = false; //検索を開始したか ( Start search flag ) + private int _richEditBoxInternalHeight; //richTextBox1の内部的な高さ ( internal height of richTextBox1 component ) + private int _WebBrowserInternalHeight; //webBrowser1の内部的な高さ(body)( internal height of webBrowser1 component ) + + private Point _preFormPos; //フォームサイズ変更前の位置を一時保存 ( Temporary form position before resizing form ) + private Size _preFormSize; //フォームサイズ変更前のサイズを一時保存 ( Temporay form size before resizing form ) + + private bool _fNoTitle = true; //無題のまま編集中かどうか ( no name of file flag ) + private string _MarkDownTextFilePath = ""; //編集中のMDファイルパス ( Editing .MD file path ) + private string _TemporaryHtmlFilePath = ""; //プレビュー用のテンポラリHTMLファイルパス ( Temporary HTML file path for preview ) + private string _SelectedCssFilePath = ""; //選択中のCSSファイルパス ( Applying CSS file path ) + private Encoding _EditingFileEncoding = Encoding.UTF8; //編集中MDファイルの文字エンコーディング ( Character encoding of MD file editing ) + + private bool _fConstraintChange = true; //更新状態の抑制 ( Constraint changing flag ) + private List _MarkdownSyntaxKeywordAarray = new List(); // Array of MarkdownSyntaxKeyword Class + private ArrayList _SyntaxArrayList = new ArrayList(); + + //----------------------------------- + // コンストラクタ ( Constructor ) + //----------------------------------- + public Form1() + { + + + InitializeComponent(); + + //IME Handler On/Off + if (MarkDownSharpEditor.AppSettings.Instance.Lang == "ja") + { + richTextBox1.IMEWorkaroundEnabled = true; + } + else + { + richTextBox1.IMEWorkaroundEnabled = false; + } + + this.richTextBox1.DragEnter += new System.Windows.Forms.DragEventHandler(this.richTextBox1_DragEnter); + this.richTextBox1.DragDrop += new System.Windows.Forms.DragEventHandler(this.richTextBox1_DragDrop); + richTextBox1.AllowDrop = true; + + //設定を読み込む ( Read options ) + //Program.csで読み込むようにした ( Load in "Program.cs" ) + //MarkDownSharpEditor.AppSettings.Instance.ReadFromXMLFile(); + + //WebBrowserClickSoundOFF(); CoInternetSetFeatureEnabled(FEATURE_DISABLE_NAVIGATION_SOUNDS, SET_FEATURE_ON_PROCESS, true); - - - } - - //---------------------------------------------------------------------- - // フォームをロード ( Load main form ) - //---------------------------------------------------------------------- - private void Form1_Load(object sender, EventArgs e) - { - - var obj = MarkDownSharpEditor.AppSettings.Instance; - - //----------------------------------- - //フォーム位置・サイズ ( Form position & size ) - //----------------------------------- - - this.Location = obj.FormPos; - this.Size = obj.FormSize; - this.richTextBox1.Width = obj.richEditWidth; - - //ウィンドウ位置の調整(へんなところに行かないように戻す) - // Ajust window position ( Set position into Desktop range ) - if (this.Left < 0 || this.Left > Screen.PrimaryScreen.Bounds.Width) - { - this.Left = 0; - } - if (this.Top < 0 || this.Top > Screen.PrimaryScreen.Bounds.Height) - { - this.Top = 0; - } - - if (obj.FormState == 1) - { //最小化 ( Minimize ) - this.WindowState = FormWindowState.Minimized; - } - else if (obj.FormState == 2) - { //最大化 ( Maximize ) - this.WindowState = FormWindowState.Maximized; - } - - //メインメニュー表示 - //View main menu - this.menuViewToolBar.Checked = obj.fViewToolBar; - this.toolStrip1.Visible = obj.fViewToolBar; - this.menuViewStatusBar.Checked = obj.fViewStatusBar; - this.statusStrip1.Visible = obj.fViewStatusBar; - this.menuViewWidthEvenly.Checked = obj.fSplitBarWidthEvenly; - - //言語 ( Language ) - if (obj.Lang == "ja") - { - menuViewJapanese.Checked = true; - menuViewEnglish.Checked = false; - } - else - { - menuViewJapanese.Checked = false; - menuViewEnglish.Checked = true; - } - - //ブラウザープレビューまでの間隔 - //Interval time of browser preview - if (obj.AutoBrowserPreviewInterval > 0) - { - timer1.Interval = obj.AutoBrowserPreviewInterval; - } - - //----------------------------------- - //RichEditBox font - FontConverter fc = new FontConverter(); - try { richTextBox1.Font = (Font)fc.ConvertFromString(obj.FontFormat); } - catch { } - //RichEditBox font color - richTextBox1.ForeColor = Color.FromArgb(obj.richEditForeColor); - //ステータスバーに表示 - //View in statusbar - toolStripStatusLabelFontInfo.Text = - richTextBox1.Font.Name + "," + richTextBox1.Font.Size.ToString() + "pt"; - - //エディターのシンタックスハイライター設定の反映 - //Syntax highlighter of editor window is enabled - _MarkdownSyntaxKeywordAarray = MarkdownSyntaxKeyword.CreateKeywordList(); - - //----------------------------------- - //選択中のエンコーディングを表示 - //View selected character encoding name - foreach (EncodingInfo ei in Encoding.GetEncodings()) - { - if (ei.GetEncoding().IsBrowserDisplay == true) - { - if (ei.CodePage == obj.CodePageNumber) - { - toolStripStatusLabelHtmlEncoding.Text = ei.DisplayName; - break; - } - } - } - - //----------------------------------- - //指定されたCSSファイル名を表示 - //View selected CSS file name - toolStripStatusLabelCssFileName.Text = Resources.toolTipCssFileName; //"CSSファイル指定なし"; ( No CSS file ) - - if (obj.ArrayCssFileList.Count > 0) - { - string FilePath = (string)obj.ArrayCssFileList[0]; - if (File.Exists(FilePath) == true) - { - toolStripStatusLabelCssFileName.Text = Path.GetFileName(FilePath); - _SelectedCssFilePath = FilePath; - } - } - - //----------------------------------- - //出力するHTMLエンコーディング表示 - //View HTML charcter encoding name for output - if (obj.HtmlEncodingOption == 0) - { - // 編集中(RichEditBox側)のエンコーディング - // 基本的にはテキストファイルが読み込まれたときに表示する - // View encoding name of editor window - toolStripStatusLabelHtmlEncoding.Text = _EditingFileEncoding.EncodingName; - } - else - { - //エンコーディングを指定する(&C) - //Select encoding - Encoding enc = Encoding.GetEncoding(obj.CodePageNumber); - toolStripStatusLabelHtmlEncoding.Text = enc.EncodingName; - } - - //----------------------------------- - //検索フォーム・オプション - //Search form options + + + } + + //---------------------------------------------------------------------- + // フォームをロード ( Load main form ) + //---------------------------------------------------------------------- + private void Form1_Load(object sender, EventArgs e) + { + + var obj = MarkDownSharpEditor.AppSettings.Instance; + + //----------------------------------- + //フォーム位置・サイズ ( Form position & size ) + //----------------------------------- + + this.Location = obj.FormPos; + this.Size = obj.FormSize; + this.richTextBox1.Width = obj.richEditWidth; + + //ウィンドウ位置の調整(へんなところに行かないように戻す) + // Ajust window position ( Set position into Desktop range ) + if (this.Left < 0 || this.Left > Screen.PrimaryScreen.Bounds.Width) + { + this.Left = 0; + } + if (this.Top < 0 || this.Top > Screen.PrimaryScreen.Bounds.Height) + { + this.Top = 0; + } + + if (obj.FormState == 1) + { //最小化 ( Minimize ) + this.WindowState = FormWindowState.Minimized; + } + else if (obj.FormState == 2) + { //最大化 ( Maximize ) + this.WindowState = FormWindowState.Maximized; + } + + //メインメニュー表示 + //View main menu + this.menuViewToolBar.Checked = obj.fViewToolBar; + this.toolStrip1.Visible = obj.fViewToolBar; + this.menuViewStatusBar.Checked = obj.fViewStatusBar; + this.statusStrip1.Visible = obj.fViewStatusBar; + this.menuViewWidthEvenly.Checked = obj.fSplitBarWidthEvenly; + + //言語 ( Language ) + if (obj.Lang == "ja") + { + menuViewJapanese.Checked = true; + menuViewEnglish.Checked = false; + } + else + { + menuViewJapanese.Checked = false; + menuViewEnglish.Checked = true; + } + + //ブラウザープレビューまでの間隔 + //Interval time of browser preview + if (obj.AutoBrowserPreviewInterval > 0) + { + timer1.Interval = obj.AutoBrowserPreviewInterval; + } + + //----------------------------------- + //RichEditBox font + FontConverter fc = new FontConverter(); + try { richTextBox1.Font = (Font)fc.ConvertFromString(obj.FontFormat); } + catch { } + //RichEditBox font color + richTextBox1.ForeColor = Color.FromArgb(obj.richEditForeColor); + //ステータスバーに表示 + //View in statusbar + toolStripStatusLabelFontInfo.Text = + richTextBox1.Font.Name + "," + richTextBox1.Font.Size.ToString() + "pt"; + + //エディターのシンタックスハイライター設定の反映 + //Syntax highlighter of editor window is enabled + _MarkdownSyntaxKeywordAarray = MarkdownSyntaxKeyword.CreateKeywordList(); + + //----------------------------------- + //選択中のエンコーディングを表示 + //View selected character encoding name + foreach (EncodingInfo ei in Encoding.GetEncodings()) + { + if (ei.GetEncoding().IsBrowserDisplay == true) + { + if (ei.CodePage == obj.CodePageNumber) + { + toolStripStatusLabelHtmlEncoding.Text = ei.DisplayName; + break; + } + } + } + + //----------------------------------- + //指定されたCSSファイル名を表示 + //View selected CSS file name + toolStripStatusLabelCssFileName.Text = Resources.toolTipCssFileName; //"CSSファイル指定なし"; ( No CSS file ) + + if (obj.ArrayCssFileList.Count > 0) + { + string FilePath = (string)obj.ArrayCssFileList[0]; + if (File.Exists(FilePath) == true) + { + toolStripStatusLabelCssFileName.Text = Path.GetFileName(FilePath); + _SelectedCssFilePath = FilePath; + } + } + + //----------------------------------- + //出力するHTMLエンコーディング表示 + //View HTML charcter encoding name for output + if (obj.HtmlEncodingOption == 0) + { + // 編集中(RichEditBox側)のエンコーディング + // 基本的にはテキストファイルが読み込まれたときに表示する + // View encoding name of editor window + toolStripStatusLabelHtmlEncoding.Text = _EditingFileEncoding.EncodingName; + } + else + { + //エンコーディングを指定する(&C) + //Select encoding + Encoding enc = Encoding.GetEncoding(obj.CodePageNumber); + toolStripStatusLabelHtmlEncoding.Text = enc.EncodingName; + } + + //----------------------------------- + //検索フォーム・オプション + //Search form options chkOptionCase.Checked = obj.fSearchOptionIgnoreCase ? false : true; - - - } - - //---------------------------------------------------------------------- - // フォームを表示 - // View Main form - //---------------------------------------------------------------------- - private void Form1_Shown(object sender, EventArgs e) - { - - string DirPath = MarkDownSharpEditor.AppSettings.GetAppDataLocalPath(); - - ArrayList FileArray = new ArrayList(); - - //TODO: 「新しいウィンドウで開く」="/new"などの引数も含まれるので、 - // その辺りの処理も将来的に入れる。 - - //コマンドラインでファイルが投げ込まれてきている - //Launch with arguments - string[] cmds = System.Environment.GetCommandLineArgs(); - for (int i = 1; i < cmds.Count(); i++) - { - if (File.Exists(cmds[i]) == true) - { - FileArray.Add(cmds[i]); - } - } - - try - { - if (FileArray.Count > 1) - { //"問い合わせ" - //"複数のファイルが読み込まれました。\n現在の設定内容でHTMLファイルへの一括変換を行いますか? - //「いいえ」を選択するとそのまますべてのファイル開きます。" - //"Question" - //"More than one were read.\nDo you wish to convert all files to HTML files on this options?\n - // if you select 'No', all files will be opend without converting." - DialogResult ret = MessageBox.Show(Resources.MsgConvertAllFilesToHTML, - Resources.DialogTitleQuestion, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information); - - if (ret == DialogResult.Yes) - { //一括でHTMLファイル出力 - //Output HTML files in batch process - BatchOutputToHtmlFiles((String[])FileArray.ToArray(typeof(string))); - return; - - } - else if (ret == DialogResult.Cancel) - { //キャンセル - //Cancel - return; - } - else - { //「いいえ」 - // "NO" button - bool fOpen = false; - foreach (string FilePath in FileArray) - { //最初のファイルだけ、このウィンドウだけ開く - //First file open in this window - if (fOpen == false) - { - richTextBox1.Modified = false; - OpenFile(FilePath); - fOpen = true; - } - else - { //他の複数ファイルは順次新しいウィンドウで開く - //Other files open in new windows - System.Diagnostics.Process.Start( - Application.ExecutablePath, string.Format("{0}", FilePath)); - } - } - } - } - else if (FileArray.Count == 1) - { - richTextBox1.Modified = false; - OpenFile((string)FileArray[0]); - } - else - { //前に編集していたファイルがあればそれを開く - //Open it if there is editing file before - if (MarkDownSharpEditor.AppSettings.Instance.fOpenEditFileBefore == true) - { - if (MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Count > 0) - { - AppHistory EditedFilePath = new AppHistory(); - EditedFilePath = (AppHistory)MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles[0]; - if (File.Exists(EditedFilePath.md) == true) - { - _TemporaryHtmlFilePath = ""; - richTextBox1.Modified = false; - OpenFile(EditedFilePath.md); - return; - } - } - } - if (_MarkDownTextFilePath == "") - { //無ければ「無題」ファイル - // "No title" if no file exists - richTextBox1.Modified = false; - OpenFile(""); - } - } - } - finally - { - _fConstraintChange = false; - //SyntaxHighlighter - if (backgroundWorker2.IsBusy == false) - { - //backgroundWorker2.WorkerReportsProgress = true; - backgroundWorker2.RunWorkerAsync(richTextBox1.Text); - } - richTextBox1.Modified = false; - //フォームタイトル更新 / Refresh form caption - FormTextChange(); - } - } - - - - //---------------------------------------------------------------------- - // フォームタイトルの表示(更新) - // Refresh form caption - //---------------------------------------------------------------------- - private void FormTextChange() - { - string FileName; - if (_fNoTitle == true) - { - FileName = Resources.NoFileName; //"(無題)" "(No title)" - } - else - { - //FileName = System.IO.Path.GetFileName(_MarkDownTextFilePath); - FileName = _MarkDownTextFilePath; - } - - if (richTextBox1.Modified == true) - { - FileName = FileName + Resources.FlagChanged; //"(更新)"; "(Changed)" - } - this.Text = FileName + " - " + Application.ProductName; - } - - //---------------------------------------------------------------------- - // 見出しリストメニューの表示 - //---------------------------------------------------------------------- - private void mnuShowHeaderListMenu_Click(object sender, EventArgs e) - { - ShowHeaderListContextMenu(); - } - - //---------------------------------------------------------------------- - // 見出しリストメニューの表示 - //---------------------------------------------------------------------- - - void ShowHeaderListContextMenu() - { - - int retCode; - - //Markdown - object[][] mkObject = { - new object[2] { 1, @"^#[^#]*?$" }, //見出し1 (headline1) - new object[2] { 1, @"^.*\n=+$" }, //見出し1 (headline1) - new object[2] { 2, @"^##[^#]*?$" }, //見出し2 (headline2) - new object[2] { 2, @"^.+\n-+$" }, //見出し2 (headline2) - new object[2] { 3, @"^###[^#]*?$" }, //見出し3 (headline3) - new object[2] { 4, @"^####[^#]*?$" }, //見出し4 (headline4) - new object[2] { 5, @"^#####[^#]*?$" }, //見出し5 (headline5) - new object[2] { 6, @"^######[^#]*?$"} //見出し6 (headline6) - }; - - //コンテキストメニュー項目を初期化(クリア) - //Clear context menus - contextMenu2.Items.Clear(); - - bool fModify = richTextBox1.Modified; - _fConstraintChange = true; - - //現在のカーソル位置 - //Current cursor position - int selectStart = this.richTextBox1.SelectionStart; - int selectEnd = richTextBox1.SelectionLength; - Point CurrentOffset = richTextBox1.AutoScrollOffset; - - //現在のスクロール位置 - //Current scroll position - int CurrentScrollPos = richTextBox1.VerticalPosition; - //描画停止 - //Stop to update - richTextBox1.BeginUpdate(); - - for (int i = 0; i < mkObject.Length; i++) - { - - Regex r = new Regex((string)mkObject[i][1], RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Compiled); - MatchCollection col = r.Matches(richTextBox1.Text, 0); - - if (col.Count > 0) - { - foreach (Match m in col) - { - int IndexNum = m.Groups[0].Index; - string title = new String(' ', (int)mkObject[i][0]) + richTextBox1.Text.Substring(m.Groups[0].Index, m.Groups[0].Length); - - if ((retCode = title.LastIndexOf("\n")) > -1) - { - title = title.Substring(0, title.LastIndexOf("\n")); - } - - //コンテキストメニューに登録 - //Regist item to context menus - bool fAdd = false; - ToolStripMenuItem item = new ToolStripMenuItem(); - for (int c = 0; c < contextMenu2.Items.Count; c++) - { - //登録されている項目よりも前の項目のときは挿入する - //Insert item to registed items - if (IndexNum < (int)contextMenu2.Items[c].Tag) - { - item.Text = title; - item.Tag = IndexNum; - contextMenu2.Items.Insert(c, item); - fAdd = true; - break; - } - } - if (fAdd == false) - { - item.Text = title; - item.Tag = IndexNum; - contextMenu2.Items.Add(item); - } - } - } - } - - //カーソル位置を戻す - //Restore cursor position - richTextBox1.Select(selectStart, selectEnd); - richTextBox1.AutoScrollOffset = CurrentOffset; - - //描画再開 - //Resume to update - richTextBox1.EndUpdate(); - richTextBox1.Modified = fModify; - - _fConstraintChange = false; - - //richTextBox1のキャレット位置 - //Curret position in richTextBox1 - Point pt = richTextBox1.GetPositionFromCharIndex(richTextBox1.SelectionStart); - //スクリーン座標に変換 - //Convert the position to screen position - pt = richTextBox1.PointToScreen(pt); - //コンテキストメニューを表示 - //View context menus - contextMenu2.Show(pt); - - } - - //---------------------------------------------------------------------- - // 見出しメニュークリックイベント - // Click event in context menus - //---------------------------------------------------------------------- - private void contextMenu2_ItemClicked(object sender, ToolStripItemClickedEventArgs e) - { - - if ((int)e.ClickedItem.Tag > 0) - { - richTextBox1.SelectionStart = (int)e.ClickedItem.Tag; - richTextBox1.ScrollToCaret(); - } - - } - - //---------------------------------------------------------------------- - // HACK: RichTextBox内容変更 [ シンタックス・ハイライター表示)] - // Apply richTextBox1 to syntax highlight with changing - //---------------------------------------------------------------------- - private void richTextBox1_TextChanged(object sender, EventArgs e) - { - - if (_fConstraintChange == true) - { - return; - } - - if (backgroundWorker2.IsBusy == false) - { - //バックグラウンドワーカーへパースを投げる / SyntaxHightlighter on BackgroundWorker - backgroundWorker2.RunWorkerAsync(richTextBox1.Text); - } - - //----------------------------------- - //Formキャプション変更 / Change form caption - FormTextChange(); - - //----------------------------------- - //ブラウザプレビュー制御 / Preview webBrowser component - if (MarkDownSharpEditor.AppSettings.Instance.fAutoBrowserPreview == true) - { - timer1.Enabled = true; - } - - } - - //---------------------------------------------------------------------- - // RichTextBox Key Press - //---------------------------------------------------------------------- - private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e) - { - //----------------------------------- - // Add undo buffer - //----------------------------------- - - //現在のUndoCounterから先を削除 - //Remove first item of undo counter - if (undoCounter < UndoBuffer.Count) - { - UndoBuffer.RemoveRange(undoCounter, UndoBuffer.Count - undoCounter); - } - - UndoBuffer.Add(richTextBox1.Rtf); - undoCounter = UndoBuffer.Count; - - //EnterやEscapeキーでビープ音が鳴らないようにする - //Stop to beep in Enter & Escape key - if (e.KeyChar == (char)Keys.Enter || e.KeyChar == (char)Keys.Escape) - { - e.Handled = true; - } - - timer2.Enabled = true; - - } - - //---------------------------------------------------------------------- - // RichTextBox VScroll event - //---------------------------------------------------------------------- - private void richTextBox1_VScroll(object sender, EventArgs e) - { - if (_fConstraintChange == false) - { - WebBrowserMoveCursor(); - } - } - - //---------------------------------------------------------------------- - // RichTextBox Enter event - //---------------------------------------------------------------------- - private void richTextBox1_Enter(object sender, EventArgs e) - { - //ブラウザプレビュー制御 / Preview webBrowser component - if (MarkDownSharpEditor.AppSettings.Instance.fAutoBrowserPreview == true) - { - timer1.Enabled = true; - } - } - - //---------------------------------------------------------------------- - // RichTextBox Mouse click - //---------------------------------------------------------------------- - private void richTextBox1_MouseClick(object sender, MouseEventArgs e) - { - - //timer1.Enabled = true; - - } - - //---------------------------------------------------------------------- - // Form Closing event - //---------------------------------------------------------------------- - private void Form1_FormClosing(object sender, FormClosingEventArgs e) - { - if (richTextBox1.Modified == true) - { - //"問い合わせ" - //"編集中のファイルがあります。保存してから終了しますか?" - //"Question" - //"This file being edited. Do you wish to save before exiting?" - DialogResult ret = MessageBox.Show(Resources.MsgSaveFileToEnd, - Resources.DialogTitleQuestion, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); - - if (ret == DialogResult.Yes) - { - if (SaveToEditingFile() == true) - { - _fNoTitle = false; - } - else - { - //キャンセルで抜けてきた - //user cancel - e.Cancel = true; - return; - } - } - else if (ret == DialogResult.Cancel) - { - e.Cancel = true; - return; - } - } - - _fConstraintChange = true; - - //無題ファイルのまま編集しているのなら削除 - //Delete file if the file is no title - if (_fNoTitle == true) - { - if (File.Exists(_MarkDownTextFilePath) == true) - { - try - { - File.Delete(_MarkDownTextFilePath); - } - catch - { - } - } - } - - //データバージョン - //Data version - System.Reflection.Assembly asmbly = System.Reflection.Assembly.GetExecutingAssembly(); - System.Version ver = asmbly.GetName().Version; - MarkDownSharpEditor.AppSettings.Instance.Version = ver.Major * 1000 + ver.Minor * 100 + ver.Build * 10 + ver.Revision; - - //フォーム位置・サイズ ( Form position & size ) - if (this.WindowState == FormWindowState.Minimized) - { //最小化 ( Minimize ) - MarkDownSharpEditor.AppSettings.Instance.FormState = 1; - //一時記憶していた位置・サイズを保存 ( Save temporary position & size value ) - MarkDownSharpEditor.AppSettings.Instance.FormPos = new Point(_preFormPos.X, _preFormPos.Y); - MarkDownSharpEditor.AppSettings.Instance.FormSize = new Size(_preFormSize.Width, _preFormSize.Height); - } - else if (this.WindowState == FormWindowState.Maximized) - { //最大化 ( Maximize ) - MarkDownSharpEditor.AppSettings.Instance.FormState = 2; - //一時記憶していた位置・サイズを保存 ( Save temporary position & size value ) - MarkDownSharpEditor.AppSettings.Instance.FormPos = new Point(_preFormPos.X, _preFormPos.Y); - MarkDownSharpEditor.AppSettings.Instance.FormSize = new Size(_preFormSize.Width, _preFormSize.Height); - } - else - { //通常 ( Normal window ) - MarkDownSharpEditor.AppSettings.Instance.FormState = 0; - MarkDownSharpEditor.AppSettings.Instance.FormPos = new Point(this.Left, this.Top); - MarkDownSharpEditor.AppSettings.Instance.FormSize = new Size(this.Width, this.Height); - } - - MarkDownSharpEditor.AppSettings.Instance.richEditWidth = this.richTextBox1.Width; - FontConverter fc = new FontConverter(); - MarkDownSharpEditor.AppSettings.Instance.FontFormat = fc.ConvertToString(richTextBox1.Font); - MarkDownSharpEditor.AppSettings.Instance.richEditForeColor = richTextBox1.ForeColor.ToArgb(); - - //表示オプションなど - //Save view options etc - MarkDownSharpEditor.AppSettings.Instance.fViewToolBar = this.menuViewToolBar.Checked; - MarkDownSharpEditor.AppSettings.Instance.fViewStatusBar = this.menuViewStatusBar.Checked; - MarkDownSharpEditor.AppSettings.Instance.fSplitBarWidthEvenly = this.menuViewWidthEvenly.Checked; - - //検索オプション - //Save search options - MarkDownSharpEditor.AppSettings.Instance.fSearchOptionIgnoreCase = chkOptionCase.Checked ? false : true; - - if (File.Exists(_MarkDownTextFilePath) == true) - { - //編集中のファイルパス - //Save editing file path - foreach (AppHistory data in MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles) - { - if (data.md == _MarkDownTextFilePath) - { //いったん削除して ( delete once ... ) - MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Remove(data); - break; - } - } - AppHistory HistroyData = new AppHistory(); - HistroyData.md = _MarkDownTextFilePath; - HistroyData.css = _SelectedCssFilePath; - MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Insert(0, HistroyData); //先頭に挿入 ( Insert at the top ) - } - - //設定の保存 - //Save settings - MarkDownSharpEditor.AppSettings.Instance.SaveToXMLFile(); - //MarkDownSharpEditor.AppSettings.Instance.SaveToJsonFile(); - - timer1.Enabled = false; - - //webBrowser1.Navigate("about:blank"); - //クリック音対策 - //Constraint click sounds - if (webBrowser1.Document != null) - { - webBrowser1.Document.OpenNew(true); - webBrowser1.Document.Write(""); - } - } - - //----------------------------------- - // Form closed event - //----------------------------------- - private void Form1_FormClosed(object sender, FormClosedEventArgs e) - { - //テンポラリファイルの削除 - //Delete temporary files - Delete_TemporaryHtmlFilePath(); - } - - //----------------------------------- - // Form resize begin event - //----------------------------------- - private void Form1_ResizeBegin(object sender, EventArgs e) - { - //リサイズ前の位置・サイズを一時記憶 - _preFormPos.X = this.Left; - _preFormPos.Y = this.Top; - _preFormSize.Width = this.Width; - _preFormSize.Height = this.Height; - } - - //----------------------------------- - // Form resize end event - //----------------------------------- - private void Form1_ResizeEnd(object sender, EventArgs e) - { - //ソースウィンドウとビューウィンドウを均等にするか - //Equalize width of source window and view window - if (menuViewWidthEvenly.Checked == true) - { - this.richTextBox1.Width = - (splitContainer1.Width - splitContainer1.SplitterWidth) / 2; - } - } - - //----------------------------------- - // richTextBox1 DragEnter event - //----------------------------------- - private void richTextBox1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e) - { - if (e.Data.GetDataPresent(DataFormats.FileDrop) == true) - { - e.Effect = DragDropEffects.Copy; - } - else - { - e.Effect = DragDropEffects.None; - } - } - - //----------------------------------- - // richTextBox1 Drag and Drop event - //----------------------------------- - private void richTextBox1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) - { - string[] FileArray = (string[])e.Data.GetData(DataFormats.FileDrop, false); - if (FileArray.Length > 1) - { - if (FileArray.Length > 0) - { - //"問い合わせ" - //"複数のファイルが読み込まれました。\n現在の設定内容でHTMLファイルへの一括変換を行いますか? - //「いいえ」を選択するとそのまますべてのファイル開きます。" - //"Question" - //"More than one were read.\nDo you wish to convert all files to HTML files on this options?\n - // if you select 'No', all files will be opend without converting." - DialogResult ret = MessageBox.Show("MsgConvertAllFilesToHTML", - Resources.DialogTitleQuestion, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information); - - if (ret == DialogResult.Yes) - { - //一括でHTMLファイル出力 - //Output HTML files in batch process - BatchOutputToHtmlFiles(FileArray); - return; - - } - else if (ret == DialogResult.Cancel) - { - //キャンセル - //Cancel - return; - } - else - { //「いいえ」 - // "No" button - bool fOpen = false; - foreach (string FilePath in FileArray) - { - //最初のファイルだけ、このウィンドウだけ開く - //First file open in this window - if (fOpen == false) - { - OpenFile(FilePath); - fOpen = true; - } - else - { - //他の複数ファイルは順次新しいウィンドウで開く - //Other files open in new windows - System.Diagnostics.Process.Start( - Application.ExecutablePath, string.Format("{0}", FilePath)); - } - } - } - } - else - { - //前に編集していたファイルがあればそれを開く - //Open it if there is editing file before - if (MarkDownSharpEditor.AppSettings.Instance.fOpenEditFileBefore == true) - { - if (MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Count > 0) - { - AppHistory EditedFilePath = new AppHistory(); - EditedFilePath = (AppHistory)MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles[0]; - - if (File.Exists(EditedFilePath.md) == true) - { - OpenFile(EditedFilePath.md); - } - } - } - } - _fConstraintChange = false; - //フォームタイトル更新 - //Refresh form caption - FormTextChange(); - - ArrayList ArrayFileList = new ArrayList(); - foreach (string FilePath in FileArray) - { - ArrayFileList.Add(FilePath); - } - - BatchOutputToHtmlFiles((String[])ArrayFileList.ToArray(typeof(string))); - - } - else if (FileArray.Count() == 1) - { - //ファイルが一個の場合は編集中のウィンドウで開く - //Open it in this window if file is one - OpenFile(FileArray[0]); - } - } - - //---------------------------------------------------------------------- - // OpenFile [ .mdファイルを開く ] - //---------------------------------------------------------------------- - private bool OpenFile(string FilePath, bool fOpenDialog = false) - { - //引数 FilePath = "" の場合は「無題」編集で開始する - // Argument "FilePath" = "" => Start editing in 'no title' - - if (FilePath == "") - { - _fNoTitle = true; // No title flag - } - else - { - _fNoTitle = false; - } - - //----------------------------------- - //編集中のファイルがある - if (richTextBox1.Modified == true) - { - //"問い合わせ" - //"編集中のファイルがあります。保存してから終了しますか?" - //"Question" - //"This file being edited. Do you wish to save before exiting?" - DialogResult ret = MessageBox.Show(Resources.MsgSaveFileToEnd, - Resources.DialogTitleQuestion, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); - if (ret == DialogResult.Yes) - { - if (SaveToEditingFile() == false) - { - //キャンセルで抜けてきた - //Cancel - return (false); - } - } - else if (ret == DialogResult.Cancel) - { - return (false); - } - - //編集履歴に残す - //Save file path to editing history - foreach (AppHistory data in MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles) - { - if (data.md == _MarkDownTextFilePath) - { //いったん削除して ( delete once ... ) - MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Remove(data); - break; - } - } - AppHistory HistroyData = new AppHistory(); - HistroyData.md = _MarkDownTextFilePath; - HistroyData.css = _SelectedCssFilePath; - MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Insert(0, HistroyData); //先頭に挿入 ( Insert at the top ) - } - - //----------------------------------- - //オープンダイアログ表示 - //View open file dialog - if (fOpenDialog == true) - { - if (File.Exists(_MarkDownTextFilePath) == true) - { //編集中のファイルがあればそのディレクトリを初期フォルダーに - //Set parent directory of editing file to initial folder - openFileDialog1.InitialDirectory = Path.GetDirectoryName(_MarkDownTextFilePath); - //テンポラリファイルがあればここで削除 - //Delete it if temporary file exists - Delete_TemporaryHtmlFilePath(); - } - openFileDialog1.FileName = ""; - if (openFileDialog1.ShowDialog() == DialogResult.OK) - { - FilePath = openFileDialog1.FileName; - _fNoTitle = false; - } - else - { - return (false); - } - } - - //編集中のファイルパスとする - //Set this file to 'editing file' path - _MarkDownTextFilePath = FilePath; - - //----------------------------------- - //文字コードを調査するためにテキストファイルを開く - //Detect encoding - if (_fNoTitle == false) - { - byte[] bs; - using (FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read)) - { - bs = new byte[fs.Length]; - fs.Read(bs, 0, bs.Length); - } - //文字コードを取得する - //Get charcter encoding - _EditingFileEncoding = GetCode(bs); - } - else - { - //「無題」はデフォルトのエンコーディング - // Set this file to default encoding in 'No title' - _EditingFileEncoding = Encoding.UTF8; - } - - //ステータスバーに表示 - //View in statusbar - toolStripStatusLabelTextEncoding.Text = _EditingFileEncoding.EncodingName; - //編集中のエンコーディングを使用する(&D)か - //Use encoding of editing file - if (MarkDownSharpEditor.AppSettings.Instance.HtmlEncodingOption == 0) - { - toolStripStatusLabelHtmlEncoding.Text = _EditingFileEncoding.EncodingName; - } - - //----------------------------------- - //ペアとなるCSSファイルがあるか探索してあれば適用する - //Apply that the pair CSS file to this file exists - foreach (AppHistory data in MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles) - { - if (data.md == _MarkDownTextFilePath) - { - if (File.Exists(data.css) == true) - { - _SelectedCssFilePath = data.css; - break; - } - } - } - - //選択中のCSSファイル名をステータスバーに表示 - //View selected CSS file name to stausbar - if (File.Exists(_SelectedCssFilePath) == true) - { - toolStripStatusLabelCssFileName.Text = Path.GetFileName(_SelectedCssFilePath); - } - else - { - toolStripStatusLabelCssFileName.Text = Resources.toolTipCssFileName; //"CSSファイル指定なし"; ( not selected CSS file) - } - - _fConstraintChange = true; - richTextBox1.Clear(); - - //RichEditBoxの「フォント」設定 - // richTextBox1 font name setting - var obj = MarkDownSharpEditor.AppSettings.Instance; - FontConverter fc = new FontConverter(); - try { richTextBox1.Font = (Font)fc.ConvertFromString(obj.FontFormat); } - catch { } - //RichEditBoxの「フォントカラー」設定 - // richTextBox1 font color setting - richTextBox1.ForeColor = Color.FromArgb(obj.richEditForeColor); - //View them in statusbar - toolStripStatusLabelFontInfo.Text = richTextBox1.Font.Name + "," + richTextBox1.Font.Size.ToString() + "pt"; - - //----------------------------------- - //テキストファイルの読み込み - //Read text file - if (File.Exists(FilePath) == true) - { - richTextBox1.Text = File.ReadAllText(FilePath, _EditingFileEncoding); - } - richTextBox1.BeginUpdate(); - richTextBox1.SelectionStart = richTextBox1.Text.Length; - richTextBox1.ScrollToCaret(); - //richTextBox1の全高さを求める - //Get height of richTextBox1 ( for webBrowser sync ) - _richEditBoxInternalHeight = richTextBox1.VerticalPosition; - //カーソル位置を戻す - //Restore cursor position - richTextBox1.SelectionStart = 0; - richTextBox1.EndUpdate(); - - //変更フラグOFF - richTextBox1.Modified = false; - - //Undoバッファに追加 - //Add all text to undo buffer - UndoBuffer.Clear(); - UndoBuffer.Add(richTextBox1.Rtf); - undoCounter = UndoBuffer.Count; - - //プレビュー更新 - PreviewToBrowser(); - - _fConstraintChange = false; - FormTextChange(); - - return (true); - - } - - //---------------------------------------------------------------------- - // 表示するHTMLのテンポラリファイルパスを取得する - // Get temporary HTML file path - //---------------------------------------------------------------------- - private string Get_TemporaryHtmlFilePath(string FilePath) - { - string DirPath = Path.GetDirectoryName(FilePath); - string FileName = Path.GetFileNameWithoutExtension(FilePath); - - MD5 md5Hash = MD5.Create(); - byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(FileName)); - StringBuilder sBuilder = new StringBuilder(); - for (int i = 0; i < data.Length; i++) - { - sBuilder.Append(data[i].ToString("x2")); - } - return (Path.Combine(DirPath, FileName + "_" + sBuilder.ToString() + ".html")); - } - - //---------------------------------------------------------------------- - // 表示しているHTMLのテンポラリファイルを削除する - // Delete temporary HTML file - //---------------------------------------------------------------------- - private void Delete_TemporaryHtmlFilePath() - { - string TempHtmlFilePath; - - if (_MarkDownTextFilePath == "") - { - return; - } - - TempHtmlFilePath = Get_TemporaryHtmlFilePath(_MarkDownTextFilePath); - //見つかったときだけ削除 - //Delete it if the file exists - if (File.Exists(TempHtmlFilePath) == true) - { - try - { + + + } + + //---------------------------------------------------------------------- + // フォームを表示 + // View Main form + //---------------------------------------------------------------------- + private void Form1_Shown(object sender, EventArgs e) + { + + string DirPath = MarkDownSharpEditor.AppSettings.GetAppDataLocalPath(); + + ArrayList FileArray = new ArrayList(); + + //TODO: 「新しいウィンドウで開く」="/new"などの引数も含まれるので、 + // その辺りの処理も将来的に入れる。 + + //コマンドラインでファイルが投げ込まれてきている + //Launch with arguments + string[] cmds = System.Environment.GetCommandLineArgs(); + for (int i = 1; i < cmds.Count(); i++) + { + if (File.Exists(cmds[i]) == true) + { + FileArray.Add(cmds[i]); + } + } + + try + { + if (FileArray.Count > 1) + { //"問い合わせ" + //"複数のファイルが読み込まれました。\n現在の設定内容でHTMLファイルへの一括変換を行いますか? + //「いいえ」を選択するとそのまますべてのファイル開きます。" + //"Question" + //"More than one were read.\nDo you wish to convert all files to HTML files on this options?\n + // if you select 'No', all files will be opend without converting." + DialogResult ret = MessageBox.Show(Resources.MsgConvertAllFilesToHTML, + Resources.DialogTitleQuestion, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information); + + if (ret == DialogResult.Yes) + { //一括でHTMLファイル出力 + //Output HTML files in batch process + BatchOutputToHtmlFiles((String[])FileArray.ToArray(typeof(string))); + return; + + } + else if (ret == DialogResult.Cancel) + { //キャンセル + //Cancel + return; + } + else + { //「いいえ」 + // "NO" button + bool fOpen = false; + foreach (string FilePath in FileArray) + { //最初のファイルだけ、このウィンドウだけ開く + //First file open in this window + if (fOpen == false) + { + richTextBox1.Modified = false; + OpenFile(FilePath); + fOpen = true; + } + else + { //他の複数ファイルは順次新しいウィンドウで開く + //Other files open in new windows + System.Diagnostics.Process.Start( + Application.ExecutablePath, string.Format("{0}", FilePath)); + } + } + } + } + else if (FileArray.Count == 1) + { + richTextBox1.Modified = false; + OpenFile((string)FileArray[0]); + } + else + { //前に編集していたファイルがあればそれを開く + //Open it if there is editing file before + if (MarkDownSharpEditor.AppSettings.Instance.fOpenEditFileBefore == true) + { + if (MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Count > 0) + { + AppHistory EditedFilePath = new AppHistory(); + EditedFilePath = (AppHistory)MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles[0]; + if (File.Exists(EditedFilePath.md) == true) + { + _TemporaryHtmlFilePath = ""; + richTextBox1.Modified = false; + OpenFile(EditedFilePath.md); + return; + } + } + } + if (_MarkDownTextFilePath == "") + { //無ければ「無題」ファイル + // "No title" if no file exists + richTextBox1.Modified = false; + OpenFile(""); + } + } + } + finally + { + _fConstraintChange = false; + //SyntaxHighlighter + if (backgroundWorker2.IsBusy == false) + { + //backgroundWorker2.WorkerReportsProgress = true; + backgroundWorker2.RunWorkerAsync(richTextBox1.Text); + } + richTextBox1.Modified = false; + //フォームタイトル更新 / Refresh form caption + FormTextChange(); + } + } + + + + //---------------------------------------------------------------------- + // フォームタイトルの表示(更新) + // Refresh form caption + //---------------------------------------------------------------------- + private void FormTextChange() + { + string FileName; + if (_fNoTitle == true) + { + FileName = Resources.NoFileName; //"(無題)" "(No title)" + } + else + { + //FileName = System.IO.Path.GetFileName(_MarkDownTextFilePath); + FileName = _MarkDownTextFilePath; + } + + if (richTextBox1.Modified == true) + { + FileName = FileName + Resources.FlagChanged; //"(更新)"; "(Changed)" + } + this.Text = FileName + " - " + Application.ProductName; + } + + //---------------------------------------------------------------------- + // 見出しリストメニューの表示 + //---------------------------------------------------------------------- + private void mnuShowHeaderListMenu_Click(object sender, EventArgs e) + { + ShowHeaderListContextMenu(); + } + + //---------------------------------------------------------------------- + // 見出しリストメニューの表示 + //---------------------------------------------------------------------- + + void ShowHeaderListContextMenu() + { + + int retCode; + + //Markdown + object[][] mkObject = { + new object[2] { 1, @"^#[^#]*?$" }, //見出し1 (headline1) + new object[2] { 1, @"^.*\n=+$" }, //見出し1 (headline1) + new object[2] { 2, @"^##[^#]*?$" }, //見出し2 (headline2) + new object[2] { 2, @"^.+\n-+$" }, //見出し2 (headline2) + new object[2] { 3, @"^###[^#]*?$" }, //見出し3 (headline3) + new object[2] { 4, @"^####[^#]*?$" }, //見出し4 (headline4) + new object[2] { 5, @"^#####[^#]*?$" }, //見出し5 (headline5) + new object[2] { 6, @"^######[^#]*?$"} //見出し6 (headline6) + }; + + //コンテキストメニュー項目を初期化(クリア) + //Clear context menus + contextMenu2.Items.Clear(); + + bool fModify = richTextBox1.Modified; + _fConstraintChange = true; + + //現在のカーソル位置 + //Current cursor position + int selectStart = this.richTextBox1.SelectionStart; + int selectEnd = richTextBox1.SelectionLength; + Point CurrentOffset = richTextBox1.AutoScrollOffset; + + //現在のスクロール位置 + //Current scroll position + int CurrentScrollPos = richTextBox1.VerticalPosition; + //描画停止 + //Stop to update + richTextBox1.BeginUpdate(); + + for (int i = 0; i < mkObject.Length; i++) + { + + Regex r = new Regex((string)mkObject[i][1], RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Compiled); + MatchCollection col = r.Matches(richTextBox1.Text, 0); + + if (col.Count > 0) + { + foreach (Match m in col) + { + int IndexNum = m.Groups[0].Index; + string title = new String(' ', (int)mkObject[i][0]) + richTextBox1.Text.Substring(m.Groups[0].Index, m.Groups[0].Length); + + if ((retCode = title.LastIndexOf("\n")) > -1) + { + title = title.Substring(0, title.LastIndexOf("\n")); + } + + //コンテキストメニューに登録 + //Regist item to context menus + bool fAdd = false; + ToolStripMenuItem item = new ToolStripMenuItem(); + for (int c = 0; c < contextMenu2.Items.Count; c++) + { + //登録されている項目よりも前の項目のときは挿入する + //Insert item to registed items + if (IndexNum < (int)contextMenu2.Items[c].Tag) + { + item.Text = title; + item.Tag = IndexNum; + contextMenu2.Items.Insert(c, item); + fAdd = true; + break; + } + } + if (fAdd == false) + { + item.Text = title; + item.Tag = IndexNum; + contextMenu2.Items.Add(item); + } + } + } + } + + //カーソル位置を戻す + //Restore cursor position + richTextBox1.Select(selectStart, selectEnd); + richTextBox1.AutoScrollOffset = CurrentOffset; + + //描画再開 + //Resume to update + richTextBox1.EndUpdate(); + richTextBox1.Modified = fModify; + + _fConstraintChange = false; + + //richTextBox1のキャレット位置 + //Curret position in richTextBox1 + Point pt = richTextBox1.GetPositionFromCharIndex(richTextBox1.SelectionStart); + //スクリーン座標に変換 + //Convert the position to screen position + pt = richTextBox1.PointToScreen(pt); + //コンテキストメニューを表示 + //View context menus + contextMenu2.Show(pt); + + } + + //---------------------------------------------------------------------- + // 見出しメニュークリックイベント + // Click event in context menus + //---------------------------------------------------------------------- + private void contextMenu2_ItemClicked(object sender, ToolStripItemClickedEventArgs e) + { + + if ((int)e.ClickedItem.Tag > 0) + { + richTextBox1.SelectionStart = (int)e.ClickedItem.Tag; + richTextBox1.ScrollToCaret(); + } + + } + + //---------------------------------------------------------------------- + // HACK: RichTextBox内容変更 [ シンタックス・ハイライター表示)] + // Apply richTextBox1 to syntax highlight with changing + //---------------------------------------------------------------------- + private void richTextBox1_TextChanged(object sender, EventArgs e) + { + + if (_fConstraintChange == true) + { + return; + } + + if (backgroundWorker2.IsBusy == false) + { + //バックグラウンドワーカーへパースを投げる / SyntaxHightlighter on BackgroundWorker + backgroundWorker2.RunWorkerAsync(richTextBox1.Text); + } + + //----------------------------------- + //Formキャプション変更 / Change form caption + FormTextChange(); + + //----------------------------------- + //ブラウザプレビュー制御 / Preview webBrowser component + if (MarkDownSharpEditor.AppSettings.Instance.fAutoBrowserPreview == true) + { + timer1.Enabled = true; + } + + } + + //---------------------------------------------------------------------- + // RichTextBox Key Press + //---------------------------------------------------------------------- + private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e) + { + //----------------------------------- + // Add undo buffer + //----------------------------------- + + //現在のUndoCounterから先を削除 + //Remove first item of undo counter + if (undoCounter < UndoBuffer.Count) + { + UndoBuffer.RemoveRange(undoCounter, UndoBuffer.Count - undoCounter); + } + + UndoBuffer.Add(richTextBox1.Rtf); + undoCounter = UndoBuffer.Count; + + //EnterやEscapeキーでビープ音が鳴らないようにする + //Stop to beep in Enter & Escape key + if (e.KeyChar == (char)Keys.Enter || e.KeyChar == (char)Keys.Escape) + { + e.Handled = true; + } + + timer2.Enabled = true; + + } + + //---------------------------------------------------------------------- + // RichTextBox VScroll event + //---------------------------------------------------------------------- + private void richTextBox1_VScroll(object sender, EventArgs e) + { + if (_fConstraintChange == false) + { + WebBrowserMoveCursor(); + } + } + + //---------------------------------------------------------------------- + // RichTextBox Enter event + //---------------------------------------------------------------------- + private void richTextBox1_Enter(object sender, EventArgs e) + { + //ブラウザプレビュー制御 / Preview webBrowser component + if (MarkDownSharpEditor.AppSettings.Instance.fAutoBrowserPreview == true) + { + timer1.Enabled = true; + } + } + + //---------------------------------------------------------------------- + // RichTextBox Mouse click + //---------------------------------------------------------------------- + private void richTextBox1_MouseClick(object sender, MouseEventArgs e) + { + + //timer1.Enabled = true; + + } + + //---------------------------------------------------------------------- + // Form Closing event + //---------------------------------------------------------------------- + private void Form1_FormClosing(object sender, FormClosingEventArgs e) + { + if (richTextBox1.Modified == true) + { + //"問い合わせ" + //"編集中のファイルがあります。保存してから終了しますか?" + //"Question" + //"This file being edited. Do you wish to save before exiting?" + DialogResult ret = MessageBox.Show(Resources.MsgSaveFileToEnd, + Resources.DialogTitleQuestion, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); + + if (ret == DialogResult.Yes) + { + if (SaveToEditingFile() == true) + { + _fNoTitle = false; + } + else + { + //キャンセルで抜けてきた + //user cancel + e.Cancel = true; + return; + } + } + else if (ret == DialogResult.Cancel) + { + e.Cancel = true; + return; + } + } + + _fConstraintChange = true; + + //無題ファイルのまま編集しているのなら削除 + //Delete file if the file is no title + if (_fNoTitle == true) + { + if (File.Exists(_MarkDownTextFilePath) == true) + { + try + { + File.Delete(_MarkDownTextFilePath); + } + catch + { + } + } + } + + //データバージョン + //Data version + System.Reflection.Assembly asmbly = System.Reflection.Assembly.GetExecutingAssembly(); + System.Version ver = asmbly.GetName().Version; + MarkDownSharpEditor.AppSettings.Instance.Version = ver.Major * 1000 + ver.Minor * 100 + ver.Build * 10 + ver.Revision; + + //フォーム位置・サイズ ( Form position & size ) + if (this.WindowState == FormWindowState.Minimized) + { //最小化 ( Minimize ) + MarkDownSharpEditor.AppSettings.Instance.FormState = 1; + //一時記憶していた位置・サイズを保存 ( Save temporary position & size value ) + MarkDownSharpEditor.AppSettings.Instance.FormPos = new Point(_preFormPos.X, _preFormPos.Y); + MarkDownSharpEditor.AppSettings.Instance.FormSize = new Size(_preFormSize.Width, _preFormSize.Height); + } + else if (this.WindowState == FormWindowState.Maximized) + { //最大化 ( Maximize ) + MarkDownSharpEditor.AppSettings.Instance.FormState = 2; + //一時記憶していた位置・サイズを保存 ( Save temporary position & size value ) + MarkDownSharpEditor.AppSettings.Instance.FormPos = new Point(_preFormPos.X, _preFormPos.Y); + MarkDownSharpEditor.AppSettings.Instance.FormSize = new Size(_preFormSize.Width, _preFormSize.Height); + } + else + { //通常 ( Normal window ) + MarkDownSharpEditor.AppSettings.Instance.FormState = 0; + MarkDownSharpEditor.AppSettings.Instance.FormPos = new Point(this.Left, this.Top); + MarkDownSharpEditor.AppSettings.Instance.FormSize = new Size(this.Width, this.Height); + } + + MarkDownSharpEditor.AppSettings.Instance.richEditWidth = this.richTextBox1.Width; + FontConverter fc = new FontConverter(); + MarkDownSharpEditor.AppSettings.Instance.FontFormat = fc.ConvertToString(richTextBox1.Font); + MarkDownSharpEditor.AppSettings.Instance.richEditForeColor = richTextBox1.ForeColor.ToArgb(); + + //表示オプションなど + //Save view options etc + MarkDownSharpEditor.AppSettings.Instance.fViewToolBar = this.menuViewToolBar.Checked; + MarkDownSharpEditor.AppSettings.Instance.fViewStatusBar = this.menuViewStatusBar.Checked; + MarkDownSharpEditor.AppSettings.Instance.fSplitBarWidthEvenly = this.menuViewWidthEvenly.Checked; + + //検索オプション + //Save search options + MarkDownSharpEditor.AppSettings.Instance.fSearchOptionIgnoreCase = chkOptionCase.Checked ? false : true; + + if (File.Exists(_MarkDownTextFilePath) == true) + { + //編集中のファイルパス + //Save editing file path + foreach (AppHistory data in MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles) + { + if (data.md == _MarkDownTextFilePath) + { //いったん削除して ( delete once ... ) + MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Remove(data); + break; + } + } + AppHistory HistroyData = new AppHistory(); + HistroyData.md = _MarkDownTextFilePath; + HistroyData.css = _SelectedCssFilePath; + MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Insert(0, HistroyData); //先頭に挿入 ( Insert at the top ) + } + + //設定の保存 + //Save settings + MarkDownSharpEditor.AppSettings.Instance.SaveToXMLFile(); + //MarkDownSharpEditor.AppSettings.Instance.SaveToJsonFile(); + + timer1.Enabled = false; + + //webBrowser1.Navigate("about:blank"); + //クリック音対策 + //Constraint click sounds + if (webBrowser1.Document != null) + { + webBrowser1.Document.OpenNew(true); + webBrowser1.Document.Write(""); + } + } + + //----------------------------------- + // Form closed event + //----------------------------------- + private void Form1_FormClosed(object sender, FormClosedEventArgs e) + { + //テンポラリファイルの削除 + //Delete temporary files + Delete_TemporaryHtmlFilePath(); + } + + //----------------------------------- + // Form resize begin event + //----------------------------------- + private void Form1_ResizeBegin(object sender, EventArgs e) + { + //リサイズ前の位置・サイズを一時記憶 + _preFormPos.X = this.Left; + _preFormPos.Y = this.Top; + _preFormSize.Width = this.Width; + _preFormSize.Height = this.Height; + } + + //----------------------------------- + // Form resize end event + //----------------------------------- + private void Form1_ResizeEnd(object sender, EventArgs e) + { + //ソースウィンドウとビューウィンドウを均等にするか + //Equalize width of source window and view window + if (menuViewWidthEvenly.Checked == true) + { + this.richTextBox1.Width = + (splitContainer1.Width - splitContainer1.SplitterWidth) / 2; + } + } + + //----------------------------------- + // richTextBox1 DragEnter event + //----------------------------------- + private void richTextBox1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.FileDrop) == true) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + + //----------------------------------- + // richTextBox1 Drag and Drop event + //----------------------------------- + private void richTextBox1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) + { + string[] FileArray = (string[])e.Data.GetData(DataFormats.FileDrop, false); + if (FileArray.Length > 1) + { + if (FileArray.Length > 0) + { + //"問い合わせ" + //"複数のファイルが読み込まれました。\n現在の設定内容でHTMLファイルへの一括変換を行いますか? + //「いいえ」を選択するとそのまますべてのファイル開きます。" + //"Question" + //"More than one were read.\nDo you wish to convert all files to HTML files on this options?\n + // if you select 'No', all files will be opend without converting." + DialogResult ret = MessageBox.Show("MsgConvertAllFilesToHTML", + Resources.DialogTitleQuestion, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information); + + if (ret == DialogResult.Yes) + { + //一括でHTMLファイル出力 + //Output HTML files in batch process + BatchOutputToHtmlFiles(FileArray); + return; + + } + else if (ret == DialogResult.Cancel) + { + //キャンセル + //Cancel + return; + } + else + { //「いいえ」 + // "No" button + bool fOpen = false; + foreach (string FilePath in FileArray) + { + //最初のファイルだけ、このウィンドウだけ開く + //First file open in this window + if (fOpen == false) + { + OpenFile(FilePath); + fOpen = true; + } + else + { + //他の複数ファイルは順次新しいウィンドウで開く + //Other files open in new windows + System.Diagnostics.Process.Start( + Application.ExecutablePath, string.Format("{0}", FilePath)); + } + } + } + } + else + { + //前に編集していたファイルがあればそれを開く + //Open it if there is editing file before + if (MarkDownSharpEditor.AppSettings.Instance.fOpenEditFileBefore == true) + { + if (MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Count > 0) + { + AppHistory EditedFilePath = new AppHistory(); + EditedFilePath = (AppHistory)MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles[0]; + + if (File.Exists(EditedFilePath.md) == true) + { + OpenFile(EditedFilePath.md); + } + } + } + } + _fConstraintChange = false; + //フォームタイトル更新 + //Refresh form caption + FormTextChange(); + + ArrayList ArrayFileList = new ArrayList(); + foreach (string FilePath in FileArray) + { + ArrayFileList.Add(FilePath); + } + + BatchOutputToHtmlFiles((String[])ArrayFileList.ToArray(typeof(string))); + + } + else if (FileArray.Count() == 1) + { + //ファイルが一個の場合は編集中のウィンドウで開く + //Open it in this window if file is one + OpenFile(FileArray[0]); + } + } + + //---------------------------------------------------------------------- + // OpenFile [ .mdファイルを開く ] + //---------------------------------------------------------------------- + private bool OpenFile(string FilePath, bool fOpenDialog = false) + { + //引数 FilePath = "" の場合は「無題」編集で開始する + // Argument "FilePath" = "" => Start editing in 'no title' + + if (FilePath == "") + { + _fNoTitle = true; // No title flag + } + else + { + _fNoTitle = false; + } + + //----------------------------------- + //編集中のファイルがある + if (richTextBox1.Modified == true) + { + //"問い合わせ" + //"編集中のファイルがあります。保存してから終了しますか?" + //"Question" + //"This file being edited. Do you wish to save before exiting?" + DialogResult ret = MessageBox.Show(Resources.MsgSaveFileToEnd, + Resources.DialogTitleQuestion, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); + if (ret == DialogResult.Yes) + { + if (SaveToEditingFile() == false) + { + //キャンセルで抜けてきた + //Cancel + return (false); + } + } + else if (ret == DialogResult.Cancel) + { + return (false); + } + + //編集履歴に残す + //Save file path to editing history + foreach (AppHistory data in MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles) + { + if (data.md == _MarkDownTextFilePath) + { //いったん削除して ( delete once ... ) + MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Remove(data); + break; + } + } + AppHistory HistroyData = new AppHistory(); + HistroyData.md = _MarkDownTextFilePath; + HistroyData.css = _SelectedCssFilePath; + MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Insert(0, HistroyData); //先頭に挿入 ( Insert at the top ) + } + + //----------------------------------- + //オープンダイアログ表示 + //View open file dialog + if (fOpenDialog == true) + { + if (File.Exists(_MarkDownTextFilePath) == true) + { //編集中のファイルがあればそのディレクトリを初期フォルダーに + //Set parent directory of editing file to initial folder + openFileDialog1.InitialDirectory = Path.GetDirectoryName(_MarkDownTextFilePath); + //テンポラリファイルがあればここで削除 + //Delete it if temporary file exists + Delete_TemporaryHtmlFilePath(); + } + openFileDialog1.FileName = ""; + if (openFileDialog1.ShowDialog() == DialogResult.OK) + { + FilePath = openFileDialog1.FileName; + _fNoTitle = false; + } + else + { + return (false); + } + } + + //編集中のファイルパスとする + //Set this file to 'editing file' path + _MarkDownTextFilePath = FilePath; + + //----------------------------------- + //文字コードを調査するためにテキストファイルを開く + //Detect encoding + if (_fNoTitle == false) + { + byte[] bs; + using (FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read)) + { + bs = new byte[fs.Length]; + fs.Read(bs, 0, bs.Length); + } + //文字コードを取得する + //Get charcter encoding + _EditingFileEncoding = GetCode(bs); + } + else + { + //「無題」はデフォルトのエンコーディング + // Set this file to default encoding in 'No title' + _EditingFileEncoding = Encoding.UTF8; + } + + //ステータスバーに表示 + //View in statusbar + toolStripStatusLabelTextEncoding.Text = _EditingFileEncoding.EncodingName; + //編集中のエンコーディングを使用する(&D)か + //Use encoding of editing file + if (MarkDownSharpEditor.AppSettings.Instance.HtmlEncodingOption == 0) + { + toolStripStatusLabelHtmlEncoding.Text = _EditingFileEncoding.EncodingName; + } + + //----------------------------------- + //ペアとなるCSSファイルがあるか探索してあれば適用する + //Apply that the pair CSS file to this file exists + foreach (AppHistory data in MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles) + { + if (data.md == _MarkDownTextFilePath) + { + if (File.Exists(data.css) == true) + { + _SelectedCssFilePath = data.css; + break; + } + } + } + + //選択中のCSSファイル名をステータスバーに表示 + //View selected CSS file name to stausbar + if (File.Exists(_SelectedCssFilePath) == true) + { + toolStripStatusLabelCssFileName.Text = Path.GetFileName(_SelectedCssFilePath); + } + else + { + toolStripStatusLabelCssFileName.Text = Resources.toolTipCssFileName; //"CSSファイル指定なし"; ( not selected CSS file) + } + + _fConstraintChange = true; + richTextBox1.Clear(); + + //RichEditBoxの「フォント」設定 + // richTextBox1 font name setting + var obj = MarkDownSharpEditor.AppSettings.Instance; + FontConverter fc = new FontConverter(); + try { richTextBox1.Font = (Font)fc.ConvertFromString(obj.FontFormat); } + catch { } + //RichEditBoxの「フォントカラー」設定 + // richTextBox1 font color setting + richTextBox1.ForeColor = Color.FromArgb(obj.richEditForeColor); + //View them in statusbar + toolStripStatusLabelFontInfo.Text = richTextBox1.Font.Name + "," + richTextBox1.Font.Size.ToString() + "pt"; + + //----------------------------------- + //テキストファイルの読み込み + //Read text file + if (File.Exists(FilePath) == true) + { + richTextBox1.Text = File.ReadAllText(FilePath, _EditingFileEncoding); + } + richTextBox1.BeginUpdate(); + richTextBox1.SelectionStart = richTextBox1.Text.Length; + richTextBox1.ScrollToCaret(); + //richTextBox1の全高さを求める + //Get height of richTextBox1 ( for webBrowser sync ) + _richEditBoxInternalHeight = richTextBox1.VerticalPosition; + //カーソル位置を戻す + //Restore cursor position + richTextBox1.SelectionStart = 0; + richTextBox1.EndUpdate(); + + //変更フラグOFF + richTextBox1.Modified = false; + + //Undoバッファに追加 + //Add all text to undo buffer + UndoBuffer.Clear(); + UndoBuffer.Add(richTextBox1.Rtf); + undoCounter = UndoBuffer.Count; + + //プレビュー更新 + PreviewToBrowser(); + + _fConstraintChange = false; + FormTextChange(); + + return (true); + + } + + //---------------------------------------------------------------------- + // 表示するHTMLのテンポラリファイルパスを取得する + // Get temporary HTML file path + //---------------------------------------------------------------------- + private string Get_TemporaryHtmlFilePath(string FilePath) + { + string DirPath = Path.GetDirectoryName(FilePath); + string FileName = Path.GetFileNameWithoutExtension(FilePath); + + MD5 md5Hash = MD5.Create(); + byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(FileName)); + StringBuilder sBuilder = new StringBuilder(); + for (int i = 0; i < data.Length; i++) + { + sBuilder.Append(data[i].ToString("x2")); + } + return (Path.Combine(DirPath, FileName + "_" + sBuilder.ToString() + ".html")); + } + + //---------------------------------------------------------------------- + // 表示しているHTMLのテンポラリファイルを削除する + // Delete temporary HTML file + //---------------------------------------------------------------------- + private void Delete_TemporaryHtmlFilePath() + { + string TempHtmlFilePath; + + if (_MarkDownTextFilePath == "") + { + return; + } + + TempHtmlFilePath = Get_TemporaryHtmlFilePath(_MarkDownTextFilePath); + //見つかったときだけ削除 + //Delete it if the file exists + if (File.Exists(TempHtmlFilePath) == true) + { + try + { File.Delete(TempHtmlFilePath); - _TemporaryHtmlFilePath = ""; - } - catch - { - //"エラー" - //"テンポラリファイルの削除に失敗しました。編集中の場所に残った可能性があります。 - //"このファイルは手動で削除していただいても問題ありません。 - //"Error" - //"Error during deleting temporary file!\na temporary file may be left in the folder the file is edited.\n" - // This file is not a problem even if you delete it manually. - MessageBox.Show(Resources.MsgErrorDeleteTemporaryFile + TempHtmlFilePath, - Resources.DialogTitleError, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - - //---------------------------------------------------------------------- - // ブラウザープレビューの間隔を調整 - // Ajust browser preview interval - //---------------------------------------------------------------------- - private void timer1_Tick(object sender, EventArgs e) - { - PreviewToBrowser(); - timer1.Enabled = false; - } - - private void timer2_Tick(object sender, EventArgs e) - { - timer2.Enabled = false; - } - - //---------------------------------------------------------------------- - // HACK: PreviewToBrowser [ ブラウザプレビュー ] - //---------------------------------------------------------------------- - private void PreviewToBrowser() - { - //更新抑制中のときはプレビューしない - //Do not preview in constraint to change - if (_fConstraintChange == true) - { - return; - } - if (backgroundWorker1.IsBusy == true) - { - return; - } - - string ResultText = ""; - backgroundWorker1.WorkerReportsProgress = true; - //編集箇所にマーカーを挿入する - //Insert marker in editing - if (richTextBox1.SelectionStart > 0) - { - //int NextLineNum = richTextBox1.GetLineFromCharIndex(richTextBox1.SelectionStart) + 1; - int ParagraphStart = richTextBox1.GetFirstCharIndexOfCurrentLine(); - //if (ParagraphStart == 0) - //{ - // ParagraphStart = 1; - //} - ResultText = - richTextBox1.Text.Substring(0, ParagraphStart) + "" + - richTextBox1.Text.Substring(ParagraphStart); - } - else - { - ResultText = richTextBox1.Text; - } - backgroundWorker1.RunWorkerAsync(ResultText); - - } - - //---------------------------------------------------------------------- - // BackgroundWorker ProgressChanged - //---------------------------------------------------------------------- - private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) - { - //ProgressBar1.Value = e.ProgressPercentage; - //Label1.Text = e.ProgressPercentage.ToString(); - } - - //---------------------------------------------------------------------- - // BackgroundWorker browser preview - //---------------------------------------------------------------------- - private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) + _TemporaryHtmlFilePath = ""; + } + catch + { + //"エラー" + //"テンポラリファイルの削除に失敗しました。編集中の場所に残った可能性があります。 + //"このファイルは手動で削除していただいても問題ありません。 + //"Error" + //"Error during deleting temporary file!\na temporary file may be left in the folder the file is edited.\n" + // This file is not a problem even if you delete it manually. + MessageBox.Show(Resources.MsgErrorDeleteTemporaryFile + TempHtmlFilePath, + Resources.DialogTitleError, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + //---------------------------------------------------------------------- + // ブラウザープレビューの間隔を調整 + // Ajust browser preview interval + //---------------------------------------------------------------------- + private void timer1_Tick(object sender, EventArgs e) + { + PreviewToBrowser(); + timer1.Enabled = false; + } + + private void timer2_Tick(object sender, EventArgs e) + { + timer2.Enabled = false; + } + + //---------------------------------------------------------------------- + // HACK: PreviewToBrowser [ ブラウザプレビュー ] + //---------------------------------------------------------------------- + private void PreviewToBrowser() + { + //更新抑制中のときはプレビューしない + //Do not preview in constraint to change + if (_fConstraintChange == true) + { + return; + } + if (backgroundWorker1.IsBusy == true) + { + return; + } + + string ResultText = ""; + backgroundWorker1.WorkerReportsProgress = true; + //編集箇所にマーカーを挿入する + //Insert marker in editing + if (richTextBox1.SelectionStart > 0) + { + //int NextLineNum = richTextBox1.GetLineFromCharIndex(richTextBox1.SelectionStart) + 1; + int ParagraphStart = richTextBox1.GetFirstCharIndexOfCurrentLine(); + //if (ParagraphStart == 0) + //{ + // ParagraphStart = 1; + //} + ResultText = + richTextBox1.Text.Substring(0, ParagraphStart) + "" + + richTextBox1.Text.Substring(ParagraphStart); + } + else + { + ResultText = richTextBox1.Text; + } + backgroundWorker1.RunWorkerAsync(ResultText); + + } + + //---------------------------------------------------------------------- + // BackgroundWorker ProgressChanged + //---------------------------------------------------------------------- + private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) + { + //ProgressBar1.Value = e.ProgressPercentage; + //Label1.Text = e.ProgressPercentage.ToString(); + } + + //---------------------------------------------------------------------- + // BackgroundWorker browser preview + //---------------------------------------------------------------------- + private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { var obj = MarkDownSharpEditor.AppSettings.Instance; // プレビューブラウザのレンダリングモード指定 - AppSettings.SetBrowserRenderingMode(obj.FeatureBrowserEmulation, obj.FeatureDocumentCompatibuleMode); - - string ResultText = (string)e.Argument; - string MkResultText = ""; - - string BackgroundColorString; - string EncodingName; - - //編集中のファイル名 - //Editing file name - string FileName = (_MarkDownTextFilePath == "" ? "" : Path.GetFileName(_MarkDownTextFilePath)); - //DOCTYPE - HtmlHeader htmlHeader = new HtmlHeader(); - string DocType = htmlHeader.GetHtmlHeader(MarkDownSharpEditor.AppSettings.Instance.HtmlDocType); - - //マーキングの色づけ - //Marker's color - if (MarkDownSharpEditor.AppSettings.Instance.fHtmlHighLightColor == true) - { - Color ColorBackground = Color.FromArgb(MarkDownSharpEditor.AppSettings.Instance.HtmlHighLightColor); - BackgroundColorString = ColorTranslator.ToHtml(ColorBackground); - } - else - { - BackgroundColorString = "none"; - } - - //指定のエンコーディング - //Codepage - int CodePageNum = MarkDownSharpEditor.AppSettings.Instance.CodePageNumber; - try - { - Encoding enc = Encoding.GetEncoding(CodePageNum); - //ブラウザ表示に対応したエンコーディングか - //Is the encoding supported browser? - if (enc.IsBrowserDisplay == true) - { - EncodingName = enc.WebName; - } - else - { - EncodingName = "utf-8"; - } - } - catch - { - //エンコーディングの取得に失敗した場合 - //Default encoding if failing to get encoding - EncodingName = "utf-8"; - } - //Header - string header = string.Format( -@"{0} - - - - - -{4} - - -", - DocType, //DOCTYPE - EncodingName, //エンコーディング ( encoding ) - _SelectedCssFilePath, //適用中のCSSファイル ( Selected CSS file ) - BackgroundColorString, //編集箇所の背景色 ( background color in Editing ) - FileName); //タイトル(=ファイル名) ( title = file name ) - - //Footer - string footer = //"\n"; - // 書き換え中 - "\n"; - - //----------------------------------- - //Markdown parse ( default ) - //Markdown mkdwn = new Markdown(); - //----------------------------------- - - //----------------------------------- - // MarkdownDeep - // Create an instance of Markdown - //----------------------------------- - var mkdwn = new MarkdownDeep.Markdown(); - // Set options - mkdwn.ExtraMode = MarkDownSharpEditor.AppSettings.Instance.fMarkdownExtraMode; - mkdwn.SafeMode = false; - //----------------------------------- - - ResultText = mkdwn.Transform(ResultText); - //表示するHTMLデータを作成 - //Creat HTML data - ResultText = header + ResultText + footer; - - //パースされた内容から編集行を探す - //Search editing line in parsed data - string OneLine; - StringReader sr = new StringReader(ResultText); - StringWriter sw = new StringWriter(); - while ((OneLine = sr.ReadLine()) != null) - { - if (OneLine.IndexOf("") >= 0) - { - MkResultText += ("
" + OneLine + "
\n"); - } - else - { - MkResultText += (OneLine + "\n"); - } - } - - //エンコーディングしつつbyte値に変換する(richEditBoxは基本的にutf-8 = 65001) - //Encode and convert it to 'byte' value ( richEditBox default encoding is utf-8 = 65001 ) - byte[] bytesData = Encoding.GetEncoding(CodePageNum).GetBytes(MkResultText); - - - //----------------------------------- - // Write to temporay file - if (_fNoTitle == false) - { - //テンポラリファイルパスを取得する - //Get temporary file path - if (_TemporaryHtmlFilePath == "") - { - _TemporaryHtmlFilePath = Get_TemporaryHtmlFilePath(_MarkDownTextFilePath); - } - //他のプロセスからのテンポラリファイルの参照と削除を許可して開く(でないと飛ぶ) - //Open temporary file to allow references from other processes - using (FileStream fs = new FileStream( - _TemporaryHtmlFilePath, - FileMode.Create, FileAccess.ReadWrite, FileShare.Read | FileShare.Delete)) - { - fs.Write(bytesData, 0, bytesData.Length); - e.Result = _TemporaryHtmlFilePath; - } - } - //----------------------------------- - // Navigate and view in browser - else - { - //Write data as it is, if the editing data is no title - ResultText = Encoding.GetEncoding(CodePageNum).GetString(bytesData); - e.Result = ResultText; - } - - } - - private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - if (e.Error != null) - { - //Error! - } - else - { - if ((string)e.Result != "") - { - //----------------------------------- - //スクロールバーの位置を退避しておく - //Memorize scroll positions - HtmlDocument doc = webBrowser1.Document; - Point scrollpos = new Point(0, 0); - if (doc == null) - { - webBrowser1.Navigate("about:blank"); - } - else - { - IHTMLDocument3 doc3 = (IHTMLDocument3)webBrowser1.Document.DomDocument; - IHTMLElement2 elm = (IHTMLElement2)doc3.documentElement; - scrollpos = new Point(elm.scrollLeft, elm.scrollTop); - } - //----------------------------------- - System.Threading.Tasks.Task waitTask; - if (_fNoTitle == false) - { - //ナビゲート - //Browser navigate - //webBrowser1.Navigate(@"file://" + (string)e.Result); - waitTask = WebBrowserNavigate(@"file://" + (string)e.Result); - richTextBox1.Focus(); - toolStripButtonBrowserPreview.Enabled = true; - } - else - { - webBrowser1.Document.OpenNew(true); - //webBrowser1.Document.Write((string)e.Result); - waitTask = WebBrowserDocumentWrite((string)e.Result); - //ツールバーの「関連付けられたブラウザーを起動」を無効に - //"Associated web browser" in toolbar is invalid - toolStripButtonBrowserPreview.Enabled = false; - } - //----------------------------------- - //スクロールバーの位置を復帰する - //Restore scroll bar position - if (doc != null) - { - waitTask.ContinueWith((arg1) => - { - this.BeginInvoke(new Action(() => - { - doc.Window.ScrollTo(scrollpos); - - this.webBrowser1.Document.Body.AttachEventHandler("onscroll", OnScrollEventHandler); - - })); - }); - } - } - } - } - /// - /// webBrowser コンポーネントにHTMLを出力して - /// DocumentComplate になるのを非同期で待ち合わせる - /// - /// - /// - System.Threading.Tasks.Task WebBrowserDocumentWrite(string html) - { - if (browserWaitTimer == null) - { - browserWaitTimer = new Timer(); - browserWaitTimer.Tick += browserWaitTimer_Tick; - browserWaitTimer.Enabled = true; - } - var obj = waitObject; - if (obj != null) - { - obj.SetCanceled(); - } - waitObject = new System.Threading.Tasks.TaskCompletionSource(); - - timerCount = 0; - - this.webBrowser1.DocumentText = html; - - browserWaitTimer.Enabled = true; - - return waitObject.Task; - } - - /// - /// webBrowser コンポーネントにHTMLを出力して - /// DocumentComplate になるのを非同期で待ち合わせる - /// - /// - /// - System.Threading.Tasks.Task WebBrowserNavigate(string url) - { - if (browserWaitTimer == null) - { - browserWaitTimer = new Timer(); - browserWaitTimer.Tick += browserWaitTimer_Tick; - browserWaitTimer.Enabled = true; - } - var obj = waitObject; - if (obj != null) - { - obj.SetCanceled(); - } - waitObject = new System.Threading.Tasks.TaskCompletionSource(); - - timerCount = 0; - - this.webBrowser1.Navigate(url); - - browserWaitTimer.Enabled = true; - - return waitObject.Task; - } - - void browserWaitTimer_Tick(object sender, EventArgs e) - { - if (waitObject == null) - { - browserWaitTimer.Enabled = false; - return; - } - - timerCount++; - - if (this.webBrowser1.ReadyState == WebBrowserReadyState.Complete) - { - waitObject.SetResult("OK"); - waitObject = null; - browserWaitTimer.Enabled = false; - } - else if (timerCount > 20) - { - // 反応ないので終わりにする - waitObject.SetResult("OK"); - waitObject = null; - browserWaitTimer.Enabled = false; - } - } - - System.Threading.Tasks.TaskCompletionSource waitObject = null; - int timerCount = 0; - Timer browserWaitTimer; - - //---------------------------------------------------------------------- - // BackgroundWorker Syntax hightlighter work - //---------------------------------------------------------------------- - private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e) - { - var text = e.Argument as string; - if (string.IsNullOrEmpty(text)) - { - e.Result = null; - return; - } - if (timer2.Enabled == true) - { - e.Result = null; - return; - } - - var result = new List(); - foreach (MarkdownSyntaxKeyword mk in _MarkdownSyntaxKeywordAarray) - { - MatchCollection col = mk.Regex.Matches(text, 0); - - if (col.Count > 0) - { - foreach (Match m in col) - { - SyntaxColorScheme sytx = new SyntaxColorScheme(); - sytx.SelectionStartIndex = m.Groups[0].Index; - sytx.SelectionLength = m.Groups[0].Length; - sytx.ForeColor = mk.ForeColor; - sytx.BackColor = mk.BackColor; - result.Add(sytx); - } - } - } - e.Result = result; - } - //---------------------------------------------------------------------- - // BackgroundWorker Editor Syntax hightlighter progress changed - //---------------------------------------------------------------------- - private void backgroundWorker2_ProgressChanged(object sender, ProgressChangedEventArgs e) - { - - } - //---------------------------------------------------------------------- - // BackgroundWorker Syntax hightlighter completed to work - //---------------------------------------------------------------------- - private void backgroundWorker2_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - if (e.Error != null || e.Cancelled == true) - { - return; - } - - var syntaxColorSchemeList = e.Result as List; - if (syntaxColorSchemeList == null) - { - return; - } - - var obj = MarkDownSharpEditor.AppSettings.Instance; - - Font fc = richTextBox1.Font; //現在のフォント設定 ( Font option ) - bool fModify = richTextBox1.Modified; //現在の編集状況 ( Modified flag ) - - _fConstraintChange = true; - - //現在のカーソル位置 / Current cursor position - int selectStart = this.richTextBox1.SelectionStart; - int selectEnd = richTextBox1.SelectionLength; - Point CurrentOffset = richTextBox1.AutoScrollOffset; - - //現在のスクロール位置 / Current scroll position - int CurrentScrollPos = richTextBox1.VerticalPosition; - //描画停止 / Stop to paint - richTextBox1.BeginUpdate(); - - //RichTextBoxの書式をクリアする / Clear richTextBox1 format options - richTextBox1.ForeColor = Color.FromArgb(obj.ForeColor_MainText); - richTextBox1.BackColor = Color.FromArgb(obj.BackColor_MainText); - - //裏でパースしていたシンタックスハイライターを反映。 - foreach (var s in syntaxColorSchemeList) - { - richTextBox1.Select(s.SelectionStartIndex, s.SelectionLength); - richTextBox1.SelectionColor = s.ForeColor; - richTextBox1.SelectionBackColor = s.BackColor; - } - - //カーソル位置を戻す / Restore cursor position - richTextBox1.Select(selectStart, selectEnd); - richTextBox1.AutoScrollOffset = CurrentOffset; - richTextBox1.VerticalPosition = CurrentScrollPos; - - //描画再開 / Resume to paint - richTextBox1.EndUpdate(); - richTextBox1.Modified = fModify; - - _fConstraintChange = false; - - if (MarkDownSharpEditor.AppSettings.Instance.AutoBrowserPreviewInterval < 0) - { - //手動更新 / Manual refresh - timer1.Enabled = false; - return; - } - else - { - timer1.Enabled = true; - } - - } - - //---------------------------------------------------------------------- - // プレビューページが読み込まれたら編集中の箇所へ自動スクロールする - // Scroll to editing line when browser is loaded - //---------------------------------------------------------------------- - private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) - { - //更新抑制中のときは抜ける - //Constraint to change - if (_fConstraintChange == true) - { - return; - } - //読み込まれた表示領域の高さを取得 - //Get viewing area to load in browser component - _WebBrowserInternalHeight = webBrowser1.Document.Body.ScrollRectangle.Height; - //ブラウザのスクロールイベントハンドラ - //Browser component event handler - webBrowser1.Document.Window.AttachEventHandler("onscroll", OnScrollEventHandler); - } - - //---------------------------------------------------------------------- - // Browser component scrolll event - //---------------------------------------------------------------------- - public void OnScrollEventHandler(object sender, EventArgs e) - { - RichEditBoxMoveCursor(); - } - - //---------------------------------------------------------------------- - // TODO: WebBrowserMoveCursor [RichEditBox → WebBrowser scroll follow] - //---------------------------------------------------------------------- - private void WebBrowserMoveCursor() - { - if (webBrowser1.Document == null) - { - return; - } - - if (richTextBox1.Focused == true) - { - //richEditBoxの内部的な高さから現在位置の割合を計算 - //Calculate current position with internal height of richTextBox1 - int LineHeight = Math.Abs(richTextBox1.GetPositionFromCharIndex(0).Y); - float perHeight = (float)LineHeight / _richEditBoxInternalHeight; - - //その割合からwebBrowserのスクロール量を計算 - //Calculate scroll amount with the ratio - _WebBrowserInternalHeight = webBrowser1.Document.Body.ScrollRectangle.Height; - int y = (int)(_WebBrowserInternalHeight * perHeight); - Point webScrollPos = new Point(0, y); - //Follow to scroll browser component - webBrowser1.Document.Window.ScrollTo(webScrollPos); - } - } - - //---------------------------------------------------------------------- - // HACK: RichEditBoxMoveCursor[ WebBrowser → RichEditBox scroll follow] - //---------------------------------------------------------------------- - private void RichEditBoxMoveCursor() - { - //ブラウザでのスクロールバーの位置 - //Position of scroll bar in browser component - if (richTextBox1.Focused == false && webBrowser1.Document != null) - { - IHTMLDocument3 doc3 = (IHTMLDocument3)webBrowser1.Document.DomDocument; - IHTMLElement2 elm = (IHTMLElement2)doc3.documentElement; - //全高さからの割合(位置) - //Ratio(Position) of height - float perHeight = (float)elm.scrollTop / _WebBrowserInternalHeight; - int y = (int)(_richEditBoxInternalHeight * perHeight); - richTextBox1.VerticalPosition = y; - } - - } - - //---------------------------------------------------------------------- - // webBrowser1 Navigated event - //---------------------------------------------------------------------- - private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e) - { - //ブラウザー操作ボタンの有効・無効化 - toolStripButtonBack.Enabled = webBrowser1.CanGoBack; - toolStripButtonForward.Enabled = webBrowser1.CanGoForward; - } - - //---------------------------------------------------------------------- - // HTML形式出力 ( Output to HTML file ) - //---------------------------------------------------------------------- - private bool OutputToHtmlFile(string FilePath, string SaveToFilePath, bool fToClipboard = false) - { - - if (File.Exists(FilePath) == false) - { - return (false); - } - - //出力内容 ( Output data ) - string ResultText = ""; - //HTMLタグ ( HTML Header tag ) - string HeaderString = ""; - string FooterString = ""; - //文字コード ( Character encoding ) - string EncodingName; - Encoding encRead = Encoding.UTF8; - Encoding encHtml = Encoding.UTF8; - - //----------------------------------- - //編集中のファイルパス or 投げ込まれたファイルパス - //Editing file path or Drag & Dropped files - string FileName = Path.GetFileName(FilePath); - - //----------------------------------- - //DOCTYPE - HtmlHeader htmlHeader = new HtmlHeader(); - string DocType = htmlHeader.GetHtmlHeader(MarkDownSharpEditor.AppSettings.Instance.HtmlDocType); - //Web用の相対パス - //Relative url - string CssPath = RerativeFilePath(FilePath, _SelectedCssFilePath); - - //----------------------------------- - //指定のエンコーディング - //Codepage - int CodePageNum = MarkDownSharpEditor.AppSettings.Instance.CodePageNumber; - try - { - encHtml = Encoding.GetEncoding(CodePageNum); - //ブラウザ表示に対応したエンコーディングか - //Is the encoding supported browser? - if (encHtml.IsBrowserDisplay == true) - { - EncodingName = encHtml.WebName; - } - else - { - EncodingName = "utf-8"; - encHtml = Encoding.UTF8; - } - } - catch - { - //エンコーディングの取得に失敗した場合はデフォルト - //Default encoding if failing to get encoding - EncodingName = "utf-8"; - encHtml = Encoding.UTF8; - } - - //HTMLのヘッダを挿入する - //Insert HTML Header - if (MarkDownSharpEditor.AppSettings.Instance.fHtmlOutputHeader == true) - { - //CSSファイルを埋め込む - //Embeding CSS file contents - if (MarkDownSharpEditor.AppSettings.Instance.HtmlCssFileOption == 0) - { - string CssContents = ""; - - if (File.Exists(_SelectedCssFilePath) == true) - { - using (StreamReader sr = new StreamReader(_SelectedCssFilePath, encHtml)) - { - CssContents = sr.ReadToEnd(); - } - } - - //ヘッダ ( Header ) - HeaderString = string.Format( -@"{0} - - - -{2} - - - -", - DocType, //DOCTYPE - EncodingName, //エンコーディング ( Encoding ) - FileName, //タイトル(=ファイル名) ( Title = file name ) - CssContents); //CSSの内容 ( Contents of CSS file ) - } - //metaタグ(外部リンキング)(Meta tag: external linking ) - else - { - //ヘッダ ( Header ) - HeaderString = string.Format( -@"{0} - - - - -{3} - - -", - DocType, //DOCTYPE - EncodingName, //エンコーディング ( Encoding ) - CssPath, //CSSファイル(相対パス)( Relative url ) - FileName); //タイトル(=ファイル名) ( Title = file name ) - } - //フッタ ( Footer ) - FooterString = "\n"; - } - else - { - HeaderString = ""; - FooterString = ""; - } - - //----------------------------------- - //Markdown parse ( default ) - //Markdown mkdwn = new Markdown(); - //----------------------------------- - - //----------------------------------- - // MarkdownDeep - // Create an instance of Markdown - //----------------------------------- - var mkdwn = new MarkdownDeep.Markdown(); - // Set options - mkdwn.ExtraMode = MarkDownSharpEditor.AppSettings.Instance.fMarkdownExtraMode; - mkdwn.SafeMode = false; - //----------------------------------- - - //編集中のファイル(richEditBoxの内容) - //Editing file path - if (_MarkDownTextFilePath == FilePath) - { - ResultText = mkdwn.Transform(richTextBox1.Text); - //エンコーディング変換(richEditBoxは基本的にutf-8) - //Convert encoding ( richEditBox default encoding is utf-8 = 65001 ) - ResultText = ConvertStringToEncoding(ResultText, Encoding.UTF8.CodePage, CodePageNum); - } - else - { - //テキストファイルを開いてその文字コードに従って読み込み - //Detect encoding in the text file - byte[] bs; - using (FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read)) - { - bs = new byte[fs.Length]; - fs.Read(bs, 0, bs.Length); - } - //文字コードを取得する - //Get charcter encoding - encRead = GetCode(bs); - //取得したバイト列を文字列に変換 - //Convert byte values to character - ResultText = encRead.GetString(bs); - - //UTF-8でないならいったん変換してパース - //Convert it if encoding is not utf-8 - if (encRead != Encoding.UTF8) - { - ResultText = ConvertStringToEncoding(ResultText, encRead.CodePage, CodePageNum); - } - ResultText = mkdwn.Transform(ResultText); - } - - //ヘッダ+本文+フッタ - //Header + Contents + Footer - ResultText = HeaderString + ResultText + FooterString; - //出力するHTMLファイルの文字コードに合わせる - //Ajust encoding to output HTML file - ResultText = ConvertStringToEncoding(ResultText, Encoding.UTF8.CodePage, CodePageNum); - - if (fToClipboard == true) - { //クリップボードに書き込む - //Set data to clipbord - Clipboard.SetText(ResultText); - } - else - { //ファイルに書き込む - //Write file - using (StreamWriter sw = new StreamWriter(SaveToFilePath, false, encHtml)) - { - sw.Write(ResultText); - } - } - return (true); - - } - - //---------------------------------------------------------------------- - // HTML形式ファイルへのバッチ出力 - // Output HTML files in batch - //---------------------------------------------------------------------- - private bool BatchOutputToHtmlFiles(string[] ArrrayFileList) - { - string OutputFilePath; - foreach (string FilePath in ArrrayFileList) - { - OutputFilePath = Path.ChangeExtension(FilePath, ".html"); - if (OutputToHtmlFile(FilePath, OutputFilePath, false) == false) - { - return (false); - } - } - return (true); - } - - //---------------------------------------------------------------------- - // 基本パスから相対パスを取得する - // Get relative file path from base file path - //---------------------------------------------------------------------- - private string RerativeFilePath(string BaseFilePath, string TargetFilePath) - { - Uri u1 = new Uri(BaseFilePath); - Uri u2 = new Uri(u1, TargetFilePath); - string RelativeFilePath = u1.MakeRelativeUri(u2).ToString(); - //URLデコードして、"/" を "\" に変更する - RelativeFilePath = System.Web.HttpUtility.UrlDecode(RelativeFilePath).Replace('/', '\\'); - return (RelativeFilePath); - } - - //---------------------------------------------------------------------- - // テキストを指定のエンコーディング文字列に変換する - // Convert text data to user encoding characters - //---------------------------------------------------------------------- - public string ConvertStringToEncoding(string source, int SrcCodePage, int DestCodePage) - { - Encoding srcEnc; - Encoding destEnc; - try - { - srcEnc = Encoding.GetEncoding(SrcCodePage); - destEnc = Encoding.GetEncoding(DestCodePage); - } - catch - { - //指定のコードページがおかしい(取得できない) - //Error: Codepage is incorrect - return (source); - } - //Byte配列で変換する - //Convert to byte values - byte[] srcByte = srcEnc.GetBytes(source); - byte[] destByte = Encoding.Convert(srcEnc, destEnc, srcByte); - char[] destChars = new char[destEnc.GetCharCount(destByte, 0, destByte.Length)]; - destEnc.GetChars(destByte, 0, destByte.Length, destChars, 0); - return new string(destChars); - } - - //====================================================================== - #region ブラウザーのツールバーメニュー ( Toolbar on browser ) - //====================================================================== - - //---------------------------------------------------------------------- - // ブラウザの「戻る」 ( Browser back ) - //---------------------------------------------------------------------- - private void toolStripButtonBack_Click(object sender, EventArgs e) - { - if (webBrowser1.CanGoBack == true) - { - webBrowser1.GoBack(); - } - } - - //---------------------------------------------------------------------- - // ブラウザの「進む」 ( Browser forward ) - //---------------------------------------------------------------------- - private void toolStripButtonForward_Click(object sender, EventArgs e) - { - if (webBrowser1.CanGoForward == true) - { - webBrowser1.GoForward(); - } - - } - - //---------------------------------------------------------------------- - // ブラウザの「更新」 ( Browser refresh ) - //---------------------------------------------------------------------- - private void toolStripButtonRefresh_Click(object sender, EventArgs e) - { - //手動更新設定 - //Manual to refresh browser - if (MarkDownSharpEditor.AppSettings.Instance.fAutoBrowserPreview == false) - { - //プレビューしているのは編集中のファイルか - //Is previewing file the editing file? - if (webBrowser1.Url.AbsoluteUri == @"file://" + _TemporaryHtmlFilePath) - { - PreviewToBrowser(); - } - } - webBrowser1.Refresh(); - } - - //---------------------------------------------------------------------- - // ブラウザの「中止」 ( Browser stop ) - //---------------------------------------------------------------------- - private void toolStripButtonStop_Click(object sender, EventArgs e) - { - webBrowser1.Stop(); - } - - //---------------------------------------------------------------------- - // 規定のブラウザーを関連付け起動してプレビュー - // Launch default web browser to preview - //---------------------------------------------------------------------- - private void toolStripButtonBrowserPreview_Click(object sender, EventArgs e) - { - if (File.Exists(_TemporaryHtmlFilePath) == true) - { - System.Diagnostics.Process.Start(_TemporaryHtmlFilePath); - } - else - { - _TemporaryHtmlFilePath = ""; - } - } - #endregion - //====================================================================== - - //====================================================================== - #region メインメニューイベント ( Main menu events ) - //====================================================================== - - //----------------------------------- - //「新しいファイルを開く」メニュー - // "New file" menu - //----------------------------------- - private void menuNewFile_Click(object sender, EventArgs e) - { - if (richTextBox1.Modified == true) - { - //"問い合わせ" - //"編集中のファイルがあります。保存してから新しいファイルを開きますか?" - //"Question" - //"This file being edited. Do you wish to save before starting new file?" - DialogResult ret = MessageBox.Show(Resources.MsgSaveFileToNewFile, - Resources.DialogTitleQuestion, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); - - if (ret == DialogResult.Yes) - { - if (SaveToEditingFile() == true) - { - _fNoTitle = false; //無題フラグOFF - } - else - { - //キャンセルで抜けてきた - //Cancel - return; - } - } - else if (ret == DialogResult.Cancel) - { - return; - } - } - - //前の編集していたテンポラリを削除する - //Delete edited temporary file before - Delete_TemporaryHtmlFilePath(); - - //無題ファイルのまま編集しているのなら削除 - //Delete it if the file is no title - if (_fNoTitle == true) - { - if (File.Exists(_MarkDownTextFilePath) == true) - { - try - { - File.Delete(_MarkDownTextFilePath); - } - catch - { - } - } - } - - //編集履歴に残す - //Add editing history - if (File.Exists(_MarkDownTextFilePath) == true) - { - foreach (AppHistory data in MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles) - { - if (data.md == _MarkDownTextFilePath) - { //いったん削除して ( delete once ... ) - MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Remove(data); - break; - } - } - AppHistory HistroyData = new AppHistory(); - HistroyData.md = _MarkDownTextFilePath; - HistroyData.css = _SelectedCssFilePath; - MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Insert(0, HistroyData); //先頭に挿入 - } - - _fConstraintChange = true; - - //ブラウザを空白にする - //Be blank in browser - webBrowser1.Navigate("about:blank"); - - //テンポラリファイルがあれば削除 - //Delete it if temporary file exists - Delete_TemporaryHtmlFilePath(); - //編集中のファイル情報をクリア - //Clear the infomation of editing file - _MarkDownTextFilePath = ""; - //「無題」編集開始 - //Start to edit in no title - _fNoTitle = true; - richTextBox1.Text = ""; - richTextBox1.Modified = false; - FormTextChange(); - _fConstraintChange = false; - - } - - //----------------------------------- - //「新しいウィンドウを開く」メニュー - // "New window" menu - //----------------------------------- - private void menuNewWindow_Click(object sender, EventArgs e) - { - //自分自身を起動する - //Launch the self - System.Diagnostics.ProcessStartInfo pInfo = new System.Diagnostics.ProcessStartInfo(Application.ExecutablePath); - pInfo.Arguments = "/new"; - System.Diagnostics.Process p = System.Diagnostics.Process.Start(pInfo); - - } - - //----------------------------------- - //「ファイルを開く」メニュー - // "Open File" menu - //----------------------------------- - private void menuOpenFile_Click(object sender, EventArgs e) - { - OpenFile("", true); - } - - //----------------------------------- - //「ファイル」メニュー - // "File" menu - //----------------------------------- - private void menuFile_Click(object sender, EventArgs e) - { - //編集履歴のサブメニューをつくる - //Create submenu of editing history - for (int i = 0; i < MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Count; i++) - { - AppHistory History = (AppHistory)MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles[i]; - ToolStripMenuItem m = new ToolStripMenuItem(History.md); - m.Tag = History.css; - m.Click += new EventHandler(HistorySubMenuItemClickHandler); - menuHistoryFiles.DropDownItems.Add(m); - } - - } - //----------------------------------- - //各履歴メニューがクリックされたとき - //Click editing history menu event - private void HistorySubMenuItemClickHandler(object sender, EventArgs e) - { - - ToolStripMenuItem clickItem = (ToolStripMenuItem)sender; - - string FilePath = clickItem.Text; - - if (File.Exists(FilePath) == true) - { - OpenFile(FilePath); - } - } - - //----------------------------------- - //編集中のファイルを保存する - //Save to editing file - //----------------------------------- - private bool SaveToEditingFile(bool fSaveAs = false) - { - //名前が付けられていない、または別名保存指定なのでダイアログ表示 - //The file is no title, or saving as oher name - if (_fNoTitle == true || fSaveAs == true) - { - if (saveFileDialog1.ShowDialog() == DialogResult.OK) - { - - using (StreamWriter sw = new StreamWriter(saveFileDialog1.FileName, false, _EditingFileEncoding)) - { - sw.Write(richTextBox1.Text); - _MarkDownTextFilePath = saveFileDialog1.FileName; - } - } - else - { - return (false); - } - } - else - { - //上書き保存 - //Overwrite - using (StreamWriter sw = new StreamWriter( - _MarkDownTextFilePath, - false, - _EditingFileEncoding)) - { - sw.Write(richTextBox1.Text); - } - - } - - //Undoバッファクリア - //Clear undo buffer - undoCounter = 0; - UndoBuffer.Clear(); - - _fNoTitle = false; //無題フラグOFF - richTextBox1.Modified = false; - FormTextChange(); - - return (true); - } - - //----------------------------------- - //「ファイルを保存」メニュー - // "Save file" menu - //----------------------------------- - private void menuSaveFile_Click(object sender, EventArgs e) - { - SaveToEditingFile(); - } - - //----------------------------------- - //「名前を付けてファイルを保存」メニュー - // "Save As" menu - //----------------------------------- - private void menuSaveAsFile_Click(object sender, EventArgs e) - { - SaveToEditingFile(true); - } - - //----------------------------------- - //「HTMLファイル出力(&P)」メニュー - // "Output to HTML file" menu - //----------------------------------- - private void menuOutputHtmlFile_Click(object sender, EventArgs e) - { - string OutputFilePath; - string DirPath = Path.GetDirectoryName(_MarkDownTextFilePath); - - if (File.Exists(_MarkDownTextFilePath) == true) - { - saveFileDialog2.InitialDirectory = DirPath; - } - //保存ダイアログを表示する - //Show Save dialog - if (MarkDownSharpEditor.AppSettings.Instance.fShowHtmlSaveDialog == true) - { - if (saveFileDialog2.ShowDialog() == DialogResult.OK) - { - OutputToHtmlFile(_MarkDownTextFilePath, saveFileDialog2.FileName, false); - } - } - else - { - //ダイアログを抑制しているので編集中のファイルのディレクトリへ保存する - //Save to editing folder in constrainting dialog - OutputFilePath = Path.Combine(DirPath, Path.GetFileNameWithoutExtension(_MarkDownTextFilePath)) + ".html"; - - if (File.Exists(OutputFilePath) == true) - { - //"問い合わせ" - //"すでに同名のファイルが存在しています。上書きして出力しますか?" - //"Question" - //"Same file exists.\nContinue to overwrite?" - DialogResult ret = MessageBox.Show( - Resources.MsgSameFileOverwrite + "\n" + OutputFilePath, - Resources.DialogTitleQuestion, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, - MessageBoxDefaultButton.Button1); // Yesがデフォルト - - if (ret == DialogResult.Yes) - { - //上書きしてHTMLファイルへ出力 - //Overwrite and output to HTML file - OutputToHtmlFile(_MarkDownTextFilePath, OutputFilePath, false); - } - else if (ret == DialogResult.No) - { - //設定されてないが一応保存ダイアログを出す - //It is no setting, but show save dialog - if (saveFileDialog2.ShowDialog() == DialogResult.OK) - { - //HTMLファイルへ出力 - //Output to HTML file - OutputToHtmlFile(_MarkDownTextFilePath, saveFileDialog2.FileName, false); - } - } - else - { - //キャンセル - //Cancel - } - } - else - { - //HTMLファイルへ出力 - //Output to HTML file - OutputToHtmlFile(_MarkDownTextFilePath, OutputFilePath, false); - } - } - } - - //----------------------------------- - //「HTMLソースコードをクリップボードへコピー(&L)」メニュー - // "Set HTML source code to clipboard" menu - //----------------------------------- - private void menuOutputHtmlToClipboard_Click(object sender, EventArgs e) - { - //HTMLソースをクリップボードへ出力 - //Output HTML source to clipboard - OutputToHtmlFile(_MarkDownTextFilePath, "", true); - - //HTMLソースをクリップボードコピーしたときに確認メッセージを表示する(&M) - //Show message to confirm when HTML source data is setting to clipboard - if (MarkDownSharpEditor.AppSettings.Instance.fShowHtmlToClipboardMessage == true) - { - //"通知" - //"クリップボードに保存されました。" - //"Information" - //"This file has been output to the clipboard." - MessageBox.Show(Resources.MsgOutputToClipboard, - Resources.DialogTitleNotice, MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } - - //----------------------------------- - //「終了」メニュー - // "Exit" menu - //----------------------------------- - private void menuExit_Click(object sender, EventArgs e) - { - Close(); - } - - //----------------------------------- - //「編集」メニュー - // "Edit" menu - //----------------------------------- - private void menuEdit_Click(object sender, EventArgs e) - { - if (undoCounter > 0) - { - menuUndo.Enabled = true; - } - else - { - menuUndo.Enabled = false; - } - - if (undoCounter < UndoBuffer.Count && undoCounter > 0) - { - menuRedo.Enabled = true; - } - else - { - menuRedo.Enabled = false; - } - - if (richTextBox1.SelectionLength > 0) - { - menuCut.Enabled = true; - menuCopy.Enabled = true; - } - else - { - menuCut.Enabled = false; - menuCopy.Enabled = false; - } - } - //----------------------------------- - //「元に戻す」メニュー - // "Undo" menu - //----------------------------------- - private void menuUndo_Click(object sender, EventArgs e) - { - if (UndoBuffer.Count > 0 && undoCounter > 0) - { //現在のカーソル位置 - //Current cursor position - int selectStart = this.richTextBox1.SelectionStart; - int selectEnd = richTextBox1.SelectionLength; - //現在のスクロール位置 - //Current scroll position - int CurrentScrollpos = richTextBox1.VerticalPosition; - //描画停止 - //Stop to paint - richTextBox1.BeginUpdate(); - - undoCounter--; - richTextBox1.Rtf = UndoBuffer[undoCounter]; - - //カーソル位置を戻す - //Restore cursor position - richTextBox1.Select(selectStart, selectEnd); - //スクロール位置を戻す - //Restore scroll position - richTextBox1.VerticalPosition = CurrentScrollpos; - //描画再開 - //Resume to paint - richTextBox1.EndUpdate(); - - if (undoCounter == 0) - { - richTextBox1.Modified = false; - FormTextChange(); - } - } - } - //----------------------------------- - //「やり直す」メニュー - // "Redo" menu - //----------------------------------- - private void menuRedo_Click(object sender, EventArgs e) - { - if (undoCounter < UndoBuffer.Count && undoCounter > 0) - { - undoCounter++; - richTextBox1.Rtf = UndoBuffer[undoCounter]; - FormTextChange(); - } - } - //----------------------------------- - //「切り取り」メニュー - // "Cut" to clipbord menu - //----------------------------------- - private void menuCut_Click(object sender, EventArgs e) - { - if (richTextBox1.SelectionLength > 0) - { - richTextBox1.Cut(); - FormTextChange(); - } - } - //----------------------------------- - //「コピー」メニュー - // "Copy" to clipboard menu - //----------------------------------- - private void menuCopy_Click(object sender, EventArgs e) - { - if (richTextBox1.SelectionLength > 0) - { - richTextBox1.Copy(); - } - } - //----------------------------------- - //「貼り付け」メニュー - // "Paste" from clipboard menu - //----------------------------------- - private void menuPaste_Click(object sender, EventArgs e) - { - IDataObject data = Clipboard.GetDataObject(); - if (data != null && data.GetDataPresent(DataFormats.Text) == true) - { - DataFormats.Format fmt = DataFormats.GetFormat(DataFormats.Text); - richTextBox1.Paste(fmt); - FormTextChange(); - } - } - //----------------------------------- - //「すべてを選択」メニュー - // "Select all" menu - //----------------------------------- - private void menuSelectAll_Click(object sender, EventArgs e) - { - richTextBox1.SelectAll(); - } - - //----------------------------------- - //「検索」メニュー - // "Search" menu - //----------------------------------- - private void menuSearch_Click(object sender, EventArgs e) - { - _fSearchStart = false; - panelSearch.Visible = true; - panelSearch.Height = 58; - textBoxSearch.Focus(); - labelReplace.Visible = false; - textBoxReplace.Visible = false; - cmdReplaceAll.Visible = false; - cmdSearchNext.Text = Resources.ButtonFindNext; //"次を検索する(&N)"; - cmdSearchPrev.Text = Resources.ButtonFindPrev; // "前を検索する(&P)"; - } - //----------------------------------- - //「置換」メニュー - // "Replace" menu - //----------------------------------- - private void menuReplace_Click(object sender, EventArgs e) - { - _fSearchStart = false; - panelSearch.Visible = true; - panelSearch.Height = 58; - textBoxSearch.Focus(); - labelReplace.Visible = true; - textBoxReplace.Visible = true; - cmdReplaceAll.Visible = true; - cmdSearchNext.Text = Resources.ButtonReplaceNext; //"置換して次へ(&N)"; - cmdSearchPrev.Text = Resources.ButtonReplacePrev; //"置換して前へ(&P)"; - } - - //----------------------------------- - // 表示の更新 - // "Refresh preview" menu - //----------------------------------- - private void menuViewRefresh_Click(object sender, EventArgs e) - { - PreviewToBrowser(); - } - - //----------------------------------- - //「ソースとビューを均等表示する」メニュー - // "Editor and Browser Width evenly" menu - //----------------------------------- - private void menuViewWidthEvenly_Click(object sender, EventArgs e) - { - if (menuViewWidthEvenly.Checked == true) - { - menuViewWidthEvenly.Checked = false; - } - else - { - menuViewWidthEvenly.Checked = true; - } - MarkDownSharpEditor.AppSettings.Instance.fSplitBarWidthEvenly = menuViewWidthEvenly.Checked; - } - - //----------------------------------- - //「言語」メニュー - // Change "Language" menu - //----------------------------------- - private void menuViewJapanese_Click(object sender, EventArgs e) - { - //"問い合わせ" - //"言語の変更を反映するには、アプリケーションの再起動が必要です。 - //今すぐ再起動しますか?" - //"Question" - //"To change the setting of language, it is necessary to restart the application. - // Do you want to restart this application now?" - DialogResult result = MessageBox.Show(Resources.MsgRestartApplication, - Resources.DialogTitleQuestion, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); - - if (result == DialogResult.Yes) - { - MarkDownSharpEditor.AppSettings.Instance.Lang = "ja"; - MarkDownSharpEditor.AppSettings.Instance.SaveToXMLFile(); - Application.Restart(); - } - else if (result == DialogResult.No) - { - MarkDownSharpEditor.AppSettings.Instance.Lang = "ja"; - menuViewJapanese.Checked = true; - menuViewEnglish.Checked = false; - } - else - { - //Cancel - } - - } - - private void menuViewEnglish_Click(object sender, EventArgs e) - { - //"問い合わせ" - //"言語の変更を反映するには、アプリケーションの再起動が必要です。 - //今すぐ再起動しますか?" - //"Question" - //"To change the setting of language, it is necessary to restart the application. - // Do you want to restart this application now?" - DialogResult result = MessageBox.Show(Resources.MsgRestartApplication, - Resources.DialogTitleQuestion, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); - - if (result == DialogResult.Yes) - { - MarkDownSharpEditor.AppSettings.Instance.Lang = "en"; - MarkDownSharpEditor.AppSettings.Instance.SaveToXMLFile(); - Application.Restart(); - } - else if (result == DialogResult.No) - { - MarkDownSharpEditor.AppSettings.Instance.Lang = "en"; - MarkDownSharpEditor.AppSettings.Instance.SaveToXMLFile(); - menuViewJapanese.Checked = false; - menuViewEnglish.Checked = true; - } - else - { - //Cancel - } - - } - - //----------------------------------- - //「ツールバーを表示する」メニュー - // "View toolbar" menu - //----------------------------------- - private void menuViewToolBar_Click(object sender, EventArgs e) - { - if (menuViewToolBar.Checked == true) - { - menuViewToolBar.Checked = false; - toolStrip1.Visible = false; - } - else - { - menuViewToolBar.Checked = true; - toolStrip1.Visible = true; - } - MarkDownSharpEditor.AppSettings.Instance.fViewToolBar = toolStrip1.Visible; - } - //----------------------------------- - //「ステータスバーを表示する」メニュー - // "View statusbar" menu - //----------------------------------- - private void menuViewStatusBar_Click(object sender, EventArgs e) - { - if (menuViewStatusBar.Checked == true) - { - menuViewStatusBar.Checked = false; - statusStrip1.Visible = false; - } - else - { - menuViewStatusBar.Checked = true; - statusStrip1.Visible = true; - } - MarkDownSharpEditor.AppSettings.Instance.fViewStatusBar = statusStrip1.Visible; - } - - //----------------------------------- - //「書式フォント」メニュー - // "Font" menu - //----------------------------------- - private void menuFont_Click(object sender, EventArgs e) - { - bool fModify = richTextBox1.Modified; - fontDialog1.Font = richTextBox1.Font; - fontDialog1.Color = richTextBox1.ForeColor; - //選択できるポイントサイズの最小・最大値 - fontDialog1.MinSize = 6; - fontDialog1.MaxSize = 72; - fontDialog1.FontMustExist = true; - //横書きフォントだけを表示する - fontDialog1.AllowVerticalFonts = false; - //色を選択できるようにする - fontDialog1.ShowColor = true; - //取り消し線、下線、テキストの色などのオプションを指定不可 - fontDialog1.ShowEffects = false; - //ダイアログを表示する - if (fontDialog1.ShowDialog() == DialogResult.OK) - { - UndoBuffer.Add(richTextBox1.Rtf); - undoCounter = UndoBuffer.Count; - this.richTextBox1.TextChanged -= new System.EventHandler(this.richTextBox1_TextChanged); - richTextBox1.Font = fontDialog1.Font; - richTextBox1.ForeColor = fontDialog1.Color; - //ステータスバーに表示 - toolStripStatusLabelFontInfo.Text = - fontDialog1.Font.Name + "," + fontDialog1.Font.Size.ToString() + "pt"; - this.richTextBox1.TextChanged += new System.EventHandler(this.richTextBox1_TextChanged); - } - //richTextBoxの書式を変えても「変更」となるので元のステータスへ戻す - richTextBox1.Modified = fModify; - } - - //----------------------------------- - //「オプション」メニュー - // "Option" menu - //----------------------------------- - private void menuOption_Click(object sender, EventArgs e) - { - Form3 frm3 = new Form3(); - frm3.ShowDialog(); - frm3.Dispose(); - - _MarkdownSyntaxKeywordAarray = MarkdownSyntaxKeyword.CreateKeywordList(); //キーワードリストの更新 - if (backgroundWorker2.IsBusy == false) - { - //SyntaxHightlighter on BackgroundWorker - backgroundWorker2.RunWorkerAsync(richTextBox1.Text); - } - - //プレビュー間隔を更新 - if (MarkDownSharpEditor.AppSettings.Instance.AutoBrowserPreviewInterval > 0) - { - timer1.Interval = MarkDownSharpEditor.AppSettings.Instance.AutoBrowserPreviewInterval; - } - } - - //----------------------------------- - // ヘルプファイルの表示 - // "Help contents" menu - //----------------------------------- - private void menuContents_Click(object sender, EventArgs e) - { - string HelpFilePath; - string DirPath = MarkDownSharpEditor.AppSettings.GetAppDataLocalPath(); - - if (MarkDownSharpEditor.AppSettings.Instance.Lang == "ja") - { - HelpFilePath = Path.Combine(DirPath, "help-ja.md"); - } - else - { - HelpFilePath = Path.Combine(DirPath, "help.md"); - } - - if (File.Exists(HelpFilePath) == true) - { //別ウィンドウで開く - //Create a new ProcessStartInfo structure. - System.Diagnostics.ProcessStartInfo pInfo = new System.Diagnostics.ProcessStartInfo(); - //Set the file name member. - pInfo.FileName = HelpFilePath; - //UseShellExecute is true by default. It is set here for illustration. - pInfo.UseShellExecute = true; - System.Diagnostics.Process p = System.Diagnostics.Process.Start(pInfo); - } - else - { //"エラー" - //"ヘルプファイルがありません。開くことができませんでした。" - //"Could not find Help file. Opening this file has failed." - MessageBox.Show(Resources.MsgNoHelpFile, - Resources.DialogTitleError, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } - } - - //----------------------------------- - // 最新バージョンのチェック - // "Check for Update" - //----------------------------------- - private void mnuCheckForUpdate_Click(object sender, EventArgs e) - { - string MsgText = ""; - Version newVersion = null; - string url = ""; - string dt = ""; - System.Xml.XmlTextReader reader; - - /* - * - * - * 1.2.1.0 - * 2013/06/18 - * http://hibara.org/software/markdownsharpeditor/ - * - */ - string xmlURL = "http://hibara.org/software/markdownsharpeditor/app_version.xml"; - using (reader = new System.Xml.XmlTextReader(xmlURL)) - { - reader.MoveToContent(); - string elementName = ""; - if ((reader.NodeType == System.Xml.XmlNodeType.Element) && (reader.Name == "markdownsharpeditor")) - { - while (reader.Read()) - { - if (reader.NodeType == System.Xml.XmlNodeType.Element) - { - elementName = reader.Name; - } - else - { - if ((reader.NodeType == System.Xml.XmlNodeType.Text) && (reader.HasValue)) - { - switch (elementName) - { - case "version": - newVersion = new Version(reader.Value); - break; - case "url": - url = reader.Value; - break; - case "date": - dt = reader.Value; - break; - } - } - } - } - } - } - - if (newVersion == null) - { - //Failed to get the latest version information. - MsgText = Resources.ErrorGetNewVersion; - MessageBox.Show(MsgText, Resources.DialogTitleError, MessageBoxButtons.OK, MessageBoxIcon.Question); - return; - } - - // get current version - Version curVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; - if (curVersion.CompareTo(newVersion) < 0) - { //"New version was found! Do you open the download site?"; - MsgText = "Update info: ver." + newVersion + " (" + dt + " ) \n" + Resources.NewVersionFound; - if (DialogResult.Yes == MessageBox.Show(this, MsgText, Resources.DialogTitleQuestion, MessageBoxButtons.YesNo, MessageBoxIcon.Question)) - { - System.Diagnostics.Process.Start(url); - } - } - else - { // You already have the latest version of this application. - MsgText = Resources.AlreadyLatestVersion + "\nver." + newVersion + " ( " + dt + " ) "; - MessageBox.Show(MsgText, Resources.DialogTitleInfo, MessageBoxButtons.OK, MessageBoxIcon.Question); - } - - } - - //----------------------------------- - // サンプル表示 - // "View Markdown sample file" - //----------------------------------- - private void menuViewSample_Click(object sender, EventArgs e) - { - string DirPath = MarkDownSharpEditor.AppSettings.GetAppDataLocalPath(); - string SampleFilePath = Path.Combine(DirPath, "sample.md"); - - if (File.Exists(SampleFilePath) == true) - { - System.Diagnostics.ProcessStartInfo pInfo = new System.Diagnostics.ProcessStartInfo(); - pInfo.FileName = SampleFilePath; - pInfo.UseShellExecute = true; - System.Diagnostics.Process p = System.Diagnostics.Process.Start(pInfo); - } - else - { - //"エラー" - //"サンプルファイルがありません。開くことができませんでした。" - //"Error" - //"Could not find sample MD file.\nOpening this file has failed." - MessageBox.Show(Resources.MsgNoSampleFile, - Resources.DialogTitleError, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } - } - - //----------------------------------- - //「MarkDownSharpについて」メニュー - // "About" menu - //----------------------------------- - private void menuAbout_Click(object sender, EventArgs e) - { - Form2 frm2 = new Form2(); - frm2.ShowDialog(); - frm2.Dispose(); - } - - #endregion - //====================================================================== - - //====================================================================== - #region ステータスバーイベント ( Statusbar event ) - //====================================================================== - - //----------------------------------- - // ステータスバー(CSS) - //----------------------------------- - private void toolStripStatusLabelCssFileName_Click(object sender, EventArgs e) - { - //ポップアップメニューに登録する - //Regist item to popup menus - contextMenu1.Items.Clear(); - - foreach (string FilePath in MarkDownSharpEditor.AppSettings.Instance.ArrayCssFileList) - { - if (File.Exists(FilePath) == true) - { - ToolStripMenuItem item = new ToolStripMenuItem(Path.GetFileName(FilePath)); - item.Tag = FilePath; - if (_SelectedCssFilePath == FilePath) - { - item.Checked = true; - } - contextMenu1.Items.Add(item); - } - } - if (contextMenu1.Items.Count > 0) - { - contextMenu1.Tag = "css"; - contextMenu1.Show(Control.MousePosition); - } - - } - - //----------------------------------- - // ステータスバー(Encoding) - //----------------------------------- - private void toolStripStatusLabelEncoding_Click(object sender, EventArgs e) - { - //ポップアップメニューに登録する - //Regist item to popup menus - contextMenu1.Items.Clear(); - foreach (EncodingInfo ei in Encoding.GetEncodings()) - { - if (ei.GetEncoding().IsBrowserDisplay == true) - { - ToolStripMenuItem item = new ToolStripMenuItem(ei.DisplayName); - item.Tag = ei.CodePage; - if (ei.CodePage == MarkDownSharpEditor.AppSettings.Instance.CodePageNumber) - { - item.Checked = true; - } - contextMenu1.Items.Add(item); - } - } - contextMenu1.Tag = "encoding"; - contextMenu1.Show(Control.MousePosition); - } - - //----------------------------------- - // ステータスバー(共通のクリックイベント) - // Common item clicked event - //----------------------------------- - private void contextMenu1_ItemClicked(object sender, ToolStripItemClickedEventArgs e) - { - //----------------------------------- - // 適用するCSSファイル変更 - // Change selected CSS file - //----------------------------------- - if ((string)contextMenu1.Tag == "css") - { - _SelectedCssFilePath = (string)e.ClickedItem.Tag; - toolStripStatusLabelCssFileName.Text = Path.GetFileName(_SelectedCssFilePath); - //プレビューも更新する - PreviewToBrowser(); - - } - //----------------------------------- - // 出力HTMLに適用する文字コードの変更 - // Change encoding to output HTML file - //----------------------------------- - else if ((string)contextMenu1.Tag == "encoding") - { - MarkDownSharpEditor.AppSettings.Instance.CodePageNumber = (int)e.ClickedItem.Tag; - //プレビューも更新する - //Refresh previewing, too - PreviewToBrowser(); - } - } - - //---------------------------------------------------------------------- - // 検索パネル ( Search panel ) - //---------------------------------------------------------------------- - private void imgSearchExit_Click(object sender, EventArgs e) - { - panelSearch.Visible = false; - } - //----------------------------------- - // 検索パネル「閉じる」ボタンイベント - // Search panel close button image event - //----------------------------------- - private void imgSearchExit_MouseEnter(object sender, EventArgs e) - { - imgSearchExit.Image = imgSearchExitEnabled.Image; - } - private void imgSearchExit_MouseLeave(object sender, EventArgs e) - { - imgSearchExit.Image = imgSearchExitUnabled.Image; - } - - //----------------------------------- - // 検索テキストボックス - // Search text box TextChanged event - //----------------------------------- - private void textBoxSearch_TextChanged(object sender, EventArgs e) - { - //検索をやり直し - //Restart to search - _fSearchStart = false; - if (textBoxReplace.Visible == true) - { - if (textBoxSearch.Text == "") - { - cmdSearchNext.Enabled = false; - cmdSearchPrev.Enabled = false; - cmdReplaceAll.Enabled = false; - } - else - { - cmdSearchNext.Enabled = true; - cmdSearchPrev.Enabled = true; - cmdReplaceAll.Enabled = true; - } - } - else - { - cmdSearchNext.Enabled = true; - cmdSearchPrev.Enabled = true; - } - } - - //----------------------------------- - // 検索テキストボックス - // Search text box KeyDown event - //----------------------------------- - private void textBoxSearch_KeyDown(object sender, KeyEventArgs e) - { - if (e.Shift && e.KeyCode == Keys.Enter) - { // Shitf + Enter で前へ - // Press Shift + Enter key to previous item - cmdSearchPrev_Click(sender, e); - } - else if (e.KeyCode == Keys.Enter) - { - cmdSearchNext_Click(sender, e); - } - else if (e.KeyCode == Keys.Escape) - { - panelSearch.Visible = false; - } - } - - //----------------------------------- - // 検索テキストボックス - // Search text box KeyPress event - //----------------------------------- - private void textBoxSearch_KeyPress(object sender, KeyPressEventArgs e) - { - //EnterやEscapeキーでビープ音が鳴らないようにする - //Constraint to beep sound with Enter & Escape key - if (e.KeyChar == (char)Keys.Enter || e.KeyChar == (char)Keys.Escape) - { - e.Handled = true; - } - } - - //----------------------------------- - // 置換テキストボックス - // Search text box KeyDown event - //----------------------------------- - private void textBoxReplace_KeyDown(object sender, KeyEventArgs e) - { - if (e.Shift && e.KeyCode == Keys.Enter) - { // Shitf + Enter で前へ - // Press Shift + Enter key to previous item - cmdSearchPrev_Click(sender, e); - } - else if (e.KeyCode == Keys.Enter) - { - cmdSearchNext_Click(sender, e); - } - else if (e.KeyCode == Keys.Escape) - { - panelSearch.Visible = false; - } - } - - //----------------------------------- - // 置換テキストボックス(KeyPress) - //----------------------------------- - private void textBoxReplace_KeyPress(object sender, KeyPressEventArgs e) - { - //EnterやEscapeキーでビープ音が鳴らないようにする - //Constraint to beep sound with Enter & Escape key - if (e.KeyChar == (char)Keys.Enter || e.KeyChar == (char)Keys.Escape) - { - e.Handled = true; - } - } - - //---------------------------------------------------------------------- - // 次を検索(または、置換して次へ)ボタン - // Press next button - //---------------------------------------------------------------------- - private void cmdSearchNext_Click(object sender, EventArgs e) - { - int StartPos; - StringComparison sc; - DialogResult result; - string MsgText = ""; - - if (textBoxSearch.Text != "") - { - //置換モードの場合は、置換してから次を検索する - //Replace the word to search next item in Replace mode - if (textBoxReplace.Visible == true && _fSearchStart == true) - { - if (richTextBox1.SelectionLength > 0) - { - richTextBox1.SelectedText = textBoxReplace.Text; - } - } - - if (chkOptionCase.Checked == true) - { - sc = StringComparison.Ordinal; - } - else - { //大文字と小文字を区別しない - //Ignore case - sc = StringComparison.OrdinalIgnoreCase; - } - - int CurrentPos = richTextBox1.SelectionStart + 1; - - //----------------------------------- - // 検索ワードが見つからない - // Searching word is not found - //----------------------------------- - if ((StartPos = richTextBox1.Text.IndexOf(textBoxSearch.Text, CurrentPos, sc)) == -1) - { - //検索を開始した直後 - //Start to search after - if (_fSearchStart == false) - { - //"ファイル末尾まで検索しましたが、見つかりませんでした。 - // ファイルの先頭から検索を続けますか?" - //"The word could not find the word to the end of this file. - // Do you wish to continue searching from the beginning of this file?" - MsgText = Resources.MsgNotFoundToEnd; - _fSearchStart = true; - } - else - { - //"ファイル末尾までの検索が完了しました。 - // ファイル先頭に戻って検索を続けますか?" - //"Searching completed to the end of this file. - // Do you wish to continue searching from the beginning of this file?" - MsgText = Resources.MsgFindCompleteToEnd; - } - result = MessageBox.Show(MsgText, Resources.DialogTitleNotice, - MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); - - if (result == DialogResult.Yes) - { - richTextBox1.SelectionStart = 0; - cmdSearchNext_Click(sender, e); - } - } - //----------------------------------- - // 検索ワードが見つかった - // Searching word were found - //----------------------------------- - else - { - //richTextBox1.HideSelection = false; - richTextBox1.Select(StartPos, textBoxSearch.Text.Length); - richTextBox1.ScrollToCaret(); - _fSearchStart = true; //検索開始 ( Start to search ) - } - } - - } - //---------------------------------------------------------------------- - // 前を検索(または、置換して前へ)ボタン - // Press previous button - //---------------------------------------------------------------------- - private void cmdSearchPrev_Click(object sender, EventArgs e) - { - int StartPos; - StringComparison sc; - DialogResult result; - string MsgText = ""; - - if (textBoxSearch.Text != "") - { - //置換モードの場合は、置換してから前を検索する - //Replace the word to search previous item in Replace mode - if (textBoxReplace.Visible == true && _fSearchStart == true) - { - if (richTextBox1.SelectionLength > 0) - { - richTextBox1.SelectedText = textBoxReplace.Text; - } - } - - if (chkOptionCase.Checked == true) - { - sc = StringComparison.Ordinal; - } - else - { //大文字と小文字を区別しない - //Ignore case - sc = StringComparison.OrdinalIgnoreCase; - } - - int CurrentPos = richTextBox1.SelectionStart - 1; - if (CurrentPos < 0) - { - CurrentPos = 0; - } - //----------------------------------- - // 検索ワードが見つからない - // Searching word is not found - //----------------------------------- - if ((StartPos = richTextBox1.Text.LastIndexOf(textBoxSearch.Text, CurrentPos, sc)) == -1) - { - //検索を開始した直後 - //Start to search after - if (_fSearchStart == false) - { - //"ファイル先頭まで検索しましたが、見つかりませんでした。 - // ファイルの末尾から検索を続けますか?" - //"The word could not find to the beginning of this file. - // Do you wish to continue searching from the end of this file?" - MsgText = Resources.MsgNotFoundToBegining; - _fSearchStart = true; - } - else - { - //"ファイル先頭までの検索が完了しました。 - // ファイル末尾から検索を続けますか?" - //"Searching completed to the beginning of this file. - // Do you wish to continue searching from the end of this file?" - MsgText = Resources.MsgFindCompleteToBegining; - } - - result = MessageBox.Show(MsgText, Resources.DialogTitleNotice, - MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); - - if (result == DialogResult.Yes) - { - richTextBox1.SelectionStart = richTextBox1.Text.Length - 1; - cmdSearchPrev_Click(sender, e); - } - } - //----------------------------------- - // 検索ワードが見つかった - // Searching word were found - //----------------------------------- - else - { - //richTextBox1.HideSelection = false; - richTextBox1.Select(StartPos, textBoxSearch.Text.Length); - richTextBox1.ScrollToCaret(); - _fSearchStart = true; //検索開始 ( Start to search ) - } - } - - } - - //----------------------------------- - // すべてを置換ボタン - // "Replace All" button - //----------------------------------- - private void cmdReplaceAll_Click(object sender, EventArgs e) - { - int StartPos; - StringComparison sc; - string MsgText = ""; - - if (chkOptionCase.Checked == true) - { - sc = StringComparison.Ordinal; - } - else - { //大文字と小文字を区別しない - //Ignore case - sc = StringComparison.OrdinalIgnoreCase; - } - - int CurrentPos = 0; - int ReplaceCount = 0; - while ((StartPos = richTextBox1.Text.IndexOf(textBoxSearch.Text, CurrentPos, sc)) > -1) - { - richTextBox1.Select(StartPos, textBoxSearch.Text.Length); - richTextBox1.ScrollToCaret(); - if (richTextBox1.SelectionLength > 0) - { - richTextBox1.SelectedText = textBoxReplace.Text; - ReplaceCount++; - CurrentPos = StartPos + textBoxReplace.Text.Length; - } - } - - if (ReplaceCount > 0) - { - //"以下のワードを" ~ "件置換しました。\n" - //"" ~ " of the word were replaced.\n" - MsgText = Resources.MsgThisWord + "\"" + ReplaceCount.ToString() + "\"" + Resources.MsgReplaced + "\n" + - textBoxSearch.Text + " -> " + textBoxReplace.Text; - } - else - { - //"ご指定の検索ワードは見つかりませんでした。" - //"The word was not found." - MsgText = Resources.MsgNotFound; - } - - MessageBox.Show(MsgText, Resources.DialogTitleNotice, MessageBoxButtons.OK, MessageBoxIcon.Information); - _fSearchStart = true; - - } - - #endregion - - //====================================================================== - #region エンコーディングの判定 ( Detecting encoding ) - //====================================================================== - // - // ここのコードはまんま、以下のサイトのものを使わせていただきました。 - // http://dobon.net/vb/dotnet/string/detectcode.html - // - // - // 文字コードを判別する - // - // - // Jcode.pmのgetcodeメソッドを移植したものです。 - // Jcode.pm(http://openlab.ring.gr.jp/Jcode/index-j.html) - // Jcode.pmのCopyright: Copyright 1999-2005 Dan Kogai - // - // 文字コードを調べるデータ - // 適当と思われるEncodingオブジェクト。 - // 判断できなかった時はnull。 - public static Encoding GetCode(byte[] bytes) - { - const byte bEscape = 0x1B; - const byte bAt = 0x40; - const byte bDollar = 0x24; - const byte bAnd = 0x26; - const byte bOpen = 0x28; //'(' - const byte bB = 0x42; - const byte bD = 0x44; - const byte bJ = 0x4A; - const byte bI = 0x49; - - int len = bytes.Length; - byte b1, b2, b3, b4; - - //Encode::is_utf8 は無視 - - bool isBinary = false; - for (int i = 0; i < len; i++) - { - b1 = bytes[i]; - if (b1 <= 0x06 || b1 == 0x7F || b1 == 0xFF) - { - //'binary' - isBinary = true; - if (b1 == 0x00 && i < len - 1 && bytes[i + 1] <= 0x7F) - { - //smells like raw unicode - return Encoding.Unicode; - } - } - } - if (isBinary) - { - return null; - } - - //not Japanese - bool notJapanese = true; - for (int i = 0; i < len; i++) - { - b1 = bytes[i]; - if (b1 == bEscape || 0x80 <= b1) - { - notJapanese = false; - break; - } - } - if (notJapanese) - { - return Encoding.ASCII; - } - - for (int i = 0; i < len - 2; i++) - { - b1 = bytes[i]; - b2 = bytes[i + 1]; - b3 = bytes[i + 2]; - - if (b1 == bEscape) - { - if (b2 == bDollar && b3 == bAt) - { - //JIS_0208 1978 - //JIS - return Encoding.GetEncoding(50220); - } - else if (b2 == bDollar && b3 == bB) - { - //JIS_0208 1983 - //JIS - return Encoding.GetEncoding(50220); - } - else if (b2 == bOpen && (b3 == bB || b3 == bJ)) - { - //JIS_ASC - //JIS - return Encoding.GetEncoding(50220); - } - else if (b2 == bOpen && b3 == bI) - { - //JIS_KANA - //JIS - return Encoding.GetEncoding(50220); - } - if (i < len - 3) - { - b4 = bytes[i + 3]; - if (b2 == bDollar && b3 == bOpen && b4 == bD) - { - //JIS_0212 - //JIS - return Encoding.GetEncoding(50220); - } - if (i < len - 5 && - b2 == bAnd && b3 == bAt && b4 == bEscape && - bytes[i + 4] == bDollar && bytes[i + 5] == bB) - { - //JIS_0208 1990 - //JIS - return Encoding.GetEncoding(50220); - } - } - } - } - - //should be euc|sjis|utf8 - //use of (?:) by Hiroki Ohzaki - int sjis = 0; - int euc = 0; - int utf8 = 0; - for (int i = 0; i < len - 1; i++) - { - b1 = bytes[i]; - b2 = bytes[i + 1]; - if (((0x81 <= b1 && b1 <= 0x9F) || (0xE0 <= b1 && b1 <= 0xFC)) && - ((0x40 <= b2 && b2 <= 0x7E) || (0x80 <= b2 && b2 <= 0xFC))) - { - //SJIS_C - sjis += 2; - i++; - } - } - for (int i = 0; i < len - 1; i++) - { - b1 = bytes[i]; - b2 = bytes[i + 1]; - if (((0xA1 <= b1 && b1 <= 0xFE) && (0xA1 <= b2 && b2 <= 0xFE)) || - (b1 == 0x8E && (0xA1 <= b2 && b2 <= 0xDF))) - { - //EUC_C - //EUC_KANA - euc += 2; - i++; - } - else if (i < len - 2) - { - b3 = bytes[i + 2]; - if (b1 == 0x8F && (0xA1 <= b2 && b2 <= 0xFE) && - (0xA1 <= b3 && b3 <= 0xFE)) - { - //EUC_0212 - euc += 3; - i += 2; - } - } - } - for (int i = 0; i < len - 1; i++) - { - b1 = bytes[i]; - b2 = bytes[i + 1]; - if ((0xC0 <= b1 && b1 <= 0xDF) && (0x80 <= b2 && b2 <= 0xBF)) - { - //UTF8 - utf8 += 2; - i++; - } - else if (i < len - 2) - { - b3 = bytes[i + 2]; - if ((0xE0 <= b1 && b1 <= 0xEF) && (0x80 <= b2 && b2 <= 0xBF) && - (0x80 <= b3 && b3 <= 0xBF)) - { - //UTF8 - utf8 += 3; - i += 2; - } - } - } - //M. Takahashi's suggestion - //utf8 += utf8 / 2; - - System.Diagnostics.Debug.WriteLine( - string.Format("sjis = {0}, euc = {1}, utf8 = {2}", sjis, euc, utf8)); - if (euc > sjis && euc > utf8) - { - //EUC - return Encoding.GetEncoding(51932); - } - else if (sjis > euc && sjis > utf8) - { - //SJIS - return Encoding.GetEncoding(932); - } - else if (utf8 > euc && utf8 > sjis) - { - //UTF8 - return Encoding.UTF8; - } - - return null; - } - - #endregion - - //====================================================================== - #region WebBrowserコンポーネントのカチカチ音制御 - - /* - // 以下のサイトのエントリーを参考にさせていただきました。 - // http://www.moonmile.net/blog/archives/1465 - - private string keyCurrent = @"AppEvents\Schemes\Apps\Explorer\Navigating\.Current"; - private string keyDefault = @"AppEvents\Schemes\Apps\Explorer\Navigating\.Default"; - - // - // クリック音をON - // - // - // - private void WebBrowserClickSoundON() - { - - //=================================== - // Win8でKeyの取得ができないときがある? - //=================================== - - // .Defaultの値を読み込んで、.Currentに書き込み - Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser; - key = key.OpenSubKey(keyDefault); - string data = (string)key.GetValue(null); - key.Close(); - - key = Microsoft.Win32.Registry.CurrentUser; - key = key.OpenSubKey(keyCurrent, true); - key.SetValue(null, data); - key.Close(); - - } - // - // クリック音をOFF - // - // - // - private void WebBrowserClickSoundOFF() - { - // .Currnetを @"" にする。 - Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser; - key = key.OpenSubKey(keyCurrent, true); - key.SetValue(null, ""); - key.Close(); - } - - */ - #endregion - - - } - -} + AppSettings.SetBrowserRenderingMode(obj.FeatureBrowserEmulation, obj.FeatureDocumentCompatibuleMode); + + string ResultText = (string)e.Argument; + string MkResultText = ""; + + string BackgroundColorString; + string EncodingName; + + //編集中のファイル名 + //Editing file name + string FileName = (_MarkDownTextFilePath == "" ? "" : Path.GetFileName(_MarkDownTextFilePath)); + //DOCTYPE + HtmlHeader htmlHeader = new HtmlHeader(); + string DocType = htmlHeader.GetHtmlHeader(MarkDownSharpEditor.AppSettings.Instance.HtmlDocType); + + //マーキングの色づけ + //Marker's color + if (MarkDownSharpEditor.AppSettings.Instance.fHtmlHighLightColor == true) + { + Color ColorBackground = Color.FromArgb(MarkDownSharpEditor.AppSettings.Instance.HtmlHighLightColor); + BackgroundColorString = ColorTranslator.ToHtml(ColorBackground); + } + else + { + BackgroundColorString = "none"; + } + + //指定のエンコーディング + //Codepage + int CodePageNum = MarkDownSharpEditor.AppSettings.Instance.CodePageNumber; + try + { + Encoding enc = Encoding.GetEncoding(CodePageNum); + //ブラウザ表示に対応したエンコーディングか + //Is the encoding supported browser? + if (enc.IsBrowserDisplay == true) + { + EncodingName = enc.WebName; + } + else + { + EncodingName = "utf-8"; + } + } + catch + { + //エンコーディングの取得に失敗した場合 + //Default encoding if failing to get encoding + EncodingName = "utf-8"; + } + //Header + string header = string.Format( +@"{0} + + + + + +{4} + + +", + DocType, //DOCTYPE + EncodingName, //エンコーディング ( encoding ) + _SelectedCssFilePath, //適用中のCSSファイル ( Selected CSS file ) + BackgroundColorString, //編集箇所の背景色 ( background color in Editing ) + FileName); //タイトル(=ファイル名) ( title = file name ) + + //Footer + string footer = "\n"; + + //----------------------------------- + //Markdown parse ( default ) + //Markdown mkdwn = new Markdown(); + //----------------------------------- + + //----------------------------------- + // MarkdownDeep + // Create an instance of Markdown + //----------------------------------- + var mkdwn = new MarkdownDeep.Markdown(); + // Set options + mkdwn.ExtraMode = MarkDownSharpEditor.AppSettings.Instance.fMarkdownExtraMode; + mkdwn.SafeMode = false; + //----------------------------------- + + ResultText = mkdwn.Transform(ResultText); + //表示するHTMLデータを作成 + //Creat HTML data + ResultText = header + ResultText + footer; + + //パースされた内容から編集行を探す + //Search editing line in parsed data + string OneLine; + StringReader sr = new StringReader(ResultText); + StringWriter sw = new StringWriter(); + while ((OneLine = sr.ReadLine()) != null) + { + if (OneLine.IndexOf("") >= 0) + { + MkResultText += ("
" + OneLine + "
\n"); + } + else + { + MkResultText += (OneLine + "\n"); + } + } + + //エンコーディングしつつbyte値に変換する(richEditBoxは基本的にutf-8 = 65001) + //Encode and convert it to 'byte' value ( richEditBox default encoding is utf-8 = 65001 ) + byte[] bytesData = Encoding.GetEncoding(CodePageNum).GetBytes(MkResultText); + + + //----------------------------------- + // Write to temporay file + if (_fNoTitle == false) + { + //テンポラリファイルパスを取得する + //Get temporary file path + if (_TemporaryHtmlFilePath == "") + { + _TemporaryHtmlFilePath = Get_TemporaryHtmlFilePath(_MarkDownTextFilePath); + } + //他のプロセスからのテンポラリファイルの参照と削除を許可して開く(でないと飛ぶ) + //Open temporary file to allow references from other processes + using (FileStream fs = new FileStream( + _TemporaryHtmlFilePath, + FileMode.Create, FileAccess.ReadWrite, FileShare.Read | FileShare.Delete)) + { + fs.Write(bytesData, 0, bytesData.Length); + e.Result = _TemporaryHtmlFilePath; + } + } + //----------------------------------- + // Navigate and view in browser + else + { + //Write data as it is, if the editing data is no title + ResultText = Encoding.GetEncoding(CodePageNum).GetString(bytesData); + e.Result = ResultText; + } + + } + + private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) + { + if (e.Error != null) + { + //Error! + } + else + { + if ((string)e.Result != "") + { + //----------------------------------- + //スクロールバーの位置を退避しておく + //Memorize scroll positions + HtmlDocument doc = webBrowser1.Document; + Point scrollpos = new Point(0, 0); + if (doc == null) + { + webBrowser1.Navigate("about:blank"); + } + else + { + IHTMLDocument3 doc3 = (IHTMLDocument3)webBrowser1.Document.DomDocument; + IHTMLElement2 elm = (IHTMLElement2)doc3.documentElement; + scrollpos = new Point(elm.scrollLeft, elm.scrollTop); + } + //----------------------------------- + System.Threading.Tasks.Task waitTask; + if (_fNoTitle == false) + { + //ナビゲート + //Browser navigate + //webBrowser1.Navigate(@"file://" + (string)e.Result); + waitTask = WebBrowserNavigate(@"file://" + (string)e.Result); + richTextBox1.Focus(); + toolStripButtonBrowserPreview.Enabled = true; + } + else + { + webBrowser1.Document.OpenNew(true); + //webBrowser1.Document.Write((string)e.Result); + waitTask = WebBrowserDocumentWrite((string)e.Result); + //ツールバーの「関連付けられたブラウザーを起動」を無効に + //"Associated web browser" in toolbar is invalid + toolStripButtonBrowserPreview.Enabled = false; + } + //----------------------------------- + //スクロールバーの位置を復帰する + //Restore scroll bar position + if (doc != null) + { + waitTask.ContinueWith((arg1) => + { + this.BeginInvoke(new Action(() => + { + doc.Window.ScrollTo(scrollpos); + + this.webBrowser1.Document.Body.AttachEventHandler("onscroll", OnScrollEventHandler); + + })); + }); + } + } + } + } + /// + /// webBrowser コンポーネントにHTMLを出力して + /// DocumentComplate になるのを非同期で待ち合わせる + /// + /// + /// + System.Threading.Tasks.Task WebBrowserDocumentWrite(string html) + { + if (browserWaitTimer == null) + { + browserWaitTimer = new Timer(); + browserWaitTimer.Tick += browserWaitTimer_Tick; + browserWaitTimer.Enabled = true; + } + var obj = waitObject; + if (obj != null) + { + obj.SetCanceled(); + } + waitObject = new System.Threading.Tasks.TaskCompletionSource(); + + timerCount = 0; + + this.webBrowser1.DocumentText = html; + + browserWaitTimer.Enabled = true; + + return waitObject.Task; + } + + /// + /// webBrowser コンポーネントにHTMLを出力して + /// DocumentComplate になるのを非同期で待ち合わせる + /// + /// + /// + System.Threading.Tasks.Task WebBrowserNavigate(string url) + { + if (browserWaitTimer == null) + { + browserWaitTimer = new Timer(); + browserWaitTimer.Tick += browserWaitTimer_Tick; + browserWaitTimer.Enabled = true; + } + var obj = waitObject; + if (obj != null) + { + obj.SetCanceled(); + } + waitObject = new System.Threading.Tasks.TaskCompletionSource(); + + timerCount = 0; + + this.webBrowser1.Navigate(url); + + browserWaitTimer.Enabled = true; + + return waitObject.Task; + } + + void browserWaitTimer_Tick(object sender, EventArgs e) + { + if (waitObject == null) + { + browserWaitTimer.Enabled = false; + return; + } + + timerCount++; + + if (this.webBrowser1.ReadyState == WebBrowserReadyState.Complete) + { + waitObject.SetResult("OK"); + waitObject = null; + browserWaitTimer.Enabled = false; + } + else if (timerCount > 20) + { + // 反応ないので終わりにする + waitObject.SetResult("OK"); + waitObject = null; + browserWaitTimer.Enabled = false; + } + } + + System.Threading.Tasks.TaskCompletionSource waitObject = null; + int timerCount = 0; + Timer browserWaitTimer; + + //---------------------------------------------------------------------- + // BackgroundWorker Syntax hightlighter work + //---------------------------------------------------------------------- + private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e) + { + var text = e.Argument as string; + if (string.IsNullOrEmpty(text)) + { + e.Result = null; + return; + } + if (timer2.Enabled == true) + { + e.Result = null; + return; + } + + var result = new List(); + foreach (MarkdownSyntaxKeyword mk in _MarkdownSyntaxKeywordAarray) + { + MatchCollection col = mk.Regex.Matches(text, 0); + + if (col.Count > 0) + { + foreach (Match m in col) + { + SyntaxColorScheme sytx = new SyntaxColorScheme(); + sytx.SelectionStartIndex = m.Groups[0].Index; + sytx.SelectionLength = m.Groups[0].Length; + sytx.ForeColor = mk.ForeColor; + sytx.BackColor = mk.BackColor; + result.Add(sytx); + } + } + } + e.Result = result; + } + //---------------------------------------------------------------------- + // BackgroundWorker Editor Syntax hightlighter progress changed + //---------------------------------------------------------------------- + private void backgroundWorker2_ProgressChanged(object sender, ProgressChangedEventArgs e) + { + + } + //---------------------------------------------------------------------- + // BackgroundWorker Syntax hightlighter completed to work + //---------------------------------------------------------------------- + private void backgroundWorker2_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) + { + if (e.Error != null || e.Cancelled == true) + { + return; + } + + var syntaxColorSchemeList = e.Result as List; + if (syntaxColorSchemeList == null) + { + return; + } + + var obj = MarkDownSharpEditor.AppSettings.Instance; + + Font fc = richTextBox1.Font; //現在のフォント設定 ( Font option ) + bool fModify = richTextBox1.Modified; //現在の編集状況 ( Modified flag ) + + _fConstraintChange = true; + + //現在のカーソル位置 / Current cursor position + int selectStart = this.richTextBox1.SelectionStart; + int selectEnd = richTextBox1.SelectionLength; + Point CurrentOffset = richTextBox1.AutoScrollOffset; + + //現在のスクロール位置 / Current scroll position + int CurrentScrollPos = richTextBox1.VerticalPosition; + //描画停止 / Stop to paint + richTextBox1.BeginUpdate(); + + //RichTextBoxの書式をクリアする / Clear richTextBox1 format options + richTextBox1.ForeColor = Color.FromArgb(obj.ForeColor_MainText); + richTextBox1.BackColor = Color.FromArgb(obj.BackColor_MainText); + + //裏でパースしていたシンタックスハイライターを反映。 + foreach (var s in syntaxColorSchemeList) + { + richTextBox1.Select(s.SelectionStartIndex, s.SelectionLength); + richTextBox1.SelectionColor = s.ForeColor; + richTextBox1.SelectionBackColor = s.BackColor; + } + + //カーソル位置を戻す / Restore cursor position + richTextBox1.Select(selectStart, selectEnd); + richTextBox1.AutoScrollOffset = CurrentOffset; + richTextBox1.VerticalPosition = CurrentScrollPos; + + //描画再開 / Resume to paint + richTextBox1.EndUpdate(); + richTextBox1.Modified = fModify; + + _fConstraintChange = false; + + if (MarkDownSharpEditor.AppSettings.Instance.AutoBrowserPreviewInterval < 0) + { + //手動更新 / Manual refresh + timer1.Enabled = false; + return; + } + else + { + timer1.Enabled = true; + } + + } + + //---------------------------------------------------------------------- + // プレビューページが読み込まれたら編集中の箇所へ自動スクロールする + // Scroll to editing line when browser is loaded + //---------------------------------------------------------------------- + private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) + { + //更新抑制中のときは抜ける + //Constraint to change + if (_fConstraintChange == true) + { + return; + } + //読み込まれた表示領域の高さを取得 + //Get viewing area to load in browser component + _WebBrowserInternalHeight = webBrowser1.Document.Body.ScrollRectangle.Height; + //ブラウザのスクロールイベントハンドラ + //Browser component event handler + webBrowser1.Document.Window.AttachEventHandler("onscroll", OnScrollEventHandler); + } + + //---------------------------------------------------------------------- + // Browser component scrolll event + //---------------------------------------------------------------------- + public void OnScrollEventHandler(object sender, EventArgs e) + { + RichEditBoxMoveCursor(); + } + + //---------------------------------------------------------------------- + // TODO: WebBrowserMoveCursor [RichEditBox → WebBrowser scroll follow] + //---------------------------------------------------------------------- + private void WebBrowserMoveCursor() + { + if (webBrowser1.Document == null) + { + return; + } + + if (richTextBox1.Focused == true) + { + //richEditBoxの内部的な高さから現在位置の割合を計算 + //Calculate current position with internal height of richTextBox1 + int LineHeight = Math.Abs(richTextBox1.GetPositionFromCharIndex(0).Y); + float perHeight = (float)LineHeight / _richEditBoxInternalHeight; + + //その割合からwebBrowserのスクロール量を計算 + //Calculate scroll amount with the ratio + _WebBrowserInternalHeight = webBrowser1.Document.Body.ScrollRectangle.Height; + int y = (int)(_WebBrowserInternalHeight * perHeight); + Point webScrollPos = new Point(0, y); + //Follow to scroll browser component + webBrowser1.Document.Window.ScrollTo(webScrollPos); + } + } + + //---------------------------------------------------------------------- + // HACK: RichEditBoxMoveCursor[ WebBrowser → RichEditBox scroll follow] + //---------------------------------------------------------------------- + private void RichEditBoxMoveCursor() + { + //ブラウザでのスクロールバーの位置 + //Position of scroll bar in browser component + if (richTextBox1.Focused == false && webBrowser1.Document != null) + { + IHTMLDocument3 doc3 = (IHTMLDocument3)webBrowser1.Document.DomDocument; + IHTMLElement2 elm = (IHTMLElement2)doc3.documentElement; + //全高さからの割合(位置) + //Ratio(Position) of height + float perHeight = (float)elm.scrollTop / _WebBrowserInternalHeight; + int y = (int)(_richEditBoxInternalHeight * perHeight); + richTextBox1.VerticalPosition = y; + } + + } + + //---------------------------------------------------------------------- + // webBrowser1 Navigated event + //---------------------------------------------------------------------- + private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e) + { + //ブラウザー操作ボタンの有効・無効化 + toolStripButtonBack.Enabled = webBrowser1.CanGoBack; + toolStripButtonForward.Enabled = webBrowser1.CanGoForward; + } + + //---------------------------------------------------------------------- + // HTML形式出力 ( Output to HTML file ) + //---------------------------------------------------------------------- + private bool OutputToHtmlFile(string FilePath, string SaveToFilePath, bool fToClipboard = false) + { + + if (File.Exists(FilePath) == false) + { + return (false); + } + + //出力内容 ( Output data ) + string ResultText = ""; + //HTMLタグ ( HTML Header tag ) + string HeaderString = ""; + string FooterString = ""; + //文字コード ( Character encoding ) + string EncodingName; + Encoding encRead = Encoding.UTF8; + Encoding encHtml = Encoding.UTF8; + + //----------------------------------- + //編集中のファイルパス or 投げ込まれたファイルパス + //Editing file path or Drag & Dropped files + string FileName = Path.GetFileName(FilePath); + + //----------------------------------- + //DOCTYPE + HtmlHeader htmlHeader = new HtmlHeader(); + string DocType = htmlHeader.GetHtmlHeader(MarkDownSharpEditor.AppSettings.Instance.HtmlDocType); + //Web用の相対パス + //Relative url + string CssPath = RerativeFilePath(FilePath, _SelectedCssFilePath); + + //----------------------------------- + //指定のエンコーディング + //Codepage + int CodePageNum = MarkDownSharpEditor.AppSettings.Instance.CodePageNumber; + try + { + encHtml = Encoding.GetEncoding(CodePageNum); + //ブラウザ表示に対応したエンコーディングか + //Is the encoding supported browser? + if (encHtml.IsBrowserDisplay == true) + { + EncodingName = encHtml.WebName; + } + else + { + EncodingName = "utf-8"; + encHtml = Encoding.UTF8; + } + } + catch + { + //エンコーディングの取得に失敗した場合はデフォルト + //Default encoding if failing to get encoding + EncodingName = "utf-8"; + encHtml = Encoding.UTF8; + } + + //HTMLのヘッダを挿入する + //Insert HTML Header + if (MarkDownSharpEditor.AppSettings.Instance.fHtmlOutputHeader == true) + { + //CSSファイルを埋め込む + //Embeding CSS file contents + if (MarkDownSharpEditor.AppSettings.Instance.HtmlCssFileOption == 0) + { + string CssContents = ""; + + if (File.Exists(_SelectedCssFilePath) == true) + { + using (StreamReader sr = new StreamReader(_SelectedCssFilePath, encHtml)) + { + CssContents = sr.ReadToEnd(); + } + } + + //ヘッダ ( Header ) + HeaderString = string.Format( +@"{0} + + + +{2} + + + +", + DocType, //DOCTYPE + EncodingName, //エンコーディング ( Encoding ) + FileName, //タイトル(=ファイル名) ( Title = file name ) + CssContents); //CSSの内容 ( Contents of CSS file ) + } + //metaタグ(外部リンキング)(Meta tag: external linking ) + else + { + //ヘッダ ( Header ) + HeaderString = string.Format( +@"{0} + + + + +{3} + + +", + DocType, //DOCTYPE + EncodingName, //エンコーディング ( Encoding ) + CssPath, //CSSファイル(相対パス)( Relative url ) + FileName); //タイトル(=ファイル名) ( Title = file name ) + } + //フッタ ( Footer ) + FooterString = "\n"; + } + else + { + HeaderString = ""; + FooterString = ""; + } + + //----------------------------------- + //Markdown parse ( default ) + //Markdown mkdwn = new Markdown(); + //----------------------------------- + + //----------------------------------- + // MarkdownDeep + // Create an instance of Markdown + //----------------------------------- + var mkdwn = new MarkdownDeep.Markdown(); + // Set options + mkdwn.ExtraMode = MarkDownSharpEditor.AppSettings.Instance.fMarkdownExtraMode; + mkdwn.SafeMode = false; + //----------------------------------- + + //編集中のファイル(richEditBoxの内容) + //Editing file path + if (_MarkDownTextFilePath == FilePath) + { + ResultText = mkdwn.Transform(richTextBox1.Text); + //エンコーディング変換(richEditBoxは基本的にutf-8) + //Convert encoding ( richEditBox default encoding is utf-8 = 65001 ) + ResultText = ConvertStringToEncoding(ResultText, Encoding.UTF8.CodePage, CodePageNum); + } + else + { + //テキストファイルを開いてその文字コードに従って読み込み + //Detect encoding in the text file + byte[] bs; + using (FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read)) + { + bs = new byte[fs.Length]; + fs.Read(bs, 0, bs.Length); + } + //文字コードを取得する + //Get charcter encoding + encRead = GetCode(bs); + //取得したバイト列を文字列に変換 + //Convert byte values to character + ResultText = encRead.GetString(bs); + + //UTF-8でないならいったん変換してパース + //Convert it if encoding is not utf-8 + if (encRead != Encoding.UTF8) + { + ResultText = ConvertStringToEncoding(ResultText, encRead.CodePage, CodePageNum); + } + ResultText = mkdwn.Transform(ResultText); + } + + //ヘッダ+本文+フッタ + //Header + Contents + Footer + ResultText = HeaderString + ResultText + FooterString; + //出力するHTMLファイルの文字コードに合わせる + //Ajust encoding to output HTML file + ResultText = ConvertStringToEncoding(ResultText, Encoding.UTF8.CodePage, CodePageNum); + + if (fToClipboard == true) + { //クリップボードに書き込む + //Set data to clipbord + Clipboard.SetText(ResultText); + } + else + { //ファイルに書き込む + //Write file + using (StreamWriter sw = new StreamWriter(SaveToFilePath, false, encHtml)) + { + sw.Write(ResultText); + } + } + return (true); + + } + + //---------------------------------------------------------------------- + // HTML形式ファイルへのバッチ出力 + // Output HTML files in batch + //---------------------------------------------------------------------- + private bool BatchOutputToHtmlFiles(string[] ArrrayFileList) + { + string OutputFilePath; + foreach (string FilePath in ArrrayFileList) + { + OutputFilePath = Path.ChangeExtension(FilePath, ".html"); + if (OutputToHtmlFile(FilePath, OutputFilePath, false) == false) + { + return (false); + } + } + return (true); + } + + //---------------------------------------------------------------------- + // 基本パスから相対パスを取得する + // Get relative file path from base file path + //---------------------------------------------------------------------- + private string RerativeFilePath(string BaseFilePath, string TargetFilePath) + { + Uri u1 = new Uri(BaseFilePath); + Uri u2 = new Uri(u1, TargetFilePath); + string RelativeFilePath = u1.MakeRelativeUri(u2).ToString(); + //URLデコードして、"/" を "\" に変更する + RelativeFilePath = System.Web.HttpUtility.UrlDecode(RelativeFilePath).Replace('/', '\\'); + return (RelativeFilePath); + } + + //---------------------------------------------------------------------- + // テキストを指定のエンコーディング文字列に変換する + // Convert text data to user encoding characters + //---------------------------------------------------------------------- + public string ConvertStringToEncoding(string source, int SrcCodePage, int DestCodePage) + { + Encoding srcEnc; + Encoding destEnc; + try + { + srcEnc = Encoding.GetEncoding(SrcCodePage); + destEnc = Encoding.GetEncoding(DestCodePage); + } + catch + { + //指定のコードページがおかしい(取得できない) + //Error: Codepage is incorrect + return (source); + } + //Byte配列で変換する + //Convert to byte values + byte[] srcByte = srcEnc.GetBytes(source); + byte[] destByte = Encoding.Convert(srcEnc, destEnc, srcByte); + char[] destChars = new char[destEnc.GetCharCount(destByte, 0, destByte.Length)]; + destEnc.GetChars(destByte, 0, destByte.Length, destChars, 0); + return new string(destChars); + } + + //====================================================================== + #region ブラウザーのツールバーメニュー ( Toolbar on browser ) + //====================================================================== + + //---------------------------------------------------------------------- + // ブラウザの「戻る」 ( Browser back ) + //---------------------------------------------------------------------- + private void toolStripButtonBack_Click(object sender, EventArgs e) + { + if (webBrowser1.CanGoBack == true) + { + webBrowser1.GoBack(); + } + } + + //---------------------------------------------------------------------- + // ブラウザの「進む」 ( Browser forward ) + //---------------------------------------------------------------------- + private void toolStripButtonForward_Click(object sender, EventArgs e) + { + if (webBrowser1.CanGoForward == true) + { + webBrowser1.GoForward(); + } + + } + + //---------------------------------------------------------------------- + // ブラウザの「更新」 ( Browser refresh ) + //---------------------------------------------------------------------- + private void toolStripButtonRefresh_Click(object sender, EventArgs e) + { + //手動更新設定 + //Manual to refresh browser + if (MarkDownSharpEditor.AppSettings.Instance.fAutoBrowserPreview == false) + { + //プレビューしているのは編集中のファイルか + //Is previewing file the editing file? + if (webBrowser1.Url.AbsoluteUri == @"file://" + _TemporaryHtmlFilePath) + { + PreviewToBrowser(); + } + } + webBrowser1.Refresh(); + } + + //---------------------------------------------------------------------- + // ブラウザの「中止」 ( Browser stop ) + //---------------------------------------------------------------------- + private void toolStripButtonStop_Click(object sender, EventArgs e) + { + webBrowser1.Stop(); + } + + //---------------------------------------------------------------------- + // 規定のブラウザーを関連付け起動してプレビュー + // Launch default web browser to preview + //---------------------------------------------------------------------- + private void toolStripButtonBrowserPreview_Click(object sender, EventArgs e) + { + if (File.Exists(_TemporaryHtmlFilePath) == true) + { + System.Diagnostics.Process.Start(_TemporaryHtmlFilePath); + } + else + { + _TemporaryHtmlFilePath = ""; + } + } + #endregion + //====================================================================== + + //====================================================================== + #region メインメニューイベント ( Main menu events ) + //====================================================================== + + //----------------------------------- + //「新しいファイルを開く」メニュー + // "New file" menu + //----------------------------------- + private void menuNewFile_Click(object sender, EventArgs e) + { + if (richTextBox1.Modified == true) + { + //"問い合わせ" + //"編集中のファイルがあります。保存してから新しいファイルを開きますか?" + //"Question" + //"This file being edited. Do you wish to save before starting new file?" + DialogResult ret = MessageBox.Show(Resources.MsgSaveFileToNewFile, + Resources.DialogTitleQuestion, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); + + if (ret == DialogResult.Yes) + { + if (SaveToEditingFile() == true) + { + _fNoTitle = false; //無題フラグOFF + } + else + { + //キャンセルで抜けてきた + //Cancel + return; + } + } + else if (ret == DialogResult.Cancel) + { + return; + } + } + + //前の編集していたテンポラリを削除する + //Delete edited temporary file before + Delete_TemporaryHtmlFilePath(); + + //無題ファイルのまま編集しているのなら削除 + //Delete it if the file is no title + if (_fNoTitle == true) + { + if (File.Exists(_MarkDownTextFilePath) == true) + { + try + { + File.Delete(_MarkDownTextFilePath); + } + catch + { + } + } + } + + //編集履歴に残す + //Add editing history + if (File.Exists(_MarkDownTextFilePath) == true) + { + foreach (AppHistory data in MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles) + { + if (data.md == _MarkDownTextFilePath) + { //いったん削除して ( delete once ... ) + MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Remove(data); + break; + } + } + AppHistory HistroyData = new AppHistory(); + HistroyData.md = _MarkDownTextFilePath; + HistroyData.css = _SelectedCssFilePath; + MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Insert(0, HistroyData); //先頭に挿入 + } + + _fConstraintChange = true; + + //ブラウザを空白にする + //Be blank in browser + webBrowser1.Navigate("about:blank"); + + //テンポラリファイルがあれば削除 + //Delete it if temporary file exists + Delete_TemporaryHtmlFilePath(); + //編集中のファイル情報をクリア + //Clear the infomation of editing file + _MarkDownTextFilePath = ""; + //「無題」編集開始 + //Start to edit in no title + _fNoTitle = true; + richTextBox1.Text = ""; + richTextBox1.Modified = false; + FormTextChange(); + _fConstraintChange = false; + + } + + //----------------------------------- + //「新しいウィンドウを開く」メニュー + // "New window" menu + //----------------------------------- + private void menuNewWindow_Click(object sender, EventArgs e) + { + //自分自身を起動する + //Launch the self + System.Diagnostics.ProcessStartInfo pInfo = new System.Diagnostics.ProcessStartInfo(Application.ExecutablePath); + pInfo.Arguments = "/new"; + System.Diagnostics.Process p = System.Diagnostics.Process.Start(pInfo); + + } + + //----------------------------------- + //「ファイルを開く」メニュー + // "Open File" menu + //----------------------------------- + private void menuOpenFile_Click(object sender, EventArgs e) + { + OpenFile("", true); + } + + //----------------------------------- + //「ファイル」メニュー + // "File" menu + //----------------------------------- + private void menuFile_Click(object sender, EventArgs e) + { + //編集履歴のサブメニューをつくる + //Create submenu of editing history + for (int i = 0; i < MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Count; i++) + { + AppHistory History = (AppHistory)MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles[i]; + ToolStripMenuItem m = new ToolStripMenuItem(History.md); + m.Tag = History.css; + m.Click += new EventHandler(HistorySubMenuItemClickHandler); + menuHistoryFiles.DropDownItems.Add(m); + } + + } + //----------------------------------- + //各履歴メニューがクリックされたとき + //Click editing history menu event + private void HistorySubMenuItemClickHandler(object sender, EventArgs e) + { + + ToolStripMenuItem clickItem = (ToolStripMenuItem)sender; + + string FilePath = clickItem.Text; + + if (File.Exists(FilePath) == true) + { + OpenFile(FilePath); + } + } + + //----------------------------------- + //編集中のファイルを保存する + //Save to editing file + //----------------------------------- + private bool SaveToEditingFile(bool fSaveAs = false) + { + //名前が付けられていない、または別名保存指定なのでダイアログ表示 + //The file is no title, or saving as oher name + if (_fNoTitle == true || fSaveAs == true) + { + if (saveFileDialog1.ShowDialog() == DialogResult.OK) + { + + using (StreamWriter sw = new StreamWriter(saveFileDialog1.FileName, false, _EditingFileEncoding)) + { + sw.Write(richTextBox1.Text); + _MarkDownTextFilePath = saveFileDialog1.FileName; + } + } + else + { + return (false); + } + } + else + { + //上書き保存 + //Overwrite + using (StreamWriter sw = new StreamWriter( + _MarkDownTextFilePath, + false, + _EditingFileEncoding)) + { + sw.Write(richTextBox1.Text); + } + + } + + //Undoバッファクリア + //Clear undo buffer + undoCounter = 0; + UndoBuffer.Clear(); + + _fNoTitle = false; //無題フラグOFF + richTextBox1.Modified = false; + FormTextChange(); + + return (true); + } + + //----------------------------------- + //「ファイルを保存」メニュー + // "Save file" menu + //----------------------------------- + private void menuSaveFile_Click(object sender, EventArgs e) + { + SaveToEditingFile(); + } + + //----------------------------------- + //「名前を付けてファイルを保存」メニュー + // "Save As" menu + //----------------------------------- + private void menuSaveAsFile_Click(object sender, EventArgs e) + { + SaveToEditingFile(true); + } + + //----------------------------------- + //「HTMLファイル出力(&P)」メニュー + // "Output to HTML file" menu + //----------------------------------- + private void menuOutputHtmlFile_Click(object sender, EventArgs e) + { + string OutputFilePath; + string DirPath = Path.GetDirectoryName(_MarkDownTextFilePath); + + if (File.Exists(_MarkDownTextFilePath) == true) + { + saveFileDialog2.InitialDirectory = DirPath; + } + //保存ダイアログを表示する + //Show Save dialog + if (MarkDownSharpEditor.AppSettings.Instance.fShowHtmlSaveDialog == true) + { + if (saveFileDialog2.ShowDialog() == DialogResult.OK) + { + OutputToHtmlFile(_MarkDownTextFilePath, saveFileDialog2.FileName, false); + } + } + else + { + //ダイアログを抑制しているので編集中のファイルのディレクトリへ保存する + //Save to editing folder in constrainting dialog + OutputFilePath = Path.Combine(DirPath, Path.GetFileNameWithoutExtension(_MarkDownTextFilePath)) + ".html"; + + if (File.Exists(OutputFilePath) == true) + { + //"問い合わせ" + //"すでに同名のファイルが存在しています。上書きして出力しますか?" + //"Question" + //"Same file exists.\nContinue to overwrite?" + DialogResult ret = MessageBox.Show( + Resources.MsgSameFileOverwrite + "\n" + OutputFilePath, + Resources.DialogTitleQuestion, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, + MessageBoxDefaultButton.Button1); // Yesがデフォルト + + if (ret == DialogResult.Yes) + { + //上書きしてHTMLファイルへ出力 + //Overwrite and output to HTML file + OutputToHtmlFile(_MarkDownTextFilePath, OutputFilePath, false); + } + else if (ret == DialogResult.No) + { + //設定されてないが一応保存ダイアログを出す + //It is no setting, but show save dialog + if (saveFileDialog2.ShowDialog() == DialogResult.OK) + { + //HTMLファイルへ出力 + //Output to HTML file + OutputToHtmlFile(_MarkDownTextFilePath, saveFileDialog2.FileName, false); + } + } + else + { + //キャンセル + //Cancel + } + } + else + { + //HTMLファイルへ出力 + //Output to HTML file + OutputToHtmlFile(_MarkDownTextFilePath, OutputFilePath, false); + } + } + } + + //----------------------------------- + //「HTMLソースコードをクリップボードへコピー(&L)」メニュー + // "Set HTML source code to clipboard" menu + //----------------------------------- + private void menuOutputHtmlToClipboard_Click(object sender, EventArgs e) + { + //HTMLソースをクリップボードへ出力 + //Output HTML source to clipboard + OutputToHtmlFile(_MarkDownTextFilePath, "", true); + + //HTMLソースをクリップボードコピーしたときに確認メッセージを表示する(&M) + //Show message to confirm when HTML source data is setting to clipboard + if (MarkDownSharpEditor.AppSettings.Instance.fShowHtmlToClipboardMessage == true) + { + //"通知" + //"クリップボードに保存されました。" + //"Information" + //"This file has been output to the clipboard." + MessageBox.Show(Resources.MsgOutputToClipboard, + Resources.DialogTitleNotice, MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + //----------------------------------- + //「終了」メニュー + // "Exit" menu + //----------------------------------- + private void menuExit_Click(object sender, EventArgs e) + { + Close(); + } + + //----------------------------------- + //「編集」メニュー + // "Edit" menu + //----------------------------------- + private void menuEdit_Click(object sender, EventArgs e) + { + if (undoCounter > 0) + { + menuUndo.Enabled = true; + } + else + { + menuUndo.Enabled = false; + } + + if (undoCounter < UndoBuffer.Count && undoCounter > 0) + { + menuRedo.Enabled = true; + } + else + { + menuRedo.Enabled = false; + } + + if (richTextBox1.SelectionLength > 0) + { + menuCut.Enabled = true; + menuCopy.Enabled = true; + } + else + { + menuCut.Enabled = false; + menuCopy.Enabled = false; + } + } + //----------------------------------- + //「元に戻す」メニュー + // "Undo" menu + //----------------------------------- + private void menuUndo_Click(object sender, EventArgs e) + { + if (UndoBuffer.Count > 0 && undoCounter > 0) + { //現在のカーソル位置 + //Current cursor position + int selectStart = this.richTextBox1.SelectionStart; + int selectEnd = richTextBox1.SelectionLength; + //現在のスクロール位置 + //Current scroll position + int CurrentScrollpos = richTextBox1.VerticalPosition; + //描画停止 + //Stop to paint + richTextBox1.BeginUpdate(); + + undoCounter--; + richTextBox1.Rtf = UndoBuffer[undoCounter]; + + //カーソル位置を戻す + //Restore cursor position + richTextBox1.Select(selectStart, selectEnd); + //スクロール位置を戻す + //Restore scroll position + richTextBox1.VerticalPosition = CurrentScrollpos; + //描画再開 + //Resume to paint + richTextBox1.EndUpdate(); + + if (undoCounter == 0) + { + richTextBox1.Modified = false; + FormTextChange(); + } + } + } + //----------------------------------- + //「やり直す」メニュー + // "Redo" menu + //----------------------------------- + private void menuRedo_Click(object sender, EventArgs e) + { + if (undoCounter < UndoBuffer.Count && undoCounter > 0) + { + undoCounter++; + richTextBox1.Rtf = UndoBuffer[undoCounter]; + FormTextChange(); + } + } + //----------------------------------- + //「切り取り」メニュー + // "Cut" to clipbord menu + //----------------------------------- + private void menuCut_Click(object sender, EventArgs e) + { + if (richTextBox1.SelectionLength > 0) + { + richTextBox1.Cut(); + FormTextChange(); + } + } + //----------------------------------- + //「コピー」メニュー + // "Copy" to clipboard menu + //----------------------------------- + private void menuCopy_Click(object sender, EventArgs e) + { + if (richTextBox1.SelectionLength > 0) + { + richTextBox1.Copy(); + } + } + //----------------------------------- + //「貼り付け」メニュー + // "Paste" from clipboard menu + //----------------------------------- + private void menuPaste_Click(object sender, EventArgs e) + { + IDataObject data = Clipboard.GetDataObject(); + if (data != null && data.GetDataPresent(DataFormats.Text) == true) + { + DataFormats.Format fmt = DataFormats.GetFormat(DataFormats.Text); + richTextBox1.Paste(fmt); + FormTextChange(); + } + } + //----------------------------------- + //「すべてを選択」メニュー + // "Select all" menu + //----------------------------------- + private void menuSelectAll_Click(object sender, EventArgs e) + { + richTextBox1.SelectAll(); + } + + //----------------------------------- + //「検索」メニュー + // "Search" menu + //----------------------------------- + private void menuSearch_Click(object sender, EventArgs e) + { + _fSearchStart = false; + panelSearch.Visible = true; + panelSearch.Height = 58; + textBoxSearch.Focus(); + labelReplace.Visible = false; + textBoxReplace.Visible = false; + cmdReplaceAll.Visible = false; + cmdSearchNext.Text = Resources.ButtonFindNext; //"次を検索する(&N)"; + cmdSearchPrev.Text = Resources.ButtonFindPrev; // "前を検索する(&P)"; + } + //----------------------------------- + //「置換」メニュー + // "Replace" menu + //----------------------------------- + private void menuReplace_Click(object sender, EventArgs e) + { + _fSearchStart = false; + panelSearch.Visible = true; + panelSearch.Height = 58; + textBoxSearch.Focus(); + labelReplace.Visible = true; + textBoxReplace.Visible = true; + cmdReplaceAll.Visible = true; + cmdSearchNext.Text = Resources.ButtonReplaceNext; //"置換して次へ(&N)"; + cmdSearchPrev.Text = Resources.ButtonReplacePrev; //"置換して前へ(&P)"; + } + + //----------------------------------- + // 表示の更新 + // "Refresh preview" menu + //----------------------------------- + private void menuViewRefresh_Click(object sender, EventArgs e) + { + PreviewToBrowser(); + } + + //----------------------------------- + //「ソースとビューを均等表示する」メニュー + // "Editor and Browser Width evenly" menu + //----------------------------------- + private void menuViewWidthEvenly_Click(object sender, EventArgs e) + { + if (menuViewWidthEvenly.Checked == true) + { + menuViewWidthEvenly.Checked = false; + } + else + { + menuViewWidthEvenly.Checked = true; + } + MarkDownSharpEditor.AppSettings.Instance.fSplitBarWidthEvenly = menuViewWidthEvenly.Checked; + } + + //----------------------------------- + //「言語」メニュー + // Change "Language" menu + //----------------------------------- + private void menuViewJapanese_Click(object sender, EventArgs e) + { + //"問い合わせ" + //"言語の変更を反映するには、アプリケーションの再起動が必要です。 + //今すぐ再起動しますか?" + //"Question" + //"To change the setting of language, it is necessary to restart the application. + // Do you want to restart this application now?" + DialogResult result = MessageBox.Show(Resources.MsgRestartApplication, + Resources.DialogTitleQuestion, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); + + if (result == DialogResult.Yes) + { + MarkDownSharpEditor.AppSettings.Instance.Lang = "ja"; + MarkDownSharpEditor.AppSettings.Instance.SaveToXMLFile(); + Application.Restart(); + } + else if (result == DialogResult.No) + { + MarkDownSharpEditor.AppSettings.Instance.Lang = "ja"; + menuViewJapanese.Checked = true; + menuViewEnglish.Checked = false; + } + else + { + //Cancel + } + + } + + private void menuViewEnglish_Click(object sender, EventArgs e) + { + //"問い合わせ" + //"言語の変更を反映するには、アプリケーションの再起動が必要です。 + //今すぐ再起動しますか?" + //"Question" + //"To change the setting of language, it is necessary to restart the application. + // Do you want to restart this application now?" + DialogResult result = MessageBox.Show(Resources.MsgRestartApplication, + Resources.DialogTitleQuestion, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); + + if (result == DialogResult.Yes) + { + MarkDownSharpEditor.AppSettings.Instance.Lang = "en"; + MarkDownSharpEditor.AppSettings.Instance.SaveToXMLFile(); + Application.Restart(); + } + else if (result == DialogResult.No) + { + MarkDownSharpEditor.AppSettings.Instance.Lang = "en"; + MarkDownSharpEditor.AppSettings.Instance.SaveToXMLFile(); + menuViewJapanese.Checked = false; + menuViewEnglish.Checked = true; + } + else + { + //Cancel + } + + } + + //----------------------------------- + //「ツールバーを表示する」メニュー + // "View toolbar" menu + //----------------------------------- + private void menuViewToolBar_Click(object sender, EventArgs e) + { + if (menuViewToolBar.Checked == true) + { + menuViewToolBar.Checked = false; + toolStrip1.Visible = false; + } + else + { + menuViewToolBar.Checked = true; + toolStrip1.Visible = true; + } + MarkDownSharpEditor.AppSettings.Instance.fViewToolBar = toolStrip1.Visible; + } + //----------------------------------- + //「ステータスバーを表示する」メニュー + // "View statusbar" menu + //----------------------------------- + private void menuViewStatusBar_Click(object sender, EventArgs e) + { + if (menuViewStatusBar.Checked == true) + { + menuViewStatusBar.Checked = false; + statusStrip1.Visible = false; + } + else + { + menuViewStatusBar.Checked = true; + statusStrip1.Visible = true; + } + MarkDownSharpEditor.AppSettings.Instance.fViewStatusBar = statusStrip1.Visible; + } + + //----------------------------------- + //「書式フォント」メニュー + // "Font" menu + //----------------------------------- + private void menuFont_Click(object sender, EventArgs e) + { + bool fModify = richTextBox1.Modified; + fontDialog1.Font = richTextBox1.Font; + fontDialog1.Color = richTextBox1.ForeColor; + //選択できるポイントサイズの最小・最大値 + fontDialog1.MinSize = 6; + fontDialog1.MaxSize = 72; + fontDialog1.FontMustExist = true; + //横書きフォントだけを表示する + fontDialog1.AllowVerticalFonts = false; + //色を選択できるようにする + fontDialog1.ShowColor = true; + //取り消し線、下線、テキストの色などのオプションを指定不可 + fontDialog1.ShowEffects = false; + //ダイアログを表示する + if (fontDialog1.ShowDialog() == DialogResult.OK) + { + UndoBuffer.Add(richTextBox1.Rtf); + undoCounter = UndoBuffer.Count; + this.richTextBox1.TextChanged -= new System.EventHandler(this.richTextBox1_TextChanged); + richTextBox1.Font = fontDialog1.Font; + richTextBox1.ForeColor = fontDialog1.Color; + //ステータスバーに表示 + toolStripStatusLabelFontInfo.Text = + fontDialog1.Font.Name + "," + fontDialog1.Font.Size.ToString() + "pt"; + this.richTextBox1.TextChanged += new System.EventHandler(this.richTextBox1_TextChanged); + } + //richTextBoxの書式を変えても「変更」となるので元のステータスへ戻す + richTextBox1.Modified = fModify; + } + + //----------------------------------- + //「オプション」メニュー + // "Option" menu + //----------------------------------- + private void menuOption_Click(object sender, EventArgs e) + { + Form3 frm3 = new Form3(); + frm3.ShowDialog(); + frm3.Dispose(); + + _MarkdownSyntaxKeywordAarray = MarkdownSyntaxKeyword.CreateKeywordList(); //キーワードリストの更新 + if (backgroundWorker2.IsBusy == false) + { + //SyntaxHightlighter on BackgroundWorker + backgroundWorker2.RunWorkerAsync(richTextBox1.Text); + } + + //プレビュー間隔を更新 + if (MarkDownSharpEditor.AppSettings.Instance.AutoBrowserPreviewInterval > 0) + { + timer1.Interval = MarkDownSharpEditor.AppSettings.Instance.AutoBrowserPreviewInterval; + } + } + + //----------------------------------- + // ヘルプファイルの表示 + // "Help contents" menu + //----------------------------------- + private void menuContents_Click(object sender, EventArgs e) + { + string HelpFilePath; + string DirPath = MarkDownSharpEditor.AppSettings.GetAppDataLocalPath(); + + if (MarkDownSharpEditor.AppSettings.Instance.Lang == "ja") + { + HelpFilePath = Path.Combine(DirPath, "help-ja.md"); + } + else + { + HelpFilePath = Path.Combine(DirPath, "help.md"); + } + + if (File.Exists(HelpFilePath) == true) + { //別ウィンドウで開く + //Create a new ProcessStartInfo structure. + System.Diagnostics.ProcessStartInfo pInfo = new System.Diagnostics.ProcessStartInfo(); + //Set the file name member. + pInfo.FileName = HelpFilePath; + //UseShellExecute is true by default. It is set here for illustration. + pInfo.UseShellExecute = true; + System.Diagnostics.Process p = System.Diagnostics.Process.Start(pInfo); + } + else + { //"エラー" + //"ヘルプファイルがありません。開くことができませんでした。" + //"Could not find Help file. Opening this file has failed." + MessageBox.Show(Resources.MsgNoHelpFile, + Resources.DialogTitleError, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + + //----------------------------------- + // 最新バージョンのチェック + // "Check for Update" + //----------------------------------- + private void mnuCheckForUpdate_Click(object sender, EventArgs e) + { + string MsgText = ""; + Version newVersion = null; + string url = ""; + string dt = ""; + System.Xml.XmlTextReader reader; + + /* + * + * + * 1.2.1.0 + * 2013/06/18 + * http://hibara.org/software/markdownsharpeditor/ + * + */ + string xmlURL = "http://hibara.org/software/markdownsharpeditor/app_version.xml"; + using (reader = new System.Xml.XmlTextReader(xmlURL)) + { + reader.MoveToContent(); + string elementName = ""; + if ((reader.NodeType == System.Xml.XmlNodeType.Element) && (reader.Name == "markdownsharpeditor")) + { + while (reader.Read()) + { + if (reader.NodeType == System.Xml.XmlNodeType.Element) + { + elementName = reader.Name; + } + else + { + if ((reader.NodeType == System.Xml.XmlNodeType.Text) && (reader.HasValue)) + { + switch (elementName) + { + case "version": + newVersion = new Version(reader.Value); + break; + case "url": + url = reader.Value; + break; + case "date": + dt = reader.Value; + break; + } + } + } + } + } + } + + if (newVersion == null) + { + //Failed to get the latest version information. + MsgText = Resources.ErrorGetNewVersion; + MessageBox.Show(MsgText, Resources.DialogTitleError, MessageBoxButtons.OK, MessageBoxIcon.Question); + return; + } + + // get current version + Version curVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; + if (curVersion.CompareTo(newVersion) < 0) + { //"New version was found! Do you open the download site?"; + MsgText = "Update info: ver." + newVersion + " (" + dt + " ) \n" + Resources.NewVersionFound; + if (DialogResult.Yes == MessageBox.Show(this, MsgText, Resources.DialogTitleQuestion, MessageBoxButtons.YesNo, MessageBoxIcon.Question)) + { + System.Diagnostics.Process.Start(url); + } + } + else + { // You already have the latest version of this application. + MsgText = Resources.AlreadyLatestVersion + "\nver." + newVersion + " ( " + dt + " ) "; + MessageBox.Show(MsgText, Resources.DialogTitleInfo, MessageBoxButtons.OK, MessageBoxIcon.Question); + } + + } + + //----------------------------------- + // サンプル表示 + // "View Markdown sample file" + //----------------------------------- + private void menuViewSample_Click(object sender, EventArgs e) + { + string DirPath = MarkDownSharpEditor.AppSettings.GetAppDataLocalPath(); + string SampleFilePath = Path.Combine(DirPath, "sample.md"); + + if (File.Exists(SampleFilePath) == true) + { + System.Diagnostics.ProcessStartInfo pInfo = new System.Diagnostics.ProcessStartInfo(); + pInfo.FileName = SampleFilePath; + pInfo.UseShellExecute = true; + System.Diagnostics.Process p = System.Diagnostics.Process.Start(pInfo); + } + else + { + //"エラー" + //"サンプルファイルがありません。開くことができませんでした。" + //"Error" + //"Could not find sample MD file.\nOpening this file has failed." + MessageBox.Show(Resources.MsgNoSampleFile, + Resources.DialogTitleError, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + + //----------------------------------- + //「MarkDownSharpについて」メニュー + // "About" menu + //----------------------------------- + private void menuAbout_Click(object sender, EventArgs e) + { + Form2 frm2 = new Form2(); + frm2.ShowDialog(); + frm2.Dispose(); + } + + #endregion + //====================================================================== + + //====================================================================== + #region ステータスバーイベント ( Statusbar event ) + //====================================================================== + + //----------------------------------- + // ステータスバー(CSS) + //----------------------------------- + private void toolStripStatusLabelCssFileName_Click(object sender, EventArgs e) + { + //ポップアップメニューに登録する + //Regist item to popup menus + contextMenu1.Items.Clear(); + + foreach (string FilePath in MarkDownSharpEditor.AppSettings.Instance.ArrayCssFileList) + { + if (File.Exists(FilePath) == true) + { + ToolStripMenuItem item = new ToolStripMenuItem(Path.GetFileName(FilePath)); + item.Tag = FilePath; + if (_SelectedCssFilePath == FilePath) + { + item.Checked = true; + } + contextMenu1.Items.Add(item); + } + } + if (contextMenu1.Items.Count > 0) + { + contextMenu1.Tag = "css"; + contextMenu1.Show(Control.MousePosition); + } + + } + + //----------------------------------- + // ステータスバー(Encoding) + //----------------------------------- + private void toolStripStatusLabelEncoding_Click(object sender, EventArgs e) + { + //ポップアップメニューに登録する + //Regist item to popup menus + contextMenu1.Items.Clear(); + foreach (EncodingInfo ei in Encoding.GetEncodings()) + { + if (ei.GetEncoding().IsBrowserDisplay == true) + { + ToolStripMenuItem item = new ToolStripMenuItem(ei.DisplayName); + item.Tag = ei.CodePage; + if (ei.CodePage == MarkDownSharpEditor.AppSettings.Instance.CodePageNumber) + { + item.Checked = true; + } + contextMenu1.Items.Add(item); + } + } + contextMenu1.Tag = "encoding"; + contextMenu1.Show(Control.MousePosition); + } + + //----------------------------------- + // ステータスバー(共通のクリックイベント) + // Common item clicked event + //----------------------------------- + private void contextMenu1_ItemClicked(object sender, ToolStripItemClickedEventArgs e) + { + //----------------------------------- + // 適用するCSSファイル変更 + // Change selected CSS file + //----------------------------------- + if ((string)contextMenu1.Tag == "css") + { + _SelectedCssFilePath = (string)e.ClickedItem.Tag; + toolStripStatusLabelCssFileName.Text = Path.GetFileName(_SelectedCssFilePath); + //プレビューも更新する + PreviewToBrowser(); + + } + //----------------------------------- + // 出力HTMLに適用する文字コードの変更 + // Change encoding to output HTML file + //----------------------------------- + else if ((string)contextMenu1.Tag == "encoding") + { + MarkDownSharpEditor.AppSettings.Instance.CodePageNumber = (int)e.ClickedItem.Tag; + //プレビューも更新する + //Refresh previewing, too + PreviewToBrowser(); + } + } + + //---------------------------------------------------------------------- + // 検索パネル ( Search panel ) + //---------------------------------------------------------------------- + private void imgSearchExit_Click(object sender, EventArgs e) + { + panelSearch.Visible = false; + } + //----------------------------------- + // 検索パネル「閉じる」ボタンイベント + // Search panel close button image event + //----------------------------------- + private void imgSearchExit_MouseEnter(object sender, EventArgs e) + { + imgSearchExit.Image = imgSearchExitEnabled.Image; + } + private void imgSearchExit_MouseLeave(object sender, EventArgs e) + { + imgSearchExit.Image = imgSearchExitUnabled.Image; + } + + //----------------------------------- + // 検索テキストボックス + // Search text box TextChanged event + //----------------------------------- + private void textBoxSearch_TextChanged(object sender, EventArgs e) + { + //検索をやり直し + //Restart to search + _fSearchStart = false; + if (textBoxReplace.Visible == true) + { + if (textBoxSearch.Text == "") + { + cmdSearchNext.Enabled = false; + cmdSearchPrev.Enabled = false; + cmdReplaceAll.Enabled = false; + } + else + { + cmdSearchNext.Enabled = true; + cmdSearchPrev.Enabled = true; + cmdReplaceAll.Enabled = true; + } + } + else + { + cmdSearchNext.Enabled = true; + cmdSearchPrev.Enabled = true; + } + } + + //----------------------------------- + // 検索テキストボックス + // Search text box KeyDown event + //----------------------------------- + private void textBoxSearch_KeyDown(object sender, KeyEventArgs e) + { + if (e.Shift && e.KeyCode == Keys.Enter) + { // Shitf + Enter で前へ + // Press Shift + Enter key to previous item + cmdSearchPrev_Click(sender, e); + } + else if (e.KeyCode == Keys.Enter) + { + cmdSearchNext_Click(sender, e); + } + else if (e.KeyCode == Keys.Escape) + { + panelSearch.Visible = false; + } + } + + //----------------------------------- + // 検索テキストボックス + // Search text box KeyPress event + //----------------------------------- + private void textBoxSearch_KeyPress(object sender, KeyPressEventArgs e) + { + //EnterやEscapeキーでビープ音が鳴らないようにする + //Constraint to beep sound with Enter & Escape key + if (e.KeyChar == (char)Keys.Enter || e.KeyChar == (char)Keys.Escape) + { + e.Handled = true; + } + } + + //----------------------------------- + // 置換テキストボックス + // Search text box KeyDown event + //----------------------------------- + private void textBoxReplace_KeyDown(object sender, KeyEventArgs e) + { + if (e.Shift && e.KeyCode == Keys.Enter) + { // Shitf + Enter で前へ + // Press Shift + Enter key to previous item + cmdSearchPrev_Click(sender, e); + } + else if (e.KeyCode == Keys.Enter) + { + cmdSearchNext_Click(sender, e); + } + else if (e.KeyCode == Keys.Escape) + { + panelSearch.Visible = false; + } + } + + //----------------------------------- + // 置換テキストボックス(KeyPress) + //----------------------------------- + private void textBoxReplace_KeyPress(object sender, KeyPressEventArgs e) + { + //EnterやEscapeキーでビープ音が鳴らないようにする + //Constraint to beep sound with Enter & Escape key + if (e.KeyChar == (char)Keys.Enter || e.KeyChar == (char)Keys.Escape) + { + e.Handled = true; + } + } + + //---------------------------------------------------------------------- + // 次を検索(または、置換して次へ)ボタン + // Press next button + //---------------------------------------------------------------------- + private void cmdSearchNext_Click(object sender, EventArgs e) + { + int StartPos; + StringComparison sc; + DialogResult result; + string MsgText = ""; + + if (textBoxSearch.Text != "") + { + //置換モードの場合は、置換してから次を検索する + //Replace the word to search next item in Replace mode + if (textBoxReplace.Visible == true && _fSearchStart == true) + { + if (richTextBox1.SelectionLength > 0) + { + richTextBox1.SelectedText = textBoxReplace.Text; + } + } + + if (chkOptionCase.Checked == true) + { + sc = StringComparison.Ordinal; + } + else + { //大文字と小文字を区別しない + //Ignore case + sc = StringComparison.OrdinalIgnoreCase; + } + + int CurrentPos = richTextBox1.SelectionStart + 1; + + //----------------------------------- + // 検索ワードが見つからない + // Searching word is not found + //----------------------------------- + if ((StartPos = richTextBox1.Text.IndexOf(textBoxSearch.Text, CurrentPos, sc)) == -1) + { + //検索を開始した直後 + //Start to search after + if (_fSearchStart == false) + { + //"ファイル末尾まで検索しましたが、見つかりませんでした。 + // ファイルの先頭から検索を続けますか?" + //"The word could not find the word to the end of this file. + // Do you wish to continue searching from the beginning of this file?" + MsgText = Resources.MsgNotFoundToEnd; + _fSearchStart = true; + } + else + { + //"ファイル末尾までの検索が完了しました。 + // ファイル先頭に戻って検索を続けますか?" + //"Searching completed to the end of this file. + // Do you wish to continue searching from the beginning of this file?" + MsgText = Resources.MsgFindCompleteToEnd; + } + result = MessageBox.Show(MsgText, Resources.DialogTitleNotice, + MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); + + if (result == DialogResult.Yes) + { + richTextBox1.SelectionStart = 0; + cmdSearchNext_Click(sender, e); + } + } + //----------------------------------- + // 検索ワードが見つかった + // Searching word were found + //----------------------------------- + else + { + //richTextBox1.HideSelection = false; + richTextBox1.Select(StartPos, textBoxSearch.Text.Length); + richTextBox1.ScrollToCaret(); + _fSearchStart = true; //検索開始 ( Start to search ) + } + } + + } + //---------------------------------------------------------------------- + // 前を検索(または、置換して前へ)ボタン + // Press previous button + //---------------------------------------------------------------------- + private void cmdSearchPrev_Click(object sender, EventArgs e) + { + int StartPos; + StringComparison sc; + DialogResult result; + string MsgText = ""; + + if (textBoxSearch.Text != "") + { + //置換モードの場合は、置換してから前を検索する + //Replace the word to search previous item in Replace mode + if (textBoxReplace.Visible == true && _fSearchStart == true) + { + if (richTextBox1.SelectionLength > 0) + { + richTextBox1.SelectedText = textBoxReplace.Text; + } + } + + if (chkOptionCase.Checked == true) + { + sc = StringComparison.Ordinal; + } + else + { //大文字と小文字を区別しない + //Ignore case + sc = StringComparison.OrdinalIgnoreCase; + } + + int CurrentPos = richTextBox1.SelectionStart - 1; + if (CurrentPos < 0) + { + CurrentPos = 0; + } + //----------------------------------- + // 検索ワードが見つからない + // Searching word is not found + //----------------------------------- + if ((StartPos = richTextBox1.Text.LastIndexOf(textBoxSearch.Text, CurrentPos, sc)) == -1) + { + //検索を開始した直後 + //Start to search after + if (_fSearchStart == false) + { + //"ファイル先頭まで検索しましたが、見つかりませんでした。 + // ファイルの末尾から検索を続けますか?" + //"The word could not find to the beginning of this file. + // Do you wish to continue searching from the end of this file?" + MsgText = Resources.MsgNotFoundToBegining; + _fSearchStart = true; + } + else + { + //"ファイル先頭までの検索が完了しました。 + // ファイル末尾から検索を続けますか?" + //"Searching completed to the beginning of this file. + // Do you wish to continue searching from the end of this file?" + MsgText = Resources.MsgFindCompleteToBegining; + } + + result = MessageBox.Show(MsgText, Resources.DialogTitleNotice, + MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); + + if (result == DialogResult.Yes) + { + richTextBox1.SelectionStart = richTextBox1.Text.Length - 1; + cmdSearchPrev_Click(sender, e); + } + } + //----------------------------------- + // 検索ワードが見つかった + // Searching word were found + //----------------------------------- + else + { + //richTextBox1.HideSelection = false; + richTextBox1.Select(StartPos, textBoxSearch.Text.Length); + richTextBox1.ScrollToCaret(); + _fSearchStart = true; //検索開始 ( Start to search ) + } + } + + } + + //----------------------------------- + // すべてを置換ボタン + // "Replace All" button + //----------------------------------- + private void cmdReplaceAll_Click(object sender, EventArgs e) + { + int StartPos; + StringComparison sc; + string MsgText = ""; + + if (chkOptionCase.Checked == true) + { + sc = StringComparison.Ordinal; + } + else + { //大文字と小文字を区別しない + //Ignore case + sc = StringComparison.OrdinalIgnoreCase; + } + + int CurrentPos = 0; + int ReplaceCount = 0; + while ((StartPos = richTextBox1.Text.IndexOf(textBoxSearch.Text, CurrentPos, sc)) > -1) + { + richTextBox1.Select(StartPos, textBoxSearch.Text.Length); + richTextBox1.ScrollToCaret(); + if (richTextBox1.SelectionLength > 0) + { + richTextBox1.SelectedText = textBoxReplace.Text; + ReplaceCount++; + CurrentPos = StartPos + textBoxReplace.Text.Length; + } + } + + if (ReplaceCount > 0) + { + //"以下のワードを" ~ "件置換しました。\n" + //"" ~ " of the word were replaced.\n" + MsgText = Resources.MsgThisWord + "\"" + ReplaceCount.ToString() + "\"" + Resources.MsgReplaced + "\n" + + textBoxSearch.Text + " -> " + textBoxReplace.Text; + } + else + { + //"ご指定の検索ワードは見つかりませんでした。" + //"The word was not found." + MsgText = Resources.MsgNotFound; + } + + MessageBox.Show(MsgText, Resources.DialogTitleNotice, MessageBoxButtons.OK, MessageBoxIcon.Information); + _fSearchStart = true; + + } + + #endregion + + //====================================================================== + #region エンコーディングの判定 ( Detecting encoding ) + //====================================================================== + // + // ここのコードはまんま、以下のサイトのものを使わせていただきました。 + // http://dobon.net/vb/dotnet/string/detectcode.html + // + // + // 文字コードを判別する + // + // + // Jcode.pmのgetcodeメソッドを移植したものです。 + // Jcode.pm(http://openlab.ring.gr.jp/Jcode/index-j.html) + // Jcode.pmのCopyright: Copyright 1999-2005 Dan Kogai + // + // 文字コードを調べるデータ + // 適当と思われるEncodingオブジェクト。 + // 判断できなかった時はnull。 + public static Encoding GetCode(byte[] bytes) + { + const byte bEscape = 0x1B; + const byte bAt = 0x40; + const byte bDollar = 0x24; + const byte bAnd = 0x26; + const byte bOpen = 0x28; //'(' + const byte bB = 0x42; + const byte bD = 0x44; + const byte bJ = 0x4A; + const byte bI = 0x49; + + int len = bytes.Length; + byte b1, b2, b3, b4; + + //Encode::is_utf8 は無視 + + bool isBinary = false; + for (int i = 0; i < len; i++) + { + b1 = bytes[i]; + if (b1 <= 0x06 || b1 == 0x7F || b1 == 0xFF) + { + //'binary' + isBinary = true; + if (b1 == 0x00 && i < len - 1 && bytes[i + 1] <= 0x7F) + { + //smells like raw unicode + return Encoding.Unicode; + } + } + } + if (isBinary) + { + return null; + } + + //not Japanese + bool notJapanese = true; + for (int i = 0; i < len; i++) + { + b1 = bytes[i]; + if (b1 == bEscape || 0x80 <= b1) + { + notJapanese = false; + break; + } + } + if (notJapanese) + { + return Encoding.ASCII; + } + + for (int i = 0; i < len - 2; i++) + { + b1 = bytes[i]; + b2 = bytes[i + 1]; + b3 = bytes[i + 2]; + + if (b1 == bEscape) + { + if (b2 == bDollar && b3 == bAt) + { + //JIS_0208 1978 + //JIS + return Encoding.GetEncoding(50220); + } + else if (b2 == bDollar && b3 == bB) + { + //JIS_0208 1983 + //JIS + return Encoding.GetEncoding(50220); + } + else if (b2 == bOpen && (b3 == bB || b3 == bJ)) + { + //JIS_ASC + //JIS + return Encoding.GetEncoding(50220); + } + else if (b2 == bOpen && b3 == bI) + { + //JIS_KANA + //JIS + return Encoding.GetEncoding(50220); + } + if (i < len - 3) + { + b4 = bytes[i + 3]; + if (b2 == bDollar && b3 == bOpen && b4 == bD) + { + //JIS_0212 + //JIS + return Encoding.GetEncoding(50220); + } + if (i < len - 5 && + b2 == bAnd && b3 == bAt && b4 == bEscape && + bytes[i + 4] == bDollar && bytes[i + 5] == bB) + { + //JIS_0208 1990 + //JIS + return Encoding.GetEncoding(50220); + } + } + } + } + + //should be euc|sjis|utf8 + //use of (?:) by Hiroki Ohzaki + int sjis = 0; + int euc = 0; + int utf8 = 0; + for (int i = 0; i < len - 1; i++) + { + b1 = bytes[i]; + b2 = bytes[i + 1]; + if (((0x81 <= b1 && b1 <= 0x9F) || (0xE0 <= b1 && b1 <= 0xFC)) && + ((0x40 <= b2 && b2 <= 0x7E) || (0x80 <= b2 && b2 <= 0xFC))) + { + //SJIS_C + sjis += 2; + i++; + } + } + for (int i = 0; i < len - 1; i++) + { + b1 = bytes[i]; + b2 = bytes[i + 1]; + if (((0xA1 <= b1 && b1 <= 0xFE) && (0xA1 <= b2 && b2 <= 0xFE)) || + (b1 == 0x8E && (0xA1 <= b2 && b2 <= 0xDF))) + { + //EUC_C + //EUC_KANA + euc += 2; + i++; + } + else if (i < len - 2) + { + b3 = bytes[i + 2]; + if (b1 == 0x8F && (0xA1 <= b2 && b2 <= 0xFE) && + (0xA1 <= b3 && b3 <= 0xFE)) + { + //EUC_0212 + euc += 3; + i += 2; + } + } + } + for (int i = 0; i < len - 1; i++) + { + b1 = bytes[i]; + b2 = bytes[i + 1]; + if ((0xC0 <= b1 && b1 <= 0xDF) && (0x80 <= b2 && b2 <= 0xBF)) + { + //UTF8 + utf8 += 2; + i++; + } + else if (i < len - 2) + { + b3 = bytes[i + 2]; + if ((0xE0 <= b1 && b1 <= 0xEF) && (0x80 <= b2 && b2 <= 0xBF) && + (0x80 <= b3 && b3 <= 0xBF)) + { + //UTF8 + utf8 += 3; + i += 2; + } + } + } + //M. Takahashi's suggestion + //utf8 += utf8 / 2; + + System.Diagnostics.Debug.WriteLine( + string.Format("sjis = {0}, euc = {1}, utf8 = {2}", sjis, euc, utf8)); + if (euc > sjis && euc > utf8) + { + //EUC + return Encoding.GetEncoding(51932); + } + else if (sjis > euc && sjis > utf8) + { + //SJIS + return Encoding.GetEncoding(932); + } + else if (utf8 > euc && utf8 > sjis) + { + //UTF8 + return Encoding.UTF8; + } + + return null; + } + + #endregion + + //====================================================================== + #region WebBrowserコンポーネントのカチカチ音制御 + + /* + // 以下のサイトのエントリーを参考にさせていただきました。 + // http://www.moonmile.net/blog/archives/1465 + + private string keyCurrent = @"AppEvents\Schemes\Apps\Explorer\Navigating\.Current"; + private string keyDefault = @"AppEvents\Schemes\Apps\Explorer\Navigating\.Default"; + + // + // クリック音をON + // + // + // + private void WebBrowserClickSoundON() + { + + //=================================== + // Win8でKeyの取得ができないときがある? + //=================================== + + // .Defaultの値を読み込んで、.Currentに書き込み + Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser; + key = key.OpenSubKey(keyDefault); + string data = (string)key.GetValue(null); + key.Close(); + + key = Microsoft.Win32.Registry.CurrentUser; + key = key.OpenSubKey(keyCurrent, true); + key.SetValue(null, data); + key.Close(); + + } + // + // クリック音をOFF + // + // + // + private void WebBrowserClickSoundOFF() + { + // .Currnetを @"" にする。 + Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser; + key = key.OpenSubKey(keyCurrent, true); + key.SetValue(null, ""); + key.Close(); + } + + */ + #endregion + + + } + +} From 5da8a9c965ad68e9c406bc23d86e8b5911159b19 Mon Sep 17 00:00:00 2001 From: Hiromi Hayashi Date: Wed, 25 Dec 2013 19:02:32 +0900 Subject: [PATCH 4/4] =?UTF-8?q?Form3=E3=81=AEPreview=20Browser=E3=82=BF?= =?UTF-8?q?=E3=83=96=E3=81=AB=E6=97=A5=E6=9C=AC=E8=AA=9E=E6=96=87=E5=AD=97?= =?UTF-8?q?=E5=88=97=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Form3のPreview Browserタブに表示用日本語文字列を追加した。 --- MarkDownSharpEditor/Form3.Designer.cs | 12 +- MarkDownSharpEditor/Form3.ja-JP.resx | 155 +++++++++----------------- MarkDownSharpEditor/Form3.resx | 4 +- 3 files changed, 60 insertions(+), 111 deletions(-) diff --git a/MarkDownSharpEditor/Form3.Designer.cs b/MarkDownSharpEditor/Form3.Designer.cs index 1162807..676bcb3 100644 --- a/MarkDownSharpEditor/Form3.Designer.cs +++ b/MarkDownSharpEditor/Form3.Designer.cs @@ -166,6 +166,7 @@ private void InitializeComponent() this.radioButtonDefaultEncoding = new System.Windows.Forms.RadioButton(); this.tabPageBrowser = new System.Windows.Forms.TabPage(); this.groupBox4 = new System.Windows.Forms.GroupBox(); + this.label8 = new System.Windows.Forms.Label(); this.comboBoxRenderingMode = new System.Windows.Forms.ComboBox(); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); @@ -173,7 +174,6 @@ private void InitializeComponent() this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog(); this.fontDialog1 = new System.Windows.Forms.FontDialog(); this.colorDialog1 = new System.Windows.Forms.ColorDialog(); - this.label8 = new System.Windows.Forms.Label(); this.panel1.SuspendLayout(); this.tabControl1.SuspendLayout(); this.tabPageMain.SuspendLayout(); @@ -1372,6 +1372,11 @@ private void InitializeComponent() this.groupBox4.TabStop = false; this.groupBox4.Enter += new System.EventHandler(this.groupBox4_Enter); // + // label8 + // + resources.ApplyResources(this.label8, "label8"); + this.label8.Name = "label8"; + // // comboBoxRenderingMode // this.comboBoxRenderingMode.FormattingEnabled = true; @@ -1404,11 +1409,6 @@ private void InitializeComponent() this.colorDialog1.AnyColor = true; this.colorDialog1.FullOpen = true; // - // label8 - // - resources.ApplyResources(this.label8, "label8"); - this.label8.Name = "label8"; - // // Form3 // resources.ApplyResources(this, "$this"); diff --git a/MarkDownSharpEditor/Form3.ja-JP.resx b/MarkDownSharpEditor/Form3.ja-JP.resx index 0c0b59d..19e13da 100644 --- a/MarkDownSharpEditor/Form3.ja-JP.resx +++ b/MarkDownSharpEditor/Form3.ja-JP.resx @@ -120,21 +120,21 @@ - iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAZdEVYdFNvZnR3YXJ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rjg0N0YiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/ - eHBhY2tldCBlbmQ9InIiPz7fdwJtAAAAmElEQVQ4T2P4//8/GCcnJxuTgA1g+pAN+N/U1EQUBqr9gNUA - YsC3b9/oaMCnT5/+b9q06f/ChQv/P3r0CCxGkgEgzUDxRiBOA+LbL1++JM2A+vp6kGJdIBMkf/jWrVs0 - NgAkuXjxYpACZAw3AEkMuwHbtm0DSbbDxHBhoBp+GBtZkHIDKPYCOqB/LODA8ISEJIZpAHn4PwMAo4rY - 5uL6sSEAAAAASUVORK5CYII= + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAABl0RVh0U29m + dHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAACYSURBVDhPY/j//z8YJycnG5OADWD6kA3439TURBQG + qv2A1QBiwLdv3+howKdPn/5v2rTp/8KFC/8/evQILEaSASDNQPFGIE4D4tsvX74kzYD6+nqQYl0gEyR/ + +NatWzQ2ACS5ePFikAJkDDcASQy7Adu2bQNJtsPEcGGgGn4YG1mQcgMo9gI6oH8s4MDwhIQkhmkAefg/ + AwCjitjm4vqxIQAAAABJRU5ErkJggg== @@ -874,4 +814,13 @@ オプション + + レンダリングモード: + + + 再起動が必要です + + + プレビューブラウザ + \ No newline at end of file diff --git a/MarkDownSharpEditor/Form3.resx b/MarkDownSharpEditor/Form3.resx index 1914c44..b9cbcfd 100644 --- a/MarkDownSharpEditor/Form3.resx +++ b/MarkDownSharpEditor/Form3.resx @@ -3861,13 +3861,13 @@ 13, 68 - 95, 12 + 88, 12 7 - 再起動が必要です + Restart required label8