Beispiel #1
0
        /// <summary>
        /// 显示提示选项
        /// </summary>
        /// <param name="eKey">按键信息</param>
        /// <param name="codeEditor">当前编辑控件</param>
        private void ShowAutoList(KeyPressEventArgs eKey, CodeEditorControl codeEditor)
        {
            if (eKey.KeyChar > 128)
            {
                return;
            }

            //获取完整对象名                     
            string keyWord = codeEditor.Caret.CurrentRow.Text.Substring(0, codeEditor.Caret.Position.X);
            string objectFullName = GetObjectFullName(keyWord);

            string functionName = "";
            int cursorPosition = 0;

            if (!((eKey.KeyChar >= 'a' && eKey.KeyChar <= 'z') || (eKey.KeyChar >= 'A' && eKey.KeyChar <= 'Z') || (eKey.KeyChar >= '0' && eKey.KeyChar <= '9') || eKey.KeyChar == '_'))
            {
                // 过滤之前的参数,获取函数名,以及光标参数所在的位置
                if (eKey.KeyChar == '\b')
                {
                    if (keyWord.Length > 0)
                    {
                        keyWord = keyWord.Substring(0, keyWord.Length - 1);
                    }
                }
                else
                {
                    keyWord += eKey.KeyChar.ToString(); // 把','也追加后面去吧
                }

                functionName = GetFunctionFullNameAndTurns(keyWord);
                int index = functionName.IndexOf("##");
                cursorPosition = int.Parse(functionName.Substring(index + 2));
                functionName = functionName.Substring(0, index);                
                
                // 获取命名空间(说白了就是函数名)
                Segment segment = codeEditor.Caret.CurrentSegment();
                
                // 看看如果是注释内,或者是引号内,就拉倒
                segment = codeEditor.Caret.CurrentSegment();

                if (segment != null)
                {
                    if (segment.BlockType.Style.Name == "Lua Comment")
                    {
                        return;
                    }

                    if (segment.BlockType.Style.Name == "Lua String")
                    {
                        return;
                    }
                    
                    string currentText = codeEditor.Caret.CurrentRow.Text;
                    currentText = currentText.Substring(0, codeEditor.Caret.Position.X);
                    currentText = currentText.Trim(invalidChartArray);

                    if (currentText.StartsWith("--"))
                    {
                        return;
                    }

                    if ((currentText.Replace("'", "").Length - currentText.Length) % 2 == 1)
                    {
                        return;
                    }

                    if ((currentText.Replace("\"", "").Length - currentText.Length) % 2 == 1)
                    {
                        return;
                    }                    
                }
            }     
               
            switch (eKey.KeyChar)
            {
                case ':':
                    {
                        goto case '.';
                    }
                case '.':
                    {
                        switch (inputState)
                        {
                            case InputState.FUNCTIONLIST_OPEN:
                                {
                                    codeEditor.AutoListVisible = false;
                                    inputState = InputState.NORMAL;

                                    break;
                                }
                            case InputState.OBJECTLIST_OPEN:
                                {
                                    goto case InputState.FUNCTIONLIST_OPEN;
                                }
                            case InputState.INTELLISENCE_OPEN:
                                {
                                    goto case InputState.FUNCTIONLIST_OPEN;
                                }
                            default:
                                {
                                    break;
                                }
                        }

                        if (objectFullName != "")
                        {
                            // 触发事件
                            QueryEventsArgs queryEventsArg = new QueryEventsArgs();
                            queryEventsArg.keyword = objectFullName;
                            List<string> objectList = StandardLib.GetObjectList(objectFullName);

                            if (objectList.Count == 0)
                            {
                                objectList = ParameterCache.findMethodInfoByFullName(objectFullName, strNs);
                            }
        
                            foreach (string objectInfo in objectList)
                            {
                                string[] infoArray = objectInfo.Split(queryObjectStringArray, StringSplitOptions.RemoveEmptyEntries);
                                string type = infoArray[1];
                                string value = infoArray[0];

                                if (!queryEventsArg.leTable.ContainsKey(objectInfo))
                                {
                                    queryEventsArg.leTable.Add(objectInfo, new LuaEditorTableItem(value, type, value, ""));
                                }
                            }

                            objectList.Clear();

                            if (queryEventsArg.leTable.Count > 0)
                            {
                                codeEditor.AutoListBeginLoad();
                                codeEditor.AutoListClear();

                                m_list_context = "";

                                foreach (LuaEditorTableItem tableItem in queryEventsArg.leTable.Values)
                                {
                                    switch (tableItem.ItemType)
                                    {
                                        case "method":
                                            {
                                                if (eKey.KeyChar == ':')
                                                {
                                                    codeEditor.AutoListAdd(tableItem.Name, tableItem.ItemValue.ToString(), tableItem.Info, 1);
                                                }

                                                break;
                                            }                                            
                                        case "function":
                                            {
                                                if (eKey.KeyChar == '.')
                                                {
                                                    codeEditor.AutoListAdd(tableItem.Name, tableItem.ItemValue.ToString(), tableItem.Info, 6);
                                                }

                                                break;
                                            }                                            
                                        case "table":
                                            {
                                                if (eKey.KeyChar == '.')
                                                {
                                                    codeEditor.AutoListAdd(tableItem.Name, tableItem.ItemValue.ToString(), tableItem.Info, 3);
                                                }

                                                break;
                                            }
                                            
                                        case "var":
                                            {
                                                if (eKey.KeyChar == '.')
                                                {
                                                    codeEditor.AutoListAdd(tableItem.Name, tableItem.ItemValue.ToString(), tableItem.Info, 4);
                                                }

                                                break;
                                            }          
                                        default:
                                            {
                                                break;
                                            }
                                    }

                                    m_list_context += "|" + tableItem.Name;
                                }

                                codeEditor.AutoListEndLoad();
                                codeEditor.AutoListPosition = new TextPoint(codeEditor.Caret.Position.X + 1, codeEditor.Caret.Position.Y);
                                codeEditor.AutoListVisible = true;
                                inputState = InputState.OBJECTLIST_OPEN;
                            }
                        }

                        break;
                    }                                      
                case ' ':
                    {
                        switch (inputState)
                        {
                            case InputState.FUNCTIONLIST_OPEN:
                                {
                                    codeEditor.AutoListVisible = false;
                                    inputState = InputState.NORMAL;

                                    break;
                                }
                            case InputState.OBJECTLIST_OPEN:
                                {
                                    goto case InputState.OBJECTLIST_OPEN;
                                }
                            case InputState.INTELLISENCE_OPEN:
                                {
                                    codeEditor.AutoListVisible = false;
                                    inputState = InputState.NORMAL;

                                    goto case InputState.NORMAL;
                                }
                            case InputState.NORMAL:
                                {
                                    break;
                                }
                            default:
                                {
                                    break;
                                }
                        }
                       
                        break;
                    }
                case ')':
                    {
                        codeEditor.InfoTipVisible = false;
                        codeEditor.AutoListVisible = false;
                        inputState = InputState.NORMAL;

                        break;
                    }
                    
                case ',':
                    {
                        switch (inputState)
                        {
                            case InputState.INTELLISENCE_OPEN:
                                {
                                    codeEditor.AutoListVisible = false;
                                    codeEditor.InfoTipVisible = false;
                                    inputState = InputState.NORMAL;

                                    break;
                                }
                            case InputState.FUNCTIONLIST_OPEN:
                                {
                                    goto case InputState.INTELLISENCE_OPEN;
                                }
                            default:
                                {
                                    break;
                                }
                        }

                        if (functionName != "")
                        {
                            PopInfo(functionName, cursorPosition, strNs, codeEditor);
                        }

                        break;
                    }                    
                case '(' :
                    {
                        switch (inputState)
                        {
                            case InputState.FUNCTIONLIST_OPEN:
                                {
                                    codeEditor.AutoListVisible = false;
                                    inputState = InputState.NORMAL;

                                    break;
                                }
                            case InputState.OBJECTLIST_OPEN:
                                {
                                    goto case InputState.OBJECTLIST_OPEN;

                                    break;
                                }
                            default:
                                {
                                    break;
                                }
                        }                        

                        if (objectFullName != "")
                        {
                            PopInfo(objectFullName, 1, strNs, codeEditor);
                        }

                        break;
                    }
                    
                case '\r':
                    {
                        switch (inputState)
                        {
                            case InputState.FUNCTIONLIST_OPEN:
                                {
                                    codeEditor.AutoListVisible = false;
                                    inputState = InputState.NORMAL;

                                    break;
                                }
                            case InputState.OBJECTLIST_OPEN:
                                {
                                    goto case InputState.FUNCTIONLIST_OPEN;
                                }
                            case InputState.INTELLISENCE_OPEN:
                                {
                                    goto case InputState.FUNCTIONLIST_OPEN;
                                }
                            default:
                                {
                                    // 尝试模拟执行当前行语句
                                    Row currentRow = codeEditor.Document[codeEditor.Caret.Position.Y - 1];
                                    CodeLineScan(currentRow.Text, strNs);

                                    // 尝试自动缩进
                                    IndentText(codeEditor);

                                    break;
                                }
                        }

                        break;
                    }
                case '\b':
                    {
                        if (inputState == InputState.INTELLISENCE_OPEN)
                        {
                            if (objectFullName == "")
                            {
                                codeEditor.AutoListVisible = false;
                                inputState = InputState.NORMAL;                                
                            }
                        }

                        break;
                    }
                case '=':
                    {
                        if (inputState != InputState.NORMAL)
                        {
                            codeEditor.AutoListVisible = false;
                            inputState = InputState.NORMAL;
                        }

                        break;
                    }
                case '+':
                    {
                        goto case '=';
                    }
                case '-':
                    {
                        goto case '=';
                    }
                case '*':
                    {
                        goto case '=';
                    }
                case '/':
                    {
                        goto case '=';
                    }
                case '?':
                    {
                        goto case '=';
                    }
                default:
                    {
                        if (inputState == InputState.NORMAL)
                        {
                            if ((eKey.KeyChar >= 'a' && eKey.KeyChar <= 'z') || (eKey.KeyChar >= 'A' && eKey.KeyChar <= 'Z') || (eKey.KeyChar >= '0' && eKey.KeyChar <= '9') || eKey.KeyChar == '_')
                            {
                                // 智能感知>
                                List<string> wordList;
                                wordList = ParameterCache.GetIntelliSenceWordList(objectFullName + eKey.KeyChar.ToString(), strNs);

                                if (wordList.Count > 0)
                                {
                                    codeEditor.AutoListBeginLoad();
                                    codeEditor.AutoListClear();

                                    m_list_context = "";

                                    foreach (string s in wordList)
                                    {
                                        codeEditor.AutoListAdd(s, s, s, 1);
                                        m_list_context += "|" + s;
                                    }

                                    codeEditor.AutoListEndLoad();
                                    
                                    codeEditor.AutoListPosition = new TextPoint(codeEditor.Caret.Position.X/* + 1*/, codeEditor.Caret.Position.Y);
                                    codeEditor.AutoListVisible = true;
                                    inputState = InputState.INTELLISENCE_OPEN;
                                }

                                if (m_list_context.ToLower().IndexOf(string.Format("|{0}{1}", objectFullName, eKey.KeyChar).ToLower()) == -1) // 输入前几个字母不匹配,则干掉列表
                                {
                                    codeEditor.AutoListVisible = false;
                                    inputState = InputState.NORMAL;
                                }

                                if (string.Format("{0}|", m_list_context).IndexOf(string.Format("|{0}{1}|", objectFullName, eKey.KeyChar)) != -1)  // 完全匹配也干掉列表
                                {
                                    codeEditor.AutoListVisible = false;
                                    inputState = InputState.NORMAL;
                                }
                            }
                        }

                        break;
                    }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 显示提示选项
        /// </summary>
        /// <param name="eKey">按键信息</param>
        /// <param name="codeEditor">当前编辑控件</param>
        private void ShowAutoList4GameLuaEditor(KeyPressEventArgs eKey, CodeEditorControl codeEditor)
        {
            // 强制规定,如果ascii码>130,那么131为F1,132为F2。。。。。
            // 不管三七二十一,先关闭列表再说
            codeEditor.AutoListVisible = false;
            codeEditor.InfoTipVisible = false;

            //计算当前输入的东东以及位置
            int nOffset = 0;
            QueryEventsArgs queryEventsArgs = new QueryEventsArgs();

            if (eKey.KeyChar != '\b' && eKey.KeyChar <= 128)
            {
                queryEventsArgs.szCode = string.Format("{0}{1}{2}", 
                                                       codeEditor.Document.Text.Substring(0, codeEditor.Selection.LogicalSelStart),
                                                       eKey.KeyChar,
                                                       codeEditor.Document.Text.Substring(codeEditor.Selection.LogicalSelStart));
                queryEventsArgs.nPos = codeEditor.Selection.LogicalSelStart + 1;

                nOffset++;
            }
            else
            {
                queryEventsArgs.szCode = codeEditor.Document.Text;
                queryEventsArgs.nPos = codeEditor.Selection.LogicalSelStart;
            }

            // 如果什么也没输入,只是按下了热键
            if (eKey.KeyChar > 128)
            {
                int ikey = (int)eKey.KeyChar - 130;
                queryEventsArgs.keyword = ikey.ToString();
            }

            // 由于Lua很变态,认为汉字的长度为2,所以我得手工看看有多少中文,然后加在长度上
            int nAdd = 0;

            for (int i = 0; i < queryEventsArgs.nPos; i++ )
            {
                if (queryEventsArgs.szCode[i] > 128)
                {
                    nAdd++;
                }
            }
            queryEventsArgs.nPos += nAdd;

            if (eKey.KeyChar == '\b')
            {
                queryEventsArgs.nPos *= -1;
            }

            // 获取新列表
            if (queryObjects != null && !codeEditorControl.ReadOnly) // 调试模式下不用启动自动完成功能
            {
                queryObjects(this, queryEventsArgs);
                bool querySuccess = false;

                if (queryEventsArgs.parms_list.Count > 0)
                {
                    codeEditor.InfoTipPosition = new TextPoint(codeEditor.Caret.Position.X + 1, codeEditor.Caret.Position.Y);
                    codeEditor.InfoTipCount = queryEventsArgs.parms_list.Count;

                    for (int i = 0; i < queryEventsArgs.parms_list.Count; i++)
                    {
                        codeEditor.InfoTipSelectedIndex = i;
                        string argIn = queryEventsArgs.parms_list[i];
                        codeEditor.InfoTipText = argIn;
                    }

                    codeEditor.InfoTipVisible = true;
                    querySuccess = true;
                }

                if (queryEventsArgs.leTable.Count > 0)
                {
                    codeEditor.AutoListBeginLoad();
                    codeEditor.AutoListClear();

                    foreach (LuaEditorTableItem tableItem in queryEventsArgs.leTable.Values)
                    {
                        codeEditor.AutoListAdd(tableItem.Name, tableItem.ItemValue.ToString(), tableItem.Info, int.Parse(tableItem.ItemType));                        
                    }

                    codeEditor.AutoListEndLoad();
                    codeEditor.AutoListPosition = new TextPoint(codeEditor.Caret.Position.X + nOffset, codeEditor.Caret.Position.Y);
                    codeEditor.AutoListPosition.X -= queryEventsArgs.nOverLen;

                    if (codeEditor.AutoListPosition.X < 0)
                    {
                        codeEditor.AutoListPosition.X = 0;
                    }

                    codeEditor.AutoListVisible = true;
                    querySuccess = true;
                }

                switch (eKey.KeyChar)
                {
                    case '\r':
                        {
                            IndentText(codeEditor);                           

                            break;
                        }
                        
                    default:
                        {
                            break;
                        }                    
                }

                if (!querySuccess)
                {
                    // ShowAutoList(eKey, codeEditor);
                }
            }            
        }