Пример #1
0
 /// <summary>Display the given script for editing.</summary>
 public void Edit(Scriptable scriptable, int which)
 {
     m_Scriptable    = scriptable;
     m_Script        = scriptable.Scripts[which];
     m_Page          = scriptable.FindPage();
     m_DefaultScript = m_Scriptable.GetDefaultScript((Scriptable.ScriptTypes)which, Globals.Root.CurrentDocument);
     FillUI();
 }
Пример #2
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);
            }
        }