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