import spacePen = require ( "atom-space-pen-views" ) ; import _ = require ( '../lodash' ) ; declare var _super ; declare var _this ; class ListView extends spacePen . SelectListView { private panel : Atom . Panel ; private previouslyFocusedElement : Node ; private eventElement : any ; private message : JQuery ; private list : JQuery ; constructor ( private question , private invokeNext ) { super ( ) ; } public static content ( ) { return this . div ( { } , ( ) => { this . p ( { outlet : 'message' } , '' ) ; ( < any > spacePen . SelectListView ) . content . call ( this ) ; } ) ; } public initialize ( ) { ( < any > spacePen . SelectListView ) . prototype . initialize . call ( this ) ; this . addClass ( 'prompt' ) ; } public getFilterKey ( ) { return 'name' ; } public cancelled ( ) { return this . hide ( ) ; } public toggle ( ) { if ( this . panel && this . panel . isVisible ( ) ) { this . cancel ( ) ; } else { this . show ( ) ; } } public show ( ) { if ( this . panel == null ) { this . panel = atom . workspace . addModalPanel ( { item : this } ) ; } this . panel . show ( ) ; this . storeFocusedElement ( ) ; this . message . text ( this . question . message ) ; if ( this . previouslyFocusedElement [ 0 ] && this . previouslyFocusedElement [ 0 ] !== document . body ) { this . eventElement = this . previouslyFocusedElement [ 0 ] ; } else { this . eventElement = atom . views . getView ( atom . workspace ) ; } this . setItems ( this . question . choices ) ; this . focusFilterEditor ( ) ; if ( this . question . default ) { var selected = this . list . find ( '[data-event-name="' + this . question . default + '"]' ) ; this . selectItemView ( < any > selected ) ; } } public hide ( ) { this . panel && this . panel . hide ( ) ; this . panel . destroy ( ) ; this . panel = null ; } public viewForItem ( item ) { return spacePen . $$ ( function ( ) { return this . li ( { "class" : 'event' , 'data-event-name' : item . value } , ( ) => { return this . span ( item . name , { title : item . name } ) ; } ) ; } ) ; } public confirmed ( item ? ) { this . cancel ( ) ; if ( this . invokeNext ) { this . invokeNext ( item . value ) ; } return null ; } } export = ListView ;