<Compile Include="$(MSBuildThisFileDirectory)Util.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)WatchDogPattern.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)WinFileStream.cs" />
</ItemGroup>
</Project>
\ No newline at end of file
set;
}
+ public event ProgressEventHandler LoadProgress;
+
/// <summary>
/// ルーラーやキャレット・行番号などの表示すべきものが変化した場合に呼び出される。ドキュメントの内容が変化した通知を受け取り場合はUpdateを使用してください
/// </summary>
/// 読み取り操作は別スレッドで行われます。
/// また、非同期操作中はこのメソッドを実行することはできません。
/// </remarks>
- internal async Task LoadAsync(IStreamReader fs, CancellationTokenSource tokenSource = null)
+ public async Task LoadAsync(TextReader fs, CancellationTokenSource tokenSource = null)
{
- if (fs.IsEnd())
+ if (fs.Peek() == -1)
return;
+ if (this.LoadProgress != null)
+ this.LoadProgress(this, new ProgressEventArgs(ProgressState.Start));
+
try
{
this.Clear();
this.FireUpdateEvent = true;
//これ以降の操作にだけダーティフラグを適用しないとおかしなことになる
this.LayoutLines.IsFrozneDirtyFlag = false;
+ if (this.LoadProgress != null)
+ this.LoadProgress(this, new ProgressEventArgs(ProgressState.Complete));
}
}
/// <param name="tokenSource">キャンセルトークン</param>
/// <returns>Taskオブジェクト</returns>
/// <remarks>非同期操作中はこのメソッドを実行することはできません</remarks>
- internal async Task SaveAsync(IStreamWriter fs, CancellationTokenSource tokenSource = null)
+ public async Task SaveAsync(TextWriter fs, CancellationTokenSource tokenSource = null)
{
try
{
}
/// <summary>
- /// IStreamReaderインターフェイス
- /// </summary>
- public interface IStreamReader
- {
- /// <summary>
- /// ストリームが空かどうかを返す
- /// </summary>
- bool IsEnd();
-
- /// <summary>
- /// ストリームから行を読み取った物を返す。LoadAsyncを呼び出す場合は必ず実装してください
- /// </summary>
- Task<string> ReadLineAsync();
- /// <summary>
- /// ストリームから指定した文字数だけ読み取る
- /// </summary>
- /// <param name="buffer">書き込み先バッファー</param>
- /// <param name="index">書き込み先バッファーのインデックス</param>
- /// <param name="count">読み取る文字数</param>
- /// <returns>読み取った文字数</returns>
- Task<int> ReadAsync(char[] buffer, int index, int count);
- }
-
- /// <summary>
- /// IStreamWriter
- /// </summary>
- public interface IStreamWriter
- {
- /// <summary>
- /// ストリームに書き込む。SaveAsyncを呼び出す場合は必ず実装してください
- /// </summary>
- Task WriteAsync(string str);
-
- /// <summary>
- /// 書き込む際に使用する改行コード
- /// </summary>
- string NewLine
- {
- get;
- set;
- }
- }
-
- /// <summary>
/// 検索結果を表す
/// </summary>
public class SearchResult
*/
//#define TEST_ASYNC
using System;
+using System.IO;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
this.Update(this, new DocumentUpdateEventArgs(UpdateType.Replace, index, length, count));
}
- internal async Task LoadAsync(IStreamReader fs, CancellationTokenSource tokenSource = null)
+ internal async Task LoadAsync(TextReader fs, CancellationTokenSource tokenSource = null)
{
char[] str = new char[1024 * 256];
int readCount;
+++ /dev/null
-using System;
-using System.Text;
-using System.IO;
-using System.Threading.Tasks;
-
-namespace FooEditEngine
-{
- class WinFileWriter : IStreamWriter
- {
- StreamWriter sw;
-
-#if !METRO && !WINDOWS_UWP
- public WinFileWriter(string filepath,Encoding enc)
- {
- this.sw = new StreamWriter(filepath,false, enc);
- }
-#else
- public WinFileWriter(StreamWriter sw)
- {
- this.sw = sw;
- }
-#endif
-
- public Task WriteAsync(string str)
- {
- return this.sw.WriteAsync(str);
- }
-
- public string NewLine
- {
- get
- {
- return this.sw.NewLine;
- }
- set
- {
- this.sw.NewLine = value;
- }
- }
-
- public void Close()
- {
-#if !METRO && !WINDOWS_UWP
- this.sw.Close();
-#else
-#endif
- }
- }
- class WinFileReader : IStreamReader
- {
- TextReader sr;
-#if !METRO && !WINDOWS_UWP
- public WinFileReader(string filepath, Encoding enc)
- {
- this.sr = new StreamReader(filepath, enc);
- }
- public WinFileReader(TextReader tr)
- {
- this.sr = tr;
- }
-#else
- public WinFileReader(StreamReader sr)
- {
- this.sr = sr;
- }
-#endif
-
- public bool IsEnd()
- {
- return this.sr.Peek() == -1;
- }
-
- public Task<string> ReadLineAsync()
- {
- return this.sr.ReadLineAsync();
- }
-
- public Task<int> ReadAsync(char[] buffer,int index, int count)
- {
- return this.sr.ReadAsync(buffer, index, count);
- }
-
-
- public void Close()
- {
-#if !METRO && !WINDOWS_UWP
- this.sr.Close();
-#else
-#endif
- }
- }
-}
/// <returns>Taskオブジェクト</returns>
public async Task LoadFileAsync(System.IO.StreamReader sr, System.Threading.CancellationTokenSource token)
{
- this.IsEnabled = false;
- this.View.LayoutLines.IsFrozneDirtyFlag = true;
- WinFileReader fs = new WinFileReader(sr);
- await this.Document.LoadAsync(fs, token);
- this.View.LayoutLines.IsFrozneDirtyFlag = false;
-
- CoreTextRange modified_range = new CoreTextRange();
- modified_range.StartCaretPosition = 0;
- modified_range.EndCaretPosition = 0;
- //キャレット位置はロード前と同じにしないと違和感を感じる
- if(this.textEditContext != null)
- this.textEditContext.NotifyTextChanged(modified_range, this.Document.Length, modified_range);
+ await this.Document.LoadAsync(sr, token);
+ }
- if (this.verticalScrollBar != null)
- this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
- this.View.CalculateLineCountOnScreen();
- this.IsEnabled = true;
+ private void Document_LoadProgress(object sender, ProgressEventArgs e)
+ {
+ if(e.state == ProgressState.Start)
+ {
+ this.IsEnabled = false;
+ }
+ else if(e.state == ProgressState.Complete)
+ {
+ CoreTextRange modified_range = new CoreTextRange();
+ modified_range.StartCaretPosition = 0;
+ modified_range.EndCaretPosition = 0;
+ //キャレット位置はロード前と同じにしないと違和感を感じる
+ if (this.textEditContext != null)
+ this.textEditContext.NotifyTextChanged(modified_range, this.Document.Length, modified_range);
+
+ if (this.verticalScrollBar != null)
+ this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
+ this.View.CalculateLineCountOnScreen();
+ this.IsEnabled = true;
+ }
}
/// <summary>
/// <returns>Taskオブジェクト</returns>
public async Task SaveFile(System.IO.StreamWriter sw, System.Threading.CancellationTokenSource token)
{
- WinFileWriter fs = new WinFileWriter(sw);
- await this.Document.SaveAsync(fs, token);
+ await this.Document.SaveAsync(sw, token);
}
#region command
{
old_doc.Update -= new DocumentUpdateEventHandler(Document_Update);
this._Document.SelectionChanged -= Controller_SelectionChanged;
+ this._Document.LoadProgress -= Document_LoadProgress;
//NotifyTextChanged()を呼び出すと落ちるのでTextConextをごっそり作り替える
this.RemoveTextContext();
this._Document = value;
this._Document.LayoutLines.Render = this.Render;
this._Document.Update += new DocumentUpdateEventHandler(Document_Update);
+ this._Document.LoadProgress += Document_LoadProgress;
//初期化が終わっていればすべて存在する
if (this.Controller != null && this.View != null)
{
/// <returns>Taskオブジェクト</returns>
public async Task LoadAsync(System.IO.TextReader tr, System.Threading.CancellationTokenSource token)
{
- WinFileReader fs = new WinFileReader(tr);
- await this.LoadAsyncImpl(fs, token);
+ await this.Document.LoadAsync(tr, token);
}
/// <summary>
/// <returns>Taskオブジェクト</returns>
public async Task LoadFileAsync(string filepath, Encoding enc,System.Threading.CancellationTokenSource token)
{
- WinFileReader fs = new WinFileReader(filepath, enc);
- await this.LoadAsyncImpl(fs, token);
+ var fs = new System.IO.StreamReader(filepath, enc);
+ await this.Document.LoadAsync(fs, token);
fs.Close();
}
- async Task LoadAsyncImpl(WinFileReader fs,System.Threading.CancellationTokenSource token)
+ private void Document_LoadProgress(object sender, ProgressEventArgs e)
{
- this.IsEnabled = false;
- await this.Document.LoadAsync(fs, token);
- TextStoreHelper.NotifyTextChanged(this.textStore, 0, 0, this.Document.Length);
- if (this.verticalScrollBar != null)
- this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
- this.View.CalculateLineCountOnScreen();
- this.IsEnabled = true;
+ if (e.state == ProgressState.Start)
+ {
+ this.IsEnabled = false;
+ }
+ else if (e.state == ProgressState.Complete)
+ {
+ TextStoreHelper.NotifyTextChanged(this.textStore, 0, 0, this.Document.Length);
+ if (this.verticalScrollBar != null)
+ this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;
+ this.View.CalculateLineCountOnScreen();
+ this.IsEnabled = true;
+ }
}
/// <summary>
/// <returns>Taskオブジェクト</returns>
public async Task SaveFile(string filepath, Encoding enc,string newLine, System.Threading.CancellationTokenSource token)
{
- WinFileWriter fs = new WinFileWriter(filepath, enc);
+ var fs = new System.IO.StreamWriter(filepath, false , enc);
fs.NewLine = newLine;
await this.Document.SaveAsync(fs, token);
fs.Close();
if (this._Document != null)
{
old_doc.Update -= new DocumentUpdateEventHandler(Document_Update);
+ old_doc.LoadProgress -= Document_LoadProgress;
old_doc.SelectionChanged += new EventHandler(Controller_SelectionChanged);
oldLength = old_doc.Length;
}
this._Document = value;
this._Document.LayoutLines.Render = this.Render;
this._Document.Update += new DocumentUpdateEventHandler(Document_Update);
+ this._Document.LoadProgress += Document_LoadProgress;
//初期化が終わっていればすべて存在する
if (this.Controller != null && this.View != null && this.textStore != null)
{
/// <returns>Taskオブジェクト</returns>
public async Task LoadAsync(System.IO.TextReader tr, System.Threading.CancellationTokenSource token)
{
- WinFileReader fs = new WinFileReader(tr);
- await this.LoadAsyncImpl(fs, token);
+ await this.Document.LoadAsync(tr, token);
}
/// <summary>
/// <returns>Taskオブジェクト</returns>
public async Task LoadFileAsync(string filepath, Encoding enc, System.Threading.CancellationTokenSource token)
{
- WinFileReader fs = new WinFileReader(filepath, enc);
- await this.LoadAsyncImpl(fs, token);
+ var fs = new System.IO.StreamReader(filepath, enc);
+ await this.Document.LoadAsync(fs, token);
fs.Close();
}
- async Task LoadAsyncImpl(WinFileReader fs, System.Threading.CancellationTokenSource token)
+ private void Document_LoadProgress(object sender, ProgressEventArgs e)
{
- this.Enabled = false;
- this.View.LayoutLines.IsFrozneDirtyFlag = true;
- await this.Document.LoadAsync(fs, token);
- this.View.LayoutLines.IsFrozneDirtyFlag = false;
- this.initScrollBars();
- this.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, MousePosition.X, MousePosition.Y, 0));
- this.View.CalculateLineCountOnScreen();
- this.Enabled = true;
+ if (e.state == ProgressState.Start)
+ {
+ this.Enabled = false;
+ }
+ else if (e.state == ProgressState.Complete)
+ {
+ this.initScrollBars();
+ this.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, MousePosition.X, MousePosition.Y, 0));
+ this.View.CalculateLineCountOnScreen();
+ this.Enabled = true;
+ }
}
/// <summary>
/// <returns>Taskオブジェクト</returns>
public async Task SaveFile(string filepath, Encoding enc, string newLine, System.Threading.CancellationTokenSource token)
{
- WinFileWriter fs = new WinFileWriter(filepath, enc);
+ var fs = new System.IO.StreamWriter(filepath, false, enc);
fs.NewLine = newLine;
await this.Document.SaveAsync(fs, token);
fs.Close();