// Create layout DXL column that shows changes to Object Text. /* This tool creates a DXL column which uses a rich-text markup scheme to show changes to Object Text with respect to some original version. The original version can be selected from the following sources: - the current value of Object Text, so that all future changes are marked up in the history column - the Object Text as it was in a named baseline of the current Module - the value of a named attribute. The original text is stored in a text attribute called "Old Text", and can be over-written by a subsequent use of the tool. The fonts used to mark up the changes in text can be selected. The default is to show inserted text using underline, and deleted text using strike-through. Current limitations: - changes to fonts in the object text are ignored. - changes to attributes other than Object Text are not shown. - deleted and moved objects are not portrayed as changes. */ /* Kitchen Tools for customizing DOORS with DXL V7.1 ------------------------------------------------- DISCLAIMER: This programming tool has been thoroughly checked and tested at all stages of its production. Telelogic cannot accept any responsibility for any loss, disruption or damage to your data or your computer system that may occur while using this script. If you do not accept these conditions, do not use this customised script. ------------------------------------------------- */ /* Modification history: WHO WHEN WHAT jd 2 Oct 98 Creation. jd 5 Oct 98 Documentation update. Set no history or changebars on OLDTEXTATTR. Fixed for shareable mode - it lock sections for setting OLDTEXTATTR. jd 16 Mar 99 Create filter for amended objects. jd 6 Apr 99 Added choice of DXL column or DXL attribute. */ pragma runLim,0 #include #include #include /////////////////////////////////////////////////////////// // Constants const int MAXATTRS = 50 // maximum number of text attributes const int MAXBASES = 50 // maximum number of baselines const string OLDTEXTATTR = "Old Text" // name of attribute to store old version of text const string HISTORYATTR = "Delta Text" // name of attribute to store history of text const string oldOpts[] = { "From current ", "From baseline", "From attribute" } // ^^^^^^^^ // padding for layout purposes const string fontOpts[] = { "Bold", "Italic", "Underline", "StrikeThrough" } const string creationOpts[] = { "DXL column", "DXL attribute" } const string helpScript = "This tool creates a DXL column or attribue which uses a rich-text " //- "markup scheme to show changes to Object Text with respect to some " //- "original version.\n\n" //- "The original version can be selected from the following sources:\n" //- "\n" //- " - the current value of Object Text, so that all future changes are marked " //- "up in the history column\n" //- "\n" //- " - the Object Text as it was in a named baseline of the current Module\n" //- "\n" //- " - the value of a named attribute.\n" //- "\n" //- "The original text is stored in a text attribute called \"" OLDTEXTATTR "\", and can be " //- "over-written by a subsequent use of the tool.\n" //- "\n" //- "The fonts used to mark up the changes in text can be selected. " //- "The default is to show inserted text using underline, and deleted text using strike-through.\n" //- "\n" //- "Current limitations:\n" //- " - changes to fonts in the object text are ignored.\n" //- " - changes to attributes other than Object Text are not shown.\n" //- " - deleted and moved objects are not portrayed as changes." /////////////////////////////////////////////////////////// // Variables Module currMod = current Object currObj = current string dummyList[] = {} string attrList[MAXATTRS] // list of text attirbutes string baseList[MAXBASES] // list of baselines Skip baseSkip = createString // mapping baseline name to baseline Skip baseObjects = create() // mapping absolute number to baseline object /////////////////////////////////////////////////////////// // Dialogs DB db = null DBE helpText = null DBE oldTextOption = null DBE baseChoice = null DBE attrChoice = null DBE newTextFont = null DBE oldTextFont = null DBE colAttrChoice = null DBE insertButton = null DBE textSizeLimit = null /////////////////////////////////////////////////////////// // Auxiliary functions void fillAttributeList(DBE dbe) { // scan all attributes int n = 0 AttrDef ad for ad in current Module do { // reject non-object attributes if ( !ad.object ) continue // reject attributes that are not text if ( ad.typeName != "Text" ) continue // reject Object Text if ( ad.name == "Object Text" ) continue attrList[n++] = ad.name } set(dbe, attrList, n) } void fillBaselineList(DBE dbe) { // empty skip list Baseline b for b in baseSkip do { string bn = key baseSkip delete(baseSkip, bn) } // refill skip list and choice list int n = 0 for b in current Module do { string baseName = (major b) "." (minor b) " (" (suffix b) ")" baseList[n++] = baseName put(baseSkip, baseName, b) } set(dbe, baseList, n) } /////////////////////////////////////////////////////////// // Call backs void doCreate(DB db) { // create attribute for saving old version if ( !exists attribute OLDTEXTATTR ) { create object type "Text" history false changeBars false attribute OLDTEXTATTR } // set old attribute values int opt = get oldTextOption int attr = get attrChoice int base = get baseChoice int colAttr = get colAttrChoice string txtLim = get textSizeLimit string attrName = ( attr >= 0 ? attrList[attr] : "" ) string baseName = ( base >= 0 ? baseList[base] : "" ) string baselineText = "" Baseline baseLine = null Module baseMod = null if ( opt == 2 ) { // check values if ( attrName == "" ) { ack "No attribute named." return } } if ( opt == 1 ) { // check values if ( baseName == "" ) { ack "No baseline named." return } // for baseline choice, open baseline module and build index to objects // get baseline info baselineText = " " baseName if ( !find(baseSkip, baseName, base) ) { ack "Cannot access baseline " baseName return } // open baseline module if ( !find(baseSkip, baseName, baseLine) ) { ack "Failed to load baseline module " baseName return } baseMod = load(currMod, baseLine, false) // build index Object o for o in baseMod do { int ky = intOf (o."Absolute Number" "") put(baseObjects, ky, o) } } Object o for o in currMod do { if ( !lockObj o ) continue string oldVal = "" if ( opt == 0 ) { // use current value of object text oldVal = o."Object Text" } else if ( opt == 1 ) { // use value of object text from named baseline int absNum = intOf(o."Absolute Number" "") Object b if ( find(baseObjects, absNum, b) ) { oldVal = b."Object Text" } else { oldVal = "" } } else if ( opt == 2 ) { // use value of named attribute oldVal = o.attrName } o.OLDTEXTATTR = oldVal if ( o."Object Text" "" != oldVal ) accept o else reject o } // get font settings int oldFont = get oldTextFont int newFont = get newTextFont if ( colAttr == 1 ) { // create attribute AttrDef ad = find(currMod, HISTORYATTR) if ( !null ad ) { if ( confirm "History attribute '" HISTORYATTR "' already exists.\n\nOverwrite?" ) { delete(currMod, ad) } else { return } } string code = "pragma runLim,0\n" //- "#include \n" //- "Buffer o = create()\n" //- "o = obj.\"" OLDTEXTATTR "\"\n" //- "Buffer n = create()\n" //- "n = obj.\"Object text\"\n" //- "if ( length(o) > " txtLim " || length(n) > " txtLim " ) \n" //- "{\n" //- " obj.\"" HISTORYATTR "\" = richText \"{\\\\i (Text too big to compare.)}\"\n" //- "} else\n" //- "{\n" //- " obj.\"" HISTORYATTR "\" = richText deltaText(o, n, " oldFont ", " newFont ")\n" //- "}\n" //- "delete(o)\n" //- "delete(n)\n" current = currMod create object type "Text" attribute HISTORYATTR dxl code ad = find(currMod, HISTORYATTR) if ( null ad ) { ack "Could not create attribute." return } } // create column string code = "pragma runLim,0\n" //- "#include \n" //- "Buffer o = create()\n" //- "o = obj.\"" OLDTEXTATTR "\"\n" //- "Buffer n = create()\n" //- "n = obj.\"Object text\"\n" //- "if ( length(o) > " txtLim " || length(n) > " txtLim " ) \n" //- "{\n" //- " displayRich \"{\\\\i (Text too big to compare.)}\"\n" //- "} else\n" //- "{\n" //- " displayRich deltaText(o, n, " oldFont ", " newFont ")\n" //- "}\n" //- "delete(o)\n" //- "delete(n)\n" current = currMod insert column 2 title(column 2, "Dynamic history" baselineText) width(column 2, 300) justify(column 2, full) if ( colAttr == 0 ) { dxl(column 2, code) } else { attribute(column 2, HISTORYATTR) } refresh current hide db } void doSelectOption(DBE dbe) { int opt = get oldTextOption if ( opt == 2 ) { active attrChoice inactive baseChoice fillAttributeList attrChoice } else if ( opt == 1 ) { active baseChoice inactive attrChoice fillBaselineList baseChoice } else { inactive attrChoice inactive baseChoice } } void doClose(DB db) { hide db } /////////////////////////////////////////////////////////// // Main program db = create "Insert dynamic history column" label(db, "Instructions:") helpText = text(db, "", helpScript, 200, 200, true) separator db oldTextOption = verticalRadioBox(db, "Source of original version:", oldOpts, 0) beside db label(db, " ") // horizontal padding label(db, " ") // horizontal positioning below db label(db, " ") // vertical padding baseChoice = choice(db, "Baseline:", dummyList, 0, 0) attrChoice = choice(db, "Attribute:", dummyList, 0, 0) left db separator db label(db, "Fonts to use for marking text:") newTextFont = checkBox(db, "Inserted text:", fontOpts, 5) oldTextFont = checkBox(db, "Deleted text:", fontOpts, 9) colAttrChoice = radioBox(db, "Create:", creationOpts, 1) textSizeLimit = field(db, "Maximum size of text to compare:", "1000", 10) insertButton = apply(db, "Create", doCreate) closeWithTrigger(db, true, doClose) set(oldTextOption, doSelectOption) doSelectOption null show db doSelect