void SetCursor(string filename, QUT.Gppg.LexLocation location) { //tbEditor.Focus(); //doesn't work after replacing listbox with treeview; //Костыль: посылаю сигнал о нажатии кнопки Tab и за счет свойств TabIndex и TabStop переходим на TextBox SendKeys.Send("{TAB}"); if (location.StartLine < 1) return; int sl = location.StartLine < 0 ? 0 : location.StartLine; int sc = location.StartColumn < 0 ? 0 : location.StartColumn; int el = location.EndLine < 0 ? 0 : location.EndLine; int ec = location.EndColumn < 0 ? 0 : location.EndColumn; int start; if (el <= tbEditor.Lines.Length) start = tbEditor.GetFirstCharIndexFromLine(sl - 1) + sc; else start = tbEditor.Text.Length; int end; if (el <= tbEditor.Lines.Length) end = tbEditor.GetFirstCharIndexFromLine(el - 1) + ec; else end = tbEditor.Text.Length; if (start > tbEditor.Text.Length) tbEditor.SelectionStart = tbEditor.Text.Length; else tbEditor.SelectionStart = start; if (end - start < 0) tbEditor.SelectionLength = 0; else tbEditor.SelectionLength = end - start; tbEditor.ScrollToCaret(); }
/// <summary> /// Находит строку из заданного диапазона, наиболее похожую на заданную строку /// </summary> /// <returns>Пара (Номер строки, степень похожести)</returns> public Pair<int, int> Similarity(QUT.Gppg.LexLocation Loc, string pattern) { //образец пуст - считаем совпадающим if (string.IsNullOrWhiteSpace(pattern)) return new Pair<int,int>(Loc.StartLine, TreeSearchOptions.Equility); //разбиваем образец на лексемы List<string> PatternTokens = TokenizeString(pattern); //если узел занимает одну строку - вычисляем похожесть для нее, возвращаем результат if (Loc.StartLine == Loc.EndLine) { string Text = _lines[Loc.StartLine - 1];//.Substring(Loc.StartColumn, Loc.EndColumn - Loc.StartColumn); List<string> TextTokens = TokenizeString(Text); int Sim = TreeSearchComparer.TokenListsSimilarity(TextTokens, PatternTokens); return new Pair<int, int>(Loc.StartLine, Sim); } //формируем списки лексем для каждой строки, занимаемой узлом List<List<string>> Lines = new List<List<string>>(); string FirstLine = _lines[Loc.StartLine-1].Substring(Loc.StartColumn); string LastLine = _lines[Loc.EndLine-1].Substring(0, Loc.EndColumn); Lines.Add(TokenizeString(FirstLine)); Lines.AddRange(TokenizeStrings(_lines, Loc.StartLine, Loc.EndLine - 2)); Lines.Add(TokenizeString(LastLine)); //Находим самую похожую строку int MaxSim = TreeSearchComparer.TokenListsSimilarity(Lines[0], PatternTokens); int MaxSimIndex = 0; for (int i = 1; i < Lines.Count; ++i) { int Sim = TreeSearchComparer.TokenListsSimilarity(Lines[i], PatternTokens); if (Sim > MaxSim) { MaxSim = Sim; MaxSimIndex = i; } } return new Pair<int, int>(MaxSimIndex + Loc.StartLine, MaxSim); }
public Directive(string text, QUT.Gppg.LexLocation loc) { this.text = text; this.loc = loc; dirs.Add(this); }