internal bool AddInVisibleItems(string text, string lastword, AutocompleteItems ITEMS, bool foundSelected) { // set active lastword in visible items foreach (var item in ITEMS) { item.Parent = Menu; CompareResult res = item.Compare(text); if (res != CompareResult.Hidden) { visibleItems.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; } } return(foundSelected); }
public void AddAutocompleteItems(AutocompleteItems items) { foreach (var item in items) { var node = Nodes.Add(item.MenuText, item.ToString(), item.ImageIndex, item.ImageIndex); node.Tag = item; } }
public void SetAutocompleteItems(ICollection <string> items) { AutocompleteItems list = new AutocompleteItems(); foreach (var item in items) { list.Add(new HMSItem(item)); } SetAutocompleteItems(list); }
internal AutocompleteListView(FastColoredTextBox tb) { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint, true); if (HMS.PFC.Families.Length > 0) // By WendyH { base.Font = new Font(HMS.PFC.Families[0], 10f, FontStyle.Regular, GraphicsUnit.Point); } else { base.Font = new Font("Segoe UI", 9, FontStyle.Regular, GraphicsUnit.Point); } visibleItems = new AutocompleteItems(); VerticalScroll.SmallChange = ItemHeight; MaximumSize = new Size(Size.Width, 180); toolTip.ShowAlways = false; AppearInterval = 250; timer.Tick += new EventHandler(timer_Tick); SelectedColor = Color.Orange; HoveredColor = Color.Red; ToolTipDuration = 10000; this.tb = tb; tb.KeyDown += new KeyEventHandler(tb_KeyDown); tb.SelectionChanged += new EventHandler(tb_SelectionChanged); tb.KeyPressed += new KeyPressEventHandler(tb_KeyPressed); Form form = tb.FindForm(); if (form != null) { form.LocationChanged += (o, e) => Menu.Close(); form.ResizeBegin += (o, e) => Menu.Close(); form.FormClosing += (o, e) => Menu.Close(); form.LostFocus += (o, e) => Menu.Close(); } tb.LostFocus += (o, e) => { if (!Menu.Focused) { Menu.Close(); } }; tb.Scroll += (o, e) => Menu.Close(); this.VisibleChanged += (o, e) => { if (this.Visible) { DoSelectedVisible(); } }; }
private void CheckItem(AutocompleteItems exactlyItems, AutocompleteItems notExacItems, HMSItem item, string word) { if ((Filter.Length > 0) && (item.Filter.Length > 0) && (Filter.IndexOf(item.Filter, StringComparison.Ordinal) < 0)) return; if (exactlyItems.ContainsName(item.MenuText) || notExacItems.ContainsName(item.MenuText)) return; string itemtext = item.ToString(); if (itemtext.StartsWith(word, StringComparison.InvariantCultureIgnoreCase)) exactlyItems.Add(item); else { string text = HmsToolTip.GetTextWithHelp(item); if (text.IndexOf(word, StringComparison.InvariantCultureIgnoreCase) > 0) notExacItems.Add(item); } }
internal AutocompleteListView(FastColoredTextBox tb) { Controls.Add(VerticalScrollBar); SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint, true); // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression if (HMS.PFC.Families.Length > 0) { // By WendyH Font = new Font(HMS.PFC.Families[0], 9.25f, FontStyle.Regular, GraphicsUnit.Point); } else { Font = new Font("Consolas", 9.75f, FontStyle.Regular, GraphicsUnit.Point); } visibleItems = new AutocompleteItems(); VerticalScrollBar.SmallChange = ItemHeight; VerticalScrollBar.LargeChange = Height; MaximumSize = new Size(Size.Width, ItemHeight * 10); ToolTip.ShowAlways = false; AppearInterval = 250; timer.Tick += timer_Tick; SelectedColor = Color.CornflowerBlue; HoveredColor = Color.Red; ToolTipDuration = 300000; this.tb = tb; BorderStyle = BorderStyle.None; tb.KeyDown += tb_KeyDown; tb.SelectionChanged += tb_SelectionChanged; tb.KeyPressed += tb_KeyPressed; Form form = tb.FindForm(); if (form != null) { form.LocationChanged += (o, e) => Menu.Close(); form.ResizeBegin += (o, e) => Menu.Close(); form.FormClosing += (o, e) => Menu.Close(); form.LostFocus += (o, e) => Menu.Close(); } tb.LostFocus += (o, e) => { if (!Menu.Focused) Menu.Close(); }; tb.Scroll += (o, e) => Menu.Close(); VisibleChanged += (o, e) => { if (Visible) DoSelectedVisible(); }; VScroll = false; HScroll = false; VerticalScrollBar.ValueChanged += VerticalScrollBar_Scroll; DoubleBuffered = true; }
public void AddFilteredItems(AutocompleteItems items) { AutocompleteItems list = new AutocompleteItems(); string filter = Menu.Filter; foreach (var item in items) { if ((filter.Length > 0) && (item.Filter.Length > 0) && (filter.IndexOf(item.Filter) < 0)) { continue; } if (list.ContainsName(item.MenuText)) { continue; } list.Add(item); } AddAutocompleteItems(list); }
internal AutocompleteListView(FastColoredTextBox tb) { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint, true); if (HMS.PFC.Families.Length > 0) { // By WendyH base.Font = new Font(HMS.PFC.Families[0], 10f, FontStyle.Regular, GraphicsUnit.Point); } else { base.Font = new Font("Segoe UI", 9, FontStyle.Regular, GraphicsUnit.Point); } visibleItems = new AutocompleteItems(); VerticalScroll.SmallChange = ItemHeight; MaximumSize = new Size(Size.Width, 180); toolTip.ShowAlways = false; AppearInterval = 250; timer.Tick += new EventHandler(timer_Tick); SelectedColor = Color.Orange; HoveredColor = Color.Red; ToolTipDuration = 10000; this.tb = tb; tb.KeyDown += new KeyEventHandler(tb_KeyDown); tb.SelectionChanged += new EventHandler(tb_SelectionChanged); tb.KeyPressed += new KeyPressEventHandler(tb_KeyPressed); Form form = tb.FindForm(); if (form != null) { form.LocationChanged += (o, e) => Menu.Close(); form.ResizeBegin += (o, e) => Menu.Close(); form.FormClosing += (o, e) => Menu.Close(); form.LostFocus += (o, e) => Menu.Close(); } tb.LostFocus += (o, e) => { if (!Menu.Focused) Menu.Close(); }; tb.Scroll += (o, e) => Menu.Close(); this.VisibleChanged += (o, e) => { if (this.Visible) DoSelectedVisible(); }; }
public static IList <string> GetPropertiesAndMethods(object obj, string objName, bool getExtensionMethods = false) { /* * if (obj is IronPython.Runtime.Types.OldInstance) * return GetPythonObjectMethods(obj, objName); */ if (obj != null) { var type = obj.GetType(); if (AutocompleteItems.ContainsKey(type)) { return(AutocompleteItems[type]); } IList <string> all = GetProperties(obj, objName); ((List <string>)all).AddRange(GetMethods(obj, objName, getExtensionMethods)); ((List <string>)all).Sort(); AutocompleteItems[type] = all; return(all); } return(new List <string>()); }
public void SetLocalssVariablesItems(AutocompleteItems items) { VisibleLocalVars = items; }
public void SetAutocompleteItems(AutocompleteItems items) { sourceItems = items; }
private void GetVariables(string txt, int indexContext, AutocompleteItems ITEMS) { MatchCollection mc = null; bool isGlobalContext = (indexContext == 0); // Collect constants if (isGlobalContext) { switch (Editor.Language) { case Language.CPPScript: mc = regexSearchConstantsCPP.Matches(txt); foreach (Match m in mc) { string name = m.Groups[1].Value; string sval = m.Groups[2].Value.Trim(); // Value if (!ITEMS.ContainsName(name)) { HMSItem item = new HMSItem(); item.Global = isGlobalContext; item.Kind = DefKind.Constant; item.ImageIndex = Images.Enum; item.Text = name.Trim(); item.MenuText = RemoveLinebeaks(item.Text); item.ToolTipTitle = item.Text; item.ToolTipText = "Объявленная константа"; item.Type = GetTypeOfConstant(sval); item.PositionStart = m.Groups[1].Index + indexContext; item.PositionEnd = item.PositionStart + name.Length; if (item.Type.Length > 0) item.ToolTipText += "\nТип: " + item.Type; if ((sval.Length == 0) || (sval == ";")) sval = regexExractConstantValue.Match(Editor.Text.Substring(m.Groups[2].Index, 96)).Value; if (sval.Length > 0) item.Help += "\nЗначение: " + sval; ITEMS.Add(item); } } break; case Language.PascalScript: Match c = regexSearchConstantsPascal1.Match(txt); if (c.Success) { mc = regexSearchConstantsPascal2.Matches(c.Groups[1].Value); foreach (Match m in mc) { string name = m.Groups[1].Value; string sval = m.Groups[2].Value.Trim(); // Value if (!ITEMS.ContainsName(name)) { HMSItem item = new HMSItem(); item.Global = isGlobalContext; item.Kind = DefKind.Constant; item.PositionStart = c.Groups[1].Index + m.Index + indexContext; item.PositionEnd = item.PositionStart + name.Length; item.ImageIndex = Images.Enum; item.Text = name.Trim(); item.MenuText = RemoveLinebeaks(item.Text); item.ToolTipTitle = item.Text; item.ToolTipText = "Объявленная константа"; item.Type = GetTypeOfConstant(sval); if (item.Type.Length > 0) item.ToolTipText += "\nТип: " + item.Type; if ((sval.Length == 0) || (sval == ";")) sval = regexExractConstantValue.Match(Editor.Text.Substring(m.Groups[2].Index, 96)).Value; if (sval.Length > 0) item.Help += "\nЗначение: " + sval; ITEMS.Add(item); } } } break; } } mc = null; switch (Editor.Language) { case Language.CPPScript : mc = regexSearchVarsCPP .Matches(txt); break; case Language.JScript : mc = regexSearchVarsJS .Matches(txt); break; case Language.PascalScript: mc = regexSearchVarsPascal.Matches(txt); break; } if (mc != null) { foreach (Match m in mc) { int index = m.Groups["vars"].Index; string names = m.Groups["vars"].Value; string type = m.Groups["type"].Value.Trim(); if (!ValidHmsType(type)) continue; names = HMS.GetTextWithoutBrackets(names); // Убираем скобки и всё что в них names = regexAssignment .Replace(names, evaluatorSpaces); // Убираем присвоение - знак равно и после names = regexConstantKeys.Replace(names, evaluatorSpaces); // Убираем ключевые слова констант (var, const) string[] aname = names.Split(','); foreach (string namePart in aname) { string name = namePart; if ((namePart.Trim().Length != 0) && !regexExcludeWords.IsMatch(namePart)) { if (Regex.IsMatch(name, @"\b(\w+).*?\b(\w+).*?\b(\w+)")) continue; Match m2 = regexTwoWords.Match(name); if (m2.Success) { bool typeFirst = (index > m.Groups["type"].Index); type = m2.Groups[typeFirst ? 1 : 2].Value; name = m2.Groups[typeFirst ? 2 : 1].Value; index += m2.Groups[typeFirst ? 2 : 1].Index; } if (!regexNotValidCharsInVars.IsMatch(name) && !ITEMS.ContainsName(name) && !Functions.ContainsName(name)) { HMSItem item = new HMSItem(); item.Global = isGlobalContext; item.Kind = DefKind.Variable; item.Text = name.Trim(); item.Type = type.Trim(); item.MenuText = RemoveLinebeaks(item.Text); item.ToolTipTitle = item.Text; item.ToolTipText = item.Global ? "Глобальная переменная" : "Локальная переменная"; item.PositionStart = index + (name.Length - name.TrimStart().Length) + indexContext; item.PositionEnd = item.PositionStart + name.Length; item.ImageIndex = Images.Field; if (item.Type.Length > 0) item.ToolTipText += "\nТип: " + item.Type; ITEMS.Add(item); } if (m2.Success) index -= m2.Groups["vars"].Index; } index += namePart.Length + 1; } } } }
public void AddAutocompleteItems(AutocompleteItems items) { lock (obj4LockItems) sourceItems.AddRange(items); }
public void SetVisibleFunctionsItems(AutocompleteItems items) { VisibleFunctions = items; }
public void SetVisibleFunctionsItems(AutocompleteItems items) { lock (obj4LockItems) VisibleFunctions = items; }
internal bool AddInVisibleItems(string text, string lastword, AutocompleteItems ITEMS, bool foundSelected) { // set active lastword in visible items foreach (var item in ITEMS) { item.Parent = Menu; CompareResult res = item.Compare(text); if (res != CompareResult.Hidden) visibleItems.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; } } return foundSelected; }
private void FillListBox(string word = "") { if (word == null) word = ""; AutocompleteItems exactlyItems = new AutocompleteItems(); AutocompleteItems notExacItems = new AutocompleteItems(); if (word == "") { exactlyItems.AddRange(HMS.ItemsFunction); exactlyItems.AddRange(HMS.ItemsVariable); exactlyItems.AddRange(HMS.ItemsClass); exactlyItems.AddRange(HMS.ItemsConstant); } else if (word.StartsWith(prevWord)) { foreach (var item in visibleItems) CheckItem(exactlyItems, notExacItems, item, word); } else { foreach (var item in HMS.ItemsFunction) CheckItem(exactlyItems, notExacItems, item, word); foreach (var item in HMS.ItemsVariable) CheckItem(exactlyItems, notExacItems, item, word); foreach (var item in HMS.ItemsClass ) CheckItem(exactlyItems, notExacItems, item, word); foreach (var item in HMS.ItemsConstant) CheckItem(exactlyItems, notExacItems, item, word); } exactlyItems.AddRange(notExacItems); visibleItems = exactlyItems.ToArray(); prevWord = word; }
public void CreateAutocomplete() { if (PopupMenu == null || PopupMenu.IsDisposed) return; lock (PopupMenuLockObject) { string hmsTypes = HMS.HmsTypesStringWithHelp; string keywords = "", snippets = ""; string hlp = ""; CurrentValidTypes = HMS.HmsTypesString; switch (ScriptLanguage) { case "C++Script": HMS.InitItemsBoolean(true); CurrentValidTypes += "int|long|void|bool|float|"; hmsTypes = hmsTypes.Replace("Integer|", "int|long|").Replace("Extended|", "extended|float|").Replace("Boolean|", "bool|").Replace("Boolean|", "bool|").Replace("String", "string") + "|{Тип функции: процедура (отсутствие возвращаемого значения)}void|"; keywords = "#include|#define|new|break|continue|exit|delete|return|if|else|switch|default|case|do|while|for|try|finally|except|in|is|nil|null|true|false|"; snippets = "for (i=0; i < ^; i++) {\n}|while (^)"; break; case "PascalScript": HMS.InitItemsBoolean(false); keywords = "Program|Uses|Const|Var|Not|In|Is|OR|XOR|DIV|MOD|AND|SHL|SHR|Break|Continue|Exit|Begin|End|If|Then|Else|Case|Of|Repeat|Until|While|Do|For|To|DownTo|Try|Finally|Except|With|Function|Procedure|Nil|Null|True|False"; snippets = "If ^ Then |If (^) Then Begin\nEnd else Begin\nEnd;"; break; case "BasicScript": HMS.InitItemsBoolean(false); keywords = "EOL|IMPORTS|DIM|AS|NOT|IN|IS|OR|XOR|MOD|AND|ADDRESSOF|BREAK|CONTINUE|EXIT|DELETE|SET|RETURN|IF|THEN|END|ELSEIF|ELSE|SELECT|CASE|DO|LOOP|UNTIL|WHILE|WEND|FOR|TO|STEP|NEXT|TRY|FINALLY|CATCH|WITH|SUB|FUNCTION|BYREF|BYVAL|NIL|NULL|TRUE|FALSE"; break; case "JScript": HMS.InitItemsBoolean(true); hmsTypes = "var"; keywords = "import|new|in|is|break|continue|exit|delete|return|if|else|switch|default|case|do|while|for|try|finally|except|function|with|Nil|Null|True|False"; break; } CurrentValidTypesReg = Regex.Replace(hmsTypes, "{.*?}", ""); HMS.Keywords = keywords; HMS.KeywordsString = keywords.ToLower(); snippets += "|ShowMessage(\"^\");|HmsLogMessage(1, \"^\");"; var items = new AutocompleteItems(); foreach (var s in keywords.Split('|')) if (s.Length > 0) items.Add(new HMSItem(s, ImagesIndex.Keyword, s, s, "Ключевое слово")); foreach (var s in snippets.Split('|')) if (s.Length > 0) items.Add(new SnippetHMSItem(s) { ImageIndex = ImagesIndex.Snippet }); foreach (var name in hmsTypes.Split('|')) { Match m = Regex.Match(name, "{(.*?)}"); if (m.Success) hlp = m.Groups[1].Value; var key = Regex.Replace(name, "{.*?}", ""); items.Add(new HMSItem(key, ImagesIndex.Keyword, key, key, hlp)); } PopupMenu.Items.SetAutocompleteItems(items); PopupMenu.Filter = HmsScriptMode.ToString(); PopupMenu.Items.AddAutocompleteItems(HMS.ItemsFunction); PopupMenu.Items.AddFilteredItems (HMS.ItemsVariable); PopupMenu.Items.AddAutocompleteItems(HMS.ItemsConstant); PopupMenu.Items.AddAutocompleteItems(HMS.ItemsClass ); PopupMenu.Items.AddAutocompleteItems(ScriptAutocompleteItems); } }
private void SearchAutocompleteItemsInScriptDescrition(Regex reBlock, ref string xml, int imageIndex, string toolTipText, DefKind kind, AutocompleteItems Items) { string xmlBlock = reBlock.Match(xml).Value; MatchCollection mc = regexCutItem.Matches(xmlBlock); foreach (Match matchItem in mc) { var text = kind == DefKind.Function ? regexCutTextF.Match(matchItem.Value).Groups[1].Value : regexCutText.Match(matchItem.Value).Groups[1].Value; var descr = regexCutDesc.Match(matchItem.Value).Groups[1].Value; if (text.Length==0) continue; var item = HMS.GetHmsItemFromLine(text); item.ImageIndex = imageIndex; item.ToolTipText = toolTipText; item.Kind = kind; item.Help = descr; if (kind == DefKind.Function) item.Kind = (item.Type.Length > 0) ? DefKind.Function : DefKind.Procedure; if (regexExcludeConst.IsMatch(item.MenuText)) continue; var foundItem = Items.GetItemOrNull(item.MenuText); if (foundItem!=null) { if (foundItem.Help.Length == 0) foundItem.Help = descr; } else { ScriptAutocompleteItems.Add(item); //Console.WriteLine(kind.ToString() + " MenuText: " + item.MenuText); } } }
// < By WendyH ----------------------------------- protected override void Dispose(bool disposing) { if (disposing) { ToolTip?.Dispose(); timer ?.Dispose(); VerticalScrollBar?.Dispose(); } FocussedItemIndexChanged = null; visibleItems = null; sourceItems = null; VisibleVariables = null; VisibleLocalVars = null; VisibleFunctions = null; tb = null; ToolTip = null; timer = null; VerticalScrollBar = null; base.Dispose(disposing); ResizeRedraw = true; }
public void SetVisibleVariablesItems(AutocompleteItems items) { lock (obj4LockItems) VisibleVariables = items; }
// > By WendyH ------------------------------------------ internal void DoAutocomplete(bool forced) { if (tb.IsDisposed) return; if (!Menu.Enabled || !Enabled ) { Menu.Close(); return; } if (!forced && Menu.AfterComplete) { Menu.AfterComplete = false; return; } visibleItems.Clear(); FocussedItemIndex = 0; VerticalScrollBar.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; if (!forced && regexBeginWithDigit.IsMatch(text)) return; Range fragmentBefore = fragment.Clone(); int iLine = fragmentBefore.Start.iLine; int iChar = fragmentBefore.Start.iChar; fragmentBefore.Start = new Place(0 , iLine); fragmentBefore.End = new Place(iChar, iLine); string wordBefore = Regex.Match(fragmentBefore.Text, @"((\w+)[^\(\S,]+)[^\(;:]*?$", RegexOptions.RightToLeft).Groups[2].Value; if (tb.Language == Language.PascalScript && regexIsPascalFunctionName.IsMatch(wordBefore)) { Menu.TempNotShow = true; return; } else if (tb.Language == Language.CPPScript && isType(wordBefore)) { Menu.TempNotShow = true; return; } // < 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 if (wordBefore.ToLower() == "new") { string wordClass = Regex.Match(fragmentBefore.Text, @"(\w+)\s+(\w+)\s*?=\s*?new", RegexOptions.RightToLeft | RegexOptions.IgnoreCase).Groups[1].Value; if (wordClass.Length > 0) { HMSItem item = HMS.ItemsClass.GetItemOrNull(wordClass); if (item != null) { visibleItems.Add(item); doNotGetFromSourceItems = true; forced = true; showTypes = true; } } } else { if (tb.Selection.GetVariableForEqual(Menu.SearchPattern, out text)) { doNotGetFromSourceItems = true; forced = true; showTypes = true; } else { return; } } } // > 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(".", StringComparison.Ordinal); 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(); bool notExacctlyfoundSelected = false; int notExacctlyFocussedItemIndex = 0; foreach (var item in sourceItems) { item.Parent = Menu; CompareResult resultCompare = item.Compare(text); if (resultCompare == CompareResult.VisibleAndSelected) { visibleItems.Add(item); if (!foundSelected && (lastword.Length > 0) && (item.MenuText == lastword)) { foundSelected = true; FocussedItemIndex = visibleItems.Count - 1; } } else if (item.NotExactlyCompare(text) == CompareResult.Visible) { notExacctly.Add(item); if (!notExacctlyfoundSelected && !foundSelected && visibleItems.Count == 0) { if ((lastword.Length > 0) && (item.MenuText == lastword)) { notExacctlyfoundSelected = true; notExacctlyFocussedItemIndex = notExacctly.Count - 1; } } } else continue; if (visibleItems.Count + notExacctly.Count > 150) break; } if (!foundSelected && notExacctlyfoundSelected) FocussedItemIndex = visibleItems.Count + notExacctlyFocussedItemIndex; visibleItems.AddRange(notExacctly); } if (visibleItems.Count > 0 && FocussedItemIndex < 0) FocussedItemIndex = 0; 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) { // < By WendyH ------------------------------- // Recalc position Menu.InitDefaultSize(); int h = MaximumSize.Height; int ih = ItemHeight; if (visibleItems.Count < HMSEditor.MaxPopupItems) { h = visibleItems.Count * ih + 4; } Point ps = tb.PointToScreen(point); if (ps.Y + h > Screen.PrimaryScreen.WorkingArea.Size.Height) { point.Y -= (h + tb.CharHeight + 4); } Size = new Size(Size.Width, h); Menu.CalcSize(); if (Menu.Visible) { Menu.Top = tb.PointToScreen(point).Y; } // > By WendyH ------------------------------- if (!Menu.Visible) { CancelEventArgs args = new CancelEventArgs(); Menu.OnOpening(args); if(!args.Cancel) Menu.Show(tb, point); } else { Invalidate(); DoSelectedVisible(); } } else Menu.Close(); }
public void SetVisibleVariablesItems(AutocompleteItems items) { VisibleVariables = items; }
public void SetAutocompleteItems(AutocompleteItems items) { lock (obj4LockItems) sourceItems = items; }
// > 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(); }
private static void BuildAutocompleteItemsFromResourse(string file, int imageIndex, string toolTipText, AutocompleteItems itemsList, DefKind kind) { string section = ""; string filter = ""; Assembly assembly = Assembly.GetExecutingAssembly(); Stream stream = assembly.GetManifestResourceStream(file); try { if (stream != null) { using (var reader = new StreamReader(stream)) { stream = null; string line; while ((line = reader.ReadLine()) != null) { var m = Regex.Match(line, @"^\*\s*?\[(.*)\]"); if (m.Success) { section = m.Groups[1].Value.Trim(); continue; } m = Regex.Match(line, @"^\*(sm\w+)" ); if (m.Success) { filter = m.Groups[1].Value.Trim(); continue; } if (filter == "smAll") filter = ""; if (line.StartsWith("*") || (line.Trim().Length == 0)) continue; // Skip comments and blank lines int indent = line.Length - line.TrimStart().Length; HMSItem item; if (indent == 0) { item = GetHmsItemFromLine(line); item.ImageIndex = imageIndex; item.ToolTipText = toolTipText + ((section.Length > 0) ? (" ("+ section + ")") : ""); item.Kind = kind; item.Filter = filter; if (kind == DefKind.Function) item.Kind = (item.Type.Length > 0) ? DefKind.Function : DefKind.Procedure; itemsList.Add(item); } else if ((indent == 2) || (line[0] == '\t')) { // it's help for parameters of last method if (itemsList.Count > 0) { item = itemsList[itemsList.Count - 1]; item.Params.Add(StylishHelp(line)); } } } } } } catch (Exception e) { LogError(e.ToString()); } finally { stream?.Dispose(); } }
public void SetLocalssVariablesItems(AutocompleteItems items) { lock (obj4LockItems) VisibleLocalVars = items; }
public void AddAutocompleteItems(AutocompleteItems items) { Items.AddRange(items); RecalcWidth(); }
public void AddAutocompleteItems(AutocompleteItems items) { sourceItems.AddRange(items); }
public void SetAutocompleteItems(AutocompleteItems items) { Items = items; RecalcWidth(); }
protected override void OnDoubleClick(EventArgs e) { var indx = FocussedItemIndex; var item = SelectedItem; if (item.IsClass) { BeginUpdate(); if (!item.Expanded) { item.Expanded = true; AutocompleteItems insertedItems = new AutocompleteItems(); insertedItems.AddRange(item.ClassInfo.StaticItems); insertedItems.AddRange(item.ClassInfo.MemberItems); Items.InsertRange(indx + 1, insertedItems); } else { item.Expanded = false; if (indx < Count - 1) { int count = 0; for (int i = indx + 1; i < Count; i++) { if (Items[i].Level < 1) break; count++; } Items.RemoveRange(indx + 1, count); } } EndUpdate(); } base.OnDoubleClick(e); }
public void AddFilteredItems(AutocompleteItems items) { AutocompleteItems list = new AutocompleteItems(); string filter = Menu.Filter; foreach (var item in items) { if ((filter.Length > 0) && (item.Filter.Length>0) && (filter.IndexOf(item.Filter)<0)) continue; if (list.ContainsName(item.MenuText)) continue; list.Add(item); } AddAutocompleteItems(list); }
// > 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(); } }
public void SetAutocompleteItems(ICollection<string> items) { AutocompleteItems list = new AutocompleteItems(); foreach (var item in items) list.Add(new HMSItem(item)); SetAutocompleteItems(list); }
public static IList <string> GetPropertiesAndMethods(string[] callTrail, bool getExtensionMethods = false) { string root = callTrail[0]; Type type = typeof(void); try { object variable = SPCoderForm.ScriptStateCSharp.GetVariable(root); if (variable != null) { variable = ((Microsoft.CodeAnalysis.Scripting.ScriptVariable)variable).Value; } type = variable.GetType(); for (int i = 1; i < callTrail.Length; i++) { string current = callTrail[i]; if (string.IsNullOrEmpty(current)) { continue; } if (current.Contains("(")) //Method { try { current = current.Substring(0, current.IndexOf('(')); //type = type.GetMethod(current).ReturnType; type = ((MethodInfo)type.GetMember(current)[0]).ReturnType; variable = null; } catch (Exception) { } } else//Property { try { //type = type.GetProperty(current).PropertyType; variable = type.GetProperty(current).GetValue(variable); if (variable == null) { type = ((PropertyInfo)type.GetMember(current)[0]).PropertyType; } else { type = variable.GetType(); } } catch (Exception) { //check for Non static property requires the target } } } } catch (Exception) { // } if (AutocompleteItems.ContainsKey(type)) { return(AutocompleteItems[type]); } IList <string> all = GetProperties(type); ((List <string>)all).AddRange(GetMethods(type, getExtensionMethods)); ((List <string>)all).Sort(); AutocompleteItems[type] = all; return(all); //return GetPropertiesAndMethods(obj, objName); }
private void CreateAutocomplete() { if (PopupMenu == null || PopupMenu.IsDisposed) return; string hmsTypes = HMS.HmsTypesStringWithHelp; string keywords = "", snippets = ""; string hlp = "", key = ""; CurrentValidTypes = HMS.HmsTypesString; switch (ScriptLanguage) { case "C++Script": CurrentValidTypes += "int|long|void|bool|float|"; hmsTypes = hmsTypes.Replace("Integer|", "int|long|").Replace("Extended|", "Extended|float|").Replace("Boolean|", "bool|") + "|{Тип функции: процедура (отсутствие возвращаемого значения)}void|"; keywords = "#include|#define|new|break|continue|exit|delete|return|if|else|switch|default|case|do|while|for|try|finally|except|in|is|"; snippets = "if (^) {\n}|if (^) {\n}\nelse {\n}|for (^;;) {\n}|while (^) {\n}|do {\n^}while ();"; break; case "PascalScript": keywords = "Program|Uses|Const|Var|Not|In|Is|OR|XOR|DIV|MOD|AND|SHL|SHR|Break|Continue|Exit|Begin|End|If|Then|Else|Casr|Of|Repeat|Until|While|Do|For|To|DownTo|Try|Finally|Except|With|Function|Procedure"; snippets = "If ^ Then |If (^) Then Begin\nEnd else Begin\nEnd;"; break; case "BasicScript": keywords = "EOL|IMPORTS|DIM|AS|NOT|IN|IS|OR|XOR|MOD|AND|ADDRESSOF|BREAK|CONTINUE|EXIT|DELETE|SET|RETURN|IF|THEN|END|ELSEIF|ELSE|SELECT|CASE|DO|LOOP|UNTIL|WHILE|WEND|FOR|TO|STEP|NEXT|TRY|FINALLY|CATCH|WITH|SUB|FUNCTION|BYREF|BYVAL"; break; case "JScript": hmsTypes = "var"; keywords = "import|new|in|is|break|continue|exit|delete|return|if|else|switch|default|case|do|while|for|try|finally|except|function|with"; break; } HMS.KeywordsString = keywords.ToLower(); snippets += "|ShowMessage(\"^\");|HmsLogMessage(1, \"^\");"; var items = new AutocompleteItems(); foreach (var s in keywords.Split('|')) if (s.Length > 0) items.Add(new HMSItem(s, Images.Keyword, s, s, "Ключевое слово")); foreach (var s in snippets.Split('|')) if (s.Length > 0) items.Add(new SnippetHMSItem(s) { ImageIndex = Images.Snippet }); foreach (var name in hmsTypes.Split('|')) { Match m = Regex.Match(name, "{(.*?)}"); if (m.Success) hlp = m.Groups[1].Value; key = Regex.Replace(name, "{.*?}", ""); items.Add(new HMSItem(key, Images.Keyword, key, key, hlp)); } PopupMenu.Items.SetAutocompleteItems(items); PopupMenu.Items.AddAutocompleteItems(HMS.ItemsFunction); PopupMenu.Items.AddFilteredItems (HMS.ItemsVariable); PopupMenu.Items.AddAutocompleteItems(HMS.ItemsConstant); PopupMenu.Items.AddAutocompleteItems(HMS.ItemsClass ); // Set templates for selected script language btnInsertTemplate.DropDownItems.Clear(); AddTemplateItemsRecursive(btnInsertTemplate, HMS.Templates[Editor.Language]); btnInsertTemplate.Visible = btnInsertTemplate.DropDownItems.Count > 0; }