Execute operation from OperationView

This commit is contained in:
Kevin Sawicki
2013-02-13 19:13:23 -08:00
parent 7c4c44df5a
commit 61481fc1d8
3 changed files with 21 additions and 15 deletions

View File

@@ -10,3 +10,18 @@ class OperationView extends View
@span prefix
@span match, class: 'match'
@span suffix
initialize: ({@previewList, @operation}) ->
@previewList.on 'core:confirm', =>
if @hasClass('selected')
@executeOperation()
false
@on 'mousedown', (e) =>
@executeOperation()
@addClass('selected')
executeOperation: ->
editSession = rootView.open(@operation.getPath())
bufferRange = @operation.execute(editSession)
editSession.setSelectedBufferRange(bufferRange, autoscroll: true) if bufferRange
@previewList.focus()

View File

@@ -5,7 +5,7 @@ $ = require 'jquery'
module.exports =
class PathView extends View
@content: ({path, operations} = {}) ->
@content: ({path, operations, previewList} = {}) ->
classes = ['path']
classes.push('readme') if fs.isReadmePath(path)
@li class: classes.join(' '), =>
@@ -13,11 +13,11 @@ class PathView extends View
@span "(#{operations.length})", class: 'path-match-number'
@ul outlet: 'matches', class: 'matches', =>
for operation in operations
@subview "operation#{operation.index}", new OperationView({operation})
@subview "operation#{operation.index}", new OperationView({operation, previewList})
initialize: ->
initialize: ({previewList}) ->
@on 'mousedown', @onPathSelected
@subscribe rootView, 'command-panel:collapse-result', =>
previewList.command 'command-panel:collapse-result', =>
@collapse(true) if @find('.selected').length
onPathSelected: (event) =>

View File

@@ -15,13 +15,12 @@ class PreviewList extends ScrollView
initialize: (@rootView) ->
super
@on 'core:move-down', => @selectNextOperation(); false
@on 'core:move-up', => @selectPreviousOperation(); false
@on 'core:confirm', => @executeSelectedOperation()
@on 'mousedown', 'li.operation', (e) =>
@setSelectedOperationIndex(parseInt($(e.target).closest('li').data('index')))
@executeSelectedOperation()
@command 'command-panel:collapse-all', => @collapseAllPaths()
@command 'command-panel:expand-all', => @expandAllPaths()
@@ -45,7 +44,7 @@ class PreviewList extends ScrollView
operation.index = index for operation, index in operations
operationsByPath = _.groupBy(operations, (operation) -> operation.getPath())
for path, operations of operationsByPath
@append new PathView({path, operations})
@append new PathView({path, operations, previewList: this})
@setSelectedOperationIndex(0)
@show()
@@ -79,14 +78,6 @@ class PreviewList extends ScrollView
@selectedOperationIndex = index
executeSelectedOperation: ->
operation = @getSelectedOperation()
editSession = @rootView.open(operation.getPath())
bufferRange = operation.execute(editSession)
editSession.setSelectedBufferRange(bufferRange, autoscroll: true) if bufferRange
@focus()
false
getPathCount: ->
_.keys(_.groupBy(@operations, (operation) -> operation.getPath())).length