2 Replies Latest reply on Apr 18, 2017 8:47 PM by JJMack

    How to listen for document events that user triggers while palette window is open

    aandk

      Hello all,

      Is there a way to listen for document events that the user triggers while a palette window is open?

      I have looked at the documentation for something like `document.addEventLister` or something, but I have not found anything.

      For example, I want to listen for the Paint Brush Tool and update my open palette window ui based on that.

      Here is what I have tried:

       

      var isDone, s2t, waitForRedraw, win, windowResource;

      var count = 0;

      var document;

      // Shortcut function

      s2t = function(stringID) {

        return app.stringIDToTypeID(stringID);

      };

       

      waitForRedraw = function() {

        var d;

        d = new ActionDescriptor();

        d.putEnumerated(s2t('state'), s2t('state'), s2t('redrawComplete'));

        return executeAction(s2t('wait'), d, DialogModes.NO);

      };

       

      //sentinel variable

      isDone = false;

       

      windowResource = "palette {  \    orientation: 'column', \    alignChildren: ['fill', 'top'],  \    preferredSize:[130, 130], \    text: 'Brush Stroke Counter 1.0',  \    margins:15, \    \    sliderPanel: Panel { \        orientation: 'row', \        alignChildren: 'right', \        margins:15, \        text: ' Brush Stroke Count ', \        st: StaticText { text: '0', characters: 5, justify: 'left'} \        } \    \    bottomGroup: Group{ \        cd: Checkbox { text:'Count Enabled', value: true }, \        cancelButton: Button { text: 'Close', properties:{name:'cancel'}, size: [120,24], alignment:['right', 'center'] }, \    }\}";

       

      win = new Window(windowResource);

       

      // Button listeners

      win.bottomGroup.cancelButton.onClick = function() {

        return isDone = true;

      };

       

      win.onClose = function() {

        return isDone = true;

      };

       

      win.show();

       

       

      activeDocument.addEventListener("Pnt ", function(){

           alert("I'm painting!");

      });

       

      while (isDone === false) {

       

           //listen for user painting here?

        alert(app.currentTool);

       

        app.refresh(); // or, alternatively, waitForRedraw();

       

      }

       

      Any help is appreciated.

      Thank you