Beispiel #1
0
        public void SetAction(Action Action)
        {
            //			if (!Action.WorksOnLayoutView)
            //			{	// das ist jetzt besser gelöst mit "OnlyThisView" etc.
            //				frame.AssureModelView(); // geht nur mit ModelView!
            //			}
            if (Action.ChangeTabInControlCenter)
            {
                Action.returnToTabPage = frame.GetActivePropertyDisplay();
                frame.ShowPropertyDisplay("Action");
            }
            Action.ActionStack = this;
            Action.OnSetAction(); // erstes Ereigniss für die neue Aktion (noch nicht auf dem Stack)
            Frame.RaiseActionStartedEvent(Action);
            Action OldAction = null;

            if (Actions.Count > 0)
            {
                OldAction = Actions.Peek() as Action;
            }
            // folgende Schleife ist notwendig, da bei Inactivate eine Aktion sich
            // selbst entfernen kann. Dann aber bekommt die drunterliegende ein Activate
            // was gleich wieder von einem Inactivate gefolgt werden muss
            while (OldAction != null)
            {
                OldAction.OnInactivate(Action, false); // alte Aktion inaktivieren (kann sich auch verabschieden)
                if (Actions.Count > 0)
                {
                    if (OldAction != Actions.Peek())
                    {
                        OldAction = Actions.Peek() as Action;
                    }
                    else
                    {
                        OldAction = null;
                    }
                }
                else
                {
                    OldAction = null;
                }
            }
            Actions.Push(Action);
            Action.OnActivate(OldAction, true);
        }
Beispiel #2
0
        public void RemoveActiveAction()
        {
            Action Action = ActiveAction;

            if (Action != null)
            {
                Action.OnInactivate(null, true);
                Actions.Pop();
                if (Action.ChangeTabInControlCenter)
                {
                    frame.ShowPropertyDisplay(Action.returnToTabPage);
                }
                Action NewActiveAction = ActiveAction;
                if (NewActiveAction != null)
                {
                    NewActiveAction.OnActivate(Action, false);
                }
                Action.OnRemoveAction();
                Frame.RaiseActionTerminatedEvent(Action);
            }
            else
            {
                throw new ActionException("RemoveActiveAction: There is no Action object on the action stack");
            }
            // der Autonmatismus, der eine Aktion automatisch wiederholen lässt.
            if (Action.AutoRepeat())
            {   // die Aktion soll automatisch wiederholt werden.
                System.Reflection.ConstructorInfo ci = Action.GetType().GetConstructor(new Type[] { });
                if (ci != null)
                {
                    object repaction = ci.Invoke(new object[] { });
                    if (repaction != null && repaction is Action)
                    {
                        (repaction as Action).AutoRepeated();
                        this.SetAction(repaction as Action);
                    }
                }
                else
                {       // 2. Versuch: gibt es einen Kontruktor, der genau den gleichen Aktionstyp als einzigen Parameter nimmt
                    ci = Action.GetType().GetConstructor(new Type[] { Action.GetType() });
                    if (ci != null)
                    {
                        try
                        {
                            object repaction = ci.Invoke(new object[] { Action });
                            if (repaction != null && repaction is Action)
                            {
                                (repaction as Action).AutoRepeated();
                                this.SetAction(repaction as Action);
                            }
                        }
                        catch (Exception e)
                        {
                            if (e is ThreadAbortException)
                            {
                                throw (e);
                            }
                        }
                    }
                }
            }
        }