diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2012-05-30 11:14:38 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2012-05-30 11:14:38 +0400 |
commit | e2ea070c27f5d029566e1b6578fb7fb0604240e3 (patch) | |
tree | 5e84163a85d0ec10f7a76885046753a5b3abc055 /main/src | |
parent | e674d13eb1f829592b2f6884025fddaa14b46b46 (diff) |
[TextEditor] Fixed threading issue.
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/core/Mono.Texteditor/Mono.TextEditor/Document/TextDocument.cs | 7 | ||||
-rw-r--r-- | main/src/core/Mono.Texteditor/Mono.TextEditor/HeightTree.cs | 15 |
2 files changed, 19 insertions, 3 deletions
diff --git a/main/src/core/Mono.Texteditor/Mono.TextEditor/Document/TextDocument.cs b/main/src/core/Mono.Texteditor/Mono.TextEditor/Document/TextDocument.cs index abfa410c87..fd74afb2af 100644 --- a/main/src/core/Mono.Texteditor/Mono.TextEditor/Document/TextDocument.cs +++ b/main/src/core/Mono.Texteditor/Mono.TextEditor/Document/TextDocument.cs @@ -992,8 +992,11 @@ namespace Mono.TextEditor InterruptFoldWorker (); bool update; if (!runInThread) { - foldedSegments = UpdateFoldSegmentWorker (newSegments, out update); - InformFoldTreeUpdated (); + var newFoldedSegments = UpdateFoldSegmentWorker (newSegments, out update); + Gtk.Application.Invoke (delegate { + foldedSegments = newFoldedSegments; + InformFoldTreeUpdated (); + }); return; } foldSegmentSrc = new CancellationTokenSource (); diff --git a/main/src/core/Mono.Texteditor/Mono.TextEditor/HeightTree.cs b/main/src/core/Mono.Texteditor/Mono.TextEditor/HeightTree.cs index 83177e665b..5f1ce13dbc 100644 --- a/main/src/core/Mono.Texteditor/Mono.TextEditor/HeightTree.cs +++ b/main/src/core/Mono.Texteditor/Mono.TextEditor/HeightTree.cs @@ -42,6 +42,7 @@ namespace Mono.TextEditor // TODO: Add support for line word wrap to the text editor - with the height tree this is possible. internal RedBlackTree<HeightNode> tree = new RedBlackTree<HeightNode> (); readonly TextEditorData editor; + readonly Thread guiThread; public double TotalHeight { get { @@ -57,12 +58,19 @@ namespace Mono.TextEditor public HeightTree (TextEditorData editor) { + guiThread = Thread.CurrentThread; this.editor = editor; this.editor.Document.Splitter.LineRemoved += HandleLineRemoved; this.editor.Document.Splitter.LineInserted += HandleLineInserted; this.editor.Document.FoldTreeUpdated += HandleFoldTreeUpdated; } + void CheckThread () + { + if (guiThread != Thread.CurrentThread) + throw new InvalidOperationException ("Called from the wrong thread."); + } + void HandleLineInserted (object sender, LineEventArgs e) { InsertLine (e.Line.LineNumber); @@ -89,6 +97,7 @@ namespace Mono.TextEditor void RemoveLine (int line) { + CheckThread (); try { var node = GetNodeByLine (line); if (node == null) @@ -126,6 +135,7 @@ namespace Mono.TextEditor void InsertLine (int line) { + CheckThread (); var newLine = new HeightNode () { count = 1, height = editor.LineHeight @@ -153,6 +163,7 @@ namespace Mono.TextEditor bool rebuild; public void Rebuild () { + CheckThread (); rebuild = true; try { markers.Clear (); @@ -184,6 +195,7 @@ namespace Mono.TextEditor public void SetLineHeight (int lineNumber, double height) { + CheckThread (); var node = GetNodeByLine (lineNumber); if (node == null) throw new Exception ("No node for line number " + lineNumber + " found. (maxLine=" + tree.Root.totalCount + ")"); @@ -241,6 +253,7 @@ namespace Mono.TextEditor public FoldMarker Fold (int lineNumber, int count) { + CheckThread (); GetSingleLineNode (lineNumber); lineNumber++; @@ -257,7 +270,7 @@ namespace Mono.TextEditor public void Unfold (FoldMarker marker, int lineNumber, int count) { - + CheckThread (); if (marker == null || !markers.Contains (marker)) return; markers.Remove (marker); |