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

Matt Guo matt at mattguo.com
Sun Mar 21 08:45:23 EDT 2010


Hi, Mike

On Sun, Mar 21, 2010 at 6:44 AM, Mike Krüger <mkrueger at novell.com> wrote:
> Hi
>
>> "editor.Document.SyntaxMode = mode;", I tried "editor.Repaint ()" or
>> "editor.Document.CommitUpdateAll", but find them didn't work.
>
>
> CommitUpdateAll should work. Try a
> SyntaxModeService.WaitUpdate(editor.Document) call before the
> CommitUpdateAll.
I referenced Mono.TextEditor.dll from MD 2.2.2 release, and in this
version, SyntaxModeService.WaitUpdate doesn't exist.
However through viewvc I can see WaitUpdate in the trunk source, I'll
try it later when I have time to checkout and try the code. since
suddenly I just find that I don't really need to change the syntax
mode on the fly.
>
> btw. syntax mode can be set with editor.Document.MimeType =
> "text/x-csharp" much faster.
Thanks.
>
> Regards
> Mike
>
>> // --- 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