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
}\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
/// <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
/// <remarks>非同期操作中はこのメソッドを実行することはできません</remarks>\r
public void Clear()\r
{\r
- if (this.State == AsyncState.Loading)\r
- throw new InvalidOperationException();\r
this.buffer.Clear();\r
}\r
\r
/// <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
/// </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
}\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
/// </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
/// </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
#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
/// </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
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
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
{\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
/// <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
/// <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
/// <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
}\r
finally\r
{\r
- doc.State = AsyncState.None;\r
progress.Report(new ProgressEventArgs(ProgressState.Complete));\r
+ Semaphore.Release();\r
}\r
}\r
}\r
{
public static bool StartCompstion(Document document)
{
- if (document.State == AsyncState.Loading)
- {
- return false;
- }
document.UndoManager.BeginUndoGroup();
return true;
}
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;
/// <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
/// <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
/// <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
/// </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
/// </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
/// </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
/// </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
/// </summary>\r
public void DeSelectAll()\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- throw new InvalidOperationException();\r
this._Controller.DeSelectAll();\r
}\r
\r
/// <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
/// <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
/// <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
/// <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
/// <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
/// <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
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
\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
\r
bool textStore_IsLoading()\r
{\r
- return this.Document.State == AsyncState.Loading;\r
+ return false;\r
}\r
\r
void textStore_CompositionEnded()\r
\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
\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
\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
\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
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
{\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
\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
\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
\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
\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
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
/// <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
/// <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
/// <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
/// </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
/// </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
/// </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
/// </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
/// <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
/// <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
/// <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
/// <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
/// <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
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
#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
\r
bool textStore_IsLoading()\r
{\r
- return this.Document.State == AsyncState.Loading;\r
+ return false;\r
}\r
\r
void textStore_CompositionEnded()\r
\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
/// <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
/// <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
/// </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
/// </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
/// </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
/// <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
\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
{\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
\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
\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
{\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
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();
}
}
/// <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
/// </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
/// </summary>\r
public void DeSelectAll()\r
{\r
- if (this.Document.State == AsyncState.Loading)\r
- throw new InvalidOperationException();\r
this.Controller.DeSelectAll();\r
}\r
\r
/// </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
/// </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
/// </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
/// <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
/// <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
/// </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
/// <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
/// <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
/// <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
/// <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
/// <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
/// <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
/// <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
/// <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
/// <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
/// <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
/// <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
/// <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
/// <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
/// <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
\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
\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
\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
\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
\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
\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
\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