[MonoDevelop] A question on dynamically change the SyntaxMode of Mono.TextEditor.Document
Doug Blank
doug.blank at gmail.com
Thu Feb 16 12:18:49 UTC 2012
Following up an old thread. In recent MonoDevelop, I can't get any
combination of calls to reformat on changing the mime type:
// FAIL: does nothing
texteditor.Document.MimeType = new_mime_type;
texteditor.Document.UpdateHighlighting();
texteditor.Document.CommitUpdateAll();
Mono.TextEditor.Highlighting.SyntaxModeService.WaitUpdate(texteditor.Document);
However, this works:
// HACK:
texteditor.Document.Text = texteditor.Document.Text;
-Doug
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