public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Configure editor from user preferences
ConfigureEditor ();
// Highligh the syntax of the text after an edit has been made
TextEditor.TextStorage.DidProcessEditing += (sender, e) => {
DocumentEdited = true;
Formatter.HighlightSyntaxRegion(TextEditor.TextStorage.Value, TextEditor.TextStorage.EditedRange);
};
// If the text selection or cursor location changes, attempt to display the Tool Tip
// for any keyword defined in the current language being syntax highlighted
TextEditor.SourceSelectionChanged += (sender, e) => {
var range = Formatter.FindWordBoundries(TextEditor.TextStorage.Value, TextEditor.SelectedRange);
var word = TextEditor.TextStorage.Value.Substring((int)range.Location, (int)range.Length);
// Update UI
if (WindowController !=null) {
WindowController.Indent.Disabled = (TextEditor.SelectedRange.Length == 0);
App.IndentItem.Enabled = (!WindowController.Indent.Disabled);
WindowController.Outdent.Disabled = WindowController.Indent.Disabled;
App.OutdentItem.Enabled = (!WindowController.Outdent.Disabled);
App.ReformatItem.Enabled = (Text.Length > 0);
}
// Live preview content changes
if (App.Preferences.LivePreviewChanges) {
PreviewContents();
}
// Found a keyword?
KeywordDescriptor info;
if (Formatter.Language.Keywords.TryGetValue(word, out info)) {
// Display the tool tip
StatusText.StringValue = string.Format("{0}: {1}", info.Type, word);
StatusText.TextColor = info.Color;
StatusDesc.StringValue = info.Tooltip;
Keyword = word;
KeywordInfo = info;
} else {
// Display the currently selected text
StatusText.StringValue = "Selection:";
StatusText.TextColor = NSColor.Black;
StatusDesc.StringValue = word;
Keyword = "";
KeywordInfo = null;
}
};
}