OSDN Git Service

LoadFileAsyncの変更がメトロ版に反映されていなかった
[fooeditengine/FooEditEngine.git] / Metro / FooEditEngine / FooTextBox.cs
index a4cb1ae..b15ff8e 100644 (file)
@@ -341,28 +341,18 @@ namespace FooEditEngine.Metro
         /// <returns>Taskオブジェクト</returns>
         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);
         }
 
         /// <summary>
         /// ドキュメントの内容をファイルに保存する
         /// </summary>
         /// <param name="sw">StreamWriter</param>
-        /// <param name="enc">エンコード</param>
+        /// <param name="token">キャンセル用トークン</param>
         /// <returns>Taskオブジェクト</returns>
         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;
+            }
+        }
+
         /// <summary>
         /// レイアウト行を表す
         /// </summary>