// Copy Views v3 /* * Copyright (c) 2007 AAI Services Corporation * http://www.aaicorp.com/ * Author: David Pechacek - dpechacek@sc-aaicorp.com, David.Pechacek@gmail.com * Created On: 1/25/2008 * * This script allows the user to copy the views to the current module from another * or from the current to multiple others. * version developed on date by notes * 0.5.0 DOORS 5.1sr1 PC 07/11/01 Telelogic NA Preliminary to see how people like the selection screen * 1.0.0 DOORS 5.2 PC 02/10/02 Telelogic NA Includes ViewDef information * 1.1.0 DOORS 5.2 PC 07/22/02 Telelogic NA Closes more modules on completion * 1.1.1 DOORS 6.0sr1 PC 01/10/03 Telelogic NA Doesn't copy title of main column * 2.0.0 DOORS 7.1 PC 08/04/04 Telelogin NA Corrected resizing issue, made more kitchen like * 3.0.0 DOORS 8.1 PC 01/19/08 David Pechacek Changed to use tree View instead of giant list view * for selecting modules * 3.1.0 DOORS 8.1 PC 01/29/08 David Pechacek Changed errors to be printed, added check to return if no * columns exist in the destination module instead of attempting * to delete them, added check to make sure seleted item in * treeView is not deleted. * 3.1.1 DOORS 8.3 PC 09/02/09 David Pechacek Fixed bug in delete function causing modules removed from the * list to still be processed. * */ if(!confirm("This tool copies views from the current module to other selected modules.\n" //- "Use this tool to manage the consistency of views across the database.\n\n" //- "Continue?" ) ) { halt } pragma runLim, 0 // Constants const string dummy[] = {} const int modListWidth = 500 const int modWidth = 150 const int pathWidth = (modListWidth - modWidth)/2 const int viewWidth = modWidth const int listLength = 20 const int MINI_EXP_FP = 1 const int MINI_EXP_LINK_MODS = 2 const int MINI_EXP_FORMAL_MODS = 4 const int MINI_EXP_DESCRIPTIVE_MODS = 8 const int MINI_EXP_SHOW_DELETED = 16 // Variables Module currMod, srcMod, destMod int dataRow; DB copyDB; DBE modListDBE; DBE viewListDBE; DBE splitDBE; DBE modFrameDBE; DBE removeModuleDBE; DBE addModuleDBE; DBE viewFrameDBE; DBE okBtnDBE; DBE applyBtnDBE; DBE miniExplorerDBE; int modSelected; int viewSelected; bool closeSrc; int itemMask = MINI_EXP_FORMAL_MODS; Skip moduleList; void closeDB(DB dbox) { delete(moduleList); moduleList = null; hide(dbox); destroy(dbox); dbox = null; } // Returns whether or not the selected item in the tree view matches the type of module the // tree view was created to be able to select bool itemMatchesSelectedMask(Item itm) { bool matchesMask = false; if(type(itm) == "Formal" && ((itemMask & MINI_EXP_FORMAL_MODS) == MINI_EXP_FORMAL_MODS)) { matchesMask = true; } else if(type(itm) == "Link" && ((itemMask & MINI_EXP_LINK_MODS) == MINI_EXP_LINK_MODS)) { matchesMask = true; } else if(type(itm) == "Descriptive" && ((itemMask & MINI_EXP_DESCRIPTIVE_MODS) == MINI_EXP_DESCRIPTIVE_MODS)) { matchesMask = true; } return(matchesMask); } void clearDest(Module m) { Column c; int i; int count = 0; current = m; for c in m do { count++; } if(count == 0) { return(); } for (i = 0; i < count; i++) { delete(column(0)); } filtering(off); sorting(off); outlining(off); ancestors(off); level(0); } // clearDest void copyViews(Module toMod) { Column srcCol; Column destCol; int viewPos; int vLevel; int colCount; ViewDef vDef; Filter vFilt; Sort vSort; bool vOutline; bool err; bool vAncestors; bool vDescendants; bool vTableCells; string errMsg; string colTitle; string attName; for viewPos in viewListDBE do { string viewName = getColumnValue(viewListDBE, viewPos, 0); err = false; vFilt = null; vSort = null; clearDest(toMod); current = srcMod; if(load(view(viewName))) { vDef = get(view(viewName)); current = toMod; colCount = 0; for srcCol in srcMod do { destCol = column colCount++; attName = attrName(srcCol); err = false; if(null(attName)) { if(main(srcCol)) { main(destCol); } else { dxl(destCol, dxl(srcCol)); } } else { AttrDef ad = find(toMod, attName); if(null(ad) && (attName != "Object Identifier") && (attName != "Object Number") && (attName != "Object Level")) { print("Unable to copy column' " title(srcCol) " in '" viewName //- "' view for module " name(srcMod) ", due to lack of '" //- attName "' attribute.\n\n"); err = true; } else { attribute(destCol, attName); } } if(err) { continue; } colTitle = title(srcCol); if(!main(srcCol)) { title(destCol, colTitle); } int colWidth = width(srcCol); width(destCol, colWidth); justify(destCol, justify(srcCol)); } // if(err) { // continue // } current = srcMod; if(filtering(srcMod)) { vFilt = current; } if(sorting(srcMod)) { vSort = current; } vLevel = level(srcMod); vOutline = outlining(srcMod); vAncestors = ancestors(srcMod); vDescendants = descendants(srcMod); vTableCells = useFilterTables(vDef); current = toMod; noError(); if(!null(vFilt)) { set(toMod, vFilt); filtering(on); } errMsg = lastError(); if(!null(errMsg)) { print("Unable to copy view '" viewName ",' due to " errMsg "\n\n"); continue; } noError(); if(!null(vSort)) { set(toMod, vSort); sorting(on); } errMsg = lastError(); if(!null(errMsg)) { print("Unable to copy view '" viewName ",' due to " errMsg "\n\n"); continue; } level(vLevel); outlining(vOutline); ancestors(vAncestors); descendants(vDescendants); useFilterTables(vDef, vTableCells); save(toMod, view(viewName), vDef); } else { print("Unable to load view '" viewName "' at the source\n\n"); } string modView = getDefaultViewForModule(srcMod); if(!null(modView)) { setDefaultViewForModule(toMod, modView); } } } void copyViewsCB(DB dbox) { string modName; string viewName = get(viewListDBE); bool closeIt; int numModulesSelected = noElems(modListDBE); if(viewName == "") { errorBox(dbox, "You must select at least one view to copy."); return(); } else if(numModulesSelected == 0) { errorBox(dbox, "You must select at least one module to copy views to."); return(); } for modName in moduleList do { if(open(module(modName))) { destMod = read(modName, false); if(isVisible(destMod)) { closeIt = false; } else { closeIt = true; } } else { closeIt = true; } destMod = read(modName, true); if(destMod == srcMod) { continue; } copyViews(destMod); if(closeIt) { close(destMod); } } } void copyViewsCB_WClose(DB dbox) { copyViewsCB(dbox); closeDB(dbox); } void addModuleToList(DBE clicked) { string selectedModule = getRealPath(dbSep get(miniExplorerDBE)); Item i = item(selectedModule); Project p = getParentProject(i); bool moduleOpen = false; int currentRow; if(isDeleted(i)) { warningBox(copyDB, "Cannot copy views to a deleted module."); return(); } // check that the source module wasn't selected if(fullName(i) == fullName(currMod)) { warningBox(copyDB, "Cannot select the source module."); return(); } // check that the item matches the module type the tree view was passed when it was created // and that it does not already exist in the list. if(find(moduleList, fullName(i))) { warningBox(copyDB, "Item of the same name already selected. Unable to add to list."); return(); } if(itemMatchesSelectedMask(i)) { currentRow = noElems(modListDBE); // put in the module list insert(modListDBE, currentRow, name(i)); set (modListDBE, currentRow, 2, fullName(i)); set (modListDBE, currentRow, 1, name(p)); put (moduleList, fullName(i), fullName(i)); } else { return(); } active(removeModuleDBE); active(okBtnDBE); active(applyBtnDBE); } void removeModuleFromList(DBE clicked) { int selectedRow = get(modListDBE); string moduleName = getColumnValue(modListDBE, selectedRow, 2); delete(moduleList, moduleName); delete(modListDBE, selectedRow); if(noElems(modListDBE) == 0) { inactive(removeModuleDBE); inactive(okBtnDBE); inactive(applyBtnDBE); } } void viewSelectionMade(DBE lstv, int sel) { active(removeModuleDBE); } void viewDeselected(DBE lstv, int sel) { inactive(removeModuleDBE); } void viewActivated(DBE lstv, int sel) {} void listViews() { string viewName; empty(viewListDBE); dataRow = 0; viewSelected--; inactive(okBtnDBE); inactive(applyBtnDBE); for viewName in views(srcMod) do { insert(viewListDBE, dataRow++, viewName); } } // Adds a new item to the tree view. void addItemToTree(DBE dbe, Item i) { string displayPath = getDisplayPath(i); // check if the path exists in the tree view if(exists(miniExplorerDBE, displayPath) == false) { // check that the item is not deleted or if it is, that the tree view was created with the option // to show deleted items. if(isDeleted(i) == false || (isDeleted(i) == true && ((itemMask & MINI_EXP_SHOW_DELETED) == MINI_EXP_SHOW_DELETED))) { // check item type if(type(i) == "Folder" || type(i) == "Project") { Icon iconOpen; Icon iconClosed; string sDummyEntry = displayPath dbSep dummyItem; // assign project or folder specific icons assignIcons(i, iconOpen, iconClosed); // add entry (plus dummy) insert(miniExplorerDBE, displayPath, iconClosed, iconOpen); insert(miniExplorerDBE, sDummyEntry, iconClosed, iconOpen); } else { if(itemMatchesSelectedMask(i)) { insert(miniExplorerDBE, displayPath, getIcon(i), getIcon(i)); } } } } } // Opens the selected Project or Folder in the tree view and loads its containing items. void displaySelectedBranch(DBE dbe, string sItemPath) { Folder fStart = folder(getRealPath(sItemPath)); if(fStart != null) { Item i; for i in all fStart do { addItemToTree(miniExplorerDBE, i); } } } // DBE callback that fires when an element in the tree view is selected. void doTreeSelect(DBE dbe) { string sel = getRealPath(dbSep get(miniExplorerDBE)); if(itemMatchesSelectedMask(item(sel))) { active(addModuleDBE); } else { inactive(addModuleDBE); } } // DBE callback that fires when an item in the tree view is double clicked. bool doTreeExpand(DBE dbe, string sItem) { string sItemPath = dbSep sItem; string sDummyItem = sItemPath dbSep dummyItem; // check status if(exists(miniExplorerDBE, sDummyItem) == true) { // remove dummy delete(miniExplorerDBE, sDummyItem); } // check status if(theCurrentView == DATABASE_VIEW) { // adjust view accordingly displaySelectedBranch(miniExplorerDBE, sItemPath); } else { Project prjOldRoot = getRootProject_(); setRootProject_(project(getRootOfPath sItemPath)); // adjust view accordingly displaySelectedBranch(miniExplorerDBE, sItemPath); setRootProject_(prjOldRoot); } return(true) } // Loads the tree view to start with the passed in folder opened. void changeToStartFolder(Folder fStart) { if(!null fStart) { int i; // calculate max bound for loop int finish = length(rootName_(fStart)); // prepare initial path string sFolderPath = ((theCurrentView == DATABASE_VIEW) ? dbDisplayRoot() : ""); string sCharacter; // process string for(i = 0; i <= finish; i++) { // obtain character sCharacter = (rootName_(fStart))[i:i] // check status if(sCharacter == dbSep || i == finish) { // check status if(theCurrentView == PROJECT_VIEW && sFolderPath == dbSep) { continue; } // update explorer displaySelectedBranch(miniExplorerDBE, sFolderPath); } sFolderPath = sFolderPath sCharacter; } // update explorer set(miniExplorerDBE, sFolderPath); } else { // default to database level displaySelectedBranch(miniExplorerDBE, dbDisplayRoot()); set(miniExplorerDBE, dbDisplayRoot()); } } void buildDB() { string projectName = ""; Project projectRoot = null; copyDB = create("Copy Views to Other Modules", styleCentered); viewFrameDBE = frame(copyDB, "Select views", modWidth + 20, listLength * 20); viewFrameDBE -> "right" -> "unattached"; viewFrameDBE -> "bottom" -> "unattached"; viewListDBE = listView(copyDB, listViewOptionMultiselect, modWidth*3/2, listLength - 3, dummy); viewListDBE -> "top" -> "inside" -> viewFrameDBE; viewListDBE -> "left" -> "inside" -> viewFrameDBE; viewListDBE -> "right" -> "inside" -> viewFrameDBE; viewListDBE -> "bottom" -> "inside" -> viewFrameDBE; set(viewListDBE, viewSelectionMade, viewDeselected, viewActivated) modFrameDBE = frame(copyDB, "Select destination module(s)", modListWidth + 20, listLength * 20); modFrameDBE -> "left" -> "unattached"; modFrameDBE -> "top" -> "aligned" -> viewFrameDBE; miniExplorerDBE = treeView(copyDB, treeViewOptionSorted, modListWidth, 9); miniExplorerDBE -> "left" -> "inside" -> modFrameDBE; miniExplorerDBE -> "right" -> "inside" -> modFrameDBE; miniExplorerDBE -> "top" -> "inside" -> modFrameDBE; miniExplorerDBE -> "bottom" -> "unattached"; modListDBE = listView(copyDB, 0, modListWidth, listLength - 12, dummy); modListDBE -> "left" -> "inside" -> modFrameDBE; modListDBE -> "right" -> "inside" -> modFrameDBE; modListDBE -> "top" -> "spaced" -> miniExplorerDBE; modListDBE -> "bottom" -> "unattached"; removeModuleDBE = button(copyDB, "Remove Module", removeModuleFromList, true, 75); removeModuleDBE -> "left" -> "unattached"; removeModuleDBE -> "right" -> "inside" -> modFrameDBE; removeModuleDBE -> "top" -> "unattached"; removeModuleDBE -> "bottom" -> "inside" -> modFrameDBE; addModuleDBE = button(copyDB, "Add Module", addModuleToList, true, 75); addModuleDBE -> "left" -> "unattached"; addModuleDBE -> "right" -> "spaced" -> removeModuleDBE; addModuleDBE -> "top" -> "unattached"; addModuleDBE -> "bottom" -> "inside" -> modFrameDBE; splitDBE = splitter(copyDB, viewFrameDBE, modFrameDBE, 5); splitDBE -> "top" -> "form"; splitDBE -> "left" -> "unattached"; splitDBE -> "right" -> "unattached"; splitDBE -> "bottom" -> "form"; okBtnDBE = ok (copyDB, "OK", copyViewsCB_WClose); applyBtnDBE = apply(copyDB, "Apply", copyViewsCB); close(copyDB, true, closeDB); inactive(removeModuleDBE); inactive(okBtnDBE); inactive(applyBtnDBE); realize(copyDB); set(miniExplorerDBE, doTreeSelect); set(miniExplorerDBE, doTreeExpand); // setExtraHeightShare(viewFrameDBE, 1.0) // setExtraHeightShare(modFrameDBE, 1.0) // setExtraWidthShare(viewFrameDBE, 0.4) // setExtraWidthShare(modFrameDBE, 0.6) insertColumn(viewListDBE, 0, "View", viewWidth, iconNone); insertColumn(modListDBE, 0, "Module", modWidth, iconNone); insertColumn(modListDBE, 1, "from Project", modWidth, iconNone); insertColumn(modListDBE, 2, "Path", pathWidth, iconNone); listViews(); // check status if(theCurrentView == DATABASE_VIEW) { // adjust accordingly insert(miniExplorerDBE, dbDisplayRoot(), iconDatabase, iconDatabase); } else { projectRoot = getRootProject_(); setRootProject_(null); // process database for projectName in database do { addItemToTree(miniExplorerDBE, item(dbSep projectName)); } setRootProject_(projectRoot); } changeToStartFolder(current Folder); } // Initializations currMod = current if(null(currMod)) { errorBox("Must be run from a module."); } else { srcMod = currMod; moduleList = createString(); modSelected = 0; viewSelected = 0; // Main buildDB(); show(copyDB); }