private void DoAutocomplete(AutocompleteItem item, Range fragment) { string newText = item.GetTextForReplace(); //replace text of fragment var tb = fragment.tb; // < By WendyH --------------------------- if (tb.ToolTip4Function.Visible) { Menu.AfterComplete = true; } if (fragment.CharBeforeStart == '=') { newText = " " + newText; } int iLine = fragment.Start.iLine; int iChar = fragment.Start.iChar; HMSItem hmsItem = item as HMSItem; if ((hmsItem != null) && ((hmsItem.Kind == DefKind.Property) || (hmsItem.Kind == DefKind.Variable)) && !HMS.TypeIsClass(hmsItem.Type)) { Range fwords = fragment.GetFragmentLookedLeft(); var f = new Range(tb, new Place(0, iLine), new Place(fwords.Start.iChar, iLine)); string line = f.Text.Trim(); if (line.Length == 0) { newText += (tb.Language == Language.PascalScript) ? " := " : " = "; } } // > By WendyH --------------------------- tb.BeginAutoUndo(); tb.TextSource.Manager.ExecuteCommand(new SelectCommand(tb.TextSource)); if (tb.Selection.ColumnSelectionMode) { var start = tb.Selection.Start; var end = tb.Selection.End; start.iChar = fragment.Start.iChar; end.iChar = fragment.End.iChar; tb.Selection.Start = start; tb.Selection.End = end; } else { tb.Selection.Start = fragment.Start; tb.Selection.End = fragment.End; } tb.InsertText(newText); tb.TextSource.Manager.ExecuteCommand(new SelectCommand(tb.TextSource)); tb.EndAutoUndo(); tb.Focus(); }
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); } }
public void ShowFunctionParams(HMSItem item, int nParam, IWin32Window window, Point p) { string title = item.ToolTipTitle; string parameters = title; string activparam = ""; string paramtype = ""; string paramHelp = item.Help; if ((nParam > 0) && (nParam <= item.Params.Count)) { paramHelp = item.Params[nParam - 1]; } Match m = regexFunctionParams.Match(title); if (m.Success) { parameters = m.Groups[1].Value; } string[] prmtrs = regexSplitFuncParam.Split(parameters); if ((nParam > 0) && (nParam <= prmtrs.Length)) { activparam = prmtrs[nParam - 1]; } if (activparam.Length > 0) { int ind = parameters.IndexOf(activparam); paramtype = HMS.GetType(parameters.Substring(ind)); } HMS.CurrentParamType = paramtype.ToLower(); if (activparam.Length > 0) { title = title.Replace(activparam, "<b>" + activparam + "</b>"); } if (paramHelp.Length == 0) { paramHelp = " "; } Help = paramHelp; ToolTipTitle = title; if (!Visible) { Show(" ", window, p); } }
internal void SetVisibleTypes(string text) { string part = ""; HMSItem item = GetHMSItemByText(text, out part); if (item != null) { if (item.Type.ToLower().StartsWith("bool")) { visibleItems.AddRange(HMS.ItemsBoolean); return; } HMSClassInfo info = HMS.HmsTypes[item.Type]; if (!string.IsNullOrEmpty(info.Name)) { visibleItems.AddRange(info.MemberItems); } } }
private void SetToolTip(HMSItem autocompleteItem) { if (IsDisposed) { return; } IWin32Window window = this.Parent ?? this; toolTip.Hide(window); if (string.IsNullOrEmpty(autocompleteItem.ToolTipTitle)) { return; // By WendyH } toolTip.Help = autocompleteItem.Help; toolTip.ToolTipTitle = autocompleteItem.ToolTipTitle; string text = autocompleteItem.ToolTipText; Point location = new Point((window == this ? Width : Right) + 3, 0); int y = FocussedItemIndex * ItemHeight - VerticalScroll.Value; // By WendyH if (y < 0) { y = 0; } if (y > ClientSize.Height - ItemHeight) { y = ClientSize.Height - ItemHeight; } location.Y = y; if (text.Length > 0) { toolTip.Show(text, window, location.X, location.Y, ToolTipDuration); } else { toolTip.Show(" ", window, location.X, location.Y, ToolTipDuration); } }
internal void SetVisibleMethods(string text) { string part = ""; HMSClassInfo info; HMSItem item = GetHMSItemByText(text, out part, true); if (item != null) { if (item.IsClass) { info = HMS.HmsClasses[item.MenuText]; if (!String.IsNullOrEmpty(info.Name)) { foreach (HMSItem childItem in info.StaticItems) { if (childItem.MenuText.ToLower().StartsWith(part)) { childItem.Parent = Menu; visibleItems.Add(childItem); } } } } else { info = HMS.HmsClasses[item.Type]; // variable founded - search type in classes if (!String.IsNullOrEmpty(info.Name)) { foreach (HMSItem childItem in info.MemberItems) { if (childItem.MenuText.ToLower().StartsWith(part)) { childItem.Parent = Menu; visibleItems.Add(childItem); } } } } } }
public new void Hide(IWin32Window window) { HmsItem = null; Visible = false; var win = window as Control; if (win != null && win.InvokeRequired) { win.Invoke((MethodInvoker)delegate { base.Hide(win); }); } else { if (win != null) base.Hide(win); } }
public void Show(HMSItem item, IWin32Window win, Point point, int duration) { // Если указан прямоугольник родителя (меню подсказок), то проверяем не перекрываем ли мы его. // Отодвигаем вверх, если перекрываем по ширине. if (item.Words.Count == 0) PrepareFastDraw(win, item); if (ParentRect.Width > 0) { Control ctrl = win as Control; if (ctrl != null) { Rectangle tipRect = ctrl.RectangleToScreen(new Rectangle(point.X, point.Y, item.ToolTipSize.Width, item.ToolTipSize.Height)); Rectangle scrRect = Screen.FromHandle(win.Handle).Bounds; if ((tipRect.X + tipRect.Width) > scrRect.Width) { point.X = ParentRect.X - tipRect.Width - 2; } } } HmsItem = item; Show(" ", win, point, duration); }
public static void PrepareFastDraw(IWin32Window win, HMSItem item) { Graphics g = Graphics.FromHwnd(win.Handle); PrepareFastDraw(item, g); }
public static void PrepareFastDraw(HMSItem item, Graphics g) { if (item.Words.Count > 0) return; /* // Prepare for rtf text for help panel RichTextBox HelpTextBox = new RichTextBox(); if (item.Rtf == "") { HelpTextBox.Text = ""; if (!string.IsNullOrEmpty(item.ToolTipTitle)) { string help = GetTextWithHelp(item); HmsToolTip.WriteWords(HelpTextBox, help); } item.Rtf = HelpTextBox.Rtf; } */ // prepeare for tooltip float heightCorrection; item.ToolTipTitle = CalcPhrasesBreaks(g, item.ToolTipTitle); string text = GetText(item, out heightCorrection); //if (text.IndexOf("HmsRegExMatch3") > 0) { // heightCorrection = 1; //} Size size = TextRenderer.MeasureText(text, FontText, MaxSize, TextFormatFlags.WordBreak); size.Width += Margin.Width * 2; size.Height += Margin.Height * 2 + (int)heightCorrection; item.ToolTipSize = WriteWords(text, new Rectangle(0, 0, size.Width, size.Height), g, item.Words); }
private void SetToolTip(HMSItem autocompleteItem) { if (IsDisposed) return; if (ToolTip.Visible && ToolTip.HmsItem == autocompleteItem) return; IWin32Window window = Parent; ToolTip.Hide(window); // By WendyH if (string.IsNullOrEmpty(autocompleteItem.ToolTipTitle)) { ToolTip.Hide(window); return; } ToolTip.ParentRect = new Rectangle(Location.X, Location.Y, Width, Height); Point location = new Point((window == this ? Width : Right) + 3, 0); int y = FocussedItemIndex * ItemHeight - VerticalScrollBar.Value; // By WendyH if (y < 0) y = 0; if (y > ClientSize.Height - ItemHeight) y = ClientSize.Height - ItemHeight; location.Y = y; ToolTip.Show(autocompleteItem, window, location, ToolTipDuration); }
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; } } } }
private void SetToolTip(HMSItem autocompleteItem) { if (IsDisposed) return; IWin32Window window = this.Parent ?? this; toolTip.Hide(window); if (string.IsNullOrEmpty(autocompleteItem.ToolTipTitle)) return; // By WendyH toolTip.Help = autocompleteItem.Help; toolTip.ToolTipTitle = autocompleteItem.ToolTipTitle; string text = autocompleteItem.ToolTipText; Point location = new Point((window == this ? Width : Right) + 3, 0); int y = FocussedItemIndex * ItemHeight - VerticalScroll.Value; // By WendyH if (y < 0) y = 0; if (y > ClientSize.Height - ItemHeight) y = ClientSize.Height - ItemHeight; location.Y = y; if (text.Length > 0) toolTip.Show(text, window, location.X, location.Y, ToolTipDuration); else toolTip.Show(" ", window, location.X, location.Y, ToolTipDuration); }
// use this event to customise the tool tip private void OnDraw(object sender, DrawToolTipEventArgs e) { #if debug var sw = System.Diagnostics.Stopwatch.StartNew(); #endif //long ts = System.Diagnostics.Stopwatch.GetTimestamp(); //if (ts - LastTS < 5000) return; Bounds = e.Bounds; // Store show Bounds Graphics g = e.Graphics; LinearGradientBrush b = new LinearGradientBrush(Bounds, Color.WhiteSmoke, Color.FromArgb(255, ColorBackgrnd), 90f); g.FillRectangle(b, Bounds); e.DrawBorder(); g.SmoothingMode = SmoothingMode.HighQuality; if (HmsItem != null && HmsItem.Words.Count > 0) { DrawFast(g, HmsItem.Words); } else if (OwnWords.Count > 0) { DrawFast(g, OwnWords); } else { float i; WriteWords(GetText(e.ToolTipText, out i), Bounds, g); } b.Dispose(); Visible = true; HmsItem = null; //LastTS = System.Diagnostics.Stopwatch.GetTimestamp(); #if debug sw.Stop(); System.Console.WriteLine("OnDraw: " + sw.ElapsedMilliseconds); #endif }
public static HMSItem GetHmsItemFromLine(string line) { HMSItem item = new HMSItem { Text = regexGetFromLineName.Match(line).Groups[1].Value.Trim(), Type = regexGetFromLineType.Match(line).Groups[1].Value.Trim(), ToolTipTitle = regexGetFromLineCmd.Match(line).Groups[1].Value.Trim(), ToolTipText = "" }; // All ok, if not success - value is empty string item.MenuText = item.Text; item.Help = StylishHelp(regexGetFromLineHelp.Match(line).Groups[1].Value); if (item.ToolTipTitle.Length == 0) { item.ToolTipTitle = item.Text; if (item.Type.Length > 0 ) item.ToolTipTitle += ": " + item.Type; } return item; }
public static void InitAndLoadHMSKnowledgeDatabase() { CreateIfNotExistDirectory(WorkingDir, true); CreateIfNotExistDirectory(TemplatesDir); CreateIfNotExistDirectory(ThemesDir); InitItemsBoolean(); // Загружаем базу данных знаний о HMS (классы, типы, функции и т.п.) из ресурсов HmsTypesString = Regex.Replace(HmsTypesStringWithHelp, "{.*?}", "").ToLower(); Assembly assembly = Assembly.GetExecutingAssembly(); bool isStatic = false; lock (HmsClasses) { Stream stream = null; try { // Load classes items HMSItem item; stream = assembly.GetManifestResourceStream(ResourcePath + "hms_classes.txt"); if (stream != null) { using (var reader = new StreamReader(stream)) { stream = null; ClassesString = "|"; HMSClassInfo hmsclass = null; var line = reader.ReadLine(); while (line != null) { if ((line.Trim().Length < 1) || (line.StartsWith("*"))) { line = reader.ReadLine(); continue; } int indent = line.Length - line.TrimStart().Length; item = GetHmsItemFromLine(line); if (indent == 0) { // it's Class if (!HmsClasses.ContainsName(item.Text)) { hmsclass = new HMSClassInfo { Name = item.Text, Type = item.Type, Help = item.Help }; HmsClasses.Add(hmsclass); item.Kind = DefKind.Class; item.ImageIndex = ImagesIndex.Class; item.ToolTipTitle = "Класс " + item.Text; item.IsClass = true; item.ClassInfo = hmsclass; ItemsClass.Add(item); ClassesString += hmsclass.Name.ToLower() + "|"; } } else if (indent == 2) { // it's method or property of the class var cmd = item.ToolTipTitle; if (cmd.StartsWith("function" )) { item.ImageIndex = ImagesIndex.Method; item.Kind = DefKind.Method ; } else if (cmd.StartsWith("procedure")) { item.ImageIndex = ImagesIndex.Method; item.Kind = DefKind.Procedure; } else if (cmd.StartsWith("property" )) { item.ImageIndex = ImagesIndex.Field ; item.Kind = DefKind.Property ; } else if (cmd.StartsWith("index" )) { item.ImageIndex = ImagesIndex.Enum ; item.Kind = DefKind.Property ; } else if (cmd.StartsWith("event" )) { item.ImageIndex = ImagesIndex.Event ; item.Kind = DefKind.Event ; } var name = Regex.Replace(cmd, @"^(function|procedure|property|index property|event)\s+", ""); name = Regex.Match(name, @"\w+").Value.Trim(); if (name.Length < 1) name += " "; item.Text = name; item.MenuText = name; item.Level = 1; if (item.ImageIndex == ImagesIndex.Enum) item.Text = name + "[^]"; else if (item.ImageIndex == ImagesIndex.Method) { if (cmd.IndexOf('(')>0) item.Text = name + "(^)"; //else item.Text = name + "()"; } if (name.ToLower() == "create") { // hmm... only one static method isStatic = true; hmsclass?.StaticItems.Add(item); } else { isStatic = false; hmsclass?.MemberItems.Add(item); } } else if ((indent == 4) || (line[0] == '\t')) { // it's help for parameters of last method if (isStatic) { if (hmsclass?.StaticItems.Count > 0) { item = hmsclass.StaticItems[hmsclass.StaticItems.Count - 1]; item.Params.Add(StylishHelp(line)); } } else { if (hmsclass?.MemberItems.Count > 0) { item = hmsclass.MemberItems[hmsclass.MemberItems.Count - 1]; item.Params.Add(StylishHelp(line)); } } } line = reader.ReadLine(); } } } // For each Class look the derived class and add his methods (info1) and methods of derived class of derived class (info2) foreach (var classItem in HmsClasses) { if (classItem.Type.Length == 0) continue; // if no type - skip HMSClassInfo info1 = HmsClasses[classItem.Type]; // get derived class if (info1.Name.Length == 0) continue; // if no found - skip HMSClassInfo info2 = HmsClasses[info1.Type]; // get derived class of the derived class if (info2.Name.Length > 0) { foreach (var i2 in info2.MemberItems) if (!classItem.MemberItems.ContainsName(i2.MenuText)) classItem.MemberItems.Add(i2); foreach (var i2 in info2.StaticItems) if (!classItem.StaticItems.ContainsName(i2.MenuText)) classItem.StaticItems.Add(i2); } foreach (var i1 in info1.MemberItems) if (!classItem.MemberItems.ContainsName(i1.MenuText)) classItem.MemberItems.Add(i1); foreach (var i1 in info1.StaticItems) if (!classItem.StaticItems.ContainsName(i1.MenuText)) classItem.StaticItems.Add(i1); classItem.MemberItems.SortByMenuText(); classItem.StaticItems.SortByMenuText(); } // Load a built-in Types (Enumerates) stream = assembly.GetManifestResourceStream(ResourcePath + "hms_types.txt"); if (stream != null) { using (var reader = new StreamReader(stream)) { stream = null; string line; while ((line = reader.ReadLine()) != null) { if (line.StartsWith("*") || (line.Trim().Length == 0)) continue; // Skip comments and blank lines item = GetHmsItemFromLine(line); if (!HmsTypes.ContainsName(item.Text)) { var hmsType = new HMSClassInfo { Name = item.Text, Type = item.Text, Help = item.Help }; string names = Regex.Match(line, @"\((.*?)\)").Groups[1].Value; foreach(string name in names.Split(',')) { item = new HMSItem { ImageIndex = ImagesIndex.Enum, Text = name, MenuText = name, ToolTipTitle = name, ToolTipText = "Перечисление типа " + hmsType.Name }; hmsType.MemberItems.Add(item); } HmsTypes.Add(hmsType); ClassesString += hmsType.Name.ToLower() + "|"; } } } } } catch (Exception e) { LogError(e.ToString()); } finally { // ReSharper disable once UseNullPropagation if (stream != null) stream.Dispose(); } } // Load a built-in Functions and Procedures items BuildAutocompleteItemsFromResourse(ResourcePath + "hms_func.txt", ImagesIndex.Procedure, "", ItemsFunction, DefKind.Function); // Load a built-in Variables BuildAutocompleteItemsFromResourse(ResourcePath + "hms_vars.txt" , ImagesIndex.Field, "Встроенная переменная", ItemsVariable, DefKind.Variable); // Load a built-in Constants BuildAutocompleteItemsFromResourse(ResourcePath + "hms_constants.txt", ImagesIndex.Enum , "Встроенная константа" , ItemsConstant, DefKind.Constant); foreach(var info in HmsTypes) { foreach(var typeitem in info.MemberItems) { ItemsConstant.Add(typeitem); } } // Check the self NotFoundedType = "|"; HmsTypesString += "int|long|void|bool|float|"; foreach (var q in HmsClasses) { CheckKnownType(q.Type); foreach (var a in q.MemberItems) CheckKnownType(a.Type); } foreach (var q in ItemsFunction) CheckKnownType(q.Type); foreach (var q in ItemsVariable) CheckKnownType(q.Type); foreach (var q in ItemsConstant) CheckKnownType(q.Type); string funcList = ""; foreach (var q in ItemsFunction) funcList += "|"+q.MenuText; funcList = funcList.Substring(1).Replace("|Int|", "|Int\\(|"); RegexHmsFunctions = new Regex(@"\b(" + funcList + @")\b", RegexOptions.IgnoreCase); string varsList = ""; foreach (var q in ItemsVariable) varsList += "|" + q.MenuText; varsList = varsList.Substring(1); RegexHmsVariables = new Regex(@"\b(" + varsList + @")\b", RegexOptions.IgnoreCase); varsList = "|true|false|nil|null"; foreach (var q in ItemsConstant) varsList += "|" + q.MenuText; varsList = varsList.Substring(1); RegexHmsConstants = new Regex(@"\b(" + varsList + @")\b", RegexOptions.IgnoreCase); ClassesString += NotFoundedType.ToLower(); HmsTypesString += ""; }
/// <summary> /// Проверка типа переменной, на возможность более удобного представления при Evaluate /// </summary> /// <param name="type">Тип переменной</param> /// <param name="text">Часть текста (имя меременной, свойства)</param> /// <returns></returns> private static string CheckTypeForToStringRules(HMSItem item, string text) { if ((text.EndsWith("]") || text.EndsWith(")")) && item.ImageIndex != ImagesIndex.Enum) return text; string type = item.Type; var info = HMS.HmsClasses[type]; if (info.MemberItems.ContainsName("SaveToString") && type.ToLower()!="tbitmap32") return text + ".SaveToString"; if (info.MemberItems.ContainsName("Text")) return text + ".Text"; switch (type) { case "THmsScriptMediaItem": return "\"" + text + "=\"+Str(" + text + ")+\" (Тип: THmsScriptMediaItem)\"#13#10+\"mpiTitle=\"+" + text + ".Properties[mpiTitle]+#13#10+\"mpiFilePath=\"+" + text + ".Properties[mpiFilePath]+#13#10+\"mpiThumbnail=\"+Str(" + text + ".Properties[mpiThumbnail])+#13#10+\"mpiTimeLength=\"+Str(" + text + ".Properties[mpiTimeLength])+#13#10+\"mpiCreateDate=\"+Str(" + text + ".Properties[mpiCreateDate])"; case "TRegExpr": return "\"" + text + "=\"+Str(" + text + ")+\" (Тип: TRegExpr)\"#13#10+\"Match(0)=\"+" + text + ".Match(0)+#13#10+\"Match(1)=\"+" + text + ".Match(1)+#13#10+\"Match(2)=\"+" + text + ".Match(2)+#13#10+\"Match(3)=\"+" + text + ".Match(3)"; } return text; }
private void ShowHelp(HMSItem item = null) { if (flatListBox1.Items.Count == 0) return; HelpTextBox.BeginUpdate(); if (item == null) item = flatListBox1.SelectedItem; if (item.Rtf.Length == 0) { string help = HmsToolTip.GetTextWithHelp(item); item.Rtf = HmsToolTip.GetRtf(help); } HelpTextBox.Rtf = item.Rtf; HelpTextBox.EndUpdate(); }
public void ShowFunctionParams(HMSItem item, int nParam, IWin32Window window, Point p) { string title = item.ToolTipTitle; string parameters = title; string activparam = ""; string paramtype = ""; string paramHelp = item.Help; if ((nParam > 0) && (nParam <= item.Params.Count)) paramHelp = item.Params[nParam - 1]; Match m = regexFunctionParams.Match(title); if (m.Success) parameters = m.Groups[1].Value; string[] prmtrs = regexSplitFuncParam.Split(parameters); if ((nParam > 0) && (nParam <= prmtrs.Length)) activparam = prmtrs[nParam-1]; if (activparam.Length > 0) { int ind = parameters.IndexOf(activparam); paramtype = HMS.GetType(parameters.Substring(ind)); } HMS.CurrentParamType = paramtype.ToLower(); if (activparam.Length > 0) title = title.Replace(activparam, "<b>" + activparam + "</b>"); if (paramHelp.Length == 0) paramHelp = " "; Help = paramHelp; ToolTipTitle = title; if (!Visible) Show(" ", window, p); }
public void ShowFunctionParams(HMSItem item, int nParam, IWin32Window window, Point p) { string title = item.ToolTipTitle; string parameters = title; string activparam = ""; string paramtype = ""; string paramHelp = item.Help; if ((nParam > 0) && (nParam <= item.Params.Count)) paramHelp = item.Params[nParam - 1]; Match m = regexFunctionParams.Match(title); if (m.Success) parameters = m.Groups[1].Value; string[] prmtrs = regexSplitFuncParam.Split(parameters); if ((nParam > 0) && (nParam <= prmtrs.Length)) activparam = prmtrs[nParam-1]; if (activparam.Length > 0) { int ind = parameters.IndexOf(activparam, StringComparison.Ordinal); paramtype = HMS.GetType(parameters.Substring(ind)); } HMS.CurrentParamType = paramtype.ToLower(); if (activparam.Length > 0) title = title.Replace(activparam, "<p>" + activparam + "</p>"); if (paramHelp.Length == 0) paramHelp = " "; Help = paramHelp; ToolTipTitle = title; if (((Control)window).InvokeRequired) { ((Control)window).Invoke((MethodInvoker)delegate { //ToolTipTitle = CalcPhrasesBreaks(window, title); if (!Visible) Show(" ", window, p); }); } else { //ToolTipTitle = CalcPhrasesBreaks(window, title); if (!Visible) Show(" ", window, p); } }
// < By WendyH ------------------------------------------ public HMSItem GetHMSItemByText(string text, out string partAfterDot, bool returnItemBeforeDot = false) { HMSItem item = null; HMSClassInfo info = new HMSClassInfo(); string[] names = text.ToLower().Split('.'); int count = 0; partAfterDot = ""; foreach (string word in names) { string name = HMS.GetTextWithoutBrackets(word); count++; partAfterDot = name; if (returnItemBeforeDot && (count >= names.Length)) { break; // return last item before the dot } if (info.Name.Length > 0) { // search in class members item = info.MemberItems.GetItemOrNull(name); if (item == null) { item = info.StaticItems.GetItemOrNull(name); } if (item != null) { info = HMS.HmsClasses[item.Type]; } } else { // try get variabe if (item == null) { item = Menu.Items.VisibleLocalVars.GetItemOrNull(name); // try visible known variables } if (item == null) { item = Menu.Items.VisibleVariables.GetItemOrNull(name); // try visible known variables } if (item == null) { item = Menu.Items.VisibleFunctions.GetItemOrNull(name); // try functions in script } if (item == null) { item = HMS.ItemsVariable.GetItemOrNull(name); // try internal variables } if (item == null) { item = HMS.ItemsConstant.GetItemOrNull(name); // try internal constants } if (item == null) { item = HMS.ItemsFunction.GetItemOrNull(name); // try internal functions } if (item == null) { item = HMS.ItemsClass.GetItemOrNull(name); // try internal classes } if (count < names.Length) { if (item != null) { info = HMS.HmsClasses[item.Type]; } else { break; } } } } return(item); }
protected override void Dispose(bool disposing) { HmsItem = null; OwnWords = null; base.Dispose(disposing); }
private void UpdateCurrentVisibleVariables(int position = -1) { if (Editor.Language == Language.YAML) return; if (position < 0) position = Editor.SelectionStart; HMSItem itemFunction = GetCurrentProcedure(position); if ((itemFunction != null) && (itemFunction.Type != "MainProcedure")) { if ((itemFunction.PositionStart == LastPtocedureIndex) && !NeedRecalcVars) return; // We are in same procedure - skip update LastPtocedureIndex = itemFunction.PositionStart; } else if ((LastPtocedureIndex == 0) && !NeedRecalcVars) { return; } else LastPtocedureIndex = 0; NeedRecalcVars = false; LocalVars.Clear(); if (itemFunction!=null) { string context = WithoutStringAndComments(Editor.GetRange(itemFunction.PositionStart, itemFunction.PositionEnd).Text); if (context.Length > 0) GetVariables(context, itemFunction.PositionStart, LocalVars); if (itemFunction.Kind == DefKind.Function) { HMSItem hmsItem = new HMSItem("Result"); hmsItem.ImageIndex = Images.Field; hmsItem.MenuText = hmsItem.Text; hmsItem.Type = itemFunction.Type; hmsItem.PositionStart = itemFunction.PositionStart; hmsItem.PositionEnd = itemFunction.PositionEnd; hmsItem.ToolTipText = "Переменная, хранящая значение, которое будет возвращено функцией как результат."; hmsItem.Help = "Используется в PascalScript, но видна как переменная и в других режимах синтаксиса.\nИмеет такой-же тип, как и функция, в которой она видна."; hmsItem.ToolTipTitle = "Result: " + hmsItem.Type; LocalVars.Add(hmsItem); } } else { Variables.Clear(); string contextGlobal = GetGlobalContext(); if (contextGlobal.Length > 0) GetVariables(contextGlobal, 0, Variables); } PopupMenu.Items.SetVisibleVariablesItems(Variables); PopupMenu.Items.SetLocalssVariablesItems(LocalVars); }
private static bool OK4Evaluate(HMSItem item) { bool success = ((item.Kind == DefKind.Property) || (item.Kind == DefKind.Variable)); if (!success && (item.Kind == DefKind.Function) || (item.Kind == DefKind.Method)) { success = successMethods4Eval.IndexOf("|"+item.MenuText.ToLower()+"|", StringComparison.Ordinal) >= 0; } return success; }
public void AddValue(int id, string name) { HMSItem item = new HMSItem(name, id); comboBox1.Items.Add(item); }
public static string GetText(HMSItem item, out float heightCorrection) { string s1 = item.ToolTipTitle.Trim(); string s2 = item.ToolTipText .Trim(); string s3 = item.Help .Trim(); string s4 = item.Value.Trim(); return StructuredText(out heightCorrection, s1, s2, s3, s4); }
public static string GetTextWithHelp(HMSItem item) { string help = ""; if (!string.IsNullOrEmpty(item.ToolTipTitle)) { help = GetText(item); if (item.Params.Count > 0) { help += "\n-----------------\nПараметры:\n"; foreach (var param in item.Params) { help += Regex.Replace(param, "^(\\w+)", "<p>$1</p>") + "\r\n"; } } if (item.IsClass) { help += "\n"; if (item.ClassInfo.StaticItems.Count > 0) { help += "<h>\nСтатические методы (конструктор):\n<t>"; foreach (var subitem in item.ClassInfo.StaticItems) { string title = subitem.ToolTipTitle; title = Regex.Replace(title, @"\b(" + subitem.MenuText + @")\b", "<b>$1</b>"); help += title + "\n"; } } if (item.ClassInfo.MemberItems.Count > 0) { help += "<h>\nСвойства и методы:\n<t>"; foreach (var subitem in item.ClassInfo.MemberItems) { string title = subitem.ToolTipTitle; title = Regex.Replace(title, @"\b("+ subitem.MenuText + @")\b", "<b>$1</b>"); help += title + "\n"; } } } } return help.TrimEnd(); }
public static string GetText(HMSItem item) { float heightCorrection; return GetText(item, out heightCorrection); }
private void BuildFunctionList() { Functions.Clear(); MatchCollection mc = null; string startBlock = "", endBlock = ""; string txt = WithoutStringAndComments(Editor.Text); switch (Editor.Language) { case Language.CPPScript : case Language.JScript : mc = regexProceduresCPP .Matches(txt); startBlock = "{"; endBlock = "}"; break; case Language.PascalScript: mc = regexProceduresPascal.Matches(txt); startBlock = @"\b(begin|try)\b"; endBlock = @"\b(end)\b"; break; case Language.BasicScript : mc = regexProceduresBasic .Matches(txt); startBlock = @"\b(Sub|Function)\b"; endBlock = @"\bEnd (Sub|Function)\b"; break; } if (mc != null) { foreach (Match m in mc) { string name = m.Groups[1].Value; if (regexExcludeWords.IsMatch(m.Value)) continue; HMSItem item = new HMSItem(); item.Type = m.Groups["type"].Value; item.Text = name; item.MenuText = name; item.Kind = regexDetectProcedure.IsMatch(m.Value) ? DefKind.Procedure : DefKind.Function; item.ImageIndex = (item.Kind == DefKind.Function) ? Images.Function : Images.Procedure; item.ToolTipTitle = name; item.ToolTipText = ((item.Kind == DefKind.Function) ? "Функция" : "Процедура") + " (объявлена в скрипте)"; item.PositionReal = m.Index; item.PositionStart = m.Groups[1].Index; item.PositionEnd = item.PositionStart + m.Groups[1].Value.Length; // check comment before procedure int iLine = Editor.PositionToPlace(item.PositionStart).iLine; if (iLine > 0) { Match matchComment = regexTextOfComment.Match(Editor.Lines[iLine-1]); if (matchComment.Success) item.Help = matchComment.Groups[1].Value; } // search end of procedure if (startBlock.Length > 0) { var stack = new Stack<string>(); MatchCollection mc2 = Regex.Matches(txt.Substring(item.PositionStart), "(" + startBlock + "|" + endBlock + ")", StdOpt); foreach (Match m2 in mc2) { if (Regex.IsMatch(m2.Value, startBlock, StdOpt)) stack.Push(startBlock); else if (stack.Count > 0) stack.Pop(); item.PositionEnd = item.PositionStart + m2.Groups[1].Index; if (stack.Count < 1) break; } item.PositionEnd += endBlock.Length; } string s = new Range(Editor, Editor.PositionToPlace(item.PositionStart), Editor.PositionToPlace(item.PositionEnd)).Text; Match m3 = Regex.Match(s, @"^(.*?)(\bvar\b|" + startBlock + ")", RegexOptions.IgnoreCase | RegexOptions.Singleline); if (m3.Success) item.ToolTipTitle = m3.Groups[1].Value.Trim().Replace("\r", "").Replace("\n", ""); if (item.Kind == DefKind.Function) { if (Editor.Language == Language.PascalScript) { item.Type = HMS.GetVarTypePascalFormat(item.ToolTipTitle); } else { item.ToolTipTitle = item.Type + " " + item.ToolTipTitle; } } Functions.Add(item); } } // add info about main start procedure if (Functions.LastEndPosition < txt.Length) { Match matchMainProc = Regex.Match(txt.Substring(Functions.LastEndPosition), startBlock, StdOpt); if (matchMainProc.Success) { HMSItem item = new HMSItem(); item.Type = "MainProcedure"; item.Text = "Главная процедура"; item.MenuText = item.Text; item.Kind = DefKind.Procedure; item.Help = "Процедура, с которой начинается запуск скрипта"; item.ImageIndex = Images.Procedure; item.PositionStart = Functions.LastEndPosition + matchMainProc.Index; item.PositionEnd = txt.Length - 1; Functions.Add(item); } } PopupMenu.Items.SetVisibleFunctionsItems(Functions); }