// > By WendyH ------------------------------------------ internal void DoAutocomplete(bool forced) { if (tb.IsDisposed) { return; } if (!Menu.Enabled || !this.Enabled) { Menu.Close(); return; } if (tb.CheckInTheStringOrComment()) { return; } if (!forced && Menu.AfterComplete) { Menu.AfterComplete = false; return; } visibleItems.Clear(); FocussedItemIndex = 0; VerticalScroll.Value = 0; //some magic for update scrolls AutoScrollMinSize -= new Size(1, 0); AutoScrollMinSize += new Size(1, 0); //get fragment around caret //Range fragment = tb.Selection.GetFragment(Menu.SearchPattern); Range fragment = tb.Selection.GetFragmentLookedLeft(); string text = fragment.Text; // < By WendyH ------------------------ bool doNotGetFromSourceItems = false; bool showTypes = false; if (text.Length == 0) { if (tb.ToolTip4Function.Visible && (HMS.CurrentParamType.Length > 0)) { if (HMS.CurrentParamType == "boolean") { visibleItems.AddRange(HMS.ItemsBoolean); doNotGetFromSourceItems = true; Menu.Fragment = fragment; } else if (HMS.HmsTypes.ContainsName(HMS.CurrentParamType)) { HMSClassInfo info = HMS.HmsTypes[HMS.CurrentParamType]; visibleItems.AddRange(info.MemberItems); doNotGetFromSourceItems = true; Menu.Fragment = fragment; } } else { text = tb.Selection.GetVariableForEqual(Menu.SearchPattern); if (text.Length > 0) { doNotGetFromSourceItems = true; forced = true; showTypes = true; } } } // > By WendyH ------------------------ //calc screen point for popup menu Point point = tb.PlaceToPoint(fragment.End); point.Offset(2, tb.CharHeight); // By WendyH if (tb.ToolTip4Function.Visible) { Rectangle b = tb.ToolTip4Function.Bounds; point.Y += b.Height + 4; } // if (forced || (text.Length >= Menu.MinFragmentLength && tb.Selection.IsEmpty && /*pops up only if selected range is empty*/ (tb.Selection.Start > fragment.Start || text.Length == 0 /*pops up only if caret is after first letter*/))) { Menu.Fragment = fragment; bool foundSelected = false; //build popup menu // < By WendyH ------------------------------------- string lastword = GetLastSelectedWord(text); if (showTypes) { SetVisibleTypes(text); } else { int indexDot = text.IndexOf("."); if (indexDot > 0) { SetVisibleMethods(text); doNotGetFromSourceItems = true; Menu.Fragment.ShiftStart(text.LastIndexOf('.') + 1); } else { foundSelected = GetActiveLastwordInVisibleItems(text, lastword); } } // > By WendyH ------------------------------------- if (!doNotGetFromSourceItems) { AutocompleteItems notExacctly = new AutocompleteItems(); foreach (var item in sourceItems) { item.Parent = Menu; CompareResult res = item.Compare(text); if (res != CompareResult.Hidden) { visibleItems.Add(item); } else if (item.NotExactlyCompare(text) == CompareResult.Visible) { notExacctly.Add(item); } if (lastword.Length > 0) { if (item.MenuText == lastword) { foundSelected = true; FocussedItemIndex = visibleItems.Count - 1; } } else if (res == CompareResult.VisibleAndSelected && !foundSelected) { foundSelected = true; FocussedItemIndex = visibleItems.Count - 1; } if (visibleItems.Count > 150) { break; } } visibleItems.AddRange(notExacctly); } if (foundSelected) { AdjustScroll(); //DoSelectedVisible(); } } if ((visibleItems.Count == 1) && (visibleItems[0].MenuText != null) && (visibleItems[0].MenuText.ToLower() == text.ToLower())) { return; } //show popup menu if (Count > 0) { if (!Menu.Visible) { CancelEventArgs args = new CancelEventArgs(); //// By WendyH //Point ps = tb.PointToScreen(point); //if (ps.Y + Menu.Height + (tb.CharHeight * 3) > SystemInformation.VirtualScreen.Bottom) { // int size = Math.Min(MaximumSize.Height, ItemHeight * visibleItems.Count) + 5; // point.Y -= (size + tb.CharHeight); // Rectangle b = tb.ToolTip4Function.Bounds; // if (tb.ToolTip4Function.Active) point.Y -= (b.Height + 4); //} Menu.OnOpening(args); if (!args.Cancel) { Menu.Show(tb, point); } } else { Invalidate(); DoSelectedVisible(); } } else { Menu.Close(); } }