Last active
March 31, 2017 09:09
-
-
Save me7/84ce33d84908c8d723c201492d029986 to your computer and use it in GitHub Desktop.
lightning launcher select first item in folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var item = LL.getEvent().getItem(); | |
if ( item.getType() != 'Folder' ) | |
{ | |
alert('Not a folder'); | |
return; | |
} | |
var items = item.getContainer().getItems(); | |
var count = items.getLength(); | |
if ( count == 0 ) | |
{ | |
alert('Empty folder'); | |
return; | |
} | |
var minItem; | |
var i = 0; | |
/* make sure we find at least a shortcut */ | |
while ( i < count ) | |
{ | |
minItem = items.getAt(i++); | |
if ( minItem.getType() == 'Shortcut' ) | |
{ | |
break; | |
} | |
} | |
if ( i == count ) | |
{ | |
alert('No shortcut found'); | |
return; | |
} | |
var minTop = minItem.getCell().getTop(); | |
var minLeft = minItem.getCell().getLeft(); | |
/* find the topmost leftmost shortcut */ | |
for ( ; i < count; i+=1 ) | |
{ | |
item = items.getAt(i); | |
if ( minItem.getType() != 'Shortcut' ) | |
continue; | |
var r = item.getCell(); | |
/* check if it is the topmost leftmost */ | |
if ( (r.getTop() < minTop) && (r.getLeft() < minLeft) ) | |
{ | |
minTop = r.getTop(); | |
minLeft = r.getLeft(); | |
minItem = item; | |
return; | |
} | |
} | |
/* launch app */ | |
minItem.launch(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment