[MonoDevelop] A question on dynamically change the SyntaxMode of Mono.TextEditor.Document

Matt Guo matt at mattguo.com
Sat Mar 20 09:41:16 EDT 2010


Hey, gurus,

Background: I need to implement a REPL IronPython editor in a project,
 currently I had an implementation by modifying the gsharp code. While
I think maybe I can get more things to reuse (syntax highlight, code
completion etc.) if I can build the editor on the basis of MD. (BTW I
know Kruger once mentioned in this list that maybe I need to reference
half of the MD dlls to support code completion.)

Now the concrete problem I had:
I used the following source to change the SyntaxMode in a button click
handler (from "none" to "csharp" syntax), but the existing editor text
remains un-styled after the click, and once I move the caret (by
key.Up, key.Down, or mouse click), the line contains the caret will be
syntax-highlighted.
So do I need to call something else after the
"editor.Document.SyntaxMode = mode;", I tried "editor.Repaint ()" or
"editor.Document.CommitUpdateAll", but find them didn't work.

// --- source ---

using Mono.TextEditor;
using Mono.TextEditor.Highlighting;

public partial class MainWindow : Gtk.Window
{
	public MainWindow () : base(Gtk.WindowType.Toplevel)
	{
		Build ();
		var editor = new TextEditor ();
		vbox1.PackStart (editor, true, true, 0);

		var btn = new Button ();
		btn.Label = "debug";
		btn.Clicked += delegate {
			var mode = SyntaxModeService.GetSyntaxMode ("text/x-csharp");
			editor.Document.SyntaxMode = mode;
		};
		vbox1.PackStart (btn, false, false, 0);

		this.Focus = editor;
	}
	...
}

//--- end of code ---

Thanks
-- 
B.R.
GUO Rui (Matt)


More information about the Monodevelop-list mailing list