OSDN Git Service

LayoutLinesをDocumentに移動した
[fooeditengine/FooEditEngine.git] / Metro / FooEditEngine / FooTextBox.cs
index c50b7f7..f40ec3b 100644 (file)
@@ -9,6 +9,7 @@
 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.\r
  */\r
 using System;\r
+using System.Text;\r
 using System.ComponentModel;\r
 using System.Threading.Tasks;\r
 using Windows.ApplicationModel.Resources.Core;\r
@@ -71,13 +72,12 @@ namespace FooEditEngine.Metro
             this.textStore.CompositionUpdated += textStore_CompositionUpdated;\r
             this.textStore.CompositionEnded += textStore_CompositionEnded;\r
 \r
-            this.Document = new Document();\r
-            DocumentExtend.Progress += Document_Progress;\r
-\r
             this.rectangle = new Windows.UI.Xaml.Shapes.Rectangle();\r
             this.rectangle.Margin = this.Padding;\r
             this.Render = new D2DRender(this,this.rectangle,this.textStore);\r
 \r
+            this.Document = new Document(this.Render);\r
+\r
             this.View = new EditView(this.Document, this.Render, new Padding(5, Gripper.HitAreaWidth, Gripper.HitAreaWidth / 2, Gripper.HitAreaWidth));\r
             this.View.SrcChanged += View_SrcChanged;\r
             this.View.InsertMode = this.InsertMode;\r
@@ -145,7 +145,6 @@ namespace FooEditEngine.Metro
                 this.View.Dispose();\r
                 this.Render.Dispose();\r
             }\r
-            DocumentExtend.Progress -= this.Document_Progress;\r
         }\r
 \r
         /// <summary>\r
@@ -319,6 +318,37 @@ namespace FooEditEngine.Metro
             this.View.PerfomLayouts();\r
         }\r
 \r
+        /// <summary>\r
+        /// ファイルからドキュメントを構築する\r
+        /// </summary>\r
+        /// <param name="sr">StremReader</param>\r
+        /// <returns>Taskオブジェクト</returns>\r
+        public async Task LoadFileAsync(System.IO.StreamReader sr, System.Threading.CancellationTokenSource token)\r
+        {\r
+            this.IsEnabled = false;\r
+            this.View.LayoutLines.IsFrozneDirtyFlag = true;\r
+            WinFileReader fs = new WinFileReader(sr);\r
+            await this.Document.LoadAsync(fs, token);\r
+            this.View.LayoutLines.IsFrozneDirtyFlag = false;\r
+            TextStoreHelper.NotifyTextChanged(this.textStore, 0, 0, this.Document.Length);\r
+            if (this.verticalScrollBar != null)\r
+                this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;\r
+            this.View.CalculateLineCountOnScreen();\r
+            this.IsEnabled = true;\r
+        }\r
+\r
+        /// <summary>\r
+        /// ドキュメントの内容をファイルに保存する\r
+        /// </summary>\r
+        /// <param name="sw">StreamWriter</param>\r
+        /// <param name="enc">エンコード</param>\r
+        /// <returns>Taskオブジェクト</returns>\r
+        public async Task SaveFile(System.IO.StreamWriter sw, System.Threading.CancellationTokenSource token)\r
+        {\r
+            WinFileWriter fs = new WinFileWriter(sw);\r
+            await this.Document.SaveAsync(fs, token);\r
+        }\r
+\r
         #region command\r
         void CopyCommand()\r
         {\r
@@ -780,11 +810,16 @@ namespace FooEditEngine.Metro
                         else\r
                             this._Controller.MoveCaretAndSelect(tp);\r
                     }\r
-                    if (this.peer != null)\r
-                        this.peer.OnNotifyCaretChanged();\r
-                    this.Refresh();\r
-                    return;\r
                 }\r
+                else\r
+                {\r
+                    TextPoint tp = this.View.GetTextPointFromPostion(p);\r
+                    this._Controller.MoveCaretAndSelect(tp);\r
+                }\r
+                if (this.peer != null)\r
+                    this.peer.OnNotifyCaretChanged();\r
+                this.Refresh();\r
+                return;\r
             }\r
             if (e.Delta.Scale < 1)\r
             {\r
@@ -1037,19 +1072,6 @@ namespace FooEditEngine.Metro
             TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);\r
         }\r
 \r
-        void Document_Progress(object sender, ProgressEventArgs e)\r
-        {\r
-            switch (e.state)\r
-            {\r
-                case ProgressState.Complete:\r
-                    TextStoreHelper.NotifyTextChanged(this.textStore,0,0,this.Document.Length);\r
-                    if (this.verticalScrollBar != null)\r
-                        this.verticalScrollBar.Maximum = this.View.LayoutLines.Count;\r
-                    this.View.CalculateLineCountOnScreen();\r
-                    break;\r
-            }\r
-        }\r
-\r
         void FooTextBox_Loaded(object sender, RoutedEventArgs e)\r
         {\r
             this.Focus(FocusState.Programmatic);\r