Exemplo n.º 1
0
        /// <summary>Run one of the scripts on the item.  If noVisit then the VisitItem is not used (but explicit Visit scripts would still run)
        /// The item which acts as the context can be provided, but is the Current/selected item normally (NOT the item on which the script is invoked - exec commands still
        /// run in the context of the pressed button)</summary>
        public void InvokeScript(Scriptable item, Scriptable.ScriptTypes which, bool noVisit = false, Scriptable contextItem = null)
        {
            //Debug.WriteLine("Invoke script " + which + " on " + item.Description);
            Script script = item.GetScript(which);

            if (contextItem == null)
            {
                contextItem = m_Current;
            }
            // find defaults first, if needed (unlike SAW6 this is possible even if there are genuine scripts)
            Script def = null;

            if (script?.RunDefault ?? true)             // if object missing entirely(?!?) default is used
            {
                def = item.GetDefaultScript(which, m_Document);
            }
            Scriptable originalCurrent = m_Current;            // used below to detect if a custom visit script changed the selection

            Command.ExecutionContext context = new Command.ExecutionContext(contextItem, this, m_Page, m_Document, m_Engine, which);
            if (def != null)
            {
                InvokeScriptCommands(def, context);
            }
            if ((script?.CommandList?.Count ?? 0) != 0)             // either null object, or no commands (only latter possible?) either counts the same
            {
                InvokeScriptCommands(script, context);
            }

            if (noVisit || context.Terminate)
            {
                return;
            }
            // however the default visit is done after any custom commands
            Scriptable target = null;

            if (script != null)
            {
                target = ResolveVisitTarget(script.Visit, contextItem); // 8.0.4 changed to context from Item -
            }
            if (target == null && def != null)                          // default is only used if self is set to None:
            {
                target = ResolveVisitTarget(def.Visit, contextItem);
            }
            if (target == null && which == Scriptable.ScriptTypes.Next && originalCurrent == m_Current)
            {
                target = item;                 // a Next script which references nothing useful should re-select the same item // but only if a custom script didn't make a selection
            }
            if (target != null)
            {
                SelectItem(target, false);
            }
        }
Exemplo n.º 2
0
        private void StartScanOnDocument()
        {         // called when first scanning OR document changes while scannign
            m_Continuous = null;
            IterateScriptable(s => { if (s.Popup)
                                     {
                                         s.Shown = false;
                                     }
                              });
            LastPopupShown = null;
            SavedPopup     = null;
            m_WordPredictionContainers.Clear();

            Command.ExecutionContext context = new Command.ExecutionContext(null, this, m_Page, m_Document, m_Engine, Scriptable.ScriptTypes.Select);
            InvokeScriptCommands(m_Document.StartupScript, context);
        }
Exemplo n.º 3
0
 /// <summary>Runs the actual commands, without any defaults, or the Visit part.
 /// contextItem may be null for startup script</summary>
 private void InvokeScriptCommands(Script script, Command.ExecutionContext context)
 {
     if (script == null)             // I don't think this is actually allowed, but in case
     {
         return;
     }
     foreach (Command c in script.CommandList)
     {
         //Debug.WriteLine("Execute: " + c.GetScriptWithParams(false));
         c.Execute(context);
         if (context?.Terminate == true)
         {
             break;
         }
     }
 }