|
/* |
|
------------------------------------------------------------------------------- |
|
Name: TB_SetResetCaptions.js |
|
Description: This script sets caption text on multiple captions across multiple panels. |
|
Usage: Select panels, then select captions, then either enter text to overwrite or leave blank to clear. |
|
Author: Karl Olson & Corey Barnes |
|
Created: 2018/08/30 |
|
Updated: 2018/09/04 |
|
Version: 1.0.0 |
|
------------------------------------------------------------------------------- |
|
*/ |
|
|
|
function SetResetCaptions() { |
|
MessageLog.trace("Set Captions--------- "); |
|
var selectionManager = new SelectionManager; |
|
var captionManager = new CaptionManager; |
|
var currentPanelSelection = selectionManager.getPanelSelection(); |
|
if (currentPanelSelection.length <= 0) return; |
|
|
|
// Create a list of all caption box names. |
|
var captionNames = new Array(0); |
|
var numberOfCaptions = captionManager.numberOfPanelCaptions(); |
|
|
|
for (var j = 0; j < numberOfCaptions; j++) { |
|
var captionName = captionManager.nameOfPanelCaption(j); |
|
if (captionNames.indexOf(captionName) == -1) |
|
captionNames.push(captionName); |
|
} |
|
|
|
// Create a dialog displaying all caption names as checkboxes & a text input. |
|
var captionEditingDialog = new Dialog; |
|
captionEditingDialog.title = "Set and Reset Captions"; |
|
captionEditingDialog.width = 400; |
|
|
|
var textInputLabel = new Label; |
|
textInputLabel.text = "Input new caption text. To delete existing captions, leave box blank."; |
|
|
|
var textInput = new TextEdit; |
|
|
|
var group = new GroupBox; |
|
group.title = "Caption Names"; |
|
var checkBoxesArray = new Array(0); |
|
|
|
for (var i = 0; i < captionNames.length; ++i) { |
|
var aCheckBox = new CheckBox; |
|
aCheckBox.text = captionNames[i]; |
|
checkBoxesArray.push(aCheckBox); |
|
group.add(aCheckBox); |
|
} |
|
|
|
captionEditingDialog.add(group); |
|
captionEditingDialog.add(textInputLabel); |
|
captionEditingDialog.add(textInput); |
|
|
|
var rc = captionEditingDialog.exec(); |
|
|
|
// If dialog cancelled, return |
|
if (!rc) { |
|
return; |
|
} |
|
|
|
// Retrieve the selected caption names from the group. |
|
var currentCaptionSelections = new Array(0); |
|
for (var i = 0; i < checkBoxesArray.length; ++i) { |
|
if (checkBoxesArray[i].checked == true) { |
|
currentCaptionSelections.push(checkBoxesArray[i].text); |
|
} |
|
} |
|
|
|
// Set the caption text if any are selected. |
|
scene.beginUndoRedoAccum("Set Captions"); |
|
|
|
if (currentCaptionSelections.length > 0) { |
|
for (var i = 0; i < currentPanelSelection.length; i++) { |
|
for (var j = 0; j < currentCaptionSelections.length; j++) { |
|
captionManager.setPanelCaptionText(currentCaptionSelections[j], currentPanelSelection[i], textInput.text); |
|
} |
|
} |
|
} |
|
|
|
scene.endUndoRedoAccum(); |
|
|
|
// Prepare report. |
|
var finalMessage; |
|
if (currentCaptionSelections.length > 0) { |
|
finalMessage = "Captions set.\n"; |
|
} else { |
|
finalMessage = "No captions set.\n"; |
|
} |
|
MessageBox.information(finalMessage); |
|
} |