Example #1
0
        /// <summary>
        /// 在指定位置插入字符
        /// </summary>
        public bool Insert(int offsert, string text, Caret caret)
        {
            InsertOperate operate = InsertOperate.None;
            Block         segment = null;

            return(Insert(offsert, text, caret, ref operate, ref segment));
        }
Example #2
0
        /// <summary>
        /// 在指定位置插入字符
        /// </summary>
        public bool Insert(int offsert, string text, Caret caret, ref InsertOperate operate, ref Block segment)
        {
            int   insertLocation = 0;
            Block nearSegment    = GetLineSegmentBeforeCaret(offsert, ref insertLocation);
            int   index          = 0;

            if (nearSegment != null)
            {
                index = m_lstBlock.IndexOf(nearSegment);
            }
            // 如果说当前行为首行的话,创建新的节点,并将新的节点做为当前节点的子节点,新节点自动换下一行并增加四个空格作为缩进
            // <first>
            //     <second>
            //     </second>
            // </first>
            // 这种排版主要为了规避当前展示时的对象结构为一行属于一个节点,而编辑时很有可能一行属于多个节点,自动进行格式设置,规避此种问题的出现

            // 若当前光标落在节点名、属性名、属性值、文本等可直接插入字符对这些内容进行补充
            if (nearSegment != null)
            {
                nearSegment.Text = nearSegment.Text.Insert(insertLocation, text);
                caret.Column    += 1;
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Updates the intellisense box's elements to show the right object list.
        /// </summary>
        /// <param name="forceNextLevel"></param>
        /// <param name="word"></param>
        /// <param name="justRead"></param>
        /// <returns></returns>
        public bool UpdateIntellisense(bool forceNextLevel, string keyWord, string justRead, InsertCharEventArgs args)
        {
            //_node = args.Node;
            _args    = args;
            _operate = args.Operate;
            //Clear all elements
            m_IntellisenseBox.Items.Clear();
            bool needShow = false;

            switch (args.Operate)
            {
            case InsertOperate.InsertNodeName:

                //List<string> lstElement = m_editor.EditController.GetElementLists(_node.Parent.Name, _node.GetLastNodeName(), _node.GetSameLevelNodeName());
                //if (lstElement.Count > 0)
                //{
                //    foreach (string element in lstElement)
                //    {
                //        IntellisenseListItem li = new IntellisenseListItem();
                //        li.Text = m_editor.LanguageReader.GetDisplayText(element);
                //        li.Image = Properties.Resources.Element;
                //        li.Tag = element;
                //        m_IntellisenseBox.Items.Add(li);
                //    }
                //    needShow = true;
                //}
                break;

            case InsertOperate.InsertAttrName:

                ///已经存在的属性
                //List<string> existAttr = new List<string>();

                //foreach (VXmlAttribute attr in _node.Attributes)
                //{
                //    existAttr.Add(attr.Name);
                //}
                //List<string> lstAttr = m_editor.EditController.GetAttributeList(_node.Name, existAttr);
                //if (lstAttr.Count > 0)
                //{
                //    foreach (string attr in lstAttr)
                //    {
                //        IntellisenseListItem li = new IntellisenseListItem();
                //        li.Text = m_editor.LanguageReader.GetDisplayText(attr);
                //        li.Tag = attr;
                //        li.Image = Properties.Resources.Attribute;

                //        m_IntellisenseBox.Items.Add(li);
                //    }
                //    needShow = true;
                //}

                break;

            case InsertOperate.InsertAttrValue:
                //string attrName = (args.Segment as AttrValueSegment).Attribute.Name;
                //List<string> lstValue = m_editor.EditController.GetAttributeEnumList(attrName);
                //if (lstValue.Count > 0)
                //{
                //    foreach (string attrValue in lstValue)
                //    {
                //        IntellisenseListItem li = new IntellisenseListItem();
                //        li.Text = m_editor.LanguageReader.GetDisplayText(attrValue);
                //        li.Tag = attrValue;
                //        li.Image = Properties.Resources.Attribute;

                //        m_IntellisenseBox.Items.Add(li);
                //    }
                //    needShow = true;
                //}

                break;
            }
            if (needShow)
            {
                //Show box
                ShowIntellisenseBoxWithoutUpdate();
            }
            else
            {
                HideIntellisenseBox();
            }
            return(true);
        }