示例#1
0
        /// <summary>
        /// 设置文本
        /// </summary>
        /// <param name="newText">新文本</param>
        /// <param name="flags">标记</param>
        /// <param name="disablePermissioin">禁止权限控制</param>
        /// <returns>操作是否修改了对象内容</returns>
        public bool SetEditorTextExt(string newText, DomAccessFlags flags, bool disablePermissioin, bool updateContent)
        {
            bool result = false;

            if (this.OwnerDocument != null)
            {
                string oldText = this.Text;
                if (oldText == null || oldText != newText)
                {
                    // 为了提高效率,只有出现不同的文本才进行文本替换操作
                    bool innerLogUndo = this.OwnerDocument.CanLogUndo;
                    if (innerLogUndo == false)
                    {
                        this.OwnerDocument.BeginLogUndo();
                    }
                    if (string.IsNullOrEmpty(newText))
                    {
                        // 直接设置空内容
                        ReplaceElementsArgs args = new ReplaceElementsArgs(
                            this,
                            0,
                            this.Elements.Count,
                            null,
                            true,
                            true,
                            true);
                        args.DisablePermission = disablePermissioin;
                        args.AccessFlags       = flags;
                        args.ChangeSelection   = false;
                        args.UpdateContent     = updateContent;
                        if (args.DisablePermission == false &&
                            this.OwnerDocument.Options.SecurityOptions.EnablePermission)
                        {
                            // 很多时候,本属性是为下拉列表文本输入域调用的,此时输入域前面的文本可能是被
                            // 当前用户输入的,后面的元素已经被逻辑删除了,此时应该应该是执行物理删除,
                            // 在此进行判断,修正删除区间。
                            for (int iCount = 0; iCount < this.Elements.Count; iCount++)
                            {
                                DomElement element = this.Elements[iCount];
                                if (element.Style.DeleterIndex >= 0)
                                {
                                    bool fix = true;
                                    for (int iCount2 = iCount; iCount2 < this.Elements.Count; iCount2++)
                                    {
                                        if (this.Elements[iCount2].Style.DeleterIndex < 0)
                                        {
                                            fix = false;
                                            break;
                                        }
                                    }
                                    if (fix)
                                    {
                                        args.DeleteLength = iCount;
                                    }
                                    break;
                                }
                            }//for
                        }
                        result = this.OwnerDocument.ReplaceElements(args) != 0;
                    }
                    else
                    {
                        // 设置文本内容
                        DomElementList list = this.OwnerDocument.CreateTextElements(newText, null, this.Style);
                        if (list != null && list.Count > 0)
                        {
                            ReplaceElementsArgs args = new ReplaceElementsArgs(
                                this,
                                0,
                                this.Elements.Count,
                                list,
                                true,
                                true,
                                true);
                            args.DisablePermission = disablePermissioin;
                            args.AccessFlags       = flags;
                            args.ChangeSelection   = false;
                            args.UpdateContent     = updateContent;
                            if (args.DisablePermission == false &&
                                this.OwnerDocument.Options.SecurityOptions.EnablePermission)
                            {
                                // 很多时候,本属性是为下拉列表文本输入域调用的,此时输入域前面的文本可能是被
                                // 当前用户输入的,后面的元素已经被逻辑删除了,此时应该应该是执行物理删除,
                                // 在此进行判断,修正删除区间。
                                for (int iCount = 0; iCount < this.Elements.Count; iCount++)
                                {
                                    DomElement element = this.Elements[iCount];
                                    if (element.Style.DeleterIndex >= 0)
                                    {
                                        bool fix = true;
                                        for (int iCount2 = iCount; iCount2 < this.Elements.Count; iCount2++)
                                        {
                                            if (this.Elements[iCount2].Style.DeleterIndex < 0)
                                            {
                                                fix = false;
                                                break;
                                            }
                                        }
                                        if (fix)
                                        {
                                            args.DeleteLength = iCount;
                                        }
                                        break;
                                    }
                                }//for
                            }
                            result = this.OwnerDocument.ReplaceElements(args) != 0;
                        }
                    }
                    if (innerLogUndo == false)
                    {
                        if (result)
                        {
                            this.OwnerDocument.EndLogUndo();
                        }
                        else
                        {
                            this.OwnerDocument.CancelLogUndo();
                        }
                    }
                    if (result)
                    {
                        this.OwnerDocument.OnDocumentContentChanged();
                        this.OwnerDocument.OnSelectionChanged();
                    }
                }
            }
            else
            {
                DomElementList list = this.SetInnerTextFast(newText);
                result = list != null && list.Count > 0;
            }
            return(result);
        }
示例#2
0
 /// <summary>
 /// 设置文本
 /// </summary>
 /// <param name="newText">新文本</param>
 /// <param name="flags">标记</param>
 /// <param name="disablePermissioin">禁止权限控制</param>
 /// <returns>操作是否修改了对象内容</returns>
 public bool SetEditorTextExt(string newText, DomAccessFlags flags, bool disablePermissioin)
 {
     return(SetEditorTextExt(newText, flags, disablePermissioin, true));
 }