with (app) {
app.scriptPreferences.version = 5;
var iniFile = new File (activeScript.path+ "/TFManager.ini");
if (iniFile.exists) {
eval ("//@include \'TFManager.ini\';");
} else {
alert("Can\'t open ini file!");
exit();
}
var myLangFile = new File (activeScript.path + "/" + iniLangFile);
if (myLangFile.exists) {
eval ("//@include \'" + iniLangFile + "\';");
} else {
alert ("Cant open lang file!");
exit();
}
if (documents.length < 1) {
alert(langNoDoc);
exit();
}
if (selection.length != 1) {
alert(langNoObj);
exit();
}
try {
var myStory = selection[0].parentStory;
var myStoryId = myStory.id;
} catch (err) {
alert(langNoObj);
exit();
}
var myDoc = activeDocument;
var mySelObject = selection[0];
var myDocPref = myDoc.documentPreferences;
var myDocViewPref = myDoc.viewPreferences;
var myDocUtinsHorisontal = myDocViewPref.horizontalMeasurementUnits;
var myDocUtinsVertical = myDocViewPref.verticalMeasurementUnits;
myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;
var myMaxHeight = myDocPref.pageHeight;
var myMaxWidth = myDocPref.pageWidth;
myDoc.undo();
myDoc.undo();
var myDialog = dialogs.add({name:iniScriptName + " " + iniSriptVersion});
with (myDialog.dialogColumns.add()) {
with (borderPanels.add()) {
with (dialogColumns.add()) {
dialogRows.add().staticTexts.add({staticLabel:langFilesOptions});
with (borderPanels.add().dialogColumns.add()) {
var mySelectNames = dialogRows.add().radiobuttonGroups.add();
with (mySelectNames) {
radiobuttonControls.add({staticLabel:langLongNames});
radiobuttonControls.add({staticLabel:langShortNames, checkedState:true});
}
var mySelectURI = dialogRows.add().checkboxControls.add({staticLabel:langURIEncoded});
with (dialogRows.add()) {
with (dialogColumns.add()) {
dialogRows.add().staticTexts.add({staticLabel:langTagBefore});
dialogRows.add().staticTexts.add({staticLabel:langTagAfter});
}
with (dialogColumns.add()) {
var mySelectTagBefore = dialogRows.add().textEditboxes.add({editContents:iniTagBefore, minWidth:50});
var mySelectTagAfter = dialogRows.add().textEditboxes.add({editContents:iniTagAfter, minWidth:50});
}
}
}
}
with (dialogColumns.add()) {
dialogRows.add().staticTexts.add({staticLabel:langManageOptions});
with (borderPanels.add().dialogColumns.add()) {
with (dialogRows.add()) {
with (dialogColumns.add()) {
var mySelectPersent = dialogRows.add().checkboxControls.add({staticLabel:langPercent, checkedState:true});
var mySelectHeight = dialogRows.add().checkboxControls.add({staticLabel:langMaxHeight, checkedState:true});
var mySelectWidth = dialogRows.add().checkboxControls.add({staticLabel:langMaxWidth, checkedState:true});
}
with (dialogColumns.add()) {
var mySelectPercentValue = dialogRows.add().percentEditboxes.add({editValue:100, minimumValue:1, maximumValue:200, largeNudge:5, smallNudge:1, minWidth:70});
var mySelectHeightValue = dialogRows.add().measurementEditboxes.add({editUnits:myDocUtinsHorisontal, minimumValue:10, maximumValue:myMaxHeight, editValue:myMaxHeight / 2, largeNudge:.5, smallNudge:1, minWidth:70});
var mySelectWidthValue = dialogRows.add().measurementEditboxes.add({editUnits:myDocUtinsVertical, minimumValue:10, maximumValue:myMaxWidth, editValue:myMaxWidth / 2, largeNudge:.5, smallNudge:1, minWidth:70});
}
}
}
dialogRows.add().staticTexts.add({staticLabel:"\u00A9 Oleg Butrin"});
dialogRows.add().staticTexts.add({staticLabel:"http://indesign.rudtp.ru"});
}
}
}
var myResult = myDialog.show();
if (!myResult) {
myDialog.destroy();
exit();
}
var myFolder = Folder.selectDialog(langSelectFolder);
if (!myFolder) {
alert(langFolderNotSelect);
myDialog.destroy();
exit();
}
var myFiles = myFolder.getFiles("*");
var myFileErrorsCount = 0;
var myPlaceErrorsCount = 0;
findTextPreferences = null;
for (myCounter = 0; myCounter < myFiles.length; myCounter++) {
if (myFiles[myCounter].constructor.name != "File") {
continue;
}
if (mySelectNames.selectedButton == 0) {
if (mySelectURI.checkedState) {
var myFileName = myFiles[myCounter].fullName;
} else {
var myFileName = myFiles[myCounter].fsName;
}
} else {
if (mySelectURI.checkedState) {
var myFileName = myFiles[myCounter].name;
} else {
var myFileName = decodeURI(myFiles[myCounter].name);
}
}
findTextPreferences.findWhat = mySelectTagBefore.editContents + String(myFileName) + mySelectTagAfter.editContents;
var myFindResult = myStory.findText(false);
if (myFindResult.length > 0) {
myFindResult.reverse();
try {
var myPage = activeWindow.activePage;
var myPlacePoint = new Array(0,0)
var myPlacedObject = myPage.place(myFiles[myCounter], myPlacePoint, undefined, false, false, true, true);
if (myPlacedObject[0].parent.contentType == ContentType.GRAPHIC_TYPE) {
myObject = myPlacedObject[0].parent;
if (mySelectPersent.checkedState) {
myObject.horizontalScale = mySelectPercentValue.editValue;
myObject.verticalScale = mySelectPercentValue.editValue;
}
if ((mySelectHeight.checkedState) && ((myObject.visibleBounds[2] - myObject.visibleBounds[0]) > mySelectHeightValue.editContents)) {
var myHeigthPercent = (mySelectHeightValue.editContents * 100 / (myObject.visibleBounds[2] - myObject.visibleBounds[0]));
myObject.horizontalScale = myHeigthPercent;
myObject.verticalScale = myHeigthPercent;
}
if ((mySelectWidth.checkedState) && ((myObject.visibleBounds[3] - myObject.visibleBounds[1]) > mySelectWidthValue.editContents)) {
var myWidthPercent = (mySelectWidthValue.editContents * 100 / (myObject.visibleBounds[3] - myObject.visibleBounds[1]));
myObject.horizontalScale = myWidthPercent;
myObject.verticalScale = myWidthPercent;
}
myObject.fit(FitOptions.CONTENT_TO_FRAME);
} else {
myObject = myPlacedObject.textFrames[0];
if ((mySelectHeight.checkedState)) {
var myHeigthPercent = (mySelectHeightValue.editContents * 100 / (myObject.visibleBounds[2] - myObject.visibleBounds[0]));
}
if ((mySelectWidth.checkedState)) {
var myWidthPercent = (mySelectWidthValue.editContents * 100 / (myObject.visibleBounds[3] - myObject.visibleBounds[1]));
}
myObject.verticalScale = myHeigthPercent;
myObject.horizontalScale = myWidthPercent;
}
myObject.select(SelectionOptions.REPLACE_WITH);
cut();
} catch (err) {
myFileErrorsCount++;
continue;
}
for (myCount = 0; myCount < myFindResult.length; myCount++) {
myFindResult[myCount].select(SelectionOptions.REPLACE_WITH);
try {
paste();
} catch (err) {
myPlaceErrorsCount++;
}
}
}
}
findTextPreferences = null;
// mySelObject.select(SelectionOptions.REPLACE_WITH);
if ((myFileErrorsCount != 0) || (myPlaceErrorsCount != 0)) {
alert(langAllDone + "\n" + String(myFileErrorsCount) + " " + langPlaceErrors + "\n" + String(myPlaceErrorsCount) + " " + langReplaceErrors);
} else {
alert(langAllDone);
}
myDialog.destroy();
exit();
}