Dear experts,
To be able to navigate to any variable in the document (used on any page type) I first collect all information about the variables. The arry elements are built by the prototype function (is this the correct term?)
function oVariable (sName, sContents, oVar, bUsed, bSystem, oTr, sPageType, iPageNr, sPageName) { this.Name = sName; // Name of variable this.Contents = sContents; // Contents of variable this.VarObj = oVar; // Var object in document this.VarUsed = bUsed; // User var is used in document this.IsSystem = bSystem; // true for system variable this.TextRange= oTr; // textrange of this occurance in the doc this.PageType = sPageType; // BodyPage or ... where var was found this.PageNr = iPageNr; // for BodyPage this.PageName = sPageName; // for the other types } //--- end oVariable
In a loop through the variables I fill the global array of objects, which works fine.
For the following don't worry about the goFMc prefix: it is the name of the global object holding all stuff.
function GetVarsInDoc (oDoc) { //=== Fill the doc variables array with all found vars in Doc ====== var bIsSystem, bIsUsed, oPage, oTR, oVar, index, iPageType, sPageType, sVarName, sVarContents; goFMc.aDocVars.length = 0; // clear array for new build up oVar = oDoc.FirstVarInDoc; // the variable in the text while (oVar.ObjectValid()) { sVarName = oVar.VarFmt.Name; // name of the variable sValue = oVar.VarFmt.Fmt; // contents of variable oTR = oVar.TextRange; // the text range of the variable bIsSystem= (oVar.VarFmt.SystemVar !== Constants.FV_VAR_USER_VARIABLE); bIsUsed = UsrVarIsUsed (oDoc, sVarName); goFMc.aDocVars.push (new oVariable (sVarName, sValue, oVar, bIsUsed, bIsSystem, oTr, null, null)); // array element oDoc.ScrollToText(oTR); // Go there to get page type oPage = oDoc.CurrentPage; sPageType = oPage.constructor.name; // BodyPage, MasterPage, RefPage [Rick Quatro] index = goFMc.aDocVars.length - 1; // use current array entry goFMc.aDocVars[index].PageType = sPageType; if (sPageType == "BodyPage") { goFMc.aDocVars[index].PageNr = oPage.PageNum; } else if (sPageType == "MasterPage") { goFMc.aDocVars[index].PageName = oPage.Name; } else if (sPageType == "RefPage") { goFMc.aDocVars[index].PageName = oPage.Name; } oVar = oVar.NextVarInDoc; } goFMc.nDocVars = goFMc.aDocVars.length; } //--- end GetVarsInDoc
To get to the first variable in the document I have the following function in the dialogue:
function ButtonFirst () { //=== Go to first variable in document ================================== var bSystemVar, iVar, jVar, oVar, sName; iVar =0; // index in doc variable array goFMc.indexDocVars = iVar; // keep for other nav buttons oVar = goFMc.aDocVars[iVar].VarObj; // first item in doc variable array sName = goFMc.aDocVars[iVar].Name; bSystemVar = goFMc.aDocVars[iVar].IsSystem; DisplayVariable (goFMc.oCurrentDoc, iVar); // can be on any page type // ... } //--- end ButtonFirst
Relevant data (the ingredients) from goFMc.aDocVars[0] for DisplayVariable is
Name = Running H/F 1 Contents = <$paratext[0chapter-title]> VarObj = // Var object in document VarUsed = false // User var is used in document IsSystem = true TextRange= // textrange of this occurance in the doc PageType = MasterPage PageName = Left
The user normally start on the body pages, while many variables can be on the master pages and even on the reference pages. Hence the display should switch between the various page types. However, in my test case the variable is on the first master page - but the display is still the current body page.
My question now is: why does DisplayVariable not jump to the appropriate page type and show the selected variable?
After executing ButtonFirst I can manually switch to the master pages where I see the variable selected on the very first one.
function DisplayVariable (oDoc, iVar) { //=== display the indexed variable ======================== var oTR; oTR = goFMc.aDocVars[iVar].TextRange; oDoc.TextSelection = oTR; oDoc.ScrollToText(oTR); } //--- end DisplayVariable
When switching manually to the last master page before I use the button then the display is correct.
But how can I make the function automatically go to the relvant page type?
I have the necessary ingredients, but no recipe...
Any ideas are welcome
Klaus