private void DoQueueJob(TextEdit edit) { var editor = edit.Boss.Get<ITextEditor>(); string key = editor.Key; Contract.Assert(!string.IsNullOrEmpty(key), "key is null or empty"); if (edit.Language != null && "CsLanguage" == edit.Language.Name) { var text = edit.Boss.Get<IText>(); lock (m_mutex) { Log.WriteLine(TraceLevel.Verbose, "Parser", "queuing {0} for edit {1}", System.IO.Path.GetFileName(key), text.EditCount); m_jobs[key] = new Job(text.EditCount, text.Text); Monitor.Pulse(m_mutex); } } }
// editedRange is the range of the new text. For example if a character // is typed it will be the range of the new character, if text is pasted it // will be the range of the inserted text. // // changeInLength is the difference in length between the old selection // and the new text. // // TODO: cStringUsingEncoding might allow us to skip a copy when getting // the text (might also help keyDown) public void textStorageDidProcessEditing(NSObject notification) { NSTextStorage storage = m_textView.Value.textStorage(); if ((storage.editedMask() & Enums.NSTextStorageEditedCharacters) != 0) { m_editCount = unchecked(m_editCount + 1); m_oldFindIndex = -1; int oldNumLines = m_metrics.LineCount; string text = Text; // TODO: this is slow for very large files NSRange range = storage.editedRange(); int lengthChange = storage.changeInLength(); DoUpdateLineLabel(text); DoUpdateRanges(range, lengthChange); m_applier.EditedRange(range); if (m_userEdit) { document().updateChangeCount(Enums.NSChangeDone); // If the user typed a closing brace and it is balanced, int left = m_metrics.BalanceLeft(text, range.location + range.length - 1); if (left != -2) { // then highlight the open brace. if (left >= 0) { NSRange openRange = new NSRange(left, 1); NSApplication.sharedApplication().BeginInvoke(() => DoShowOpenBrace(openRange, range)); // can't do a show if we're in the middle of an edit... } else if (range.location >= 0 && range.location < text.Length) { // Otherwise pop up a translucent warning window for a second. ShowWarning("Unmatched '" + text[range.location] + "'"); } } // Auto-indent new lines. if (range.length == 1 && text[range.location] == '\n' && lengthChange > 0) { int i = range.location - 1; while (i > 0 && text[i] != '\n') --i; ++i; int count = 0; while (i + count < range.location && char.IsWhiteSpace(text[i + count])) ++count; if (count > 0) { string padding = text.Substring(i, count); NSApplication.sharedApplication().BeginInvoke(() => m_textView.Value.insertText(NSString.Create(padding))); } } } var edit = new TextEdit{ Boss = m_boss, Language = m_language, UserEdit = m_userEdit, EditedRange = range, ChangeInLength = lengthChange, ChangeInLines = m_metrics.LineCount - oldNumLines, StartLine = m_metrics.GetLine(range.location)}; Broadcaster.Invoke("text changed", edit); } }
public void OnBroadcast(string name, object value) { switch (name) { case "text default color changed": DoUpdateDefaultColor(name, value); break; case "languages changed": if (Path != null || m_boss.Has<IDocumentExtension>()) Language = DoFindLanguage(); var edit = new TextEdit{ Boss = m_boss, Language = m_language, UserEdit = true, EditedRange = NSRange.Empty, ChangeInLength = 0, ChangeInLines = 0, StartLine = 1}; DoSetTabSettings(); Broadcaster.Invoke("text changed", edit); break; case "directory prefs changed": DoSetTabSettings(); break; default: Contract.Assert(false, "bad name: " + name); break; } }
public void showTabs(NSObject sender) { Boss boss = ObjectModel.Create("Stylers"); var white = boss.Get<IWhitespace>(); white.ShowTabs = !white.ShowTabs; m_editCount = unchecked(m_editCount + 1); m_applier.EditedRange(NSRange.Empty); var edit = new TextEdit{ Boss = m_boss, Language = m_language, UserEdit = true, EditedRange = NSRange.Empty, ChangeInLength = 0, ChangeInLines = 0, StartLine = 1}; Broadcaster.Invoke("text changed", edit); }
private void DoUpdateLines(TextEdit edit) { var editor = edit.Boss.Get<ITextEditor>(); string path = editor.Path; // Need the user edit check so that re-opening the file doesn't // hose our line numbers. if (path != null && edit.UserEdit) { foreach (BuildError error in m_errors) { string errorPath = System.IO.Path.Combine(m_dirPath, error.File); if (Paths.AreEqual(errorPath, path)) { if (edit.ChangeInLines <= 0) if (edit.StartLine <= error.Line && error.Line <= edit.StartLine - edit.ChangeInLines) error.Column = -1; if (edit.StartLine < error.Line) error.Line += edit.ChangeInLines; } } } }