Skip to main content
Loic.Aigon
Legend
January 20, 2023
Question

How to Identify the exact canceled operation?

  • January 20, 2023
  • 1 reply
  • 258 views

Hi guys,

 

One can add an menuAction eventListeners on the "Cancel" command with :

app.menuActions.itemByID(265).eventListeners.add('onInvoke', handler);

That will basically catch any cancel command that user fires.

 

I noticed that while the id remain constant, the menuAction name and title vary depending on the operation to cancel. That makes sense, no worries.

 

The problem I see is that I want to react for specific cancel commands, not all of them. Conceptually speaking, it would be ensuring the cancel menuaction name matches specific strings. And here the troubles begin.

 

For ex, if I edit document props in the UI, my French version will display "Annuler Format de document". But the latter string seems to be built on the fly based on the generic "cancel" menuaction. In other words, there are no specific canceling menuActions for every single command in the app.

 

Back to my issue, if I ambition to compare the menuAction name to a locale independant specific string, I can't.

app.findKeyStrings("Annuler Format de document") //returns nothing. 

But 

app.findKeyStrings("Format de document") //returns $ID/Document Setup,$ID/Document Format

and

app.findKeyStrings("Annuler") //return $ID/Cancel

 

So I thought I could concat those strings identifiers and do something with them but soon realize I was drowning myself in a glass of water and searched in docs and here in the forum with no luck. So here I am to receive your lights 🙂

 

To sum things up, has anyone a hint to properly decrypt the command that is cancelable in the UI in a non-locale-dependent way?

 

Thanks in advance,

 

Loïc

 

 

 

 

This topic has been closed for replies.

1 reply

Community Expert
January 25, 2023

Hi Loïc,

did you make progress with this?

 

You said: "One can add an menuAction eventListeners on the "Cancel" command with :"

Hm. isn't that the menu action for the Undo command?

At least id 265 for that menu command is invoking an Undo with my German version of InDesign.

app.menuActions.itemByID(265).invoke();

 

And: "In other words, there are no specific canceling menuActions for every single command in the app."

Right. It's a bit unspecific. If I add a rectangle to a page the undo command is "Undo: Add New Item" and not "Undo: Add New Rectangle". Or when I change the stroke width of an object, there is no way to tell from the Undo what stroke weight was applied.

 

That aside:

If your French InDesign is using a ": " after the first word, like "Annuler"+": "+"<String what could be undone>", my code should work for you. It's my assumption that the locale version of "Undo" is always first; followed by ": ".

That may not work with the Arabic or the Hebrew version of InDesign.

 

// BEFORE: Added a rectangle using the GUI's tool:

var reactOnThatString = "$ID/Add New Item";
/*
	In my German InDesign the name of the menu action now is:
	Rückgängig: Neues Objekt hinzufügen
	
	Translated:
	Undo: Add New Item
	
	So we could split the string and use the second part
*/

var nameWithoutTheUndoPart = app.menuActions.itemByID(265).name.split(": ")[1];
var localeIndependent = app.findKeyStrings( nameWithoutTheUndoPart )[0];

localeIndependent == reactOnThatString; // Returns true

 

Note: app.findkeyStrings() always returns an array of strings.

So perhaps we have to loop that array to draw conclusions.

 

Also note, that you could check the document's undoHistory array.

But that will give you the same unspecific strings.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Loic.Aigon
Legend
January 25, 2023

Thanks @Laubender 

It confirms my understanding. The french menu doesn't use a colon but sure I could find some trickery. However, I was more into something more predictable and locale independent. 

But that's ok, the eventHandler is executed for every undo operation even if I wouldn't need it in most cases, but the cost of the operation seems acceptable. I guess I will leave it here for now.

Thanks anyway.

Loic