agoeb
agoeb

Reputation: 269

How can a MonoDevelop addin highlight a line in a text editor?

I am working on a MonoDevelop Addin that mostly works on the source editor. Now I would like to highlight a particular line with a background color based on the line's content.

So far I see two approaches, which both do not seem to work: The first is to use the standard way MonoDevelop draws line backgrounds, which is based on errors or warnings by creating a Task and adding it to TaskService.Errors - but here I don't have the ability to define a custom color, and I only want to give a visual indication, not indicate a problem.

The second is based on the answer to Mono.TextEditor highlight line, which gives some valuable hints, but requires that I have an instance of Mono.TextEditor at hand. I already use MonoDevelop.Ide.IdeApp.Workbench.ActiveDocument, but this is an instance of MonoDevelop.Ide.Gui.Document, and I don't see how to get a Mono.TextEditor.TextDocument from it.

Does anyone see a way to achieve this without defining a custom editor?

Upvotes: 1

Views: 332

Answers (1)

Matt Ward
Matt Ward

Reputation: 47967

You do not say how you are getting the MonoDevelop.Ide.Gui.Document so I am going to guess that you are doing something similar to:

MonoDevelop.Ide.Gui.Document doc = MonoDevelop.Ide.IdeApp.Workbench.ActiveDocument;

You can get access to the TextEditor and the TextEditorDocument using similar code:

var view = MonoDevelop.Ide.IdeApp.Workbench.ActiveDocument.Window.ActiveViewContent as MonoDevelop.SourceEditor.SourceEditorView;
var textEditor = view.TextEditor;
var textEditorDoc = view.Document;

You would need to reference the MonoDevelop.SourceEditor addin to be able to use the SourceEditorView.

Upvotes: 3

Related Questions