#include pragma runLim, 0 ////////////////////////////////////////////// // Variables const Module m = current const Folder f = current if ( null m ) { warningBox "Please run this script from a module."; halt } const string dummy[] = {} DB mainDB, editDB, diffDB DBE linkSetListView, editButton, sourceModField, targetModField, targetBrowseButton, linkModField, linkBrowseButton, optionsRadioBox, okButton, difftextbox string oldLinkMod = null string oldTgtMod = null Skip cLinks = create () Skip LinkPairings = create () const string Notfound = "Notfound" const string foundMod = "foundMod" const string foundLnk = "foundLnk" int doSortString(string s1, string s2) { return(cistrcmp(s1, s2)) } int doSortStringReverse(string s1, string s2) { return(cistrcmp(s2, s1)) } int doSortInt(string str1, string str2) { int s1 = intOf(realOf(str1)) int s2 = intOf(realOf(str2)) int Result = 0 if (s1 == s2) Result = 0 elseif (s1 > s2) Result = 1 elseif (s1 < s2) Result = -1 else{} return(Result) } bool createLinksetPair(string src, string trg, string linkModName) { // Adds linkModuleDescriptor entry bool mandatory = true bool overridable = !mandatory bool exclusive = true bool ret = true if (null f){ errorBox ("Could not access the folder containing module " src ) //return false } string res = "" res = addLinkModuleDescriptor(f, src, trg, overridable, mandatory, linkModName, "") if (!null res) { // Possible duplicate entry of combination src->trg //print (res " (" src "->" trg ")\n" ) res = removeLinkModuleDescriptor(f,src,trg) //print ("Removed entry " src "->" trg "via link module" linkModName) ret = createLinksetPair(src,trg,linkModName) } if (!null res) { errorBox(res) ret = false } else { setLinkModuleDescriptorsExclusive(f, module src,exclusive) //print ("Created entry " src "->" trg "via link module" linkModName "\n") } return ret } void getLinkParingVsLinks() { LinkModuleDescriptor LMD = null Link l = null Object osrc = null ModName_ otherMod = null Object othero = null string err = null string tgtMod = null string linkMod = null Skip addLinkPairings = create () bool isManditory = false if(get(optionsRadioBox) == 0) { isManditory = true } for LMD in f do { if (getSourceName(LMD) "" == fullName(m)"") { put(LinkPairings, getTargetName(LMD) "", LMD) } } for osrc in entire m do { if(null osrc) continue if(isDeleted osrc) continue for l in all(osrc->"*") do { ModuleVersion otherVersion = targetVersion l otherMod = module(otherVersion) if (null otherMod || isDeleted otherMod) {delete otherVersion; continue} othero = target l if (null othero) {load(otherVersion,false)} othero = target l if (null othero) {delete otherVersion; continue} if (isDeleted othero) {delete otherVersion; continue} LMD = null if(find(LinkPairings, fullName(module(othero)) "", LMD)) { if(fullName(module(l)) == name(LMD) "") { delete(LinkPairings, getTargetName(LMD) "") } } if(find(LinkPairings, fullName(module(othero)) "", LMD)) { if(fullName(module(l)) != name(LMD) "") { put(addLinkPairings, fullName(module(othero)) "" fullName(module(l)) "", l) } } delete otherVersion } } for LMD in LinkPairings do { err = null if ( confirm "WARNING: do you want to remove this [" getTargetName(LMD) "] unused Linkpairing Decription\n" //- "\t\t\t via [" name(LMD) "] LinkModule?\n\nContinue?") { err = removeLinkModuleDescriptor(f, fullName(m) "", getTargetName(LMD)"") if(!null err) { ack err } } } for l in addLinkPairings do { err = null othero = target l tgtMod = fullName(module(othero)) linkMod = fullName(module(l)) if ( confirm "WARNING: do you want to add this [" tgtMod "] Linkpairing Decription\n" //- "\t\t\t via [" fullName(module(l)) "] LinkModule?\n\nContinue?") { err = addLinkModuleDescriptor(f, fullName(m) "", tgtMod, !isManditory, isManditory, linkMod, "") if(!null err) { ack err "\n\nPlease Check that all Link(s) are they going through the correct [LinkModule]!" } } } delete addLinkPairings } string diffLinks() { Link l ModName_ otherMod = null Object othero = null Object osrc = null Buffer skp = create (); skp = "" //Store/Display Links for osrc in entire m do { if(null osrc) continue //if(isDeleted osrc) continue for l in all(osrc->"*") do { ModuleVersion otherVersion = targetVersion l otherMod = module(otherVersion) if (null otherMod || isDeleted otherMod) {delete otherVersion; continue} othero = target l if (null othero) {load(otherVersion,false)} othero = target l if (null othero) {delete otherVersion; continue} if (isDeleted othero) {delete otherVersion; continue} if(isDeleted osrc) { skp += "Softdeleted - " } skp += fullName(module(osrc)) "-" probeAttr_(osrc,"Absolute Number") "\t->\t[" fullName(module(l)) "]\t->\t" fullName(otherMod) "-" probeAttr_(othero,"Absolute Number") //skp += fullName(module(osrc)) "-" probeAttr_(osrc,"Absolute Number") "\t->\t" fullName(otherMod) "-" probeAttr_(othero,"Absolute Number") if (isBaseline(otherVersion)) {skp += " [" versionString(otherVersion) "]"} skp += "\n" delete otherVersion } } string temp = stringOf(skp) delete skp return temp } void getLinkSets() { empty(linkSetListView) setempty(cLinks) Link l = null Object osrc = null AttrDef Ad = null ModName_ otherMod = null Object othero = null string text = null int cnt = 0 //Store/Display Links for osrc in entire m do { if(null osrc) continue //if(isDeleted osrc) continue for l in all(osrc->"*") do { ModuleVersion otherVersion = targetVersion l otherMod = module(otherVersion) if (null otherMod || isDeleted otherMod) {delete otherVersion; continue} othero = target l if (null othero) {load(otherVersion,false)} othero = target l if (null othero) {delete otherVersion; continue} if (isDeleted othero) {delete otherVersion; continue} insert(linkSetListView, cnt, probeAttr_(osrc,"Absolute Number"), iconNone) if(isDeleted osrc) { set(linkSetListView, cnt, 0, iconLinkDeleted) set(linkSetListView, cnt, 7, "DELETED") } text = "(Inaccessible)" Ad = find(module othero, "Object Heading") if (!null Ad and canRead(module othero, "Object Heading")) { text = probeAttr_(othero, "Object Heading") } if (null text) { Ad = find(module othero,"Object Text") if(!null Ad and canRead(module othero, "Object Text")) { text = probeAttr_(othero, "Object Text") } else { text = "(Inaccessible)" } } set(linkSetListView, cnt, 1, text) set(linkSetListView, cnt, 2, fullName(otherVersion)) set(linkSetListView, cnt, 3, probeAttr_(othero,"Absolute Number")) text = "(Inaccessible)" Ad = find(module osrc, "Object Heading") if (!null Ad and canRead(module osrc, "Object Heading")) { text = probeAttr_(osrc, "Object Heading") } if (null text) { Ad = find(module osrc, "Object Text") if(!null Ad and canRead(module osrc, "Object Text")) { text = probeAttr_(osrc, "Object Text") } else { text = "(Inaccessible)" } } set(linkSetListView, cnt, 4, text) set(linkSetListView, cnt, 5, fullName(module(l))) if (isBaseline(otherVersion)) { set(linkSetListView, cnt, 6, "[" versionString(otherVersion) "]") } set(linkSetListView, cnt, 8, cnt"") put(cLinks, cnt++, l) delete otherVersion } } } void diffx(Buffer &buff1, Buffer &buff2) { //print tempStringOf(buff1) "\n\n\n\n" tempStringOf(buff2) Buffer resBuf = create() diff(resBuf, buff1, buff2, true) realize diffDB useRTFColour(difftextbox, true) set(difftextbox, tempStringOf resBuf) show diffDB delete resBuf } void doUpdateLinks(DB x) { if (!isEdit(m) and !isShare(m)) { edit(fullName(m),false) if (isRead m) { warningBox "Source module '" fullName(m) "' must be open editable!" return } } Link l = null Object osrc = null Object otgt = null int max = noElems(linkSetListView) int index = 0 int cIndex = 0 bool isManditory = false string linkMod = get(linkModField) string err = null string tgtMod = null Buffer firstrun = create (0); firstrun = diffLinks() Buffer secondrun = create (0); secondrun = "" if(get(optionsRadioBox) == 0) { isManditory = true } for index in 0:max-1 do { cIndex = intOf(realOf(getColumnValue(linkSetListView, index, 8))) tgtMod = getColumnValue(linkSetListView, index, 2) oldLinkMod = getColumnValue(linkSetListView, index, 5) err = null if (selected(linkSetListView,index)) { if (getColumnValue(linkSetListView, index, 7) "" == "DELETED") { continue } if(find(cLinks, cIndex, l)) { if((linkMod != oldLinkMod) && (createLinksetPair(fullName(m) "",tgtMod, linkMod))) { int Error = linkErrorNoError noError() osrc = gotoObject(sourceAbsNo(l), read(fullName(m), false)) err = lastError() if (!null err) { errorBox(err) continue } ModuleVersion otherVersion = targetVersion l otherMod = module(otherVersion) if (null otherMod || isDeleted otherMod) { errorBox("{Null} Object") } else { otgt = object(targetAbsNo(l), load(otherVersion,false)) if (null otgt || isDeleted otgt) { errorBox("{Null} Object") } else { Error = createLink_(osrc, linkMod, otgt) if (Error != linkErrorNoError) { reportLinkError_(osrc, otgt, linkMod, "", Error) } else { delete l } } } delete otherVersion } } } } flushDeletions() secondrun = diffLinks() //Reset display getLinkSets() //Diff if(stringOf(firstrun) != stringOf(secondrun)) { //print (stringOf(firstrun) "\n\n\n" stringOf(secondrun)) diffx(firstrun, secondrun) } delete firstrun delete secondrun refresh(m) infoBox("Done!") } void closeCallback (DB x) { getLinkParingVsLinks() delete cLinks delete LinkPairings destroy(diffDB) diffDB = null destroy(mainDB) mainDB = null } void editLinkset(DB x) { int sel = get(linkSetListView) oldLinkMod = getColumnValue(linkSetListView, sel, 3) oldTgtMod = getColumnValue(linkSetListView, sel, 1) set(sourceModField, fullName(m)) set(targetModField, getColumnValue(linkSetListView, sel, 2)) set(linkModField, getColumnValue(linkSetListView, sel, 5)) //future code.... /* if(getColumnValue(linkSetListView, sel, 2) == "Manditory") { set(optionsRadioBox, 0) } else { set(optionsRadioBox, 1) } */ set(optionsRadioBox, 0) inactive(optionsRadioBox) inactive(targetModField) inactive(targetBrowseButton) show editDB } void openTrgMod(DB x) { Link l = null string err = null int sel = get(linkSetListView) int Index = intOf(realOf(getColumnValue(linkSetListView, sel, 8))) noError() if(find(cLinks, Index, l)){ ModuleVersion otherVersion = targetVersion l gotoObject(targetAbsNo(l), load(otherVersion,true)) delete otherVersion } err = lastError() if (!null err) { errorBox(err) } } void targetPathCB (DBE) { Item i = item fnMiniExplorer(editDB,MINI_EXP_FORMAL_MODS,null,null) if(!null i) { set(targetModField, fullName i) } } void linkPathCB (DBE) { Item i = item fnMiniExplorer(editDB,MINI_EXP_LINK_MODS,null,null) if(!null i) { set(linkModField, fullName i) } } void linkSelectionMade(DBE lstv, int sel) { //future code.... active editButton } // linkSelectionMade void linkDeselection(DBE lstv, int sel) { //future code.... inactive editButton } // linkDeselection void linkActivated(DBE lstv, int sel) { openTrgMod(null) } // linkActivated //diffDB diffDB = create("diff...", styleCentered) difftextbox = richText(diffDB, "modifications", "", 850, 400, true) //editDB editDB = create("Edit Linkset and Update Links...", styleCentered) sourceModField = field(editDB, "Source module:", "", 30, true) sourceModField -> "top" -> "form"; sourceModField -> "left" -> "form"; sourceModField -> "right" -> "unattached"; sourceModField -> "bottom" -> "unattached" targetModField = field(editDB, "Target module:", "", 30, false) targetModField -> "top" -> "flush" -> sourceModField; targetModField -> "left" -> "unattached"; targetModField -> "right" -> "aligned" -> sourceModField; targetModField -> "bottom" -> "unattached" targetBrowseButton = button(editDB, "Browse...", targetPathCB) targetBrowseButton -> "top" -> "aligned" -> targetModField; targetBrowseButton -> "left" -> "flush" -> targetModField; targetBrowseButton -> "right" -> "unattached"; targetBrowseButton -> "bottom" -> "unattached" linkModField = field(editDB, "Link module:", "", 30, false) linkModField -> "top" -> "flush" -> targetModField; linkModField -> "left" -> "unattached"; linkModField -> "right" -> "aligned" -> targetModField; linkModField -> "bottom" -> "unattached" linkBrowseButton = button(editDB, "Browse...", linkPathCB) linkBrowseButton -> "top" -> "aligned" -> linkModField; linkBrowseButton -> "left" -> "flush" -> linkModField; linkBrowseButton -> "right" -> "unattached"; linkBrowseButton -> "bottom" -> "unattached" string choices[2] = {"Manditory","Overrideable"} optionsRadioBox = radioBox(editDB, "", choices, 0) optionsRadioBox -> "top" -> "flush" -> linkModField; optionsRadioBox -> "left" -> "form"; optionsRadioBox -> "right" -> "unattached"; optionsRadioBox -> "bottom" -> "form" okButton = ok(editDB, "OK", doUpdateLinks) //mainDB mainDB = create("Show Module Links..." , styleCentered) linkSetListView = listView(mainDB, listViewOptionMultiselect|listViewOptionSortText, 1180, 15, dummy) //listViewOptionSortText, listViewOptionMultiselect linkSetListView -> "top" -> "form"; linkSetListView -> "left" -> "form"; linkSetListView -> "right" -> "form"; linkSetListView -> "bottom" -> "form" set(linkSetListView, linkSelectionMade, linkDeselection, linkActivated) editButton = apply(mainDB, "Edit", editLinkset); inactive(editButton) close (mainDB, true, closeCallback) realize(mainDB) insertColumn(linkSetListView, 0, "ID", 60, iconNone); set(linkSetListView, 0, doSortInt) // Allow sorting this column insertColumn(linkSetListView, 1, "Object Heading/Text", 150, iconNone) insertColumn(linkSetListView, 2, "Target Module", 300, iconFormal); set(linkSetListView, 2, doSortString) // Allow sorting this column insertColumn(linkSetListView, 3, "ID", 60, iconNone); set(linkSetListView, 3, doSortInt) // Allow sorting this column insertColumn(linkSetListView, 4, "Object Heading/Text", 150, iconNone) insertColumn(linkSetListView, 5, "Link Module", 250, iconLink); set(linkSetListView, 5, doSortString) // Allow sorting this column insertColumn(linkSetListView, 6, "Baseline", 90, iconNone); set(linkSetListView, 6, doSortStringReverse) // Allow sorting this column insertColumn(linkSetListView, 7, "Status", 90, iconNone); set(linkSetListView, 7, doSortStringReverse) // Allow sorting this column insertColumn(linkSetListView, 8, "Index", 90, iconNone); set(linkSetListView, 8, doSortInt) // Allow sorting this column getLinkSets() show(mainDB)olumn getLinkSets() show(mainDB