Copy link to clipboard
Copied
I'm been searching for how to hook the double click event for a text-frame to launch a script.
I working on an application that extends InDesign to solve a very specific problem domain. Each object is represented as a text-frame. By double clicking the text-frame, it will launch a script that allows you to edit the object represented by the text-frame. The object data is encoded into XML where a single instance of the XML data is associated with the text-frame.
Thanks in advance
Hi Bill,
Might we fake it?
...#targetengine FakeDblClickHandler
// YOUR HANDLER COMES HERE
// ---
function onTextFrameDblClick(/*TextFrame*/target)
{
alert( "You have just double-clicked " + target );
// etc.
};
const checkDblClick = function F(/*IdleEvent*/ev, o,t)
// -----------------------------------------------
{
(o=(o=app.properties.selection) && (1==o.length) && o[0]);
t = +ev.timeStamp;
o instanceof TextFrame ? (F.Q = t) : (t -= F.Q||0);
if( t < 120 && o instanceof InsertionPoint )
Copy link to clipboard
Copied
Hi Bill,
Might we fake it?
#targetengine FakeDblClickHandler
// YOUR HANDLER COMES HERE
// ---
function onTextFrameDblClick(/*TextFrame*/target)
{
alert( "You have just double-clicked " + target );
// etc.
};
const checkDblClick = function F(/*IdleEvent*/ev, o,t)
// -----------------------------------------------
{
(o=(o=app.properties.selection) && (1==o.length) && o[0]);
t = +ev.timeStamp;
o instanceof TextFrame ? (F.Q = t) : (t -= F.Q||0);
if( t < 120 && o instanceof InsertionPoint )
{
onTextFrameDblClick(o.parentTextFrames[0]);
}
};
(function(tasks,name,rate,callback)
// -----------------------------------------------
// Register the IdleTask
{
var t = tasks.itemByName(name);
if( t.isValid )
{
t.eventListeners.everyItem().remove();
t.remove();
}
tasks.add({name:name, sleep:rate})
.addEventListener(IdleEvent.ON_IDLE, callback, false);
})(app.idleTasks,$.engineName,15,checkDblClick);
Purely experimental, of course 😉
Best,
Marc
Copy link to clipboard
Copied
Hi Marc and Bill,
I'm not sure what is asked here.
My interpretation:
The user is supposed to double-click a text frame to run a script or a function that lurks in memory provided by a startup-script.
Guess, yes. First I thought about a solution based on a selectionChanged event.
Now Marc is working with an IdleEvent—very nice–by defining a double-click as a sequence of clicks less than 120 milliseconds.
Cool.
I tested Marc's code and see a potential problem concerning implementation:
Supposed we have two text frames on a page with functional code.
Nothing is selected.
The Selection tool is the current tool.
The user is double-clicking the first text frame.
The Text tool is the current tool now.
Code is running (Marc's alert is showing up).
All is good so far.
But now the user turns to the next text frame:
Does a double-click.
The Text tool is still the current tool.
Code is not running. Alert is not showing.
One solution could be, that the activated code will switch the current tool to the Selection tool:
function onTextFrameDblClick(/*TextFrame*/target)
{
app.toolBoxTools.currentTool = UITools.SELECTION_TOOL;
alert( "You have just double-clicked " + target );
// etc.
};
But after testing that, the alert did not come up sometimes.
So I decided to deselect the selection as well. And finally that worked better.
Though, sometimes it did not work so I had to press ESC to select the frame with the Selection Tool, had to wait perhaps a second before trying another double-click on the text frame to activate the alert.
// YOUR HANDLER COMES HERE
// ---
function onTextFrameDblClick(/*TextFrame*/target)
{
app.select(null);
app.toolBoxTools.currentTool = UITools.SELECTION_TOOL;
alert( "You have just double-clicked " + target );
// etc.
};
Regards,
Uwe
Copy link to clipboard
Copied
Hi there,
The solutions unluckly don't work anymore. My environment is InDesign CC 2021 on Win 10.
Please can you help me for listen click event fired?
Tnx
PS: Moreover in ExtendScript it appeares a debugging error: checkDblClick redeclared although i have renamed many times the functional constant.
Copy link to clipboard
Copied
Hi Francesco,
just testing Marc's code with the latest version of my German InDesign 2021 on Windows 10.
I started the script from the Scripts panel of InDesign.
It is working, but not as much as I like.
It requires two, sometimes even more attempts of double-clicks to monitor the double-click.
( I have added an alert and also an action that will color the double-clicked text frame. )
Maybe you'll get better results if you change t < 120 to t < 180 ?
As I already wrote in 2016:
"Though, sometimes it did not work so I had to press ESC to select the frame with the Selection Tool, had to wait perhaps a second before trying another double-click on the text frame to activate the alert."
Regards,
Uwe Laubender
( ACP )