Ejemplo n.º 1
0
        private void m_Engine_Trigger(bool isRepeat)
        {
            if (m_frmReport != null)
            {
                m_frmReport.SwitchActivated();
                return;
            }
            if (m_RepeatItem?.HasRepeatingScript ?? false)
            {             // currently doing custom repeats scripts
                if (CurrentConfig.ReadBoolean(Config.Repeat_PressStop) && !isRepeat)
                {
                    StopCustomRepeat();
                }
                // either way no further action is taken on this - the separate timer activates this
                return;
            }
            if (m_Continuous != null)
            {             // a command has captured the output to make a selection
                if (!m_Continuous.Trigger(isRepeat))
                {
                    m_Continuous?.Stop();                     // ? needed in case the command removed itself already
                    m_Continuous = null;
                }
                return;
            }
            var item = isRepeat ? m_RepeatItem : m_Current;

            if (item == null)             // usually this will be because repeating is not enabled on the last item, but also covers the case where nothing was selected for a genuine switch activation
            {
                return;
            }
            if (CurrentConfig.ReadBoolean(Config.Use_Swap_Switch))
            {
                LogicalSwapper.Swap = !LogicalSwapper.Swap && !item.ResetSwap;
            }
            // if item has ResetSwap then the state is forced to false
            // when repeating we explicitly use the remembered item -it may have selected something else as "current"
            //Debug.WriteLine("Trigger");
            var current = m_Current;

            if (isRepeat && item.HasRepeatingScript)
            {
                InvokeScript(item, Scriptable.ScriptTypes.Repeat, true, item);
            }
            else
            {
                InvokeScript(m_Current, Scriptable.ScriptTypes.Select);
            }
            if (!isRepeat)                                                                            // for first activation, set up repeating if needed.
            {                                                                                         // if item is not AutoRepeat, failing to set this will ensure the repeat triggers are ignored
                if (current.HasRepeatingScript)
                {                                                                                     // start up the timer for custom repeat scripts
                    m_RepeatItem = current;
                    InvokeScript(m_RepeatItem, Scriptable.ScriptTypes.PreRepeat, true, m_RepeatItem); // this one fires immediately.
                    m_RepeatTimer.Interval = m_Engine.ConfiguredTiming(Switches.Engine.Timings.FirstRepeat);
                    m_RepeatTimer.Enabled  = true;
                }
                else if (current.AutoRepeat)
                {
                    m_RepeatItem = current;
                }
            }
        }