@@ -22,8 +22,8 @@ if (app.extractLabel("px:debugID") == "Jp07qcLlW3aDHuCoNpBK_Gregor-") {
2222}
2323/****************
2424* Logging Class
25- * @Version : 1.07
26- * @Date : 2018-10-10
25+ * @Version : 1.11
26+ * @Date : 2019-03-06
2727* @Author : Gregor Fellenz, http://www.publishingx.de
2828* Acknowledgments: Library design pattern from Marc Aturet https://forums.adobe.com/thread/1111415
2929
@@ -40,7 +40,6 @@ $.global.hasOwnProperty('idsLog') || (function (HOST, SELF) {
4040 * PRIVATE
4141 */
4242 var INNER = { } ;
43- INNER . version = "2018-09-26-1.06" ;
4443 INNER . disableAlerts = false ;
4544 INNER . logLevel = 0 ;
4645 INNER . SEVERITY = [ ] ;
@@ -50,19 +49,82 @@ $.global.hasOwnProperty('idsLog') || (function (HOST, SELF) {
5049 INNER . SEVERITY [ "INFO" ] = 1 ;
5150 INNER . SEVERITY [ "DEBUG" ] = 0 ;
5251
53- INNER . processMsg = function ( msg ) {
52+ INNER . processMsg = function ( msg , object ) {
5453 if ( msg == undefined ) {
5554 msg = "" ; // return ?
5655 }
5756 if ( ( msg instanceof Error ) ) {
5857 msg = msg + " Line: " + msg . line + " # " + msg . number + " File: " + msg . fileName ;
5958 }
60- if ( msg . constructor . name != String ) {
59+ if ( msg . constructor . name != " String" ) {
6160 msg = msg . toString ( ) ;
6261 }
62+
63+ if ( object != undefined ) {
64+ msg += " " + localize ( { en : "Object is located at" , de : "Objekt befindet sich auf" } ) + " [" + INNER . getPageNameFromObject ( object ) + "]" ;
65+ }
6366 return msg ;
6467 }
6568
69+ INNER . getPageNameFromObject = function ( object ) {
70+ var pagePositionMessage = "" ;
71+ if ( object != null ) {
72+ object = object . getElements ( ) [ 0 ] ; // Get Object from Superclass like PageItem
73+ if ( object . hasOwnProperty ( "baseline" ) ) {
74+ if ( object . parentTextFrames . length == 0 ) {
75+ object = object . parentStory . textContainers [ object . parentStory . textContainers . length - 1 ] ;
76+ pagePositionMessage += localize ( { en : "Overset text. Position of the last text frame: " , de : "Im Übersatz. Position des letzten Textrahmens: " } ) ;
77+ }
78+ else {
79+ object = object . parentTextFrames [ 0 ] ;
80+ }
81+ }
82+ while ( object != null ) {
83+ if ( object . hasOwnProperty ( "parentPage" ) ) {
84+ if ( object . parentPage == null && object . parent instanceof Spread ) {
85+ pagePositionMessage += localize ( { en : "Spread " , de : "Druckbogen " } ) ;
86+ return pagePositionMessage + ( object . parent . index + 1 ) ;
87+ }
88+ else if ( object . parentPage == null ) {
89+ object = object . parent ;
90+ continue ;
91+ }
92+ else {
93+ return localize ( { en : "Page " , de : "Seite " } ) + object . parentPage . name ;
94+ }
95+ }
96+ var whatIsIt = object . constructor ;
97+ switch ( whatIsIt ) {
98+ case Page : return pagePositionMessage + localize ( { en : "Page " , de : "Seite " } ) + object . name ;
99+ case Character : object = object . parentTextFrames [ 0 ] ; break ;
100+ case Footnote : ; // drop through
101+ case Cell : object = object . insertionPoints [ 0 ] . parentTextFrames [ 0 ] ; break ;
102+ case Note : object = object . storyOffset . parentTextFrames [ 0 ] ; break ;
103+ case XMLElement :
104+ if ( object . pageItems . length > 0 ) {
105+ object = object . pageItems [ 0 ] ;
106+ }
107+ else if ( object . insertionPoints [ 0 ] != null ) {
108+ if ( object . insertionPoints [ 0 ] . parentTextFrames . length > 0 ) {
109+ object = object . insertionPoints [ 0 ] . parentTextFrames [ 0 ] ;
110+ }
111+ else {
112+ return pagePositionMessage + localize ( { en : "Could not detect page" , de : "Konnte Seite nicht ermitteln" } ) ;
113+ }
114+ }
115+ break ;
116+ case Application : return pagePositionMessage + localize ( { en : "Could not detect page Application" , de : "Konnte Seite nicht ermitteln Application" } ) ;
117+ default : object = object . parent ;
118+ }
119+ if ( object == null ) return pagePositionMessage + localize ( { en : "Could not detect page null" , de : "Konnte Seite nicht ermitteln null" } ) ;
120+ }
121+ return pagePositionMessage + object ;
122+ }
123+ else {
124+ return pagePositionMessage + localize ( { en : "Could not detect page" , de : "Konnte Seite nicht ermitteln" } ) ;
125+ }
126+ }
127+
66128 INNER . writeLog = function ( msg , severity , file ) {
67129 var date = new Date ( ) ;
68130 var month = date . getMonth ( ) + 1 ;
@@ -146,12 +208,12 @@ $.global.hasOwnProperty('idsLog') || (function (HOST, SELF) {
146208 INNER . confirmMessages = function ( title , msgArray , type ) {
147209 if ( ! INNER . disableAlerts && msgArray . length > 0 ) {
148210 var callingScriptVersion = " " ;
149- if ( $ . global . hasOwnProperty ( "px" ) && $ . global . px . hasOwnProperty ( "projectName" ) ) {
150- callingScriptVersion += px . projectName ;
151- }
152- if ( $ . global . hasOwnProperty ( "px" ) && $ . global . px . hasOwnProperty ( "version" ) ) {
153- callingScriptVersion += " v" + px . version ;
154- }
211+ // if ($.global.hasOwnProperty("px") && $.global.px.hasOwnProperty("projectName")) {
212+ // callingScriptVersion += px.projectName;
213+ // }
214+ // if ($.global.hasOwnProperty("px") && $.global.px.hasOwnProperty("version")) {
215+ // callingScriptVersion += " v" + px.version;
216+ // }
155217 var msg = msgArray . join ( "\n" ) ;
156218 var dialogWin = new Window ( "dialog" , title + callingScriptVersion ) ;
157219 dialogWin . etMsg = dialogWin . add ( "edittext" , undefined , msg , { multiline : true , scrolling : true } ) ;
@@ -176,7 +238,7 @@ $.global.hasOwnProperty('idsLog') || (function (HOST, SELF) {
176238 texFile . close ( ) ;
177239 }
178240 }
179- dialogWin . gControl . add ( "button" , undefined , localize ( { en : "Cancel script " , de : "Skript Abbrechen" } ) , { name : "cancel" } ) ;
241+ dialogWin . gControl . add ( "button" , undefined , localize ( { en : "Cancel" , de : "Abbrechen" } ) , { name : "cancel" } ) ;
180242 dialogWin . gControl . add ( "button" , undefined , "Ok" , { name : "ok" } ) ;
181243 return dialogWin . show ( ) ;
182244 }
@@ -273,9 +335,10 @@ $.global.hasOwnProperty('idsLog') || (function (HOST, SELF) {
273335 /**
274336 * Writes a debug log message
275337 * @message {String} message Message to log.
338+ * @object {Object} Log the page name of the given object
276339 */
277- writeln : function ( message ) {
278- message = INNER . processMsg ( message ) ;
340+ writeln : function ( message , object ) {
341+ message = INNER . processMsg ( message , object ) ;
279342 if ( typeof px != "undefined" && px . hasOwnProperty ( "debug" ) && px . debug ) {
280343 $ . writeln ( message ) ;
281344 }
@@ -287,9 +350,10 @@ $.global.hasOwnProperty('idsLog') || (function (HOST, SELF) {
287350 /**
288351 * Writes a debug log message
289352 * @message {String} message Message to log.
353+ * @object {Object} Log the page name of the given object
290354 */
291- debug : function ( message ) {
292- message = INNER . processMsg ( message ) ;
355+ debug : function ( message , object ) {
356+ message = INNER . processMsg ( message , object ) ;
293357 if ( INNER . logLevel == 0 ) {
294358 INNER . writeLog ( message , "DEBUG" , logFile ) ;
295359 counter . debug ++ ;
@@ -298,9 +362,10 @@ $.global.hasOwnProperty('idsLog') || (function (HOST, SELF) {
298362 /**
299363 * Writes an info log message
300364 * @message {String} message Message to log.
365+ * @object {Object} Log the page name of the given object
301366 */
302- info : function ( message ) {
303- message = INNER . processMsg ( message ) ;
367+ info : function ( message , object ) {
368+ message = INNER . processMsg ( message , object ) ;
304369 if ( INNER . logLevel <= 1 ) {
305370 INNER . writeLog ( message , "INFO" , logFile ) ;
306371 counter . info ++ ;
@@ -310,9 +375,10 @@ $.global.hasOwnProperty('idsLog') || (function (HOST, SELF) {
310375 /**
311376 * Writes an info log message und displays an Alert-Window
312377 * @message {String} message Message to log.
378+ * @object {Object} Log the page name of the given object
313379 */
314- infoAlert : function ( message ) {
315- message = INNER . processMsg ( message ) ;
380+ infoAlert : function ( message , object ) {
381+ message = INNER . processMsg ( message , object ) ;
316382 if ( INNER . logLevel <= 2 ) {
317383 INNER . writeLog ( message , "INFO" , logFile ) ;
318384 counter . info ++ ;
@@ -325,9 +391,10 @@ $.global.hasOwnProperty('idsLog') || (function (HOST, SELF) {
325391 useful to add information to the warning messages without incrementing the warn counter.
326392 e.g. put information about file name while processing different documents.
327393 * @message {String} message Message to log.
394+ * @object {Object} Log the page name of the given object
328395 */
329- warnInfo : function ( message ) {
330- message = INNER . processMsg ( message ) ;
396+ warnInfo : function ( message , object ) {
397+ message = INNER . processMsg ( message , object ) ;
331398 if ( INNER . logLevel <= 1 ) {
332399 INNER . writeLog ( message , "INFO" , logFile ) ;
333400 counter . info ++ ;
@@ -340,9 +407,10 @@ $.global.hasOwnProperty('idsLog') || (function (HOST, SELF) {
340407 /**
341408 * Writes a warn log message
342409 * @message {String} message Message to log.
410+ * @object {Object} Log the page name of the given object
343411 */
344- warn : function ( message ) {
345- message = INNER . processMsg ( message ) ;
412+ warn : function ( message , object ) {
413+ message = INNER . processMsg ( message , object ) ;
346414 if ( typeof px != "undefined" && px . hasOwnProperty ( "debug" ) && px . debug ) {
347415 $ . writeln ( "WARN: \n" + message ) ;
348416 }
@@ -355,9 +423,10 @@ $.global.hasOwnProperty('idsLog') || (function (HOST, SELF) {
355423 /**
356424 * Writes a warn log message und displays an Alert-Window
357425 * @message {String} message Message to log.
426+ * @object {Object} Log the page name of the given object
358427 */
359- warnAlert : function ( message ) {
360- message = INNER . processMsg ( message ) ;
428+ warnAlert : function ( message , object ) {
429+ message = INNER . processMsg ( message , object ) ;
361430 if ( INNER . logLevel <= 2 ) {
362431 INNER . writeLog ( message , "WARN" , logFile ) ;
363432 counter . warn ++ ;
@@ -368,9 +437,10 @@ $.global.hasOwnProperty('idsLog') || (function (HOST, SELF) {
368437 /**
369438 * Writes a error log message
370439 * @message {String} message Message to log.
440+ * @object {Object} Log the page name of the given object
371441 */
372- error : function ( message ) {
373- message = INNER . processMsg ( message ) ;
442+ error : function ( message , object ) {
443+ message = INNER . processMsg ( message , object ) ;
374444 if ( INNER . logLevel <= 3 ) {
375445 INNER . writeLog ( message , "ERROR" , logFile ) ;
376446 counter . error ++ ;
@@ -388,17 +458,29 @@ $.global.hasOwnProperty('idsLog') || (function (HOST, SELF) {
388458 * Confirm all warnings
389459 */
390460 confirmWarnings : function ( ) {
391- var message = "confirmWarnings: Es gab " + counter . warn + " Warnmeldungen "
461+ var message = "Sollen die folgenden Operationen ausgeführt werden? "
392462 INNER . writeLog ( message , "INFO" , logFile ) ;
393463
394464 var res = INNER . confirmMessages ( message , messages . warn , localize ( { en : "warnings" , de : "der Warnungen" } ) ) ;
395465 INNER . writeLog ( "User interaction: " + res , "INFO" , logFile ) ;
396- return res ;
466+ messages . warn = [ ] ;
467+ if ( res == 1 ) {
468+ return true ;
469+ }
470+ else {
471+ return false ;
472+ }
397473 } ,
398474
399- /* Confirm a warning */
400- confirm : function ( message , noAsDefault , title ) {
401- message = INNER . processMsg ( message ) ;
475+ /**
476+ * Confirm a warning
477+ * @message {String} message Message to log.
478+ * @noAsDefault {Boolean}
479+ * @title {String}
480+ * @object {Object} Log the page name of the given object
481+ * */
482+ confirm : function ( message , noAsDefault , title , object ) {
483+ message = INNER . processMsg ( message , object ) ;
402484 if ( title == undefined ) {
403485 title = "" ;
404486 }
@@ -514,11 +596,18 @@ $.global.hasOwnProperty('idsLog') || (function (HOST, SELF) {
514596 */
515597 getLogFolder : function ( ) {
516598 return logFile . parent ;
517- }
599+ } ,
600+ /**
601+ * Returns the current log File path
602+ */
603+ getLogFile : function ( ) {
604+ return logFile ;
605+ }
518606 }
519607 } ;
520608} ) ( $ . global , { toString : function ( ) { return 'idsLog' ; } } ) ;
521609
610+
522611main ( ) ;
523612
524613function main ( ) {
0 commit comments