Skip to content

Commit

Permalink
upd Add progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
pchiorean committed Mar 27, 2022
1 parent b521d67 commit 7e850f5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
15 changes: 11 additions & 4 deletions cleanup/DefaultSwatches.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Default swatches 22.3.16
Default swatches 22.3.27
(c) 2020-2022 Paul Chiorean (jpeg@basement.ro)
Adds swatches from a 5-column TSV file named 'swatches.txt':
Expand Down Expand Up @@ -44,34 +44,39 @@
SOFTWARE.
*/

if (!(doc = app.activeDocument)) exit();

// @include '../lib/GetDataFile.jsxinc';
// @include '../lib/IsInArray.jsxinc';
// @include '../lib/Report.jsxinc';

if (!(doc = app.activeDocument)) exit();
// @include '../lib/ProgressBar.jsxinc';

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined,
UndoModes.ENTIRE_SCRIPT, 'Default swatches');

function main() {
var VERBOSITY = ScriptUI.environment.keyboardState.ctrlKey ? 2 : 1; // 0: FAIL, 1: +WARN, 2: +INFO
var file, data, messages, i, n;
var file, data, messages, i, n, progressBar;
var counter = { add: 0, merge: 0 };
if (doc.converted && VERBOSITY > 0) {
alert('Can\'t get document path.\nThe document was converted from a previous InDesign version. ' +
'The default swatch substitution list will be used.');
}

if (!(file = getDataFile('swatches.txt'))) {
if (VERBOSITY > 1) {
alert('Can\'t locate a swatch substitution list.\nThe file must be saved in the current folder, ' +
'on the desktop, or next to the script. Check docs for details.');
}
exit();
}

data = parseDataFile(file);
if (data.errors.fail.length > 0) { report(data.errors.fail, decodeURI(file.getRelativeURI(doc.filePath))); exit(); }
if (data.records.length > 0) {
if (data.records.length > 9) progressBar = new ProgressBar('Default swatches', data.records.length);
for (i = 0, n = data.records.length; i < n; i++) {
if (progressBar) progressBar.update();
addSwatch(
data.records[i].name,
data.records[i].model,
Expand All @@ -81,6 +86,8 @@ function main() {
);
}
}
if (progressBar) progressBar.close();

if (VERBOSITY > 0) {
messages = data.errors.warn;
if (VERBOSITY > 1) messages = messages.concat(data.errors.info);
Expand Down
16 changes: 11 additions & 5 deletions cleanup/ReplaceLinks.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Replace links 22.3.17
Replace links 22.3.23
(c) 2020-2022 Paul Chiorean (jpeg@basement.ro)
Replaces document links from a 2-column TSV file named 'links.txt':
Expand Down Expand Up @@ -38,26 +38,27 @@
SOFTWARE.
*/

if (!(doc = app.activeDocument)) exit();

// @include '../lib/GetDataFile.jsxinc';
// @include '../lib/IsInArray.jsxinc';
// @include '../lib/Report.jsxinc';

if (!(doc = app.activeDocument)) exit();
// @include '../lib/ProgressBar.jsxinc';

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined,
UndoModes.ENTIRE_SCRIPT, 'Replace links');

function main() {
var VERBOSITY = ScriptUI.environment.keyboardState.ctrlKey ? 2 : 1; // 0: FAIL, 1: +WARN, 2: +INFO
var file, data, messages, i, r;
var file, data, messages, i, r, progressBar;
var counter = 0;
var links = doc.links.everyItem().getElements();
var linkS = (function () {
var s = [];
for (i = 0; i < links.length; i++) s.push(decodeURI(links[i].name));
return s;
}());

var counter = 0;
if (doc.converted && VERBOSITY > 0) {
alert('Can\'t get document path.\nThe document was converted from a previous InDesign version. ' +
'The default link substitution list will be used.');
Expand All @@ -69,10 +70,13 @@ function main() {
}
exit();
}

data = parseDataFile(file);
if (data.errors.fail.length > 0) { report(data.errors.fail, decodeURI(file.getRelativeURI(doc.filePath))); exit(); }
if (data.records.length > 0) {
if (links.length > 2) progressBar = new ProgressBar('Replace links', links.length);
for (i = 0; i < links.length; i++) {
if (progressBar) progressBar.update();
for (r = 0; r < data.records.length; r++) {
if (!isInArray(links[i].name, data.records[r].oldLinks)) continue; // Skip not matched
if (File(links[i].filePath).fullName === File(data.records[r].newLink).fullName &&
Expand All @@ -84,6 +88,8 @@ function main() {
}
}
}
if (progressBar) progressBar.close();

if (VERBOSITY > 0) {
messages = data.errors.warn;
if (VERBOSITY > 1) messages = messages.concat(data.errors.info);
Expand Down

0 comments on commit 7e850f5

Please sign in to comment.