It is not clear to me, how the user loops through all tables.
But you'll get informed about changing insertion point via Notify Notification(Constants.FA_Note_PostMouseCommand,true);
Here is an example:
IMPORTANT: Dont forget to remove the notification when closing the dialog
var goDoc = app.ActiveDoc;
if (goDoc.ObjectValid())
{
var oDia = new Window("palette","ShowPgfFmt");
BuildDialogue();
Notification(Constants.FA_Note_PostMouseCommand,true);
}
else
{
alert("No active document");
}
function BuildDialogue()
{
oDia.Group = oDia.add("group");
oDia.PgfName = oDia.Group.add("statictext",undefined,"");
oDia.PgfName.size = [240,40];
oDia.onClose = RemoveNotification;
oDia.show();
}
function Notify(note, object)
{
switch (note)
{
case Constants.FA_Note_PostMouseCommand:
{
ShowPgfName();
break;
}
}
}
function ShowPgfName()
{
oDia.PgfName.text = ReadPgfName();
oDia.update()
}
function ReadPgfName(locPgf)
{
var tRange = goDoc.TextSelection;
var locStartPgf = tRange.beg.obj.Name;
alert(locStartPgf);
return locStartPgf;
}
function RemoveNotification()
{
Notification(Constants.FA_Note_PostMouseCommand,false);
}