mirror of
https://github.com/atom/atom.git
synced 2026-01-25 23:08:18 -05:00
Execute operation from OperationView
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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) =>
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user