OSDN Git Service

Document.Stateプロパティを廃止した
authorgdkhd812 <jbh03215@htmil.co.jp>
Sat, 7 Dec 2013 15:08:52 +0000 (00:08 +0900)
committergdkhd812 <jbh03215@htmil.co.jp>
Sat, 7 Dec 2013 15:08:52 +0000 (00:08 +0900)
Common/Document.cs
Common/DocumentExtend.cs
Common/TextServiceFramework/TextStoreHelper.cs
Metro/FooEditEngine/FooTextBox.cs
Metro/Test/MainPage.xaml.cs
WPF/FooEditEngine/FooTextBox.cs
WPF/Test/MainWindow.xaml.cs
Windows/FooEditEngine/FooTextBox.cs

index 361a856..f4859bf 100644 (file)
@@ -35,24 +35,6 @@ namespace FooEditEngine
         Complete,\r
     }\r
     /// <summary>\r
-    /// 非同期操作の状態を表す\r
-    /// </summary>\r
-    public enum AsyncState\r
-    {\r
-        /// <summary>\r
-        /// 非同期操作は行われていないことを表す\r
-        /// </summary>\r
-        None,\r
-        /// <summary>\r
-        /// 読み出し中であることを表す\r
-        /// </summary>\r
-        Loading,\r
-        /// <summary>\r
-        /// 書き込み中であることを表す\r
-        /// </summary>\r
-        Saving\r
-    }\r
-    /// <summary>\r
     /// 進行状況を表すためのイベントデータ\r
     /// </summary>\r
     public sealed class ProgressEventArgs : EventArgs\r
@@ -209,15 +191,6 @@ namespace FooEditEngine
         }\r
 \r
         /// <summary>\r
-        /// 非同期操作の状態を表す\r
-        /// </summary>\r
-        public AsyncState State\r
-        {\r
-            get;\r
-            internal set;\r
-        }\r
-\r
-        /// <summary>\r
         /// 文字列の長さ\r
         /// </summary>\r
         public int Length\r
@@ -413,8 +386,6 @@ namespace FooEditEngine
         /// <remarks>読み出し操作中はこのメソッドを実行することはできません</remarks>\r
         public void Replace(int index, int length, string s)\r
         {\r
-            if (this.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (index < 0 || index > this.buffer.Length || index + length > this.buffer.Length || length < 0)\r
                 throw new ArgumentOutOfRangeException();\r
             if (length == 0 && (s == string.Empty || s == null))\r
@@ -435,8 +406,6 @@ namespace FooEditEngine
         /// <remarks>非同期操作中はこのメソッドを実行することはできません</remarks>\r
         public void Clear()\r
         {\r
-            if (this.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             this.buffer.Clear();\r
         }\r
 \r
@@ -487,8 +456,6 @@ namespace FooEditEngine
         /// <remarks>見つかったパターン以外を置き換えた場合、正常に動作しないことがあります</remarks>\r
         public IEnumerator<SearchResult> Find(int start, int length)\r
         {\r
-            if (this.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (this.regex == null)\r
                 throw new InvalidOperationException();\r
             if (start < 0 || start >= this.Length)\r
index 05fe89e..5cc3ff7 100644 (file)
@@ -24,6 +24,8 @@ namespace FooEditEngine
     /// </summary>\r
     public static class DocumentExtend\r
     {\r
+        const int MaxSemaphoreCount = 1;\r
+        static SemaphoreSlim Semaphore = new SemaphoreSlim(MaxSemaphoreCount);\r
         static Progress<ProgressEventArgs> _Progress = new Progress<ProgressEventArgs>();\r
         /// <summary>\r
         /// 進捗処理を表す\r
@@ -40,6 +42,17 @@ namespace FooEditEngine
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// 非同期操作中なら真を返し、そうでないなら偽を返す\r
+        /// </summary>\r
+        public static bool IsOperationNow\r
+        {\r
+            get\r
+            {\r
+                return Semaphore.CurrentCount == MaxSemaphoreCount;\r
+            }\r
+        }\r
+\r
 #if !METRO\r
         /// <summary>\r
         /// ファイルからドキュメントを構築します\r
@@ -52,8 +65,6 @@ namespace FooEditEngine
         /// </remarks>\r
         public static void Load(this Document doc, string filepath, Encoding enc)\r
         {\r
-            if (doc.State != AsyncState.None)\r
-                throw new InvalidOperationException();\r
             using (StreamReader sr = new StreamReader(filepath, enc))\r
             {\r
                 Load(doc,sr);\r
@@ -73,8 +84,6 @@ namespace FooEditEngine
         /// </remarks>\r
         public static async Task LoadAsync(this Document doc, string filepath, Encoding enc, CancellationTokenSource token)\r
         {\r
-            if (doc.State != AsyncState.None)\r
-                throw new InvalidOperationException();\r
             using (StreamReader sr = new StreamReader(filepath, enc))\r
             {\r
                 await LoadAsync(doc,sr, token);\r
@@ -83,6 +92,17 @@ namespace FooEditEngine
 #endif\r
 \r
         /// <summary>\r
+        /// 非同期操作を行っているなら真を返す\r
+        /// </summary>\r
+        public static bool IsNowAsyncOperation\r
+        {\r
+            get\r
+            {\r
+                return Semaphore.CurrentCount == MaxSemaphoreCount;\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
         /// ストリームからドキュメントを構築します\r
         /// </summary>\r
         /// <param name="doc">Documentオブジェクト</param>\r
@@ -109,8 +129,6 @@ namespace FooEditEngine
         /// </remarks>\r
         public static async Task LoadAsync(this Document doc, TextReader sr, CancellationTokenSource tokenSource = null)\r
         {\r
-            if (doc.State != AsyncState.None)\r
-                throw new InvalidOperationException();\r
             if (sr.Peek() == -1)\r
             {\r
                 return;\r
@@ -119,9 +137,9 @@ namespace FooEditEngine
             IProgress<ProgressEventArgs> progress = _Progress;\r
             try\r
             {\r
+                await Semaphore.WaitAsync().ConfigureAwait(false);\r
                 progress.Report(new ProgressEventArgs(ProgressState.Start));\r
                 doc.StringBuffer.Clear();\r
-                doc.State = AsyncState.Loading;\r
                 doc.FireUpdateEvent = false;\r
                 doc.UndoManager.BeginLock();\r
                 string str;\r
@@ -131,7 +149,7 @@ namespace FooEditEngine
                     if (index < 0)\r
                         index = 0;\r
 \r
-                    doc.StringBuffer.Replace(index, 0, Util.GetEnumrator(str + Document.NewLine),str.Length + 1);\r
+                    doc.Replace(index,0,str + Document.NewLine);\r
 \r
                     if (tokenSource != null)\r
                         tokenSource.Token.ThrowIfCancellationRequested();\r
@@ -144,8 +162,8 @@ namespace FooEditEngine
             {\r
                 doc.FireUpdateEvent = true;\r
                 doc.UndoManager.EndLock();\r
-                doc.State = AsyncState.None;\r
                 progress.Report(new ProgressEventArgs(ProgressState.Complete));\r
+                Semaphore.Release();\r
             }\r
         }\r
 \r
@@ -160,8 +178,6 @@ namespace FooEditEngine
         /// <remarks>非同期操作中はこのメソッドを実行することはできません</remarks>\r
         public static void Save(this Document doc, string filepath, Encoding enc, string newline)\r
         {\r
-            if (doc.State != AsyncState.None)\r
-                throw new InvalidOperationException();\r
             using (StreamWriter sw = new StreamWriter(filepath, false, enc))\r
             {\r
                 sw.NewLine = newline;\r
@@ -180,8 +196,6 @@ namespace FooEditEngine
         /// <remarks>非同期操作中はこのメソッドを実行することはできません</remarks>\r
         public static async Task SaveAsync(this Document doc, string filepath, Encoding enc, string newline,CancellationTokenSource token)\r
         {\r
-            if (doc.State != AsyncState.None)\r
-                throw new InvalidOperationException();\r
             using (StreamWriter sw = new StreamWriter(filepath, false, enc))\r
             {\r
                 sw.NewLine = newline;\r
@@ -213,13 +227,11 @@ namespace FooEditEngine
         /// <remarks>非同期操作中はこのメソッドを実行することはできません</remarks>\r
         public static async Task SaveAsync(this Document doc,StreamWriter sw, CancellationTokenSource tokenSource = null)\r
         {\r
-            if (doc.State != AsyncState.None)\r
-                throw new InvalidOperationException();\r
             IProgress<ProgressEventArgs> progress = _Progress;\r
             try\r
             {\r
+                await Semaphore.WaitAsync().ConfigureAwait(false);\r
                 progress.Report(new ProgressEventArgs(ProgressState.Start));\r
-                doc.State = AsyncState.Saving;\r
                 StringBuilder line = new StringBuilder();\r
                 for (int i = 0; i < doc.Length; i++)\r
                 {\r
@@ -241,8 +253,8 @@ namespace FooEditEngine
             }\r
             finally\r
             {\r
-                doc.State = AsyncState.None;\r
                 progress.Report(new ProgressEventArgs(ProgressState.Complete));\r
+                Semaphore.Release();\r
             }\r
         }\r
     }\r
index 0e2aef7..1b52ceb 100644 (file)
@@ -19,10 +19,6 @@ namespace FooEditEngine
     {
         public static bool StartCompstion(Document document)
         {
-            if (document.State == AsyncState.Loading)
-            {
-                return false;
-            }
             document.UndoManager.BeginUndoGroup();
             return true;
         }
@@ -54,12 +50,6 @@ namespace FooEditEngine
 
         public static void GetStringExtent(Document document,EditView view,int i_startIndex,int i_endIndex,out Point startPos,out Point endPos)
         {
-            if (document.State == AsyncState.Loading)
-            {
-                startPos = new Point();
-                endPos = startPos;
-                return;
-            }
             var endIndex = i_endIndex < 0 ? document.Length - 1 : i_endIndex;
             TextPoint endTextPoint;
 
index cb5cb14..ba24940 100644 (file)
@@ -154,8 +154,6 @@ namespace FooEditEngine.Metro
         /// <param name="length">長さ</param>\r
         public void Select(int start, int length)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             this._Controller.Select(start, length);\r
         }\r
 \r
@@ -166,8 +164,6 @@ namespace FooEditEngine.Metro
         /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>\r
         public void JumpCaret(int index)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             this._Controller.JumpCaret(index);\r
         }\r
         /// <summary>\r
@@ -178,8 +174,6 @@ namespace FooEditEngine.Metro
         /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>\r
         public void JumpCaret(int row, int col)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             this._Controller.JumpCaret(row, col);\r
         }\r
 \r
@@ -188,8 +182,6 @@ namespace FooEditEngine.Metro
         /// </summary>\r
         public void Copy()\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             string text = this._Controller.SelectedText;\r
             if (text != null && text != string.Empty)\r
             {\r
@@ -206,8 +198,6 @@ namespace FooEditEngine.Metro
         /// </summary>\r
         public void Cut()\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             string text = this._Controller.SelectedText;\r
             if (text != null && text != string.Empty)\r
             {\r
@@ -226,9 +216,6 @@ namespace FooEditEngine.Metro
         /// </summary>\r
         public async Task PasteAsync()\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
-\r
             var dataPackageView = Clipboard.GetContent();\r
             if (dataPackageView.Contains(StandardDataFormats.Text))\r
             {\r
@@ -241,8 +228,6 @@ namespace FooEditEngine.Metro
         /// </summary>\r
         public void SelectAll()\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             this._Controller.Select(0, this.Document.Length);\r
         }\r
 \r
@@ -251,8 +236,6 @@ namespace FooEditEngine.Metro
         /// </summary>\r
         public void DeSelectAll()\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             this._Controller.DeSelectAll();\r
         }\r
 \r
@@ -264,8 +247,6 @@ namespace FooEditEngine.Metro
         /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>\r
         public Windows.Foundation.Point GetPostionFromTextPoint(TextPoint tp)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (this.Document.FireUpdateEvent == false)\r
                 throw new InvalidOperationException("");\r
             return this.View.GetPostionFromTextPoint(tp);\r
@@ -278,8 +259,6 @@ namespace FooEditEngine.Metro
         /// <returns>テキストポイント</returns>\r
         public TextPoint GetTextPointFromPostion(Windows.Foundation.Point p)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (this.Document.FireUpdateEvent == false)\r
                 throw new InvalidOperationException("");\r
             return this.View.GetTextPointFromPostion(p);\r
@@ -292,8 +271,6 @@ namespace FooEditEngine.Metro
         /// <returns>行の高さ</returns>\r
         public double GetLineHeight(int row)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (this.Document.FireUpdateEvent == false)\r
                 throw new InvalidOperationException("");\r
             return this.View.LayoutLines.GetLayout(row).Height; ;\r
@@ -306,8 +283,6 @@ namespace FooEditEngine.Metro
         /// <returns>座標を返す</returns>\r
         public Windows.Foundation.Point GetPostionFromIndex(int index)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (this.Document.FireUpdateEvent == false)\r
                 throw new InvalidOperationException("");\r
             TextPoint tp = this.View.GetLayoutLineFromIndex(index);\r
@@ -321,8 +296,6 @@ namespace FooEditEngine.Metro
         /// <returns>インデックスを返す</returns>\r
         public int GetIndexFromPostion(Windows.Foundation.Point p)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (this.Document.FireUpdateEvent == false)\r
                 throw new InvalidOperationException("");\r
             TextPoint tp = this.View.GetTextPointFromPostion(p);\r
@@ -424,8 +397,6 @@ namespace FooEditEngine.Metro
         /// <inheritdoc/>\r
         protected override async void OnKeyDown(KeyRoutedEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             bool isControlPressed = this.IsModiferKeyPressed(VirtualKey.Control);\r
             bool isShiftPressed = this.IsModiferKeyPressed(VirtualKey.Shift);\r
             bool isMovedCaret = false;\r
@@ -593,7 +564,7 @@ namespace FooEditEngine.Metro
             this.gestureRecongnizer.ProcessMoveEvents(e.GetIntermediatePoints(this));\r
             e.Handled = true;\r
 \r
-            if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse && this.Document.State != AsyncState.Loading)\r
+            if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)\r
             {\r
                 Point p = e.GetCurrentPoint(this).Position;\r
                 if (this.View.HitTextArea(p.X, p.Y))\r
@@ -648,7 +619,7 @@ namespace FooEditEngine.Metro
 \r
         void CoreWindow_CharacterReceived(CoreWindow sender, CharacterReceivedEventArgs args)\r
         {\r
-            if (this.FocusState == FocusState.Unfocused || this.Document.State == AsyncState.Loading)\r
+            if (this.FocusState == FocusState.Unfocused || !this.IsEnabled)\r
                 return;\r
             if (args.KeyCode >= 00 && args.KeyCode <= 0x1f)\r
                 return;\r
@@ -663,7 +634,7 @@ namespace FooEditEngine.Metro
 \r
         bool textStore_IsLoading()\r
         {\r
-            return this.Document.State == AsyncState.Loading;\r
+            return false;\r
         }\r
 \r
         void textStore_CompositionEnded()\r
@@ -725,8 +696,6 @@ namespace FooEditEngine.Metro
 \r
         void _textStore_SetSelectionIndex(int i_startIndex, int i_endIndex)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             TextStoreHelper.SetSelectionIndex(this._Controller, this.View, i_startIndex, i_endIndex);\r
             this.Refresh();\r
         }\r
@@ -778,9 +747,6 @@ namespace FooEditEngine.Metro
 \r
         void gestureRecongnizer_ManipulationUpdated(GestureRecognizer sender, ManipulationUpdatedEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
-\r
             if (HittedCaret)\r
             {\r
                 Point p;\r
@@ -921,9 +887,6 @@ namespace FooEditEngine.Metro
 \r
         void JumpCaret(Point p)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
-            \r
             TextPoint tp = this.View.GetTextPointFromPostion(p);\r
             if (tp == TextPoint.Null)\r
                 return;\r
@@ -951,8 +914,6 @@ namespace FooEditEngine.Metro
 \r
         void gestureRecongnizer_Dragging(GestureRecognizer sender, DraggingEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             Point p = e.Position;\r
             if (this.View.HitTextArea(p.X, p.Y))\r
             {\r
@@ -975,7 +936,7 @@ namespace FooEditEngine.Metro
                 return;\r
 \r
             this.Render.BeginDraw();\r
-            if (this.Document.State != AsyncState.Loading)\r
+            if (this.IsEnabled)\r
                 this.View.Draw(updateRect);\r
             else\r
                 this.Render.FillBackground(updateRect);\r
@@ -989,7 +950,7 @@ namespace FooEditEngine.Metro
         {\r
             if (width == 0 || height == 0)\r
                 throw new ArgumentOutOfRangeException();\r
-            if (this.Document.State != AsyncState.Loading && this.Render.Resize(this.rectangle, width, height))\r
+            if (this.Render.Resize(this.rectangle, width, height))\r
             {\r
                 this.View.PageBound = new Rectangle(0, 0, width, height);\r
 \r
@@ -1026,7 +987,7 @@ namespace FooEditEngine.Metro
 \r
         void FooTextBox_SizeChanged(object sender, SizeChangedEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading || this.Resize(this.rectangle.ActualWidth, this.rectangle.ActualHeight))\r
+            if (this.Resize(this.rectangle.ActualWidth, this.rectangle.ActualHeight))\r
             {\r
                 this.Refresh();\r
                 return;\r
@@ -1035,8 +996,6 @@ namespace FooEditEngine.Metro
 \r
         void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             if (this.horizontalScrollBar == null)\r
                 return;\r
             double toX;\r
@@ -1052,8 +1011,6 @@ namespace FooEditEngine.Metro
 \r
         void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             if (this.verticalScrollBar == null)\r
                 return;\r
             int newRow = (int)this.verticalScrollBar.Value;\r
@@ -1067,15 +1024,13 @@ namespace FooEditEngine.Metro
 \r
         void Document_Update(object sender, DocumentUpdateEventArgs e)\r
         {\r
-            if (this.textStore.IsLocked() || this.Document.State == AsyncState.Loading)\r
+            if (this.textStore.IsLocked())\r
                 return;\r
             TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);\r
         }\r
 \r
         void Document_Progress(object sender, ProgressEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             switch (e.state)\r
             {\r
                 case ProgressState.Complete:\r
index 75c9451..3806536 100644 (file)
@@ -111,12 +111,14 @@ namespace Test
             StorageFile file = await openPicker.PickSingleFileAsync();\r
             if (file != null)\r
             {\r
+                this.fooTextBox.IsEnabled = false;\r
                 using (Stream stream = await file.OpenStreamForReadAsync())\r
                 using(StreamReader reader = new StreamReader(stream))\r
                 {\r
                     await this.fooTextBox.Document.LoadAsync(reader);\r
                     this.fooTextBox.FoldingStrategy = new CharFoldingMethod('{', '}');\r
                     this.fooTextBox.LayoutLineCollection.GenerateFolding();\r
+                    this.fooTextBox.IsEnabled = true;\r
                     this.fooTextBox.Refresh();\r
                 }\r
             }\r
index f500430..077a43a 100644 (file)
@@ -198,8 +198,6 @@ namespace FooEditEngine.WPF
         /// <param name="length">長さ</param>\r
         public void Select(int start, int length)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             this._Controller.Select(start, length);\r
             this.textStore.NotifySelectionChanged();\r
         }\r
@@ -211,8 +209,6 @@ namespace FooEditEngine.WPF
         /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>\r
         public void JumpCaret(int index)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             this._Controller.JumpCaret(index);\r
         }\r
         /// <summary>\r
@@ -223,8 +219,6 @@ namespace FooEditEngine.WPF
         /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>\r
         public void JumpCaret(int row, int col)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             this._Controller.JumpCaret(row, col);\r
         }\r
 \r
@@ -233,8 +227,6 @@ namespace FooEditEngine.WPF
         /// </summary>\r
         public void Copy()\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             string text = this._Controller.SelectedText;\r
             if (text != null && text != string.Empty)\r
                 Clipboard.SetText(text);\r
@@ -245,8 +237,6 @@ namespace FooEditEngine.WPF
         /// </summary>\r
         public void Cut()\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             string text = this._Controller.SelectedText;\r
             if (text != null && text != string.Empty)\r
             {\r
@@ -260,8 +250,6 @@ namespace FooEditEngine.WPF
         /// </summary>\r
         public void Paste()\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (Clipboard.ContainsText() == false)\r
                 return;\r
             string text = Clipboard.GetText();\r
@@ -273,8 +261,6 @@ namespace FooEditEngine.WPF
         /// </summary>\r
         public void DeSelectAll()\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             this._Controller.DeSelectAll();\r
             this.textStore.NotifySelectionChanged();\r
         }\r
@@ -287,8 +273,6 @@ namespace FooEditEngine.WPF
         /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>\r
         public System.Windows.Point GetPostionFromTextPoint(TextPoint tp)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (this.Document.FireUpdateEvent == false)\r
                 throw new InvalidOperationException("");\r
             return this.View.GetPostionFromTextPoint(tp);\r
@@ -301,8 +285,6 @@ namespace FooEditEngine.WPF
         /// <returns>テキストポイント</returns>\r
         public TextPoint GetTextPointFromPostion(System.Windows.Point p)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (this.Document.FireUpdateEvent == false)\r
                 throw new InvalidOperationException("");\r
             return this.View.GetTextPointFromPostion(p);\r
@@ -315,8 +297,6 @@ namespace FooEditEngine.WPF
         /// <returns>行の高さ</returns>\r
         public double GetLineHeight(int row)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (this.Document.FireUpdateEvent == false)\r
                 throw new InvalidOperationException("");\r
             return this.View.LayoutLines.GetLayout(row).Height;;\r
@@ -329,8 +309,6 @@ namespace FooEditEngine.WPF
         /// <returns>座標を返す</returns>\r
         public System.Windows.Point GetPostionFromIndex(int index)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (this.Document.FireUpdateEvent == false)\r
                 throw new InvalidOperationException("");\r
             TextPoint tp = this.View.GetLayoutLineFromIndex(index);\r
@@ -344,8 +322,6 @@ namespace FooEditEngine.WPF
         /// <returns>インデックスを返す</returns>\r
         public int GetIndexFromPostion(System.Windows.Point p)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (this.Document.FireUpdateEvent == false)\r
                 throw new InvalidOperationException("");\r
             TextPoint tp = this.View.GetTextPointFromPostion(p);\r
@@ -405,7 +381,7 @@ namespace FooEditEngine.WPF
             this.timer.Stop();\r
 \r
             this.Render.BegineDraw();\r
-            if (this.Document.State != AsyncState.Loading)\r
+            if (this.IsEnabled)\r
                 this.View.Draw(updateRect);\r
             else\r
                 this.Render.FillBackground(updateRect);\r
@@ -417,7 +393,7 @@ namespace FooEditEngine.WPF
         #region Commands\r
         void CanExecute(object sender, CanExecuteRoutedEventArgs e)\r
         {\r
-            e.CanExecute = this.Document.State != FooEditEngine.AsyncState.Loading;\r
+            e.CanExecute = this.IsEnabled;\r
         }\r
 \r
         void ToggleCodePointCommand(object sender, RoutedEventArgs e)\r
@@ -510,7 +486,7 @@ namespace FooEditEngine.WPF
 \r
         bool textStore_IsLoading()\r
         {\r
-            return this.Document.State == AsyncState.Loading;\r
+            return false;\r
         }\r
 \r
         void textStore_CompositionEnded()\r
@@ -582,8 +558,6 @@ namespace FooEditEngine.WPF
 \r
         void _textStore_SetSelectionIndex(int i_startIndex, int i_endIndex)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             TextStoreHelper.SetSelectionIndex(this._Controller, this.View, i_startIndex, i_endIndex);\r
             this.Refresh();\r
         }\r
@@ -634,8 +608,6 @@ namespace FooEditEngine.WPF
         /// <inheritdoc/>\r
         protected override void OnTextInput(TextCompositionEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             if (e.Text == "\r")\r
             {\r
                 this._Controller.DoEnterAction();\r
@@ -669,8 +641,6 @@ namespace FooEditEngine.WPF
         /// <inheritdoc/>\r
         protected override void OnKeyDown(KeyEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             if (this.textStore.IsLocked())\r
                 return;\r
 \r
@@ -764,8 +734,6 @@ namespace FooEditEngine.WPF
         /// </remarks>\r
         protected override void OnMouseDoubleClick(MouseButtonEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             System.Windows.Point p = e.GetPosition(this);\r
             TextPoint tp = this.View.GetTextPointFromPostion(p);\r
             if (tp == TextPoint.Null)\r
@@ -804,9 +772,6 @@ namespace FooEditEngine.WPF
         /// </remarks>\r
         protected override void OnMouseDown(MouseButtonEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
-            \r
             System.Windows.Point p = e.GetPosition(this);\r
             TextPoint tp = this.View.GetTextPointFromPostion(p);\r
             if (tp == TextPoint.Null)\r
@@ -857,12 +822,6 @@ namespace FooEditEngine.WPF
         /// </remarks>\r
         protected override void  OnMouseMove(MouseEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-            {\r
-                this.Cursor = Cursors.Wait;\r
-                base.OnMouseMove(e);\r
-                return;\r
-            }\r
             System.Windows.Point p = e.GetPosition(this);\r
             TextPoint tp = this.View.GetTextPointFromPostion(p);\r
             if (tp == TextPoint.Null)\r
@@ -903,8 +862,6 @@ namespace FooEditEngine.WPF
         /// <inheritdoc/>\r
         protected override void OnMouseWheel(MouseWheelEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             if(Keyboard.Modifiers == ModifierKeys.None)\r
             {\r
                 if (e.Delta > 0)\r
@@ -946,20 +903,17 @@ namespace FooEditEngine.WPF
 \r
         void Document_Update(object sender, DocumentUpdateEventArgs e)\r
         {\r
-            if (this.textStore.IsLocked() || this.Document.State == AsyncState.Loading)\r
+            if (this.textStore.IsLocked())\r
                 return;\r
             TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);\r
         }\r
 \r
         void Document_Progress(object sender, ProgressEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             switch (e.state)\r
             {\r
                 case ProgressState.Complete:\r
                     TextStoreHelper.NotifyTextChanged(this.textStore,0,0,this.Document.Length);\r
-                    this.OnMouseMove(new MouseEventArgs(Mouse.PrimaryDevice, new TimeSpan(DateTime.Now.Ticks).Milliseconds));\r
                     if(this.verticalScrollBar != null)\r
                         this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;\r
                     this.View.CalculateLineCountOnScreen();\r
@@ -971,7 +925,7 @@ namespace FooEditEngine.WPF
         {\r
             if (this.image.ActualWidth == 0 || this.image.ActualHeight == 0)\r
                 return;\r
-            if (this.Document.State == AsyncState.Loading || this.Resize(this.image.ActualWidth, this.image.ActualHeight))\r
+            if (this.Resize(this.image.ActualWidth, this.image.ActualHeight))\r
             {\r
                 this.Refresh();\r
                 return;\r
@@ -993,8 +947,6 @@ namespace FooEditEngine.WPF
 \r
         void horizontalScrollBar_Scroll(object sender, ScrollEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             if (this.horizontalScrollBar == null)\r
                 return;\r
             double toX;\r
@@ -1008,8 +960,6 @@ namespace FooEditEngine.WPF
 \r
         void verticalScrollBar_Scroll(object sender, ScrollEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             if (this.verticalScrollBar == null)\r
                 return;\r
             int newRow = (int)this.verticalScrollBar.Value;\r
@@ -1057,7 +1007,7 @@ namespace FooEditEngine.WPF
         {\r
             if (width == 0 || height == 0)\r
                 throw new ArgumentOutOfRangeException();\r
-            if (this.Render.Resize(width, height) && this.Document.State != AsyncState.Loading)\r
+            if (this.Render.Resize(width, height))\r
             {\r
                 this.View.PageBound = new Rectangle(0, 0, width, height);\r
 \r
index 96e07fe..a864549 100644 (file)
@@ -127,7 +127,9 @@ namespace Test
             bool result = (bool)ofd.ShowDialog(this);
             if (result == true)
             {
+                this.fooTextBox.IsEnabled = false;
                 await this.fooTextBox.Document.LoadAsync(ofd.FileName, Encoding.Default,this.cancleTokenSrc);
+                this.fooTextBox.IsEnabled = true;
                 this.fooTextBox.Refresh();
             }
         }
index 978a457..6f3d56a 100644 (file)
@@ -628,8 +628,6 @@ namespace FooEditEngine.Windows
         /// <param name="length">長さ</param>\r
         public void Select(int start, int length)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             this.Controller.Select(start, length);\r
             this.HScrollBar.Value = (int)this.View.Src.X;\r
             this.VScrollBar.Value = this.View.Src.Row;\r
@@ -640,8 +638,6 @@ namespace FooEditEngine.Windows
         /// </summary>\r
         public void SelectAll()\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             this.Controller.Select(0, this.Document.Length - 1);\r
         }\r
 \r
@@ -650,8 +646,6 @@ namespace FooEditEngine.Windows
         /// </summary>\r
         public void DeSelectAll()\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             this.Controller.DeSelectAll();\r
         }\r
 \r
@@ -660,8 +654,6 @@ namespace FooEditEngine.Windows
         /// </summary>\r
         public void Copy()\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             string text = this.SelectedText;\r
             if(text != null && text != string.Empty)\r
                 Clipboard.SetText(text);\r
@@ -672,8 +664,6 @@ namespace FooEditEngine.Windows
         /// </summary>\r
         public void Cut()\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             string text = this.SelectedText;\r
             if (text != null && text != string.Empty)\r
             {\r
@@ -687,8 +677,6 @@ namespace FooEditEngine.Windows
         /// </summary>\r
         public void Paste()\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (Clipboard.ContainsText() == false)\r
                 return;\r
             this.Controller.SelectedText = Clipboard.GetText();\r
@@ -701,8 +689,6 @@ namespace FooEditEngine.Windows
         /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>\r
         public void JumpCaret(int index)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             this.Controller.JumpCaret(index);\r
         }\r
         /// <summary>\r
@@ -713,8 +699,6 @@ namespace FooEditEngine.Windows
         /// <remarks>このメソッドを呼び出すと選択状態は解除されます</remarks>\r
         public void JumpCaret(int row, int col)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             this.Controller.JumpCaret(row, col);\r
         }\r
 \r
@@ -723,8 +707,6 @@ namespace FooEditEngine.Windows
         /// </summary>\r
         public new void Refresh()\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             if (this.Document.FireUpdateEvent == false)\r
                 throw new InvalidOperationException("");\r
             if(this.View.CaretBlink)\r
@@ -740,8 +722,6 @@ namespace FooEditEngine.Windows
         /// <returns>高さ</returns>\r
         public double GetLineHeight(int row)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (this.Document.FireUpdateEvent == false)\r
                 throw new InvalidOperationException("");\r
             return this.View.LayoutLines.GetLayout(row).Height;\r
@@ -755,8 +735,6 @@ namespace FooEditEngine.Windows
         /// <remarks>テキストポイントがクライアント領域の原点より外にある場合、返される値は原点に丸められます</remarks>\r
         public System.Drawing.Point GetPostionFromTextPoint(TextPoint tp)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (this.Document.FireUpdateEvent == false)\r
                 throw new InvalidOperationException("");\r
             return this.View.GetPostionFromTextPoint(tp);\r
@@ -769,8 +747,6 @@ namespace FooEditEngine.Windows
         /// <returns>テキストポイント</returns>\r
         public TextPoint GetTextPointFromPostion(System.Drawing.Point p)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (this.Document.FireUpdateEvent == false)\r
                 throw new InvalidOperationException("");\r
             return this.View.GetTextPointFromPostion(p);\r
@@ -783,8 +759,6 @@ namespace FooEditEngine.Windows
         /// <returns>座標を返す</returns>\r
         public System.Drawing.Point GetPostionFromIndex(int index)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (this.Document.FireUpdateEvent == false)\r
                 throw new InvalidOperationException("");\r
             TextPoint tp = this.View.GetLayoutLineFromIndex(index);\r
@@ -798,8 +772,6 @@ namespace FooEditEngine.Windows
         /// <returns>インデックスを返す</returns>\r
         public int GetIndexFromPostion(System.Drawing.Point p)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                throw new InvalidOperationException();\r
             if (this.Document.FireUpdateEvent == false)\r
                 throw new InvalidOperationException("");\r
             TextPoint tp = this.View.GetTextPointFromPostion(p);\r
@@ -863,8 +835,6 @@ namespace FooEditEngine.Windows
         /// <returns>文字がコントロールによって処理された場合は true。それ以外の場合は false。 </returns>\r
         protected override bool ProcessCmdKey(ref Message msg, Keys keyData)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return false;\r
             const int WM_KEYDOWN = 0x100;\r
             if (msg.Msg != WM_KEYDOWN)\r
                 return base.ProcessCmdKey(ref msg, keyData);\r
@@ -985,9 +955,6 @@ namespace FooEditEngine.Windows
         /// <param name="e">インベントデータ</param>\r
         protected override void OnMouseDown(MouseEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
-\r
             TextPoint tp = this.View.GetTextPointFromPostion(e.Location);\r
             if (tp == TextPoint.Null)\r
                 return;\r
@@ -1027,9 +994,6 @@ namespace FooEditEngine.Windows
         /// <param name="e">インベントデータ</param>\r
         protected override void OnMouseClick(MouseEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
-\r
             int index = this.GetIndexFromPostion(e.Location);\r
 \r
             FooMouseEventArgs mouseEvent = new FooMouseEventArgs(index, e.Button, e.Clicks, e.X, e.Y, e.Delta);\r
@@ -1043,9 +1007,6 @@ namespace FooEditEngine.Windows
         /// <param name="e">インベントデータ</param>\r
         protected override void OnMouseDoubleClick(MouseEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
-\r
             TextPoint tp = this.View.GetTextPointFromPostion(e.Location);\r
             if (tp == TextPoint.Null)\r
                 return;\r
@@ -1069,11 +1030,6 @@ namespace FooEditEngine.Windows
         /// <param name="e">インベントデータ</param>\r
         protected override void OnMouseMove(MouseEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-            {\r
-                this.Cursor = Cursors.WaitCursor;\r
-                return;\r
-            }\r
             if (this.Focused == false)\r
                 return;\r
 \r
@@ -1105,9 +1061,6 @@ namespace FooEditEngine.Windows
         /// <param name="e">インベントデータ</param>\r
         protected override void OnMouseWheel(MouseEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
-\r
             base.OnMouseWheel(e);\r
 \r
             ScrollDirection dir = e.Delta > 0 ? ScrollDirection.Up : ScrollDirection.Down;\r
@@ -1121,7 +1074,7 @@ namespace FooEditEngine.Windows
         /// <param name="e">インベントデータ</param>\r
         protected override void OnPaint(PaintEventArgs e)\r
         {\r
-            if (DesignMode || this.Document.State == AsyncState.Loading)\r
+            if (DesignMode)\r
             {\r
                 SolidBrush brush = new SolidBrush(this.BackColor);\r
                 e.Graphics.FillRectangle(brush, this.ClientRectangle);\r
@@ -1167,9 +1120,6 @@ namespace FooEditEngine.Windows
         /// <param name="e">インベントデータ</param>\r
         protected override void OnKeyDown(KeyEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
-\r
             base.OnKeyDown(e);\r
             \r
             if (e.Handled)\r
@@ -1247,9 +1197,6 @@ namespace FooEditEngine.Windows
         /// <param name="e">インベントデータ</param>\r
         protected override void OnKeyPress(KeyPressEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
-\r
             base.OnKeyPress(e);\r
 \r
             if (e.Handled)\r
@@ -1312,16 +1259,12 @@ namespace FooEditEngine.Windows
 \r
         void VScrollBar_Scroll(object sender, ScrollEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             this.View.TryScroll(this.View.Src.X, e.NewValue);\r
             this.Refresh();\r
         }\r
 \r
         void HScrollBar_Scroll(object sender, ScrollEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             int toX;\r
             if (this.RightToLeft == System.Windows.Forms.RightToLeft.Yes)\r
                 toX = -e.NewValue;\r
@@ -1333,8 +1276,6 @@ namespace FooEditEngine.Windows
 \r
         void Ime_StartCompstion(object sender, StartCompstionEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             this.Ime.Font = this.Font;\r
             this.Ime.Location = this.GetPostionFromIndex(this.Controller.SelectionStart);\r
             this.View.HideCaret = true;\r
@@ -1347,16 +1288,12 @@ namespace FooEditEngine.Windows
 \r
         void Ime_ImeCompstion(object sender, ImeCompstionEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             this.Controller.DoInputString(e.InputText);\r
             this.Refresh();\r
         }\r
 \r
         void Ime_ImeDocumentFeed(object sender, ImeDocumentFeedEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             TextPoint tp = this.CaretPostion;\r
             e.Pragraph = this.LayoutLines[tp.row];\r
             e.pos = tp.col;\r
@@ -1364,8 +1301,6 @@ namespace FooEditEngine.Windows
 \r
         void Ime_ImeReconvert(object sender, ImeReconvertStringEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             if (this.RectSelection)\r
                 return;\r
             if (this.Controller.SelectionLength == 0)\r
@@ -1385,9 +1320,6 @@ namespace FooEditEngine.Windows
 \r
         void Ime_ImeQueryReconvert(object sender, ImeQueryRecovertStringEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
-\r
             TextPoint tp = this.LayoutLines.GetTextPointFromIndex(this.Controller.SelectionStart);\r
             tp.col = e.offset;\r
 \r
@@ -1403,8 +1335,6 @@ namespace FooEditEngine.Windows
 \r
         void Document_Progress(object sender, ProgressEventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Saving)\r
-                return;\r
             if (e.state == ProgressState.Complete)\r
             {\r
                 this.initScrollBars();\r
@@ -1425,8 +1355,6 @@ namespace FooEditEngine.Windows
 \r
         void Timer_Tick(object sender,EventArgs e)\r
         {\r
-            if (this.Document.State == AsyncState.Loading)\r
-                return;\r
             if (this.View.CaretPostion.row >= this.View.LayoutLines.Count || DesignMode)\r
                 return;\r
 \r