Skip to main content
km79
Participating Frequently
December 17, 2010
Question

Access a selected collection

  • December 17, 2010
  • 1 reply
  • 619 views

Hi,

how can I get the name/id of the collection I clicked with the rigth mouse button on to open the context menu?

I want to run a function on the current selected collection via a submenu commen like "Rename" or "Delete".

I only can find a couple of functions to manipulate and create/delete a collection, but no function or object that tells me the current collection.


How can I access this?

Thanks

Konrad

This topic has been closed for replies.

1 reply

Paul Riggott
Inspiring
December 17, 2010

Here is an example of accessing collections.


#target bridge  
   if( BridgeTalk.appName == "bridge" ) { 
collectionFind = MenuElement.create("command", "Find in Collection", "at the end of Tools");
}
collectionFind.onSelect = function () {
   findInCollections();
   }

function findInCollections(){
var cols =app.getCollections();
if(!cols.length) {
    alert("There are no Collections to search!");
    return;
    }
var win = new Window('dialog',"Collections");
win.orientation = "column";
win.pnl1 = win.add('panel', undefined, undefined, {borderStyle:"black"});
win.g1 = win.pnl1.add('group');
win.title = win.g1.add('statictext',undefined,'Find in Collection');
win.title.alignment="fill";
var g = win.title.graphics;
g.font = ScriptUI.newFont("Georgia","BOLDITALIC",22);
win.g5 = win.pnl1.add('group');
win.g5.orientation = "row";
win.g5.alignment="left";
win.g5.st1 = win.g5.add('statictext',undefined,'Select Collection...');
win.g5.dd1 = win.g5.add('dropdownlist');
for(var a in cols) { win.g5.dd1.add('item', cols.name);}
win.g5.dd1.selection=0;

win.g10 = win.pnl1.add('group');
win.g10.orientation = "row";
win.g10.alignment="left";
win.g10.st1 = win.g10.add('statictext',undefined,'Find ...');
win.g10.et1 = win.g10.add('edittext');
win.g10.et1.preferredSize=[200,20];

win.g100 = win.add('group');
win.g100.orientation = "row";
win.g100.alignment="center";
win.find = win.g100.add('button',undefined,'Find');
win.find.preferredSize=[100,30];
win.cancel= win.g100.add('button',undefined,'Cancel');
win.cancel.preferredSize=[100,30];

win.find.onClick=function(){
  if(win.g10.et1.text == ''){
      alert("You haven't entered anything to find!");
      return;
      }
  win.close(1);
var collectionToSearch = app.getCollectionMembers(cols[Number(win.g5.dd1.selection.index)]);
var newCollection = [];
var REX = new RegExp(win.g10.et1.text,"gi");
for(var s in collectionToSearch){
     if(collectionToSearch.name.match(REX)) newCollection.push(collectionToSearch);
     }
if(!newCollection.length){
     alert("No match found");
     return;
     }
var Name = "Found in " + win.g5.dd1.selection.text;
var foundFiles = app.createCollection(Name);
for(var c in newCollection){
     app.addCollectionMember(foundFiles,new Thumbnail(newCollection));
     }
app.document.thumbnail = foundFiles;
}
win.center();
win.show();
}

km79
km79Author
Participating Frequently
December 17, 2010

Paul Riggott wrote:

Here is an example of accessing collections.

...

I found this code snippet in another thread here in the forum - but it gets a list of all collections and iterates it. This is not the same as getting a specific, selected collection.

I tried some other things and came up with this code in my function that is called via a submenu item:

var items = app.getCollectionMembers (app.document.thumbnail);

This lines gives me all items (members) of the current selected collection in the collections pane.