예제 #1
0
        public void SetAutocompleteItems(ICollection <string> items)
        {
            AutocompleteItems list = new AutocompleteItems();

            foreach (var item in items)
            {
                list.Add(new HMSItem(item));
            }
            SetAutocompleteItems(list);
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        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);
                            }
                        }
                    }
                }
            }
        }
예제 #4
0
        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);
        }
예제 #5
0
        // > 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();
            }
        }
예제 #6
0
        // > 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();
        }
예제 #7
0
 public void SetAutocompleteItems(ICollection<string> items)
 {
     AutocompleteItems list = new AutocompleteItems();
     foreach (var item in items)
         list.Add(new HMSItem(item));
     SetAutocompleteItems(list);
 }
예제 #8
0
 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);
 }
예제 #9
0
        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();
            }
        }
예제 #10
0
        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);
            }
        }
예제 #11
0
        // > 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();
        }
예제 #12
0
        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;
                    }
                }
            }
        }
예제 #13
0
        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;
        }