コード例 #1
0
ファイル: ZYTextBlock.cs プロジェクト: xuanximoming/key
        //双击弹出窗口
        public override bool HandleDblClick(int x, int y, MouseButtons Button)
        {
            this.Clicked = true;

            //当前字符,用于判断是否在[]{}中
            ZYTextElement curChar = this.OwnerDocument.GetElementByPos(x, y);
            //Debug.WriteLine("block handledbclick 当前元素 " + curChar);

            //选项的字符串
            StringBuilder str = new StringBuilder();

            this.GetFinalText(str);
            int m = this.ChildElements.IndexOf(curChar);

            int tmpindex = -1;

            //方括号[]的配对索引
            List <int> start = new List <int>();
            List <int> end   = new List <int>();

            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == '[')
                {
                    start.Add(i);
                }
                if (str[i] == ']')
                {
                    end.Add(i);
                }
            }

            //花括号{}的配对索引
            List <int> startm = new List <int>();
            List <int> endm   = new List <int>();

            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == '{')
                {
                    startm.Add(i);
                }
                if (str[i] == '}')
                {
                    endm.Add(i);
                }
            }

            foreach (ZYTextElement ele in this.ChildElements)
            {
                if (ele.Bounds.Contains(x, y))
                {
                    this.Clicked = true;

                    if (this is ZYSelectableElement)
                    {
                        //如果当前字是选项模板中的一个,则替换模板
                        //替换子模板
                        //并把原有选项中内容展开,把[xxx]转换成真正的模板元素
                        ArrayList al = new ArrayList();
                        if (ele == curChar)
                        {
                            #region bwy //循环[]匹配的组
                            for (int i = 0; i < start.Count; i++)
                            {
                                if (start[i] < m && m < end[i])
                                {
                                    //弹出将要展开模板的警告
                                    if (MessageBox.Show("确定要将选项展开为模板吗?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
                                    {
                                        return(true);
                                    }
                                    else
                                    {
                                        this.OwnerDocument.BeginUpdate();
                                        this.OwnerDocument.BeginContentChangeLog();

                                        tmpindex = i;
                                        //展开
                                        this.OwnerDocument._Delete();
                                        string f       = "[]";
                                        bool   isintmp = false;
                                        string tmpname = "";
                                        foreach (char c in str.ToString())
                                        {
                                            if (f.IndexOf(c) == 0)
                                            {
                                                isintmp = true;
                                                tmpname = "";
                                                continue;
                                            }
                                            if (f.IndexOf(c) == 1)
                                            {
                                                isintmp = false;
                                                //插入名为tmpname的模板
                                                ZYTemplate tmp = new ZYTemplate();
                                                tmp.Name          = tmpname;
                                                tmp.Parent        = this.Parent;
                                                tmp.OwnerDocument = this.OwnerDocument;
                                                this.OwnerDocument._InsertBlock(tmp);

                                                al.Add(tmp);

                                                continue;
                                            }
                                            if (isintmp)
                                            {
                                                tmpname += c;
                                            }
                                            else
                                            {
                                                this.OwnerDocument.Content.InsertString(c.ToString());
                                            }
                                        }
                                        ZYTemplate tmp2 = al[tmpindex] as ZYTemplate;
                                        this.OwnerDocument.Content.CurrentElement = tmp2.FirstElement;
                                        tmp2.HandleDblClick(tmp2.FirstElement.RealLeft, tmp2.FirstElement.RealTop, Button);

                                        this.OwnerDocument.Content.SelectLength = 0;
                                        this.OwnerDocument.EndContentChangeLog();
                                        this.OwnerDocument.EndUpdate();

                                        Debug.WriteLine("应该展开模板 " + (al[tmpindex] as ZYTemplate).Name);
                                        return(true);
                                    }
                                }
                            }
                            #endregion bwy

                            #region bwy 循环{}匹配的每一组
                            for (int j = 0; j < startm.Count; j++)
                            {
                                //如果当前元素在某个提示中间
                                if (startm[j] < m && m < endm[j])
                                {
                                    //弹出录入提示
                                    string tmpname = str.ToString().Substring(startm[j] + 1, endm[j] - startm[j] - 1);
                                    //弹出名为tmpname的录入提示
                                    ZYPromptText p = new ZYPromptText();
                                    p.Name          = tmpname;
                                    p.Parent        = this.Parent;
                                    p.OwnerDocument = this.OwnerDocument;

                                    FormatFrm HelpWinx = new FormatFrm(p, this as ZYSelectableElement, startm[j], endm[j]);
                                    HelpWinx.Show();
                                    return(true);
                                }
                            }
                            #endregion bwy
                        }

                        ImplementFrm HelpWin = new ImplementFrm((ZYSelectableElement)this);
                        HelpWin.Show();
                        //Debug.WriteLine("显示弹出窗口OK");
                        return(true);
                    }
                    if (this is ZYFormatDatetime || this is ZYFormatNumber || this is ZYFormatString || this is ZYPromptText)
                    {
                        FormatFrm HelpWin = new FormatFrm(this);
                        HelpWin.Show();
                        return(true);
                    }

                    if (this is ZYTemplate)
                    {
                        this.OwnerDocument.ReplaceTemplate(this.Type, this.Name);
                        return(true);
                    }

                    if (this is ZYReplace)
                    {
                        TextBoxFrm TextWin = new TextBoxFrm(this);
                        TextWin.ShowDialog();
                        return(true);
                    }
                    if (this is ZYLookupEditor)
                    {
                        LookupEditorForm TextWin = new LookupEditorForm(this);
                        if (TextWin.NormalWordBook == null || TextWin.NormalWordBook == "")
                        {
                            return(false);
                        }
                        TextWin.ShowDialog();
                        return(true);
                    }
                }
            }

            return(base.HandleDblClick(x, y, Button));
        }
コード例 #2
0
 public PropertyPromptText(object o)
     : base(o)
 {
     _e = (ZYPromptText)o;
 }