示例#1
0
文件: Command.cs 项目: stuart2w/SAW
 public ExecutionContext(Scriptable target, RunView view, Page page, Document doc, Switches.Engine scanEngine, Scriptable.ScriptTypes scriptType)
 {
     TargetItem = target;
     View       = view;
     Page       = page;
     Document   = doc;
     ScanEngine = scanEngine;
     ScriptType = scriptType;
 }
示例#2
0
文件: RunView.cs 项目: stuart2w/SAW
        /// <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);
            }
        }