public GetPositionFromPoint ( Point point ) : TextViewPosition? | ||
point | Point | The position, relative to top left /// corner of TextEditor control |
return | TextViewPosition? |
public IEnumerable<int> SelectIndexes(TextEditor textEditor) { int start = 0; int end = 0; if (textEditor.SelectionLength != 0) { start = textEditor.SelectionStart; end = textEditor.SelectionStart + textEditor.SelectionLength; } else { var position = textEditor.GetPositionFromPoint(MouseUtils.GetMousePosition(textEditor)); if (position != null) { start = textEditor.Document.GetOffset(position.Value.Line, position.Value.Column); end = start; } } var list = new List<int>(); for (int i = 0; i < _ranges.Count; i++) { var range = _ranges[i]; if ((range.Start <= start && range.End <= start) || (range.Start >= end && range.End >= end)) continue; list.Add(i); } return list; }
public void EditorMouseHover(ICSharpCode.AvalonEdit.TextEditor editor, DepthScanner scanner, MouseEventArgs e) { TextViewPosition?pos = editor.GetPositionFromPoint(e.GetPosition(editor)); if (pos != null) { try { int line = pos.Value.Line; int offset = editor.Document.GetOffset(pos.Value.Location); Globals globs = GetGlobals(); if (globs != null) { bool isFunc = false; string[] words = IntellisenseHelper.ExtractPath(editor.Document, offset, pos.Value.Location.Line, out isFunc); if (words != null && words.Length > 0) { BaseTypeInfo info = null; FunctionInfo func = null; NameResolver reso = new NameResolver(globs, scanner); if (words.Length > 1) { for (int i = 0; i < words.Length; ++i) { if (i == words.Length - 1 && info != null && isFunc) { if (info is TypeInfo) { func = ((TypeInfo)info).Functions.FirstOrDefault(f => f.Name.Equals(words[i])); } } else { if (info == null) { info = reso.GetClassType(editor.Document, editor.TextArea.Caret.Line, words[i]); } else if (info != null && info is TypeInfo) { if (((TypeInfo)info).Properties.ContainsKey(words[i])) { info = ((TypeInfo)info).Properties[words[i]]; } } } } } else if (isFunc && words.Length == 1) { func = globs.GetFunction(words[0]); } else if (!isFunc && words.Length == 1) { info = reso.GetClassType(editor.Document, line, words[0]); if (info == null) { TypeInfo ty = globs.GetTypeInfo(words[0]); if (ty != null) { info = ty; } } } string msg = ""; // Ask documentation for the information if (info != null && func != null && info is TypeInfo) { //member function msg = func.ReturnType.Name + " " + func.Name; string m = IDEProject.inst().DocDatabase.GetDocumentationFor(((TypeInfo)info).Name + "::" + func.Name + func.Inner); if (m != null) { msg += "\r\n" + m; } } else if (func != null) { //global function msg = func.ReturnType.Name + " " + func.Name; string m = IDEProject.inst().DocDatabase.GetDocumentationFor(func.Name + func.Inner); if (m != null) { msg += "\r\n" + m; } } else if (info != null && info is TypeInfo) { //global or member type msg = ((TypeInfo)info).Name; string m = IDEProject.inst().DocDatabase.GetDocumentationFor(((TypeInfo)info).Name); if (m != null) { msg += "\r\n" + m; } } if (msg.Length > 0) { InsightWindow window = new InsightWindow(editor.TextArea); window.Content = msg; window.Show(); } } } } catch (Exception ex) { //deliberately swallow any exceptions here } } }