Ejemplo n.º 1
0
        /// <summary>
        /// 查询对象
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件参数</param>
        public static void QueryObjects(object sender, luaEditor.QueryEventsArgs e)
        {
            // 参数规定:
            // szCode: 所有的代码
            // nPos: 光标位置(汉字按2个字符算)
            // nIsDelete: 0为正常输入,1为删除,
            // 11-22为F1-F12,
            // 1111代表Ctrl+Shift+F1,
            // 1011代表Ctrl+F1
            // 111代表Shift+F1
            int nIsDelete = e.nPos > 0 ? 0 : 1;

            if (e.keyword != "")
            {
                nIsDelete = 10 + int.Parse(e.keyword);
            }

            IntPtr ls_out = IntPtr.Zero;

            LuaRuntime.Init();
            bool   bret   = LuaRuntime.LuaRun("OnCodeSense", e.szCode, Math.Abs(e.nPos), nIsDelete, "true,1024,显示所有,1,false,语法检查", ref ls_out);
            string strOut = Marshal.PtrToStringAnsi(ls_out);

            if (string.IsNullOrEmpty(strOut))
            {
                return;
            }

            string[] as_data = strOut.Split(new char[] { '|' });

            if (as_data.Length < 3)
            {
                MessageBox.Show("返回值不正确,返回值为:" + strOut, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // 读取overlen
            e.nOverLen = int.Parse((as_data[0]));

            // 初始化游标
            int nPosition = 3;

            // 读取list
            int nListCount = int.Parse((as_data[1]));

            if (as_data.Length < 3 + nListCount)
            {
                MessageBox.Show("List返回值个数不正确,返回值为:" + strOut, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            for (int i = 0; i < nListCount; i++)
            {
                string s_name = as_data[nPosition++];
                string s_word = as_data[nPosition++];
                string s_type = as_data[nPosition++];
                string s_info = as_data[nPosition++];
                e.leTable.Add(s_name, new luaEditor.LuaEditorTableItem(s_name, s_type, s_word, s_info));
            }

            // 读取info
            int nInfoCount = Int32.Parse((as_data[2]));

            if (as_data.Length < 3 + nListCount + nInfoCount)
            {
                MessageBox.Show("Info返回值个数不正确,返回值为:" + strOut, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            for (int i = 0; i < nInfoCount; i++)
            {
                string s_text = as_data[nPosition++] as string;
                e.parms_list.Add(s_text.Replace("\n", "<BR>"));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据keyword弹出参数提示
        /// </summary>
        /// <param name="keyword">函数全名</param>
        /// <param name="index">活动参数位置</param>
        /// <param name="codeEditor">luaEditorControl引用</param>
        private void PopInfo(string keyword, int index, string strNs, CodeEditorControl codeEditor)
        {
            string content = "";
            QueryEventsArgs queryEventArgs = new QueryEventsArgs();

            // 先看本文档里有没有
            foreach (FunctionList functionList in cmbFunctionList.Items)
            {
                if (keyword == functionList.FunctionName)
                {
                    content = functionList.FullText;
                    break;
                }
            }

            // 没有啊,那么去查标准库
            if (content == "")
            {
                queryEventArgs.keyword = keyword;
                content = StandardLib.GetFunctionInfo(keyword);
            }

            // 标准库里查不到,那就去反射缓存里查查
            if (content == "")
            {
                content = ParameterCache.FindMethodParameterByFullName(keyword, strNs);
            }

            //缓存里也没有,那就只能回调了
            if (content == "" && queryParms != null)
            {
                queryParms(this, queryEventArgs);         /*回调,获取Parms列表*/
            }


            if (content != "")
            {
                string[] spec = { "<%newline%>" };
                string[] aspp = content.Split(spec, StringSplitOptions.RemoveEmptyEntries);
                foreach (string sitem in aspp)
                {
                    queryEventArgs.parms_list.Add(sitem.Replace("\r\n", "<BR>"));
                }
            }

            //把重载了的参数放进去
            if (queryEventArgs.parms_list.Count > 0)
            {
                codeEditor.InfoTipPosition = new TextPoint(codeEditor.Caret.Position.X + 1, codeEditor.Caret.Position.Y);
                codeEditor.InfoTipCount = queryEventArgs.parms_list.Count;

                for (int i = 0; i < queryEventArgs.parms_list.Count; i++)
                {
                    codeEditor.InfoTipSelectedIndex = i;
                    string argIn = queryEventArgs.parms_list[i];
                    if(argIn.IndexOf("<BR>") == -1)
                    {
                        argIn += "<BR>";
                    }

                    try 
                    {
                        string sc1 = argIn.Substring(0, argIn.IndexOf("<BR>"));
                        if(sc1.IndexOf('(') != -1)
                        {
                            string s1 = sc1.Substring(0, sc1.LastIndexOf('('));
                            string s2 = sc1.Substring(sc1.LastIndexOf('(') + 1);
                            s2 = s2.Substring(0, s2.Length - 1);
                            string s3 = argIn.Substring(argIn.IndexOf("<BR>"));

                            string[] asp = { "," };
                            string[] argIns = s2.Split(asp, StringSplitOptions.RemoveEmptyEntries);
                            if (argIns.Length > index - 1)
                            {
                                string t = argIns[index - 1].Trim();
                                if (t.Substring(t.Length - 1) == "[")
                                    argIns[index - 1] = "<b>" + t.Substring(0, t.Length - 1) + "</b>[";
                                else if (t.Substring(t.Length - 1) == "]")
                                    argIns[index - 1] = "<b>" + t.Substring(0, t.Length - 1) + "</b>]";
                                else
                                    argIns[index - 1] = "<b>" + t + "</b>";
                            }
                            s2 = string.Join(",", argIns);
                            codeEditor.InfoTipText = s1 + "(" + s2 + ")" + s3;         
                        }
                    }
                    catch
                    {
                        codeEditor.InfoTipText = argIn;
                        throw;
                    }

                }
                codeEditor.InfoTipVisible = true;
                inputState = InputState.PARMSLIST_OPEN;
            }
        }
Ejemplo n.º 3
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;
                    }
            }
        }
Ejemplo n.º 4
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);
                }
            }            
        }
Ejemplo n.º 5
0
 public static void regEvent(QueryEventsArgs e, string funcName, string strInfo, leParm lep1, leParm lep2, leParm lep3, leParm lep4)
 {
     List<leParm> tlist = new List<leParm>();
     tlist.Add(lep1);
     tlist.Add(lep2);
     tlist.Add(lep3);
     tlist.Add(lep4);
     e.leec.m_list.Add(new leEvent(funcName, tlist, strInfo));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 搬过来的函数
 /// </summary>
 /// <param name="e"></param>
 /// <param name="funcName"></param>
 /// <param name="strInfo"></param>
 /// <param name="leps"></param>
 /// 
 public static void regEvent(QueryEventsArgs e, string funcName, string strInfo)
 {
     List<leParm> tlist = new List<leParm>();
     e.leec.m_list.Add(new leEvent(funcName, tlist, strInfo));
 }