Message Board for Rorohiko Workflow Resources
https://www.rorohiko.com/cgi-bin/yabb2/YaBB.pl
General Category >> General Board >> Observing the selection with a ScriptUI palette
https://www.rorohiko.com/cgi-bin/yabb2/YaBB.pl?num=1223237364

Message started by Kris Coppieters on 10/06/08 at 08:09:24

Title: Observing the selection with a ScriptUI palette
Post by Kris Coppieters on 10/06/08 at 08:09:24
Below a copy of some info I passed on to some APID developers - it's pretty useful, so I duplicated it here...

With APIDToolAssistant installed and a document open, create a page item on the pasteboard; this page item will be used as a 'controller' for this demo. Select it and bring up the APID ToolAssistant palette.

Set the list of subjects to "*"

Set the event filter to "subjectSelected#myLittlePaletteEngine, subjectDeselected#myLittlePaletteEngine".

This captures the selection and deselection events for all page items, and routes them into a persistent engine (myLittlePaletteEngine) for handling.

Because the engine is persistent, it will 'remember' gPalette and gField on subsequent events after they have been created the first time around.

Set the script to:


Code (]
//----

var gPalette;
var gField;
var gController = theItem;

function CreatePalette()
{
 gPalette =
   new Window(
     "palette",
     "What is it");
 gField = gPalette.add("statictext",[0,0,200,20):

,"testfield");
}

if (gPalette == undefined)
{
 gController.setDataStore("$GROUP_EVENTS$",true);
 CreatePalette();
 gPalette.show();
}

gField.text = app.selection.toString();

//----


This does work for 'page item' selections - it won't work for text selections. To make that work too, you need to change the event filter to "*#myLittlePaletteEngine" (* is a wildcard and matches all events, including idle - which is used to update the text selection info).

This last method (relying on idle) is not terribly good or efficient; I am currently looking how I could avoid the need for capturing 'idle' in version 1.0.46 (which will support CS4).

Cheers,

Kris

Message Board for Rorohiko Workflow Resources » Powered by YaBB 2.5.2!
YaBB Forum Software © 2000-2024. All Rights Reserved.