From b60e6d4f0a8b866eb16cd30588539a2c3f33db73 Mon Sep 17 00:00:00 2001 From: konekoneko Date: Mon, 10 Oct 2016 23:14:18 +0530 Subject: [PATCH] =?utf8?q?LoadFileAsync=E3=81=AE=E5=A4=89=E6=9B=B4?= =?utf8?q?=E3=81=8C=E3=83=A1=E3=83=88=E3=83=AD=E7=89=88=E3=81=AB=E5=8F=8D?= =?utf8?q?=E6=98=A0=E3=81=95=E3=82=8C=E3=81=A6=E3=81=84=E3=81=AA=E3=81=8B?= =?utf8?q?=E3=81=A3=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Metro/FooEditEngine/FooTextBox.cs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/Metro/FooEditEngine/FooTextBox.cs b/Metro/FooEditEngine/FooTextBox.cs index a4cb1ae..b15ff8e 100644 --- a/Metro/FooEditEngine/FooTextBox.cs +++ b/Metro/FooEditEngine/FooTextBox.cs @@ -341,28 +341,18 @@ namespace FooEditEngine.Metro /// Taskオブジェクト public async Task LoadFileAsync(System.IO.StreamReader sr, System.Threading.CancellationTokenSource token) { - this.IsEnabled = false; - this.View.LayoutLines.IsFrozneDirtyFlag = true; - WinFileReader fs = new WinFileReader(sr); - await this.Document.LoadAsync(fs, token); - this.View.LayoutLines.IsFrozneDirtyFlag = false; - TextStoreHelper.NotifyTextChanged(this.textStore, 0, 0, this.Document.Length); - if (this.verticalScrollBar != null) - this.verticalScrollBar.Maximum = this.View.LayoutLines.Count; - this.View.CalculateLineCountOnScreen(); - this.IsEnabled = true; + await this.Document.LoadAsync(sr, token); } /// /// ドキュメントの内容をファイルに保存する /// /// StreamWriter - /// エンコード + /// キャンセル用トークン /// Taskオブジェクト public async Task SaveFile(System.IO.StreamWriter sw, System.Threading.CancellationTokenSource token) { - WinFileWriter fs = new WinFileWriter(sw); - await this.Document.SaveAsync(fs, token); + await this.Document.SaveAsync(sw, token); } #region command @@ -1236,12 +1226,14 @@ namespace FooEditEngine.Metro if (this._Document != null) { old_doc.Update -= new DocumentUpdateEventHandler(Document_Update); + old_doc.LoadProgress -= _Document_LoadProgress; oldLength = old_doc.Length; } this._Document = value; this._Document.LayoutLines.Render = this.Render; this._Document.Update += new DocumentUpdateEventHandler(Document_Update); + this._Document.LoadProgress += _Document_LoadProgress; //初期化が終わっていればすべて存在する if (this.Controller != null && this.View != null && this.textStore != null) { @@ -1271,6 +1263,20 @@ namespace FooEditEngine.Metro } } + private void _Document_LoadProgress(object sender, ProgressEventArgs e) + { + if(e.state == ProgressState.Start) + this.IsEnabled = false; + else if(e.state == ProgressState.Complete) + { + TextStoreHelper.NotifyTextChanged(this.textStore, 0, 0, this.Document.Length); + if (this.verticalScrollBar != null) + this.verticalScrollBar.Maximum = this.View.LayoutLines.Count; + this.View.CalculateLineCountOnScreen(); + this.IsEnabled = true; + } + } + /// /// レイアウト行を表す /// -- 2.11.0