Ejemplo n.º 1
0
 public void Clearup()
 {
     if (ComponentChanged == false)
     {
         return;
     }
     SEUndoUnitAbstract[] unitArray = new SEUndoUnitAbstract[this.Count];
     this.CopyTo(unitArray, 0);
     foreach (SEUndoUnitAbstract unit in unitArray)
     {
         SEUndoUnitFormDesigner undoUnitFormDesigner = unit as SEUndoUnitFormDesigner;
         if (undoUnitFormDesigner == null)
         {
             continue;
         }
         if (undoUnitFormDesigner.ComponentChanged)
         {
             if (undoUnitFormDesigner.Type == SEUndoUnitFormDesigner.UndoUnitType.ComponentAdded)
             {
                 IShellControlDev shellControlDev;
                 shellControlDev = undoUnitFormDesigner.Components as IShellControlDev;
                 Debug.Assert(shellControlDev != null, "Component没有实现IShellControlDev");
                 if (shellControlDev != null)
                 {
                     undoUnitFormDesigner.Entity = shellControlDev.Entity;
                 }
             }
         }
         else
         {
             this.Remove(unit);
         }
     }
 }
        /// <summary>
        /// 在组件已移除时发生
        /// 注意:在 DesignSurface Dispose 时,所有组件都会触发此事件
        /// 所以在 DesignSurface 的 Unloading 事件里注销了此事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void componentChangeService_ComponentRemoved(object sender, ComponentEventArgs e)
        {
            if (_designSurfaceUnloading)
            {
                return;
            }

            Control          control         = e.Component as Control;
            IShellControlDev shellControlDev = control as IShellControlDev;

            //将关联的实体对象从formEntity中删除
            this._windowEntity.Elements.Remove((UIElement)shellControlDev.Entity);

            ComponentListChanged = true;

            #region 封装可撤销的工作单元

            //这里也要考虑同时删除多个组件的可能,比如粘贴操作,需要把同时添加的多个组件封装为一个事务
            if (!_undoEngine.Working)
            {
                SEUndoUnitFormDesigner undoUnit = new SEUndoUnitFormDesigner("ComponentRemoved");
                undoUnit.Type       = SEUndoUnitFormDesigner.UndoUnitType.ComponentRemoved;
                undoUnit.Components = e.Component as IComponent;
                undoUnit.Entity     = shellControlDev.Entity;
                this._undoUnitList.Add(undoUnit);
            }

            #endregion

            Debug.WriteLine("删除了窗体对象:" + shellControlDev.Entity.Code);
            Debug.WriteLine("当前窗体元素个数:" + this._windowEntity.Elements.Count);
        }
Ejemplo n.º 3
0
        public int Add(string name, SEUndoUnitFormDesigner.UndoUnitType type, EntityBase entity, params SEUndoMember[] members)
        {
            SEUndoUnitFormDesigner undoUnit = new SEUndoUnitFormDesigner(name);

            undoUnit.Type   = type;
            undoUnit.Entity = entity;
            undoUnit.Members.AddRange(members);
            return(Add(undoUnit));
        }
        private void PropertyGrid_ObjectPropertyValueChanged(object sender, ObjectPropertyValueChangedEventArgs e)
        {
            #region 封装可撤销的工作单元

            if (ActiveHosting.Loaded)
            {
                SEUndoUnitFormDesigner undoUnit = new SEUndoUnitFormDesigner(e.PropertyName);
                undoUnit.Type   = SEUndoUnitFormDesigner.UndoUnitType.ComponentChanged;
                undoUnit.Entity = (EntityBase)e.RootObject;
                undoUnit.Value  = e.TargetObject;
                undoUnit.Members.Add(e.Row.PropertyName, e.OldValue, e.NewValue);
                ActiveHosting.AddUndoUnitList(undoUnit);

                Debug.WriteLine("封装可撤销的工作单元:" + undoUnit.ToString());
            }

            #endregion
        }
        /// <summary>
        /// 在组件属性发生更改时发生
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void componentChangeService_ComponentChanged(object sender, ComponentChangedEventArgs e)
        {
            if (_designSurfaceUnloading)
            {
                return;
            }



            if (this.HostingContainer.PropertyChanging)
            {
                return;
            }

            //同步到控件所关联的Entity中

            Control control = e.Component as Control;

            if (control == null)
            {
                return;
            }

            IShellControlDev shellControlDev = control as IShellControlDev;

            if (shellControlDev == null)
            {
                throw new NotImplementedException();
            }

            if (shellControlDev.Entity == null)
            {
                return;
            }

            if (shellControlDev.ViewUpdating)
            {
                return;
            }

            this._componentChanging = true;

            //在ComponentAdded之后,ComponentChanged会进来多次
            //虽然ComponentAdded事件中已经处理了控件的显示文本,但是最后一次进入ComponentChanged时
            //其显示文本又会是类型名开头的文本,不知道为什么,看调用堆栈是从Toolbox过来的
            //这里做个判断,若不同强制其更新使用Entity中的文本
            if (control.Text != shellControlDev.GetText())
            {
                control.Text = shellControlDev.GetText();
            }


            //start:这两行代码拿到Host_TransactionClosed里还不行
            //添加控件后触发Host_TransactionClosed事件中,
            //this._selectionService.GetSelectedComponents()取下来的不是添加的那个控件,而是根容器窗体,
            //或者说添加控件的父控件(暂没实现多级,这一说法未测,目前的情况就是窗体)
            //而如果是改变控件的ZOrder,进到这里时,取到的 e.Component是被改变的控件的父控件
            //需要到Host_TransactionClosed事件中,去同步实体对象以更新ZOrder
            //注意的是,撤销重做操作均不引发ComponentChanged和Host_TransactionClosed事件,需在Undo,Redo操作中同步ZOrder
            shellControlDev.UpdateEntity();

            //通知属性网格属性已更改
            //不能在这里判断_componentChanging,因为更新属性行上的属性值还是必须的
            //需要在属性值更新后引发的PropertyGrid_PropertyChanged事件中判断
            this.HostingContainer.UpdatePropertyGrid();
            //end

            #region 封装可撤销的工作单元


            if (!_undoEngine.Working)// && !e.NewValue.Equals(e.OldValue))
            {
                if (e.Member.Name != "Controls")
                {
                    SEUndoUnitFormDesigner undoUnit = new SEUndoUnitFormDesigner(e.Member.Name);
                    undoUnit.Type       = SEUndoUnitFormDesigner.UndoUnitType.ComponentChanged;
                    undoUnit.Components = e.Component as IComponent;
                    undoUnit.Entity     = shellControlDev.Entity;
                    undoUnit.Members.Add(e.Member.Name, e.OldValue, e.NewValue);
                    this._undoUnitList.Add(undoUnit);
                }
            }

            #endregion

            this._componentChanging = false;

            MakeDirty();

            Debug.WriteLine("对象属性已更新:" + shellControlDev.Entity.Code);
        }
        /// <summary>
        /// 在组件已添加时发生
        /// 此事件在 FormFormDesinger_Load 执行 InitialseFormElementsComponent() 后挂接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void componentChangeService_ComponentAdded(object sender, ComponentEventArgs e)
        {
            //这个事件里的代码主要是为添加的组件添加实体对象

            Control control = e.Component as Control;

            //如果是窗体,返回
            //这里不能和_rootComponentForm比较,_designSurface.CreateRootComponent执行后结果才会赋值到_rootComponentForm
            //另外窗体所对应的实体对象不在这里设置
            if (control is IWindowDesignerRootComponent)
            {
                return;
            }

            //为新增的组件绑定一个实体对象
            IShellControlDev shellControlDev = control as IShellControlDev;


            if (shellControlDev.Entity == null)
            {
                //shellControlDev.CreateEntity(this._formEntity);
                CreateEntity(shellControlDev);
                _windowEntity.Elements.Add((UIElement)shellControlDev.Entity);
            }
            else
            {
                if (this.WindowEntity.Elements.Contains(shellControlDev.Entity as UIElement) == false)
                {
                    UIElement formElementEntity = shellControlDev.Entity.Clone() as UIElement;

                    //要先清除,不能直接赋值
                    //因为IShellControlDev.Entity的set中有逻辑处理.会把set过来的Entity对象放到原Entity对象一样的FormEntity中
                    shellControlDev.ClearEntity();

                    shellControlDev.Entity = formElementEntity;

                    //添加实体对象到当前FormEntity.Elements中
                    this.WindowEntity.Elements.Add(formElementEntity);
                }
            }


            shellControlDev.UpdateView();

            ComponentListChanged = true;

            #region 封装可撤销的工作单元

            //这里也要考虑同时添加多个组件的可能,比如粘贴操作,需要把同时添加的多个组件封装为一个事务
            if (!_undoEngine.Working)
            {
                SEUndoUnitFormDesigner undoUnit = new SEUndoUnitFormDesigner("ComponentAdded");
                undoUnit.Type       = SEUndoUnitFormDesigner.UndoUnitType.ComponentAdded;
                undoUnit.Components = e.Component as IComponent;

                this._undoUnitList.Add(undoUnit);
            }

            #endregion

            Debug.WriteLine("增加了窗体对象:" + shellControlDev.Entity.Code + "( " + shellControlDev.Entity.GetType().Name + " )");
            Debug.WriteLine("当前窗体元素个数:" + this._windowEntity.Elements.Count);
        }