Quantcast
Channel: Adobe Community: Message List
Viewing all articles
Browse latest Browse all 97529

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

$
0
0

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


Viewing all articles
Browse latest Browse all 97529

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>