// ADSFiltersAndTags // Julianon 2016 // V1.1 // This is a script for Directory Opus. // See https://resource.dopus.com/viewtopic.php?f=35&t=25951 for development information. // PLEASE ATTEND TO USER CONFIGURATIONS A, B, C AND D BELOW. Then copy and store what has been // configured in the addin file — this may be needed in case of re-installation or upgrade. // USER CONFIGURATION A: // * Edit or add filters and tags following the pattern below. // * The filters and the tags should be consecutive, without gaps. // * Do not delete a filter or tag that has already been used. Just ignore it. // * The names, column widths, and justifications can be edited afterwards, // but the index in square brackets of the filter or tag label must not be varied. var aFilterLabels = new Array var aFilterColumnWidths = new Array aFilterLabels [0] = "Mantua" // Filter name to appear as heading in the display aFilterColumnWidths [0] = 53 // Default column width in pixels aFilterLabels [1] = "Heorot" aFilterColumnWidths [1] = 49 aFilterLabels [2] = "Malvern" aFilterColumnWidths [2] = 56 aFilterLabels [3] = "Check" aFilterColumnWidths [3] = 45 var aTagLabels = new Array var aTagColumnWidths = new Array var aTagColumnJustify = new Array aTagLabels [0] = "&Mark" // Tag name to appear as heading in the display aTagColumnWidths [0] = 39 // Default column width in pixels aTagColumnJustify [0] = "right" // Justification: "left" OR "right" OR "center" aTagLabels [1] = "Commen&t" aTagColumnWidths [1] = 100 aTagColumnJustify [1] = "left" aTagLabels [2] = "&Done" aTagColumnWidths [2] = 52 aTagColumnJustify [2] = "center" // Each filter below ends with three statements that enable matches for filters. // Each such statement has the form cmd.match.push_back ("..."). // Add similar statements to the tags sections if filters are required for them; // this has been done for the first two tags sections. // To use more that 10 filters or 10 tags, add more sections to the script below. // First, search for: cmd.method = "onFilter009" or cmd.method = "onFilter009" // Then copy the 12-line section, including the opening "if" statement and // the final curly bracket, and paste it and edit it appropriately. // Secondly, search for: function onFilter009 or function onTag009 // Then copy the function, and paste it and edit it appropriately. // USER CONFIGURATION B: // When a filter or tag is set or removed, the 'Date last modified' may be: // set to now, or remain unchanged, or be advanced one minute. // Advancing one minute is recommended, because then when a sync is performed, // the item, together will its new filters or tags, will be synced. // One of the following three lines must be uncommented: // var sDateModified = "Now" // var sDateModified = "Unchanged" var sDateModified = "AdvanceOneMinute" // USER CONFIGURATION C: Raw editing of an ADS text file requires an editor. // One of the following two lines must be uncommented, or another added. // (Notepad++ removes ADS files when a file is edited, // but it can edit and save one ADS file without removing anything.) // var sEditor = "UEStudio" // Full path rather than alias may be required. var sEditor = "Notepad" // USER CONFIGURATION D: Not recommended. If the names of the filter or tag ADS files // are changed this must be at the start before any filters or tags have been set. var sADSFilterFileName = "MultiFilters.txt" var sADSTagFileName = "MultiTags.txt" // ********** END OF USER CONFIGURATION ********** // STRUCTURE OF THE ADDIN: // 10 columns to display filters (potentially expandable to a ridiculous 999) // 10 columns to display tags (potentially expandable to a ridiculous 999) // 1 columns to display all filters + 1 column to display all tags // 1 column to display the number of ADS files attached to each item // - - - - - - - - // Seven functions that the addin made available to the user: // 2 functions to set multiple filters, and to set tags: // SetADSFilters and SetADSTags // 2 functions to copy filters and tags from one item and paste to selected items: // ChooseReferenceItem and PasteADSFiltersOrTags // 2 functions to toggle filter columns, and to toggle tag columns: // ToggleADSFilterColumns and ToggleADSTagColumns // 1 function for raw editing of ADS files: // EditADSFiles // - - - - - - - - // Various helping functions, each named: function do... () // Calculations based on the user configuration var sVersion = "V1.1" var aFilterNames = new Array var sMessageFilters = "" for (nn = 0; nn < aFilterLabels.length; nn++) { aFilterNames [nn] = aFilterLabels [nn].replace ("&", "") if (typeof aFilterColumnWidths [nn] == "number") { if (!(aFilterColumnWidths [nn] > 0)) aFilterColumnWidths [nn] = 60 } else { aFilterColumnWidths [nn] = 60 } sMessageFilters = sMessageFilters + "Filter" + doBuffer (nn, 3) + " = " + aFilterNames [nn] + " " + aFilterColumnWidths [nn] + ", " } var nFilterNames = aFilterNames.length DOpus.Output (sMessageFilters) var aTagNames = new Array sMessageTags = "" for (nn = 0; nn < aTagLabels.length; nn++) { aTagNames [nn] = aTagLabels [nn].replace ("&", "") if (typeof aTagColumnWidths [nn] == "number") { if (!(aTagColumnWidths [nn] > 0)) aTagColumnWidths [nn] = 60 } else { aTagColumnWidths [nn] = 60 } sMessageTags = sMessageTags + "Tag" + doBuffer (nn, 3) + " = " + aTagNames [nn] + " " + aTagColumnWidths [nn] + " " + aTagColumnJustify [nn] + ", " } var nTagNames = aTagNames.length DOpus.Output (sMessageTags) var oFSO = new ActiveXObject ("Scripting.FileSystemObject") // ********** THE OnInit FUNCTION ********** function OnInit (initData) { var url = "https://resource.dopus.com/viewtopic.php?f=35&t=25951" var UID = "552A20C9-4A1B-4F06-AC2A-C7A64A8F6C64" initData.name = "ADSFiltersAndTags" initData.desc = "An ADS system of multiple filters and tags that can be associated with any file." initData.copyright = "(c) Julianon March 2016" initData.version = "1.1" initData.default_enable = true // ********** Columns to display filters ********** var cmd = initData.AddColumn() cmd.name = "Filter000" cmd.method = "onFilter000" cmd.label = aFilterNames [0] cmd.defwidth = aFilterColumnWidths [0] + "px" cmd.defsort = -1 cmd.autogroup = true cmd.autorefresh = true cmd.justify = "center" cmd.match.push_back ("Yes") // This is the "On" value. cmd.match.push_back ("- -") // This is the "Off" value. cmd.match.push_back (" ") // Three spaces is the "Not set" value. if (nFilterNames > 1) { var cmd = initData.AddColumn() cmd.name = "Filter001" cmd.method = "onFilter001" cmd.label = aFilterNames [1] cmd.defwidth = aFilterColumnWidths [1] + "px" cmd.defsort = -1 cmd.autogroup = true cmd.autorefresh = true cmd.justify = "center" cmd.match.push_back ("Yes") cmd.match.push_back ("- -") cmd.match.push_back (" ") } if (nFilterNames > 2) { var cmd = initData.AddColumn() cmd.name = "Filter002" cmd.method = "onFilter002" cmd.label = aFilterNames [2] cmd.defwidth = aFilterColumnWidths [2] + "px" cmd.defsort = -1 cmd.autogroup = true cmd.autorefresh = true cmd.justify = "center" cmd.match.push_back ("Yes") cmd.match.push_back ("- -") cmd.match.push_back (" ") } if (nFilterNames > 3) { var cmd = initData.AddColumn() cmd.name = "Filter003" cmd.method = "onFilter003" cmd.label = aFilterNames [3] cmd.defwidth = aFilterColumnWidths [3] + "px" cmd.defsort = -1 cmd.autogroup = true cmd.autorefresh = true cmd.justify = "center" cmd.match.push_back ("Yes") cmd.match.push_back ("- -") cmd.match.push_back (" ") } if (nFilterNames > 4) { var cmd = initData.AddColumn() cmd.name = "Filter004" cmd.method = "onFilter004" cmd.label = aFilterNames [4] cmd.defwidth = aFilterColumnWidths [4] + "px" cmd.defsort = -1 cmd.autogroup = true cmd.autorefresh = true cmd.justify = "center" cmd.match.push_back ("Yes") cmd.match.push_back ("- -") cmd.match.push_back (" ") } if (nFilterNames > 5) { var cmd = initData.AddColumn() cmd.name = "Filter005" cmd.method = "onFilter005" cmd.label = aFilterNames [5] cmd.defwidth = aFilterColumnWidths [5] + "px" cmd.defsort = -1 cmd.autogroup = true cmd.autorefresh = true cmd.justify = "center" cmd.match.push_back ("Yes") cmd.match.push_back ("- -") cmd.match.push_back (" ") } if (nFilterNames > 6) { var cmd = initData.AddColumn() cmd.name = "Filter006" cmd.method = "onFilter006" cmd.label = aFilterNames [6] cmd.defwidth = aFilterColumnWidths [6] + "px" cmd.defsort = -1 cmd.autogroup = true cmd.autorefresh = true cmd.justify = "center" cmd.match.push_back ("Yes") cmd.match.push_back ("- -") cmd.match.push_back (" ") } if (nFilterNames > 7) { var cmd = initData.AddColumn() cmd.name = "Filter007" cmd.method = "onFilter007" cmd.label = aFilterNames [7] cmd.defwidth = aFilterColumnWidths [7] + "px" cmd.defsort = -1 cmd.autogroup = true cmd.autorefresh = true cmd.justify = "center" cmd.match.push_back ("Yes") cmd.match.push_back ("- -") cmd.match.push_back (" ") } if (nFilterNames > 8) { var cmd = initData.AddColumn() cmd.name = "Filter008" cmd.method = "onFilter008" cmd.label = aFilterNames [8] cmd.defwidth = aFilterColumnWidths [8] + "px" cmd.defsort = -1 cmd.autogroup = true cmd.autorefresh = true cmd.justify = "center" cmd.match.push_back ("Yes") cmd.match.push_back ("- -") cmd.match.push_back (" ") } if (nFilterNames > 9) { var cmd = initData.AddColumn() cmd.name = "Filter009" cmd.method = "onFilter009" cmd.label = aFilterNames [9] cmd.defwidth = aFilterColumnWidths [9] + "px" cmd.defsort = -1 cmd.autogroup = true cmd.autorefresh = true cmd.justify = "center" cmd.match.push_back ("Yes") cmd.match.push_back ("- -") cmd.match.push_back (" ") } // ********** Columns to display tags ********** var cmd = initData.AddColumn() cmd.name = "Tag000" cmd.method = "onTag000" cmd.label = aTagNames [0] cmd.defwidth = aTagColumnWidths [0] + "px" cmd.autogroup = true cmd.autorefresh = true cmd.justify = aTagColumnJustify [0] cmd.match.push_back (" ") // Three spaces is the empty value and the "Not set" value cmd.match.push_back ("31") cmd.match.push_back ("19") cmd.match.push_back ("23") if (nTagNames > 1) { var cmd = initData.AddColumn() cmd.name = "Tag001" cmd.method = "onTag001" cmd.label = aTagNames [1] cmd.defwidth = aTagColumnWidths [1] + "px" cmd.autogroup = true cmd.autorefresh = true cmd.justify = aTagColumnJustify [1] cmd.match.push_back (" ") cmd.match.push_back ("Good") cmd.match.push_back ("Poor") } if (nTagNames > 2) { var cmd = initData.AddColumn() cmd.name = "Tag002" cmd.method = "onTag002" cmd.label = aTagNames [2] cmd.defwidth = aTagColumnWidths [2] + "px" cmd.autogroup = true cmd.autorefresh = true cmd.justify = aTagColumnJustify [2] cmd.match.push_back (" ") } if (nTagNames > 3) { var cmd = initData.AddColumn() cmd.name = "Tag003" cmd.method = "onTag003" cmd.label = aTagNames [3] cmd.defwidth = aTagColumnWidths [3] + "px" cmd.autogroup = true cmd.autorefresh = true cmd.justify = aTagColumnJustify [3] cmd.match.push_back (" ") } if (nTagNames > 4) { var cmd = initData.AddColumn() cmd.name = "Tag004" cmd.method = "onTag004" cmd.label = aTagNames [4] cmd.defwidth = aTagColumnWidths [4] + "px" cmd.autogroup = true cmd.autorefresh = true cmd.justify = aTagColumnJustify [4] cmd.match.push_back (" ") } if (nTagNames > 5) { var cmd = initData.AddColumn() cmd.name = "Tag005" cmd.method = "onTag005" cmd.label = aTagNames [5] cmd.defwidth = aTagColumnWidths [5] + "px" cmd.autogroup = true cmd.autorefresh = true cmd.justify = aTagColumnJustify [5] cmd.match.push_back (" ") } if (nTagNames > 6) { var cmd = initData.AddColumn() cmd.name = "Tag006" cmd.method = "onTag006" cmd.label = aTagNames [6] cmd.defwidth = aTagColumnWidths [6] + "px" cmd.autogroup = true cmd.autorefresh = true cmd.justify = aTagColumnJustify [6] cmd.match.push_back (" ") } if (nTagNames > 7) { var cmd = initData.AddColumn() cmd.name = "Tag007" cmd.method = "onTag007" cmd.label = aTagNames [7] cmd.defwidth = aTagColumnWidths [7] + "px" cmd.autogroup = true cmd.autorefresh = true cmd.justify = aTagColumnJustify [7] cmd.match.push_back (" ") } if (nTagNames > 8) { var cmd = initData.AddColumn() cmd.name = "Tag008" cmd.method = "onTag008" cmd.label = aTagNames [8] cmd.defwidth = aTagColumnWidths [8] + "px" cmd.autogroup = true cmd.autorefresh = true cmd.justify = aTagColumnJustify [8] cmd.match.push_back (" ") } if (nTagNames > 9) { var cmd = initData.AddColumn() cmd.name = "Tag009" cmd.method = "onTag009" cmd.label = aTagNames [9] cmd.defwidth = aTagColumnWidths [9] + "px" cmd.autogroup = true cmd.autorefresh = true cmd.justify = aTagColumnJustify [9] cmd.match.push_back (" ") } // ********** Columns to show all filters and all tags in one column ********** var cmd = initData.AddColumn() cmd.name = "AllFilters" cmd.method = "onAllFilters" cmd.label = "AllFilters" cmd.defwidth = "100px" cmd.autogroup = true cmd.autorefresh = true cmd.justify = "left" var cmd = initData.AddColumn() cmd.name = "AllTags" cmd.method = "onAllTags" cmd.label = "AllTags" cmd.defwidth = "100px" cmd.autogroup = true cmd.autorefresh = true cmd.justify = "left" // ********** A column to show the number of ADS files ********** var cmd = initData.AddColumn () cmd.name = "ADSCount" cmd.method = "onADSCount" cmd.label = "ADS" cmd.defwidth = "34px" cmd.autogroup = true cmd.autorefresh = true cmd.justify = "center" // ********** Functions to set multiple filters or tags for selected items ********** var cmd = initData.AddCommand () cmd.name = "SetADSFilters" cmd.method = "onSetADSFilters" cmd.desc = initData.desc cmd.label = "Add multiple filters to selected items using an ADS file." // cmd.template = "NUMBER/N,FROM/K/N,NODESELECT/S" var cmd = initData.AddCommand () cmd.name = "SetADSTags" cmd.method = "onSetADSTags" cmd.desc = initData.desc cmd.label = "Add multiple tags to selected items using an ADS file." // cmd.template = "NUMBER/N,FROM/K/N,NODESELECT/S" // ********** Functions to copy and paste tags to selected items ********** var cmd = initData.AddCommand () cmd.name = "ChooseReferenceItem" cmd.method = "onChooseReferenceItem" cmd.desc = initData.desc cmd.label = "Choose the reference item whose properties are to be used." // cmd.template = "NUMBER/N,FROM/K/N,NODESELECT/S" var cmd = initData.AddCommand () cmd.name = "PasteADSFiltersOrTags" cmd.method = "onPasteADSFiltersOrTags" cmd.desc = initData.desc cmd.label = "Copy filters or tags from a reference to selected items." // cmd.template = "NUMBER/N,FROM/K/N,NODESELECT/S" // ********** Functions to toggle filter and tag columns in a display ********** var cmd = initData.AddCommand () cmd.name = "ToggleADSFilterColumns" cmd.method = "onToggleADSFilterColumns" cmd.desc = initData.desc cmd.label = "Toggle a filter columnin a lister display." // cmd.template = "NUMBER/N,FROM/K/N,NODESELECT/S" var cmd = initData.AddCommand () cmd.name = "ToggleADSTagColumns" cmd.method = "onToggleADSTagColumns" cmd.desc = initData.desc cmd.label = "Toggle a tag column in a lister display." // cmd.template = "NUMBER/N,FROM/K/N,NODESELECT/S" // ********** A function for raw edit of ADS files ********** var cmd = initData.AddCommand () cmd.name = "EditADSFiles" cmd.method = "onEditADSFiles" cmd.desc = initData.desc cmd.label = "Edit a selected ADS File." // cmd.template = "NUMBER/N,FROM/K/N,NODESELECT/S" } // End of OnInit function // ********** THESE OnInit FUNCTIONS SET THE COLUMNS FOR FILTERS ********** function onFilter000 (scriptColData) { // Mantua var sFilterFile = scriptColData.item + ":" + sADSFilterFileName scriptColData.value = doSetFilterValues (sFilterFile, 0) } function onFilter001 (scriptColData) { // Heorot var sFilterFile = scriptColData.item + ":" + sADSFilterFileName scriptColData.value = doSetFilterValues (sFilterFile, 1) } function onFilter002 (scriptColData) { // Malvern var sFilterFile = scriptColData.item + ":" + sADSFilterFileName scriptColData.value = doSetFilterValues (sFilterFile, 2) } function onFilter003 (scriptColData) { // Checked var sFilterFile = scriptColData.item + ":" + sADSFilterFileName scriptColData.value = doSetFilterValues (sFilterFile, 3) } function onFilter004 (scriptColData) { var sFilterFile = scriptColData.item + ":" + sADSFilterFileName scriptColData.value = doSetFilterValues (aFilterNames [4], sFilterFile) } function onFilter005 (scriptColData) { var sFilterFile = scriptColData.item + ":" + sADSFilterFileName scriptColData.value = doSetFilterValues (aFilterNames [5], sFilterFile) } function onFilter006 (scriptColData) { var sFilterFile = scriptColData.item + ":" + sADSFilterFileName scriptColData.value = doSetFilterValues (aFilterNames [6], sFilterFile) } function onFilter007 (scriptColData) { var sFilterFile = scriptColData.item + ":" + sADSFilterFileName scriptColData.value = doSetFilterValues (aFilterNames [7], sFilterFile) } function onFilter008 (scriptColData) { var sFilterFile = scriptColData.item + ":" + sADSFilterFileName scriptColData.value = doSetFilterValues (aFilterNames [8], sFilterFile) } function onFilter009 (scriptColData) { var sFilterFile = scriptColData.item + ":" + sADSFilterFileName scriptColData.value = doSetFilterValues (aFilterNames [9], sFilterFile) } // ********** THESE OnInit FUNCTIONS SET THE COLUMNS FOR TAGS ********** function onTag000 (scriptColData) { // Mark var sTagFile = scriptColData.item + ":" + sADSTagFileName scriptColData.value = doSetTagValues (sTagFile, 0) } function onTag001 (scriptColData) { // Comment var sTagFile = scriptColData.item + ":" + sADSTagFileName scriptColData.value = doSetTagValues (sTagFile, 1) } function onTag002 (scriptColData) { // Processed var sTagFile = scriptColData.item + ":" + sADSTagFileName scriptColData.value = doSetTagValues (sTagFile, 2) } function onTag003 (scriptColData) { var sTagFile = scriptColData.item + ":" + sADSTagFileName scriptColData.value = doSetTagValues (sTagFile, 3) } function onTag004 (scriptColData) { var sTagFile = scriptColData.item + ":" + sADSTagFileName scriptColData.value = doSetTagValues (sTagFile, 4) } function onTag005 (scriptColData) { var sTagFile = scriptColData.item + ":" + sADSTagFileName scriptColData.value = doSetTagValues (sTagFile, 5) } function onTag006 (scriptColData) { var sTagFile = scriptColData.item + ":" + sADSTagFileName scriptColData.value = doSetTagValues (sTagFile, 6) } function onTag007 (scriptColData) { var sTagFile = scriptColData.item + ":" + sADSTagFileName scriptColData.value = doSetTagValues (sTagFile, 7) } function onTag008 (scriptColData) { var sTagFile = scriptColData.item + ":" + sADSTagFileName scriptColData.value = doSetTagValues (sTagFile, 8) } function onTag009 (scriptColData) { var sTagFile = scriptColData.item + ":" + sADSTagFileName scriptColData.value = doSetTagValues (sTagFile, 9) } function doSetFilterValues (sFilterFile, nFilter) { // Used in onFilter above. var sValue = "" var aFilterLines = doOrganiseFilters (doReadFile (sFilterFile)) if (nFilter < nFilterNames) sValue = aFilterLines [nFilter].substr (11) return sValue } function doSetTagValues (sTagFile, nTag) { // Used in onTag functions above. var sValue = "" var aTagLines = doOrganiseTags (doReadFile (sTagFile)) if (nTag < nTagNames) sValue = aTagLines [nTag].substr (8) return sValue } // ********** THIS OnInit FUNCTION SETS THE COLUMN TO SHOW ALL FILTERS ********** function onAllFilters (scriptColData) { var sFilterFile = scriptColData.item + ":" + sADSFilterFileName var aFilterLines = doOrganiseFilters (doReadFile (sFilterFile)) var sValue = "|" var nn = 0 for (nn = 0; nn < aFilterLines.length; nn++) sValue = sValue + aFilterLines [nn].substr (11) + "|" scriptColData.value = sValue } // ********** THIS OnInit FUNCTION SETS THE COLUMN TO SHOW ALL TAGS ********** function onAllTags (scriptColData) { var sTagFile = scriptColData.item + ":" + sADSTagFileName aTagLines = doOrganiseTags (doReadFile (sTagFile)) sValue = "|" var nn = 0 for (nn = 0; nn < aTagLines.length; nn++) sValue = sValue + aTagLines [nn].substr (8) + "|" scriptColData.value = sValue } // ********** THIS OnInit FUNCTION SETS THE COLUMN COUNTING ADS FILES ********** function onADSCount (scriptColData) { var oItem = scriptColData.item var sItemName = oItem.name var sItemType = "file" if (oItem.is_dir) sItemType = "directory" oWSShell = new ActiveXObject ("WScript.Shell") if (sItemType == "file") { oWSShell.Run ('Cmd /C Dir "' + oItem + '" /R | Clip', 0, true) var aADSLines = DOpus.GetClip ().split ("\r\n") var nADSLines = aADSLines.length if (aADSLines [5].substr (34) == sItemName) { var nADSCount = 0 for (nn = 6; nn < nADSLines - 2; nn++) { var sADSLine = aADSLines [nn] if (sADSLine.substr (34).split (":").length == 3 && sADSLine.substr (34).split (":") [0] == sItemName) nADSCount++ } } } else { var oItemWild = String (oItem).slice (0, -1) + "?" oWSShell.Run ('Cmd /C Dir "' + oItemWild + '" /R | Clip', 0, true) var aADSLines = DOpus.GetClip ().split ("\r\n") var nADSLines = aADSLines.length for (ii = 5; ii < nADSLines - 2; ii++) { if (aADSLines [ii].substr (34) == sItemName) { var nADSCount = 0 for (nn = ii + 1; nn < nADSLines - 2; nn++) { var sADSLine = aADSLines [nn] if (sADSLine.substr (34).split (":").length == 3 && sADSLine.substr (34).split (":") [0] == sItemName) nADSCount++ } break } } } scriptColData.value = nADSCount } // **** function 1 of 8 addin functions ****************** function onSetADSFilters (scriptCmdData) { DOpus.Output ("- - - - - - - ->") // ******************************************************* // This OnInit function sets one of more filters of selected items. // The filters are written into successive lines of the ADS file MultiFilters.txt // where they are labelled Filter000, Filter001, ... // ******************************************************* // STEP 1: Initialise some variables, including the collection of selected items. var bContinue = true var nn = 0 var ii = 0 var oFSO = new ActiveXObject ("Scripting.FileSystemObject") var eSelected = new Enumerator (scriptCmdData.func.sourcetab.selected) if (eSelected.atEnd ()) { var oDlg = DOpus.dlg oDlg.title = "Setting filters" oDlg.icon = "warn" oDlg.message = "No files or directories have been selected.\r\n\r\nSelect at least one item and run the procedure again." oDlg.buttons = "&OK" oDlg.show bContinue = false // Excludes nothing selected. } // STEP 2: Choose filters to be set, and action. Exclude some trivial cases. if (bContinue) { eSelected.moveNext () var sPlural = "s" if (eSelected.atEnd ()) sPlural = "" var oDlg = DOpus.Dlg oDlg.title = "Setting filters" oDlg.message = "Check the filters to be processed for the selected item" + sPlural + ", then choose an action.\r\n(Any other filters will remain unchanged.)\r\n\r\nOR\r\n\r\nChoose an action for all filters." //\r\n\r\nThen choose the action for the selected item" + sPlural + ":\r\n Set checked filter(s) ON, or\r\n Set checked filter(s) OFF, or\r\n Remove the checked filter(s)\r\n\r\nOr turn all filters on or off or remove them all." var vChoices = DOpus.Create.Vector var vList = DOpus.Create.Vector for (nn = 0; nn < nFilterNames; nn++) { vChoices (nn) = "Filter" + doBuffer (nn, 3) + ": " + aFilterNames [nn] vList (nn) = false } oDlg.choices = vChoices oDlg.list = vList oDlg.sort = false oDlg.buttons = "O&n|O&ff|&Remove|&All filters turned on|All filters &turned off|All filters re&moved|&Cancel" var nChoice = oDlg.show if (nChoice == 0) bContinue = false // Excludes nChoice = 0. if (nChoice == 1 || nChoice == 2 || nChoice == 3) { bContinue = false for (nn = 0; nn < oDlg.list.length; nn++) { if (oDlg.list (nn)) bContinue = true // Excludes (no boxes checked with nChoice = 1 or 2). } } } // STEP 3: For each selected item, get date modified and advance one minute if required. if (bContinue) { eSelected.moveFirst () while (!eSelected.atEnd ()) { // Process each item in turn. var oItem = eSelected.item () var dItemDate = new Date (oItem.modify) if (sDateModified == "AdvanceOneMinute") dItemDate = new Date (oItem.modify + 60000) var sItemDate = dItemDate.getFullYear () + doBuffer (dItemDate.getMonth () + 1) + doBuffer (dItemDate.getDate ()) + " " sItemDate = sItemDate + doBuffer (dItemDate.getHours ()) + ":" + doBuffer (dItemDate.getMinutes ()) + ":" + doBuffer (dItemDate.getSeconds ()) // STEP 4: Read the old filter file, and add the dialogue input. var aFilterLines = new Array // This array will contain the new filter lines. var sFilterFile = oItem + ":" + sADSFilterFileName // This is the ADS file. if (nChoice == 1 || nChoice == 4) // Define the filter. var sFilterAction = "Yes" // This is the "On" value. if (nChoice == 2 || nChoice == 5) var sFilterAction = "- -" // This is the "Off" value. if (nChoice == 3 || nChoice == 6) var sFilterAction = " " // Three spaces is the "Not set" value. if (nChoice > 3) { // Complete the cases involving all filters. for (nn = 0; nn < nFilterNames; nn++) aFilterLines [nn] = doFilterStem (nn) + sFilterAction } else { // Complete the cases involving checkboxes. aFilterLines = doOrganiseFilters (doReadFile (sFilterFile)) for (nn = 0; nn < nFilterNames; nn++) { if (oDlg.list (nn)) aFilterLines [nn] = "Filter" + doBuffer (nn, 3) + ": " + sFilterAction } } // STEP 5: Write the FilterNames array to the filter file. if (nChoice < 6 || oFSO.FileExists (sFilterFile)) { // Exclude another trivial case. var oFileWrite = oFSO.OpenTextFile (sFilterFile, 2, true) // Create if missing. for (nn = 0; nn < aFilterLines.length; nn++) { // ** DOpus.Output (aFilterLines [nn]) oFileWrite.WriteLine (aFilterLines [nn]) } oFileWrite.Close () // STEP 6: Set date modified now, or the original, or the original advanced one minute. if (!(sDateModified == "Now")) scriptCmdData.Func.Command.RunCommand ('SetAttr "' + oItem + '" Meta "lastmodifieddate:' + sItemDate + '"') } eSelected.moveNext () } } DOpus.Output ("<- - - - - - - -") } function doFilterStem (nn) { // Used above. nn must be a whole number return "Filter" + doBuffer (nn, 3) + ": " } // **** function 2 of 8 addin functions ****************** function onSetADSTags (scriptCmdData) { DOpus.Output ("- - - - - - - ->") // ******************************************************* // This OnInit function sets one of more tags of selected items. // The tags are written into successive lines of the ADS file MultiTags.txt // where they are labelled Tag000, Tag001, ... // ******************************************************* // STEP 1: Initialise some variables, including the collection of selected items. var bContinue = true var nn = 0 var ii = 0 var oFSO = new ActiveXObject ("Scripting.FileSystemObject") var eSelected = new Enumerator (scriptCmdData.func.sourcetab.selected) if (eSelected.atEnd()) { var oDlg = DOpus.dlg oDlg.title = "Setting tags" oDlg.icon = "warn" oDlg.message = "No files or directories have been selected.\r\n\r\nSelect at least one item and run the procedure again." oDlg.buttons = "&OK" oDlg.show bContinue = false // Excludes nothing selected. } // STEP 2: Choose the tag to be edited. if (bContinue) { var oItem = eSelected.item () eSelected.moveNext () var sPlural = "s" if (eSelected.atEnd ()) sPlural = "" var oDlg = DOpus.Dlg oDlg.title = "Setting tags" var sMessage = "Edit a tag value for the selected item" + sPlural + ". Other tag values will not change.\r\n" var sButtons = "" var sTemp for (nn = 0; nn < nTagNames; nn++) { sMessage = sMessage + "\r\nTag" + doBuffer (nn, 3) + ": (" + aTagNames [nn] + ")" sButtons = sButtons + "|" + aTagLabels [nn] // if (nn < 10) // sButtons = sButtons.slice (0, -1) + "&" + sButtons.slice (sButtons.length -1) } oDlg.message = sMessage oDlg.buttons = sButtons + "|&Remove all tags|&Cancel" var nTag = oDlg.show - 1 // nTag now indexes the tags. if (nTag == -1) // Cancel was selected. bContinue = false } // STEP 3: Enter the text for the tag. if (bContinue && nTag < nTagNames) { var oDlg = DOpus.Dlg oDlg.title = "Setting Tag" + doBuffer (nTag, 3) + ": " + aTagNames [nTag] oDlg.max = 512 sMessage = "Enter new text for Tag" + doBuffer (nTag, 3) + " labelled \"" + aTagNames [nTag] + "\"." if (sPlural == "") { var sTagFile = oItem + ":" + sADSTagFileName // This is the ADS file var aTagLines = doOrganiseTags (doReadFile (sTagFile), true) sDefault = doTrim (aTagLines [nTag].substr (8)) if (sDefault.length > 0) sMessage = sMessage + "\r\n\r\nThe current value of the tag is the default value below:" oDlg.defvalue = doTrim (aTagLines [nTag].substr (8)) oDlg.select = true } oDlg.message = sMessage oDlg.buttons = "&Set the tag|&Cancel" var nChoice = oDlg.show var sTagAction = doTrim (String (oDlg.Input)) if (sTagAction == "") sTagAction = " " sTagText = "Tag" + doBuffer (nTag, 3) + ": " + sTagAction if (nChoice == 0) bContinue = false } // STEP 4: For each selected item, get the date and advance it one minute if required. if (bContinue) { eSelected.moveFirst () while (!eSelected.atEnd ()) { // Process each item in turn. var oItem = eSelected.item () var dItemDate = new Date (oItem.modify) if (sDateModified == "AdvanceOneMinute") dItemDate = new Date (oItem.modify + 60000) var sItemDate = dItemDate.getFullYear () + doBuffer (dItemDate.getMonth () + 1) + doBuffer (dItemDate.getDate ()) + " " sItemDate = sItemDate + doBuffer (dItemDate.getHours ()) + ":" + doBuffer (dItemDate.getMinutes ()) + ":" + doBuffer (dItemDate.getSeconds ()) // STEP 5: Read the old tag file, and add the dialogue input. var aTagLines = new Array // This array will contain the new tag lines. var sTagFile = oItem + ":" + sADSTagFileName // This is the ADS file if (nTag == nTagNames) { // The user chose 'Remove all tags'. for (nn = 0; nn < nTagNames; nn++) aTagLines [nn] = "Tag" + doBuffer (nn, 3) + ": " + " " } else { aTagLines = doOrganiseTags (doReadFile (sTagFile), true) aTagLines [nTag] = sTagText } // STEP 6: Write the TagLines array to the ADS tag file. if (nTag < nTagNames || oFSO.FileExists (sTagFile)) { // Exclude another trivial case. var oFileWrite = oFSO.OpenTextFile (sTagFile, 2, true) // Create if missing. for (nn = 0; nn < nTagNames; nn++) { DOpus.Output (aTagLines [nn]) oFileWrite.WriteLine (aTagLines [nn]) } oFileWrite.Close () // STEP 7: Set the date now, or the original date, or the original advanced one minute. if (!(sDateModified == "Now")) { scriptCmdData.Func.Command.RunCommand ('SetAttr "' + oItem + '" Meta "lastmodifieddate:' + sItemDate + '"') } eSelected.moveNext () } } // End of while statement. } // End of if bContinue statement DOpus.Output ("<- - - - - - - -") } // End of function onSetTags // **** function 3 of 8 addin functions ****************** function onChooseReferenceItem (scriptCmdData) { DOpus.Output ("- - - - - - - ->") // ******************************************************* // This OnInit function reads the full pathname of a single selected item // into the global variable ReferenceItem. The immediate purpose of this is // to copy its s or tags to other items using the function PasteADSFiltersOrTags, // but any aspects of the reference item may be used in subsequent operations. // ******************************************************* var sAction = "" var nn = 0 var oDlg = DOpus.Dlg oDlg.title = "Reference item" sSelection = "single" var eSelected = new Enumerator (scriptCmdData.func.sourcetab.selected) if (eSelected.atEnd()) { sSelection = "none" } else { eSelected.moveFirst () oNewReference = eSelected.item () eSelected.moveNext () var sNewReferenceType = "file" if (oNewReference.Is_Dir) sNewReferenceType = "directory" if (!(eSelected.atEnd ())) sSelection = "multiple" } if (sSelection == "single") { var sMessageNew = "\r\n\r\nThe selected item can be set as the new reference item:\r\n" + oNewReference var sFilterFile = oNewReference + ":" + sADSFilterFileName var sTagFile = oNewReference + ":" + sADSTagFileName aFilterLines = doOrganiseFilters (doReadFile (sFilterFile), false) aTagLines = doOrganiseTags (doReadFile (sTagFile), false) if (!(aFilterLines.length > 0) && !(aTagLines.length > 0)) // No filters, no tags sMessageNew = sMessageNew + "\r\n\r\nThe selected item has no filters and no tags." if (aFilterLines.length > 0 && aTagLines.length > 0) { // Filters and tags sMessageNew = sMessageNew + "\r\n\r\nThe selected item has filters:" for (nn = 0; nn < nFilterNames; nn++) sMessageNew = sMessageNew + "\r\n" + aFilterLines [nn] + " (" + aFilterNames [nn] + ")" sMessageNew = sMessageNew + "\r\n\r\nThe selected item has tags:" for (nn = 0; nn < nTagNames; nn++) sMessageNew = sMessageNew + "\r\n" + aTagLines [nn] + " (" + aTagNames [nn] + ")" } if (aFilterLines.length > 0 && !(aTagLines.length > 0)) { // Filters, but no tags sMessageNew = sMessageNew + "\r\n\r\nThe selected item has filters:" for (nn = 0; nn < nFilterNames; nn++) sMessageNew = sMessageNew + "\r\n" + aFilterLines [nn] + " (" + aFilterNames [nn] + ")" sMessageNew = sMessageNew + "\r\n\r\nThe selected item has no tags." } if (!(aFilterLines.length > 0) && aTagLines.length > 0) { // Tags, but no filters sMessageNew = sMessageNew + "\r\n\r\nThe selected item has no filters." sMessageNew = sMessageNew + "\r\n\r\nThe selected item has tags:" for (nn = 0; nn < nTagNames; nn++) sMessageNew = sMessageNew + "\r\n" + aTagLines [nn] + " (" + aTagNames [nn] + ")" } var sButtonsNew = "Set the selected item as the &New reference item|" } else { var sButtonsNew = "|" if (sSelection == "none") var sMessageNew = "\r\n\r\nNo item has been selected. Select exactly one item as a new reference item.\r\nThen run the procedure again." if (sSelection == "multiple") var sMessageNew = "\r\n\r\nMultiple items have been selected. Select exactly one item as a new reference item.\r\nThen run the procedure again." } if (DOpus.Vars.Exists ("ReferenceItem")) { var sOldReference = DOpus.Vars.Get ("ReferenceItem") if (oFSO.FileExists (sOldReference) || oFSO.FolderExists (sOldReference)) { var oOldReference = DOpus.Vars.Get ("ReferenceItem") var sOldReferenceType = "file" if (oOldReference.Is_Dir) sOldReferenceType = "directory" var sMessageOld = "The current reference item is the " + sOldReferenceType + ":\r\n" + oOldReference var sButtonsOld = "&Go to current reference item|&View filters and tags of current reference item|&Cancel|" } else { var sMessageOld = "The current reference item no longer exists:\r\n" + sOldReference var sButtonsOld = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - &Cancel - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" } } else { var sMessageOld = "No reference item has been chosen." var sButtonsOld = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - &Cancel - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" } oDlg.message = sMessageOld + sMessageNew oDlg.buttons = sButtonsNew + sButtonsOld nChoice = oDlg.show if (sSelection == "single") { if (nChoice == 1) sAction = "New reference item" if (DOpus.Vars.Exists ("ReferenceItem")) { if (nChoice == 2) scriptCmdData.func.Command.RunCommand ("Go " + oOldReference) if (nChoice == 3) sAction = "View old filters and tags" } } else { if (DOpus.Vars.Exists ("ReferenceItem")) { if (oFSO.FileExists (sOldReference) || oFSO.FolderExists (sOldReference)) { if (nChoice == 1) scriptCmdData.func.Command.RunCommand ("Go " + oOldReference) if (nChoice == 2) sAction = "View old filters and tags" } } } if (sAction == "New reference item") { DOpus.Vars.Set ("ReferenceItem", oNewReference) DOpus.Vars ("ReferenceItem").persist = true var sMessage = "The new reference " + sOldReferenceType + " has been set:\r\n" + oOldReference + "\r\n\r\n" var aFilterLines = doOrganiseFilters (doReadFile (oNewReference + ":" + sADSFilterFileName)) var aTagLines = doOrganiseTags (doReadFile (oNewReference + ":" + sADSTagFileName)) if (aFilterLines.length > 0) { sMessage = sMessage + "The new reference " + sNewReferenceType + " has filters:\r\n" for (nn = 0; nn < nFilterNames; nn++) sMessage = sMessage + aFilterLines [nn] + " (" + aFilterNames [nn] + ")\r\n" sMessage = sMessage + "\r\n" } else { var sMessage = sMessage + "The new reference " + sNewReferenceType + " has no filters:\r\n\r\n" } if (aTagLines.length > 0) { sMessage = sMessage + "The new reference " + sNewReferenceType + " has tags:" for (nn = 0; nn < nTagNames; nn++) sMessage = sMessage + "\r\n" + aTagLines [nn] + " (" + aTagNames [nn] + ")" } else { sMessage = sMessage + "The new reference " + sNewReferenceType + " has no tags." } var oDlg = DOpus.Dlg oDlg.title = "New reference item chosen" oDlg.message = sMessage //"The new reference item is the " + sNewReferenceType + ":\r\n\r\n" + oNewReference oDlg.buttons = " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - &OK - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- - -" oDlg.show } if (sAction == "View old filters and tags") { var sMessage = "The current reference " + sOldReferenceType + " is:\r\n" + oOldReference + "\r\n\r\n" var oOldReferenceFilterFile = oOldReference + ":" + sADSFilterFileName var aFilterLines = doOrganiseFilters (doReadFile (oOldReferenceFilterFile), false) var oOldReferenceTagFile = oOldReference + ":" + sADSTagFileName var aTagLines = doOrganiseTags (doReadFile (oOldReferenceTagFile), false) if (aFilterLines.length > 0) { sMessage = sMessage + "The reference " + sOldReferenceType + " has filters:\r\n" for (nn = 0; nn < nFilterNames; nn++) sMessage = sMessage + aFilterLines [nn] + " (" + aFilterNames [nn] + ")\r\n" sMessage = sMessage + "\r\n" } else { var sMessage = sMessage + "The reference " + sOldReferenceType + " has no filters:\r\n\r\n" } if (aTagLines.length > 0) { sMessage = sMessage + "The reference " + sOldReferenceType + " has tags:" for (nn = 0; nn < nTagNames; nn++) sMessage = sMessage + "\r\n" + aTagLines [nn] + " (" + aTagNames [nn] + ")" } else { sMessage = sMessage + "The reference " + sOldReferenceType + " has no tags." } var oDlg = DOpus.Dlg oDlg.title = "Old reference item" oDlg.buttons = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - &OK - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" oDlg.message = sMessage oDlg.show } DOpus.Output ("<- - - - - - - -") } // **** function 4 of 8 addin functions ****************** function onPasteADSFiltersOrTags (scriptCmdData) { DOpus.Output ("- - - - - - - ->") // ******************************************************* // This OnInit function the pastes filters, or tabs, of the reference item to all // the reference items. All the previous filters, or tags, are overwritten. // ******************************************************* var oFSO = new ActiveXObject ("Scripting.FileSystemObject") var oDlg = DOpus.Dlg var bContinue = true var nn = 0 var bSomeItemsSelected = true var eSelected = new Enumerator (scriptCmdData.func.sourcetab.selected) if (eSelected.atEnd()) bSomeItemsSelected = false if (DOpus.Vars.Exists ("ReferenceItem")) { var sReferenceItem = DOpus.Vars.Get ("ReferenceItem") if (oFSO.FileExists (sReferenceItem) || oFSO.FolderExists (sReferenceItem)) { var oReferenceItem = DOpus.FSUtil.GetItem (sReferenceItem) var sReferenceFilterFile = sReferenceItem + ":" + sADSFilterFileName aFilterLines = doOrganiseFilters (doReadFile (sReferenceFilterFile), false) var sReferenceTagFile = sReferenceItem + ":" + sADSTagFileName aTagLines = doOrganiseTags (doReadFile (sReferenceTagFile), false) } else { bContinue = false oDlg.title = "Missing reference item" oDlg.icon = "warn" oDlg.message = "The reference item no longer exists:\r\n" + sReferenceItem + "\r\n\r\nSelect a new reference item before continuing with this procedure." oDlg.buttons = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - &OK - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" oDlg.show } } else { bContinue = false oDlg.title = "Reference item not chosen" oDlg.icon = "warn" oDlg.message = "No reference item has been chosen.\r\n\r\nSelect a reference item before continuing with this procedure." oDlg.buttons = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - &OK - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" oDlg.show } if (bContinue) { var sReferenceType = "file" if (oReferenceItem.is_dir) sReferenceType = "directory" var sMessage = "The current reference item is the " + sReferenceType + ":\r\n" + sReferenceItem + "\r\n" var sMessageFilters = "" var sMessageTags = "" var sAction = "" if (!(aFilterLines.length > 0) && !(aTagLines.length > 0)) { // No filters, no tags oDlg.title = "No filters or tags" oDlg.message = sMessage + "\r\nThe reference file has no filters and no tags." oDlg.buttons = "&Go to reference item|- - - - - - - - - - - - - - - - - - - - - - - - &OK - - - - - - - - - - - - - - - - - - - - - - - -" var nChoice = oDlg.show if (nChoice == 1) scriptCmdData.func.Command.RunCommand ("Go " + sReferenceItem) } if (aFilterLines.length > 0 && aTagLines.length > 0) { // Filters and tags sMessage = sMessage + "\r\nThe reference file has filters:" for (nn = 0; nn < nFilterNames; nn++) sMessage = sMessage + "\r\n" + aFilterLines [nn] + " (" + aFilterNames [nn] + ")" sMessage = sMessage + "\r\n\r\nThe reference file has tags:" for (nn = 0; nn < nTagNames; nn++) sMessage = sMessage + "\r\n" + aTagLines [nn] + " (" + aTagNames [nn] + ")" oDlg.title = "Paste filters or tags" oDlg.Message = sMessage + "\r\n\r\nThis action will paste all its filters, or all its tags, to the selected items:" oDlg.buttons = "|Paste all &Filters to selected items|Paste all &Tags to selected items|Paste &Both filters and tags|&Go to reference item|&Cancel" var nChoice = oDlg.show if (nChoice == 1 || nChoice == 3) sAction = doCopyFiltersOrTags (aFilterLines, sADSFilterFileName) if (nChoice == 2 || nChoice == 3) sAction = doCopyFiltersOrTags (aTagLines, sADSTagFileName) if (nChoice == 4) scriptCmdData.func.Command.RunCommand ("Go " + sReferenceItem) } if (aFilterLines.length > 0 && !(aTagLines.length > 0)) { // Filters, but no tags sMessage = sMessage + "\r\nThe reference file has filters:" for (nn = 0; nn < nFilterNames; nn++) sMessage = sMessage + "\r\n" + aFilterLines [nn] + " (" + aFilterNames [nn] + ")" sMessage = sMessage + "\r\n\r\nThe reference file has no tags." oDlg.title = "Paste filters" oDlg.Message = sMessage + sMessageFilters + "\r\n\r\nThis action will paste all its filters to the selected items:" oDlg.buttons = "|Paste all &Filters|&Go to reference item|- - - - - - - - - - - - - - - - &Cancel - - - - - - - - - - - - - - - -|" var nChoice = oDlg.show if (nChoice == 1) sAction = doCopyFiltersOrTags (aFilterLines, sADSFilterFileName) if (nChoice == 2) scriptCmdData.func.Command.RunCommand ("Go " + sReferenceItem) } if (!(aFilterLines.length > 0) && aTagLines.length > 0) { // Tags, but no filters sMessage = sMessage + "\r\nThe reference file has no filters." sMessage = sMessage + "\r\n\r\nThe reference file has tags:" for (nn = 0; nn < nTagNames; nn++) sMessage = sMessage + "\r\n" + aTagLines [nn] + " (" + aTagNames [nn] + ")" oDlg.title = "Paste tags" oDlg.Message = sMessage + sMessageTags + "\r\n\r\nThis action will paste all its tags to the selected items." oDlg.buttons = "|Paste all &Tags|&Go to reference item|- - - - - - - - - - - - - - - - &Cancel - - - - - - - - - - - - - - - -|" var nChoice = oDlg.show if (nChoice == 1) sAction = doCopyFiltersOrTags (aTagLinCes, sADSTagFileName) if (nChoice == 2) scriptCmdData.func.Command.RunCommand ("Go " + sReferenceItem) } } function doCopyFiltersOrTags (aLines, sADSFileName) { if (aLines.length > 0){ eSelected.moveFirst () while (!eSelected.atEnd ()) { var oItem = eSelected.item () var dItemDate = new Date (oItem.modify) // Read the date modified. if (sDateModified == "AdvanceOneMinute") // Add a minute if required. dItemDate = new Date (oItem.modify + 60000) var sItemDate = dItemDate.getFullYear () + doBuffer (dItemDate.getMonth () + 1) + doBuffer (dItemDate.getDate ()) + " " sItemDate = sItemDate + doBuffer (dItemDate.getHours ()) + ":" + doBuffer (dItemDate.getMinutes ()) + ":" + doBuffer (dItemDate.getSeconds ()) sItemADSFile = oItem + ":" + sADSFileName // Write the tag file. var oFileWrite = oFSO.OpenTextFile (sItemADSFile, 2, true) for (nn = 0; nn < aLines.length; nn++) oFileWrite.WriteLine (aLines [nn]) oFileWrite.Close () if (!(sDateModified == "Now")) // Reset the date modified. scriptCmdData.Func.Command.RunCommand ('SetAttr "' + oItem + '" Meta "lastmodifieddate:' + sItemDate + '"') eSelected.moveNext () } } } DOpus.Output ("<- - - - - - - -") } // **** function 5 of 8 addin functions ****************** function onToggleADSFilterColumns (scriptCmdData) { DOpus.Output ("- - - - - - - ->") // ******************************************************* // This OnInit function toggles the filter columns in a display. // The chosen filter columns become columns 3, 4, ... // It also allows a column showing all filters at once, // and another column showing the number of associated ADS files. // ******************************************************* var nn = 0 var oDlg = DOpus.dlg oDlg.Title = "Toggle a filter column" oDlg.message = "Select the columns that are to be toggled. Or turn on or off all filter columns." var vChoices = DOpus.Create.Vector for (nn = 0; nn < nFilterNames; nn++) vChoices (nn) = "Filter" + doBuffer (nn, 3) + ": " + aFilterNames [nn] oDlg.choices = vChoices oDlg.list = DOpus.Create.Vector (false) oDlg.sort = false oDlg.buttons = "&Toggle checked columns|All filter columns O&N|All filter columns O&FF|Toggle all filters in &One column|Toggle column for &ADS files count|&Cancel" var nChoice = oDlg.show if (nChoice == 5) { var sCommand = 'Set ColumnsToggle="scp:ADSFiltersAndTags/ADSCount(3)"' scriptCmdData.func.Command.RunCommand (sCommand) } if (nChoice == 4) { var sCommand = 'Set ColumnsToggle="scp:ADSFiltersAndTags/AllFilters(3)"' scriptCmdData.func.Command.RunCommand (sCommand) } if (nChoice == 3) { for (nn = nFilterNames - 1; nn > -1; nn--) { var sFilterText = "Filter" + doBuffer (nn, 3) var sCommand = 'Set ColumnsRemove="scp:ADSFiltersAndTags/' + sFilterText + '"' scriptCmdData.func.Command.RunCommand (sCommand) } } if (nChoice == 2) { for (nn = nFilterNames - 1; nn > -1; nn--) { var sFilterText = "Filter" + doBuffer (nn, 3) var sCommand = 'Set ColumnsRemove="scp:ADSFiltersAndTags/' + sFilterText + '"' scriptCmdData.func.Command.RunCommand (sCommand) sCommand = 'Set ColumnsToggle="scp:ADSFiltersAndTags/' + sFilterText + '(3)"' scriptCmdData.func.Command.RunCommand (sCommand) } } if (nChoice == 1) { for (nn = nFilterNames - 1; nn > -1; nn--) { if (oDlg.list (nn)) { var sFilterText = "Filter" + doBuffer (nn, 3) var sCommand = 'Set ColumnsToggle=scp:ADSFiltersAndTags/' + sFilterText + '(3)"' scriptCmdData.func.Command.RunCommand (sCommand) } } } DOpus.Output ("<- - - - - - - -") } // **** function 6 of 8 addin functions ****************** function onToggleADSTagColumns (scriptCmdData) { DOpus.Output ("- - - - - - - ->") // ******************************************************* // This OnInit function toggles the tag columns in a display. // The chosen tag columns become columns 3, 4, ... // It also allows a column showing all tags at once, // and another column showing the number of associated ADS files. // ******************************************************* var nn = 0 var oDlg = DOpus.dlg oDlg.Title = "Toggle a tag column" oDlg.message = "Select the columns that are to be toggled. Or turn on or off all tag columns." var vChoices = DOpus.Create.Vector for (nn = 0; nn < nTagNames; nn++) vChoices (nn) = "Tag" + doBuffer (nn, 3) + ": " + aTagNames [nn] oDlg.choices = vChoices oDlg.list = DOpus.Create.Vector (false) oDlg.sort = false oDlg.buttons = "&Toggle checked columns|All tag columns O&N|All tag columns O&FF|Toggle all tags in &One column|Toggle column for &ADS files count|&Cancel" var nChoice = oDlg.show if (nChoice == 5) { var sCommand = 'Set ColumnsToggle="scp:ADSFiltersAndTags/ADSCount(3)"' scriptCmdData.func.Command.RunCommand (sCommand) } if (nChoice == 4) { var sCommand = 'Set ColumnsToggle="scp:ADSFiltersAndTags/AllTags(3)"' scriptCmdData.func.Command.RunCommand (sCommand) } if (nChoice == 3) { for (nn = nTagNames - 1; nn > -1; nn--) { var sTagText = "Tag" + doBuffer (nn, 3) var sCommand = 'Set ColumnsRemove="scp:ADSFiltersAndTags/' + sTagText + '"' scriptCmdData.func.Command.RunCommand (sCommand) } } if (nChoice == 2) { for (nn = nTagNames - 1; nn > -1; nn--) { var sTagText = "Tag" + doBuffer (nn, 3) var sCommand = 'Set ColumnsRemove="scp:ADSFiltersAndTags/' + sTagText + '"' scriptCmdData.func.Command.RunCommand (sCommand) sCommand = 'Set ColumnsToggle="scp:ADSFiltersAndTags/' + sTagText + '(3)"' scriptCmdData.func.Command.RunCommand (sCommand) } } if (nChoice == 1) { for (nn = nTagNames - 1; nn > -1; nn--) { if (oDlg.list (nn)) { var sTagText = "Tag" + doBuffer (nn, 3) var sCommand = 'Set ColumnsToggle=scp:ADSFiltersAndTags/' + sTagText + '(3)"' scriptCmdData.func.Command.RunCommand (sCommand) } } } DOpus.Output ("<- - - - - - - -") } // **** function 7 of 8 addin functions ****************** function onEditADSFiles (scriptCmdData) { DOpus.Output ("- - - - - - - ->") // ******************************************************* // This OnInit function displays all the ADS files of an item, // presenting options for the text editing of any ADS files // and for the creation of a new ADS text file. // ******************************************************* // STEP 1: Obtain the collection of selected items and determine programme flow. var eSelected = new Enumerator (scriptCmdData.func.sourcetab.selected) eSelected.moveFirst () if (eSelected.atEnd ()) { // If nothing is selected, look at ADS files in the whole directory doGetDirR (scriptCmdData) } else { var oItem = eSelected.item () eSelected.moveNext () if (eSelected.atEnd()) { // If exactly one item is selected, process its ADS files. doGetDirRItem (scriptCmdData, oItem) } else { var oDlg = DOpus.dlg // If two or more items selected, end it. oDlg.title = "Programme cancelled" oDlg.message = "Select one file or directory in order to process its ADS files or create a new ADS file.\r\n\r\nOR\r\n\r\nSelect no items in order to choose and edit any ADS file in the directory." oDlg.buttons = "&OK" oDlg.show } } DOpus.Output ("<- - - - - - - -") } // End of function onEditADSFiles // The remaining two steps define the functions called in Step 1 above. // STEP 2: Function called in Step 1 when one item has been selected. function doGetDirRItem (scriptCmdData, oItem) { var sItemType = "file" if (oItem.is_dir) sItemType = "directory" dItemDate = new Date (oItem.modify) if (sDateModified == "AdvanceOneMinute") dItemDate = new Date (oItem.modify + 60000) sItemDate = dItemDate.getFullYear () + doBuffer (dItemDate.getMonth () + 1) + doBuffer (dItemDate.getDate ()) + " " sItemDate = sItemDate + doBuffer (dItemDate.getHours ()) + ":" + doBuffer (dItemDate.getMinutes ()) + ":" + doBuffer (dItemDate.getSeconds ()) var sTempFile = DOpus.aliases ("temp").path + "\\DOpusDirRFile.txt" oWSShell = new ActiveXObject ("WScript.Shell") oWSShell.Run ("Cmd /C Dir \"" + oItem + "\" /R > " + sTempFile, 0, true) var aADSLines = doReadFile (sTempFile) scriptCmdData.Func.Command.RunCommand ("Delete " + sTempFile + " Quiet") var nn = 0 var ii = 0 var ADSLine = "" var sMessage = "\r\n" var aADSFiles = new Array for (nn = 0; nn < aADSLines.length; nn++) { sADSLine = aADSLines [nn] aADSLine = sADSLine.split (":") if (aADSLine.length > 2) { nItem = oItem.name.length sMessage = sMessage + "\r\n" + sADSLine.substr (20, 13) + " " + sADSLine.substr (35 + nItem, sADSLine.length - 41 - nItem) aADSFiles [ii] = aADSLine [1] ii++ } } var nADSFiles = aADSFiles.length var sButtons = "" var oDlg = DOpus.dlg oDlg.title = "ADS files of " + oItem.name if (nADSFiles == 0) { oDlg.message = "There are no ADS files associated with the " + sItemType + ":\r\n" + oItem + "\r\n\r\nA new ADS file associated with this " + sItemType + " can be created." oDlg.buttons = "|Create a &New ADS file|- - - - - - - - &Cancel - - - - - - - -" } else { if (nADSFiles == 1){ oDlg.message = "The single ADS file, and its size, associated with the " + sItemType + ":\r\n" + oItem + sMessage + "\r\n\r\nEdit this ADS file, or create a new ADS file associated with this " + sItemType + "." oDlg.buttons = "&1. " + aADSFiles [0] + "|Create a &New ADS file|- - - - - - - - - - - - - - - - &Cancel - - - - - - - - - - - - - - - -" } else { oDlg.message = "Listed below are the " + nADSFiles + " ADS files and their sizes associated with the " + sItemType + ":\r\n" + oItem + sMessage + "\r\n\r\nChoose and edit one ADS file as a text file, or create a new ADS file associated with this " + sItemType + "." for (nn = 0; nn < nADSFiles; nn++) { sButtons = sButtons + "|" + (nn + 1) sButtons = sButtons.slice (0, -1) + "&" + sButtons.slice (sButtons.length -1) sButtons = sButtons + ". " + aADSFiles [nn] } oDlg.Buttons = sButtons + "|Create a &New ADS file|- - - - - - - - - - - - - - - - &Cancel - - - - - - - - - - - - - - - -" } } var nChoice = oDlg.show if (nChoice > nADSFiles) { var nAction = 0 var oDlg = DOpus.dlg oDlg.title = "Choose a filename" oDlg.message = "This procedure will create a new hidden ADS file associated with the " + sItemType + "\r\n" + oItem.name + "\r\nand allow it to be edited.\r\n\r\nEnter the filename, with extension, of the new ADS file of " + oItem.name + ":" oButtons = "&OK|&Cancel" oDlg.max = 128 nAction = oDlg.show sNewADS = oDlg.input scriptCmdData.Func.Command.RunCommand (sEditor + ' "' + oItem + ':' + sNewADS +'"') if (nAction == 1) DOpus.Output (sEditor + ' "' + oItem + ':' + sNewADS +'"') } else { if (nChoice > 0) { var sADSFile = aADSFiles [nChoice - 1] var oDlg = DOpus.dlg scriptCmdData.Func.Command.RunCommand (sEditor + ' "' + oItem + ':' + sADSFile + '"') } } if (nChoice > 0) { if (sDateModified != "Now") { DOpus.Output ('SetAttr "' + oItem + '" Meta "lastmodifieddate:' + sItemDate + '"') scriptCmdData.Func.Command.RunCommand ('SetAttr "' + oItem + '" Meta "lastmodifieddate:' + sItemDate + '"') } } } // STEP 3: Function called in Step 1 when no items have been selected. function doGetDirR (scriptCmdData) { oWSShell = new ActiveXObject ("WScript.Shell") sSourceTab = scriptCmdData.Func.sourcetab.path oWSShell.CurrentDirectory = sSourceTab sTempFile = DOpus.aliases ("temp").path + "\\DOpusDirR.txt" oWSShell.Run ('Cmd /C Dir /R > ' + sTempFile, 0, true) var aADSLines = doReadFile (sTempFile) scriptCmdData.Func.Command.RunCommand ("Delete " + sTempFile + " Quiet") var nn = 0 var ii = 0 var aADSFiles = new Array var aMessage = new Array for (nn = 0; nn < aADSLines.length; nn++) { var sADSLine = aADSLines [nn] aADSLine = sADSLine.split (":") if (aADSLine.length < 3) { var sItemDetails = sADSLine.substr (0, 34) } else { aADSFiles [ii] = sADSLine.substr (34, sADSLine.length - 40) if (ii > 8) { aMessage [ii] = (ii + 1) + ". " + sItemDetails + aADSLine [0].substr (25) + ":" + aADSLine [1] } else { aMessage [ii] = "0" + (ii + 1) + ". " + sItemDetails + aADSLine [0].substr (25) + ":" + aADSLine [1] } DOpus.Output (aMessage [ii]) ii++ } } var nADSFiles = aADSFiles.length DOpus.Output ("nADSFiles = " + nADSFiles) if (aADSFiles.length == 0) { var oDlg = DOpus.dlg oDlg.title = "No ADS files" oDlg.message = "No files in this directory have hidden ADS files." oDlg.buttons = "&OK|&Cancel" oDlg.show } else { var nGroups = 0 nn = nADSFiles while (nn > 0) { nGroups++ for (ii = 0; ii < 10; ii++) nn = nn - 1 } } nn = 0 for (ii = 0; ii < nGroups; ii++) { var sMessage = "Choose an ADS file to edit as a text file. The date modified and the size of the main file are given first, then the size of the ADS file.\r\n" var sButtons = "" while (nn < nADSFiles && nn < (ii + 1) * 10) { sMessage = sMessage + "\n" + aMessage [nn] sButtons = sButtons + "|" + (nn + 1) sButtons = sButtons.slice (0, -1) + "&" + sButtons.slice (sButtons.length -1) nn++ } if (nn < nADSFiles) { sMessage = sMessage + "\n . . . There are " + (nADSFiles - nn) + " more ADS files." sButtons = sButtons + "|&Next group|- - - - - - - - - - - - - - - - - - - - - - - - &Cancel the job - - - - - - - - - - - - - - - - - - - - - - - -|" } else { sButtons = sButtons + "|- - - - - - - - - - - - - - - - - - - - - - - - &Cancel - - - - - - - - - - - - - - - - - - - - - - - -" } var oDlg = DOpus.Dlg oDlg.title = "Edit an ADS file: Screen " + (ii + 1) oDlg.message = sMessage oDlg.buttons = sButtons var nChoice = oDlg.show DOpus.delay (250) DOpus.Output ("nChoice = " + nChoice + " and ii * 10 + nChoice = " + (ii * 10 + nChoice)) if (nChoice > 0) { var nItem = ii * 10 + nChoice if (nItem <= nn) { var oADSFile = DOpus.FSUtil.GetItem (scriptCmdData.func.sourcetab.path + "\\" + aADSFiles [nItem - 1]) var oItem = DOpus.FSUtil.GetItem (scriptCmdData.func.sourcetab.path + "\\" + aADSFiles [nItem - 1].split (":") [0]) dItemDate = new Date (oItem.modify) if (sDateModified == "AdvanceOneMinute") dItemDate = new Date (oItem.modify + 60000) sItemDate = dItemDate.getFullYear () + doBuffer (dItemDate.getMonth () + 1) + doBuffer (dItemDate.getDate ()) + " " sItemDate = sItemDate + doBuffer (dItemDate.getHours ()) + ":" + doBuffer (dItemDate.getMinutes ()) + ":" + doBuffer (dItemDate.getSeconds ()) scriptCmdData.Func.Command.RunCommand (sEditor + ' "' + oADSFile + '"') if (sDateModified != "Now") { DOpus.Output ('SetAttr "' + oItem + '" Meta "lastmodifieddate:' + sItemDate + '"') scriptCmdData.Func.Command.RunCommand ('SetAttr "' + oItem + '" Meta "lastmodifieddate:' + sItemDate + '"') } break } else { sMessage = "" sButtons = "" } } else { break } } } // ********** FURTHER GENERAL HELPER FUNCTIONS ********** function doBuffer (nNumber, nLength) { // String, non-negative whole numbers if (arguments.length < 2) // Default is length 2 nLength = 2 var sNumber = "" if (nNumber >= 0 && Math.floor (nNumber) == nNumber && nLength >= 0 && Math.floor (nLength) == nLength) { sNumber = nNumber.toString () // This will be the buffered or truncated number. while (sNumber.length < nLength) // This bit adds zeroes at the front. sNumber = "0" + sNumber if (sNumber.length > nLength) // This bit truncates from the left. sNumber = sNumber.substr (sNumber.length - nLength) } return sNumber } // ********************************************** function doTrim (sString) { // Trims spaces and tabs from ends of string. if (sString.length > 0) { while (sString.substr (0, 1) == " " || sString.substr (0, 1) == "\t" ) sString = sString.substr (1) while (sString.substr (sString.length - 1) == " " || sString.substr (sString.length - 1) == "\t") sString = sString.substr (0, sString.length - 1) } return sString } // ********************************************** function doReadFile (sFile) { // Reads the lines of the file into an array. var oFSO = new ActiveXObject ("Scripting.FileSystemObject") var aLines = false // Arrays are truthy, so this carries non-existence. if (oFSO.FileExists (sFile)) { aLines = new Array var nn = 0 var oFileRead = oFSO.OpenTextFile (sFile, 1) while (!oFileRead.AtEndOfStream) { aLines [nn] = oFileRead.ReadLine () nn++ } oFileRead.Close () } return aLines } // ********************************************** function doOrganiseFilters (aFilterLines, bDoIt) { // aFilterLines is an array or 0. // bDoIt produces a full-length array even if aFilterLines = 0. if (arguments.length < 2) bDoIt = true // The default var aNewFilters = new Array var nn = 0 var nIndex = 0 for (nn = 0; nn < nFilterNames; nn++) aNewFilters [nn] = "Filter" + doBuffer (nn, 3) + ": " if (aFilterLines) { for (nn = aFilterLines.length - 1; nn > -1; nn--) { nIndex = 1 * aFilterLines [nn].substr (6, 3) var sOldStem = aFilterLines [nn].substr (0, 11) var sOldValue = doTrim (aFilterLines [nn].substr (11)) if (sOldValue == "Yes" || sOldValue == "- -") { var sNewStem = "Filter" + doBuffer (nIndex, 3) + ": " if (nIndex < nFilterNames && sOldStem == sNewStem) { aNewFilters [nIndex] = sNewStem + sOldValue bDoIt = true // Checks if any line is a valid filter line. } } } } if (!bDoIt) aNewFilters = 0 return aNewFilters } // ********************************************** function doOrganiseTags (aTagLines, bDoIt) { // aTagLines is an array or 0. // bDoIt = true produces a full-length array even if aTagLines = 0. if (arguments.length < 2) bDoIt = true // The default var aNewTags = new Array var nn = 0 var nIndex = 0 for (nn = 0; nn < nTagNames; nn++) aNewTags [nn] = "Tag" + doBuffer (nn, 3) + ": " if (aTagLines) { var nn = 0 for (nn = aTagLines.length - 1; nn > -1; nn--) { nIndex = 1 * aTagLines [nn].substr (3, 3) var sOldStem = aTagLines [nn].substr (0, 8) var sOldValue = doTrim (aTagLines [nn].substr (8)) if (sOldValue.length > 0) { var sNewStem = "Tag" + doBuffer (nIndex, 3) + ": " if (nIndex < nTagNames && sOldStem == sNewStem) { aNewTags [nIndex] = sNewStem + sOldValue bDoIt = true // Checks if any line is a valid tag line. } } } } if (!bDoIt) aNewTags = 0 return aNewTags }