4 Replies Latest reply on Jun 6, 2014 2:18 AM by tobias.wantzen

    [CC/Mac, JS] Palette looses layoutWindow focus when double clicking listbox items several times

    tobias.wantzen Level 1

      Hello!

       

      My script collects all notes (»notes[]«) and displays them with [...].page.name and note.texts in a listbox of a palette (»new Window("palette",  "Notes Browser", undefined, {resizeable:true})«). By double clicking an item, InDesign should select the invisible notes character and center the view at the right position in the layoutWindow. This works three or four times perfectly, then the rulers of InDesign are grayed out and a double click to a different listbox item does nothing any more.

       

      Interestingly this version (without selecting anything) works perfectly:

      function lstNoteItems_onDoubleClick(){
        var idClicked = this.selection[0].id;
          var item2select = g.arrNoteItems[idClicked].storyOffset;
          showIt(item2select);
      }
      
      
      function showIt(theObj) {
          if (arguments.length > 0) {
              app.select(theObj);
          }
          var myZoom = app.activeWindow.zoomPercentage;
          app.activeWindow.zoom(ZoomOptions.showPasteboard);
          app.activeWindow.zoomPercentage = myZoom;
      }
      
      

       

      But my script should select the invisible character. This does work three or four times and then InDesign looses a kind of focus:

       

      function lstNoteItems_onDoubleClick(){
        var idClicked = this.selection[0].id;
          var item2select = g.arrNoteItems[idClicked].storyOffset;
        var item2selectStory = g.arrNoteItems[idClicked].storyOffset.parentStory; // select note’s story
        var item2selectIndex = g.arrNoteItems[idClicked].storyOffset.index; // select note’s insertion point
          showIt(item2select);
          item2selectStory.characters[item2selectIndex].select();
      }
      
      
      function showIt(theObj) {
          if (arguments.length > 0) {
              app.select(theObj);
          }
          var myZoom = app.activeWindow.zoomPercentage;
          app.activeWindow.zoom(ZoomOptions.showPasteboard);
          app.activeWindow.zoomPercentage = myZoom;
      }
      
      
      
      

       

      Any suggestions?

      Thanks

      Tobias

        • 1. Re: [CC/Mac, JS] Palette looses layoutWindow focus when double clicking listbox items several times
          Laubender Adobe Community Professional & MVP

          @Tobias – without seeing more code this is hard to answer (or to test).

          Just a suggestion packed in a question: Do you make the page of the found instance the explicitly active one? Or do you rely on the mechanism, that a new selection will automatically lead to a new active page or spread?

           

          Did you do tests with InDesign versions below CC. Maybe CS6 or CS5.5?
          And if yes, are there any differences in behavior?

           

          Uwe

          • 2. Re: Re: [CC/Mac, JS] Palette looses layoutWindow focus when double clicking listbox items several times
            tobias.wantzen Level 1

            Thanks for your suggestions, Uwe!

             

            More or less accidentally I found out, that if InDesign’s notes panel (which is accessible from the standard UI) is _not_ active (not showing), the script which selects the hidden notes char runs perfectly within CS5.5, CS6 and CC. If the panel is active, all versions of InDesign stop working as expected after a few successful clicks.

             

            I relied on the mechanism, that a new selection will automatically lead to a new active page. I added activePage explicitly and now the screen updating works perfectly: With every click, InDesign jumps to the right position and the hidden char is correctly selected! That was a very good hint!


            Only thing:

            When you select the hidden note char in the UI, then the UI note panel immediately shows the content and metadata of the selected note. My script (with your improvement) does this only for the first click after start. All following clicks do not change the UI note panel.

            If I click outside my palette and then click in it again, again with the first click the UI note panel works fine, all following clicks are ignored.

             

            It seems to me, that after the click in my palette the palette get’s the focus. Is there a trick to focus back on the document after a click to the palette?


            For better understanding, here’s my script:

             

            #targetengine "session"
            
            
            var g = {};
            main();
            
            
            
            
            function main(){
              if(app.documents.length== 0){
              alert("Please open a document.");
              }
              else{loadItems(); buildDialog(); updateListbox();}
            }
            
            
            
            
            function loadItems(){
              docNoteItemsList();
            
            
              function docNoteItemsList(){
              g.doc = app.activeDocument;
              g.winProg = new Window('palette', undefined, undefined, {closeButton:false});
              g.winProg.prg =g.winProg.add('progressbar', [0, 0, 400, 20]);
              var stxPrg = g.winProg.add('statictext', [100, 30, 300, 50], 'Updating notes list ...');
            
            
                    g.arrNoteItems = [];
                    for ( s = 0; s < g.doc.stories.count(); s++ ) {
                        var _myStory = g.doc.stories[s];
                        for ( n = 0; n < _myStory.notes.count(); n++ ) {
                            g.arrNoteItems.push(_myStory.notes[n]);
                            g.winProg.prg.value ++;
                        }
                    }
              g.winProg.prg.value = 0;
              g.winProg.prg.maxvalue = g.arrNoteItems.length;
              }
            
            
            } // End function loadItems
            
            
            
            
            function buildDialog(){
              createWindow();
              notesItemsListbox();
              g.winMain.show();
                
              function createWindow(){
              g.winMain = new Window("palette",  "Notes Browser", undefined, {resizeable:true});
              g.winMain.orientation = "column";
              g.winMain.alignChildren = "top";
                    g.winMain.onResizing = function () { this.layout.resize (); }
                    g.winMain.onShow = function () {
                        g.winMain.layout.layout();
                        g.winMain.minimumSize = g.winMain.preferredSize;
                    }
                }
            
              function notesItemsListbox(){
              g.lstNoteItems = g.winMain.add('listbox', undefined, undefined,
              {
                                 multiselect:true, numberOfColumns: 2, 
              showHeaders:true,
              columnTitles:['Page', 'Content'], 
              columnWidths:[50, 350]
              });
                    g.lstNoteItems.minimumSize = [100, 400];
                    g.lstNoteItems.alignment = ["fill", "fill"];
                    g.lstNoteItems.onChange = lstNoteItems_onChange;
              }
            
            } // end function createDialog
            
            
            
            
            function updateListbox(){
              app.scriptPreferences.enableRedraw = false;
              g.lstNoteItems.selection = null;
              g.lstNoteItems.removeAll();
              g.winProg.show();
              for (var i = 0; i < g.arrNoteItems.length; i++){
                    var currentNoteItem =g.arrNoteItems[i];
                    // Collect note page number
                    var _NotePage = currentNoteItem.storyOffset.parentTextFrames[0].parentPage.name;
                    // Collect note text
                    var _noteTextArr = [];
                    for ( j = 0; j < currentNoteItem.texts.count(); j++ ) _noteTextArr.push(currentNoteItem.texts[j].contents);
                    var _NoteTxt = _noteTextArr.join('\t').replace(/[\r\n]+/g, " <br> ");
                    // add note item to listbox
                    var currentListItem = g.lstNoteItems.add('item', _NotePage); // 1st item
                    currentListItem.subItems[0].text = _NoteTxt; // 2nd item
                    currentListItem.id = i;
                    g.winProg.prg.value ++;
              }
              g.winProg.prg.value =0;
              g.winProg.close();
              app.scriptPreferences.enableRedraw = true;
            } // end function updateListbox
            
            
            
            
            
            
            
            
            function lstNoteItems_onChange(){
              var idClicked = this.selection[0].id;
                var item2select = g.arrNoteItems[idClicked].storyOffset;
              var item2selectStory = item2select.parentStory;
              var item2selectIndex = item2select.index;
                app.activeWindow.activePage = item2select.parentTextFrames[0].parentPage;
                showIt(item2select);
                item2selectStory.characters[item2selectIndex].select();
            }
            
            
            
            
            function showIt(theObj) {
                if (arguments.length > 0) app.select(theObj);
                var myZoom = app.activeWindow.zoomPercentage;
                app.activeWindow.zoom(ZoomOptions.showPasteboard);
                app.activeWindow.zoomPercentage = myZoom;
            }
            

             

            Thanks!

            Tobias

            • 3. Re: Re: Re: [CC/Mac, JS] Palette looses layoutWindow focus when double clicking listbox items several times
              Laubender Adobe Community Professional & MVP

              @Tobias – hm, would it help to deactivate/activate the Notes Panel?

              It's just a plain panel, that you can get by its name and set visibility to true or false.

               

              Did not try that yet with your code.

               

              For a German InDesign that would be:

               

              app.panels.itemByName("Notizen").visible = false;
              

               

              For all versions of InDesign we first have to look for an appropriate string.

              In my German InDesign I am searching with:

               

              app.findKeyStrings("Notizen");
              

               

              which gives me an array with two entrys:

              $ID/#AppBarNotes,
              $ID/Notes
              

               

              So the following should work in all InDesign versions:

               

              app.panels.itemByName("$ID/Notes").visible = false;
              

               

              Uwe

              • 4. Re: Re: Re: Re: [CC/Mac, JS] Palette looses layoutWindow focus when double clicking listbox items several times
                tobias.wantzen Level 1

                Uwe, thanks again for your hint!

                 

                Actually changing lines 114–122 to the following code finally does, what I want to achieve: change of layout view and the correct note shown in the notes panel.

                function lstNoteItems_onChange(){
                  var idClicked = this.selection[0].id;
                    var item2select = g.arrNoteItems[idClicked].storyOffset;
                  var item2selectStory = item2select.parentStory;
                  var item2selectIndex = item2select.index;
                    var _panelVisible = false;
                    if (app.panels.itemByName("$ID/Notes").visible){
                        _panelVisible = true;
                        app.panels.itemByName("$ID/Notes").visible = false;
                    }
                    app.activeWindow.activePage = item2select.parentTextFrames[0].parentPage;
                    showIt(item2select);
                    item2selectStory.characters[item2selectIndex].select();
                    if (_panelVisible) app.panels.itemByName("$ID/Notes").visible = true;
                }
                

                 

                Toggling the visibility of the panel does a little flicker, so it’s just a workaround, but I’m fine with it.

                 

                Other suggestions are still welcome!

                Kind regards

                Tobias