Example #1
0
        /// <summary>
        /// 在编辑窗体中打开脚本文件
        /// </summary>
        /// <param name="fileName">文件路径</param>
        /// <param name="requireProcessFileName">是否需要处理文件名</param>
        /// <returns>是否打开成功</returns>
        private EditForm OpenFileInEditor(string fileName, bool requireProcessFileName)
        {
            EditForm editForm = null;    
            string filePath = fileName.Replace(Helper.ClientPath, "").TrimStart(new char[] { '\\', '/' });

            foreach (EditForm eForm in this.MdiChildren)
            {
                string editorFileName = eForm.FileName;

                if (requireProcessFileName)
                {
                    editorFileName = ProcessFileName(editorFileName);
                }

                if (editorFileName == filePath)
                {
                    SelectEditForm(eForm);
                    return eForm;                    
                }
            }

            string content = Helper.FileToString(fileName);

            if (!string.IsNullOrEmpty(content))
            {
                editForm = new EditForm("localFile");
                editForm.ID = "0";

                // InitEditForm(editForm, content, filePath);                
                InitEditForm(editForm, content, fileName);
                editForm.Show();
                SelectEditForm(editForm);
            }

            return editForm;
        }
Example #2
0
        /// <summary>
        /// 初始化编辑窗体
        /// </summary>
        /// <param name="editForm">编辑窗体</param>
        /// <param name="scriptCode">脚本内容</param>
        /// <param name="scriptPath">脚本路径</param>
        private void InitEditForm(EditForm editForm, string scriptCode, string scriptPath)
        {
            editForm.ScriptCode = scriptCode;
            editForm.WindowState = FormWindowState.Maximized;
            editForm.MdiParent = this;
            editForm.FileName = scriptPath;
            editForm.EditorContextMenu = popRight;
            editForm.luaEditBox.ScriptFont = Helper.ScriptFont;
            editForm.luaEditBox.ScriptForeColor = Helper.ScriptForeColor;
            editForm.HandleBreakPointAdded += new EditForm.BreakPointAdded(EditFormBreakPointAdded);
            editForm.HandleBreakPointRemoved += new EditForm.BreakPointRemoved(EditFormBreakPointRemoved);
            editForm.HandleWordMouseHover += new EditForm.WordMouseHover(EditFormWordMouseHover);
            editForm.luaEditBox.KeyDown += new KeyEventHandler(EditForm_KeyDown);
            editForm.luaEditBox.ReadOnly = startDebug; // 调试模式下的打开窗体只能只读的

            if (startDebug)
            {
                editForm.Text = string.Format("{0} [已锁定]", editForm.Text);
            }
        }
Example #3
0
        /// <summary>
        /// 编辑窗体删除断点
        /// </summary>
        /// <param name="editForm">编辑窗体</param>
        /// <param name="row">断点所在行</param>
        private void EditFormBreakPointRemoved(EditForm editForm, Fireball.Syntax.Row row)
        {
            int removeRowIndex = -1;
            string fileName = null;
            int currentLineIndex = row.Index + 1;

            foreach (DataGridViewRow breakPointRow in breakPointView.Rows)
            {
                fileName = breakPointRow.Cells["BreakPointFileName"].Value as string;
                string lineIndex = breakPointRow.Cells["BreakPointLineIndex"].Value as string;

                if (fileName == editForm.FileName && lineIndex == currentLineIndex.ToString())
                {
                    removeRowIndex = breakPointRow.Index;
                    break;
                }
            }

            if (removeRowIndex != -1)
            {
                breakPointView.Rows.RemoveAt(removeRowIndex);
                
                // 动态取消注册断点
                if (startDebug)
                {
                    string message = string.Format("delete_break_point {0} {1}", fileName, currentLineIndex.ToString());
                    PrintOutputText(string.Format("取消注册断点 —— 文件名:{0},行号:{1}", fileName, currentLineIndex.ToString()));
                    string receivedMessage = SendAndWaitMessage(message, string.Format("<ldb>delete_break_point: {0},{1}", 
                                                                                       fileName, currentLineIndex.ToString()), false);

                    if (receivedMessage != null)
                    {
                        receivedMessage = "取消注册断点成功...";
                    }
                    else
                    {
                        receivedMessage = "接收消息超时...";
                    }

                    PrintOutputText(receivedMessage);
                }
            }            
        }
Example #4
0
        /// <summary>
        /// 选中编辑控件
        /// </summary>
        /// <param name="editForm">编辑控件</param>
        private void SelectEditForm(EditForm editForm)
        {           
            foreach (DevComponents.DotNetBar.TabItem tabItem in this.tabStrip1.Tabs)
            {
                if (tabItem.AttachedControl == editForm)
                {
                    tabStrip1.SelectedTab = tabItem;
                    break;
                }
            }

            editForm.Activate();
            editForm.Focus();
        }
Example #5
0
        /// <summary>
        /// 编辑窗体添加断点
        /// </summary>
        /// <param name="editForm">编辑窗体</param>
        /// <param name="row">断点所在行</param>
        private void EditFormBreakPointAdded(EditForm editForm, Fireball.Syntax.Row row)
        {
            bool exist = false;
            int currentLineIndex = -1;
            string fileName = null;

            foreach (DataGridViewRow breakPointRow in breakPointView.Rows)
            {
                fileName = breakPointRow.Cells["BreakPointFileName"].Value as string;
                string lineIndex = breakPointRow.Cells["BreakPointLineIndex"].Value as string;
                currentLineIndex = row.Index + 1;

                if (fileName == editForm.FileName && lineIndex == currentLineIndex.ToString())
                {
                    exist = true;
                    break;
                }
            }

            if (!exist)
            {
                fileName = editForm.FileName;
                currentLineIndex = row.Index + 1;                
                breakPointView.Rows.Add(1);
                DataGridViewRow newRow = breakPointView.Rows[breakPointView.Rows.Count - 1];
                newRow.Cells["EnableBreakPoint"].Value = true;
                newRow.Cells["BreakPointFileName"].Value = fileName;
                newRow.Cells["BreakPointLineIndex"].Value = currentLineIndex.ToString();

                // 动态注册断点
                if (startDebug)
                {
                    string message = string.Format("add_break_point {0} {1}", fileName, currentLineIndex.ToString());
                    PrintOutputText(string.Format("注册断点 —— 文件名:{0},行号:{1}", fileName, currentLineIndex.ToString()));

                    string receivedMessage = SendAndWaitMessage(message, string.Format("<ldb>add_break_point: {0},{1}", fileName, currentLineIndex), false);

                    if (receivedMessage != null)
                    {
                        newRow.Cells["BreakPointState"].Value = "注册成功";
                        newRow.Cells["BreakPointState"].Style.ForeColor = Color.Black;
                    }
                    else
                    {
                        receivedMessage = "接收消息超时...";
                        newRow.Cells["BreakPointState"].Value = "接收消息超时";
                        newRow.Cells["BreakPointState"].Style.ForeColor = Color.Red;
                    }

                    PrintOutputText(receivedMessage);
                }
            }
        }
Example #6
0
        /// <summary>
        /// 编辑窗体取词
        /// </summary>
        /// <param name="editForm">编辑窗体</param>
        /// <param name="e">取词参数</param>
        private void EditFormWordMouseHover(EditForm editForm, ref WordMouseEventArgs e)
        {
            string fileName = editForm.FileName;
            string varName = e.Word.Text;
            editForm.luaEditBox.CloseTipText();

            if (startDebug && enableFetchWord && mouseFetchWord && !string.IsNullOrEmpty(varName))
            {
                // 只接收合法命名的单词
                Regex regex = new Regex(@"[A-Za-z0-9_]+");
               
                if (regex.IsMatch(varName))
                {
                    if (ProcessFileName(editForm.FileName) == currentDebugFile)
                    {
                        string message = string.Format("print_var {0}", varName);
                        string receivedMessage = SendAndWaitMessage(message, string.Format("<ldb>print_var: {0}", varName), true);
                        string tipText = null;

                        if (receivedMessage != null)
                        {
                            if (receivedMessage == string.Format("<ldb>print_var: {0} failed!", varName))
                            {
                                tipText = "无效变量";
                            }
                            else
                            {
                                receivedMessage = receivedMessage.Replace(string.Format("<ldb>print_var: {0} -> ", varName), "");
                                receivedMessage = receivedMessage.Replace("<", "<").Replace(">", ">"); // 遇到<和>符号的时候会出bug,先暂时替换掉
                                receivedMessage = receivedMessage.Replace("\n", "<BR>"); // 替换换行符
                                tipText = string.Format("<b>{0}</b><BR>{1}", varName, receivedMessage);
                            }                           
                        }
                        else
                        {
                            tipText = "接收消息超时";
                        }

                        TextPoint location = new TextPoint(e.Word.Column + e.Word.Text.Length, e.Word.Row.Index);
                        editForm.luaEditBox.SetTipText(tipText, location);
                    }
                }
            }
        }
Example #7
0
 //检查指定窗口的代码错误
 public string ScriptCheck(EditForm fe)
 {
     string strCode = "";
     if (fe != null)
     {
         if (fe.luaEditBox.Text != null)
         {
             strCode = fe.luaEditBox.Text;
         }
     }
     if (strCode == "")
     {
         return null;
     }
     return ScriptCheck(strCode);
 }        
Example #8
0
        /// <summary>
        /// 用户选择查看历史记录
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件</param>
        private void btnHistory_Click(object sender, EventArgs e)
        {
            TreeNode currentNode = treePh.SelectedNode;

            if (currentNode != null && currentNode.Tag != null)
            {
                Hashtable infoTable = currentNode.Tag as Hashtable;

                if (infoTable["type"] as string == "file" && infoTable["scriptType"] as string == "databaseFile")
                {
                    string id = infoTable["id"] as string;          
                    HistoryForm hForm = new HistoryForm(DataBaseManager.GetDataBaseManager().Connection, id);
                    hForm.TreeImageList = imageList1;
                    hForm.Text = string.Format("查看历史记录  {0}", currentNode.FullPath);

                    if (hForm.ShowDialog() == DialogResult.Yes)
                    {
                        if (hForm.RecoverRecord) // 恢复历史记录
                        {
                            InsertNewNode(hForm.Path, hForm.ScriptData);
                        }
                        else // 读取历史记录
                        {
                            EditForm feshow = null;

                            foreach (EditForm fe in this.MdiChildren)
                            {
                                if (fe.ID == id)
                                {
                                    feshow = fe;
                                    break;
                                }
                            }

                            if (feshow == null)
                            {
                                feshow = new EditForm("databaseFile");
                            }

                            feshow.ID = id;
                            feshow.ScriptCode = hForm.ScriptData;
                            feshow.WindowState = FormWindowState.Maximized;
                            feshow.MdiParent = this;
                            feshow.FileName = currentNode.FullPath;
                            feshow.Show();
                        }                  
                    }
                }
                else
                {
                    MessageBox.Show("请选择要查看历史记录的脚本文件!", "查看历史记录", MessageBoxButtons.OK, MessageBoxIcon.Information);
                } 
            }
            else
            {
                MessageBox.Show("请选择要查看历史记录的脚本文件!", "查看历史记录", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #9
0
        /// <summary>
        /// 双击树结点
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件参数</param>
        private void treePh_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            TreeNode currentNode = treePh.SelectedNode;

            if (currentNode.Tag == null)
            {
                return;
            }

            Hashtable infoTable = currentNode.Tag as Hashtable;

            if (infoTable["type"] as string == "folder")
            {
                return;
            }

            string scriptType = infoTable["scriptType"] as string;

            if (scriptType == "databaseFile") // 打开数据库里的脚本文件
            {
                string id = infoTable["id"] as string;
                EditForm editForm = null;

                foreach (EditForm eForm in this.MdiChildren)
                {
                    if (eForm.ID == id)
                    {
                        editForm = eForm;
                    }
                }

                if (editForm == null)
                {
                    editForm = new EditForm("databaseFile");
                    editForm.ID = id;
                    DataBaseManager dbm = DataBaseManager.GetDataBaseManager();
                    string strCode = dbm.GetScriptData(id);

                    if (strCode == null)
                    {
                        MessageBox.Show("加载脚本失败!", "加载脚本", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    InitEditForm(editForm, strCode, currentNode.FullPath);
                    editForm.Show();
                }

                SelectEditForm(editForm);
            }
            else if (scriptType == "localFile") // 打开本地的脚本文件
            {
                string filePath = infoTable["filePath"] as string;
                filePath = Path.Combine(Helper.ClientPath, filePath);
                OpenFileInEditor(filePath, false);
            }
        }