Beispiel #1
0
        /// <summary>
        /// Fügt einen neuen Eintrag in die Undo-Liste ein, wenn ein neues Control angelegt wird.
        /// </summary>
        /// <param name="ctl"></param>
        public void AddNew(HitbaseControl ctl)
        {
            if (!initialized)
            {
                return;
            }

            if (currentUndoStep == null)
            {
                throw new Exception("BeginUndoStep must be called first.");
            }

            UndoEntry entry = new UndoEntry();

            entry.undoAction = UndoAction.New;
            entry.controlID  = ctl.ControlID;
            if (ctl.Parent == null)
            {
                entry.parentControlID = 0;      // Hat keinen Parent
            }
            else
            {
                entry.parentControlID = ctl.Parent.ControlID;
            }
            currentUndoStep.undoEntry.Push(entry);
        }
Beispiel #2
0
        /// <summary>
        /// Führt einen einzelnen Undo-Step aus.
        /// </summary>
        /// <param name="step"></param>
        private void DoUndoStep(UndoStep step)
        {
            while (step.undoEntry.Count > 0)
            {
                UndoEntry entry = step.undoEntry.Pop();

                switch (entry.undoAction)
                {
                case UndoAction.ChangeProperty:
                {
                    // Property-Änderung rückgängig machen.
                    HitbaseControl hlControl = mainWindowControl.FindHitbaseControlFromID(entry.controlID);

                    mainWindowControl.ChangeProperty(hlControl, entry.property, entry.value);

                    break;
                }

                case UndoAction.Delete:
                {
                    // Löschen eines Objektes rückgängig machen.
                    HitbaseControl newControl = mainWindowControl.AddControlFromStream(entry.parentControlID, entry.controlIndex, entry.serializedObject, true);
                    newControl.SetTabIndex(entry.tabIndex);
                    break;
                }

                case UndoAction.New:
                {
                    HitbaseControl ctl = mainWindowControl.FindHitbaseControlFromID(entry.controlID);
                    HitbaseControl parent;

                    if (entry.parentControlID != 0)
                    {
                        parent = mainWindowControl.FindHitbaseControlFromID(entry.controlID);
                    }
                    else
                    {
                        parent = null;
                    }

                    mainWindowControl.DeleteHitbaseControlWithChilds(parent, ctl);
                    break;
                }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Fügt einen neuen Eintrag in die Undo-Liste ein, wenn eine Property eines Controls geändert wird.
        /// </summary>
        /// <param name="controlID"></param>
        /// <param name="prop"></param>
        /// <param name="value"></param>
        public void AddPropertyChange(int controlID, string prop, object value)
        {
            if (!initialized)
            {
                return;
            }

            if (currentUndoStep == null)
            {
                throw new Exception("BeginUndoStep must be called first.");
            }

            UndoEntry entry = new UndoEntry();

            entry.undoAction = UndoAction.ChangeProperty;
            entry.controlID  = controlID;
            entry.property   = prop;
            entry.value      = value;
            currentUndoStep.undoEntry.Push(entry);
        }
Beispiel #4
0
        /// <summary>
        /// Fügt einen neuen Eintrag in die Undo-Liste ein, wenn ein Control gelöscht wird.
        /// </summary>
        /// <param name="ctl"></param>
        public void AddDelete(HitbaseControl ctl)
        {
            if (!initialized)
            {
                return;
            }

            if (currentUndoStep == null)
            {
                throw new Exception("BeginUndoStep must be called first.");
            }

            UndoEntry entry = new UndoEntry();

            entry.undoAction = UndoAction.Delete;
            entry.controlID  = ctl.ControlID;

            BinaryFormatter bf  = new BinaryFormatter();
            MemoryStream    mem = new MemoryStream();

            bf.Serialize(mem, ctl);
            entry.serializedObject = mem.ToArray();
            mem.Close();

            if (ctl.Parent == null)
            {
                entry.parentControlID = 0;
            }
            else
            {
                entry.parentControlID = ctl.Parent.ControlID;
                entry.controlIndex    = ctl.Parent.GetChildIndex(ctl);
                entry.tabIndex        = ctl.GetTabIndex();
            }

            currentUndoStep.undoEntry.Push(entry);
        }