From 61481fc1d89dd47f97d332f43db2733407ccdac5 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 13 Feb 2013 19:13:23 -0800 Subject: [PATCH] Execute operation from OperationView --- .../command-panel/lib/operation-view.coffee | 15 +++++++++++++++ src/packages/command-panel/lib/path-view.coffee | 8 ++++---- .../command-panel/lib/preview-list.coffee | 13 ++----------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/packages/command-panel/lib/operation-view.coffee b/src/packages/command-panel/lib/operation-view.coffee index 8f231ab75..580c2a037 100644 --- a/src/packages/command-panel/lib/operation-view.coffee +++ b/src/packages/command-panel/lib/operation-view.coffee @@ -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() diff --git a/src/packages/command-panel/lib/path-view.coffee b/src/packages/command-panel/lib/path-view.coffee index 05d28ecde..de7672618 100644 --- a/src/packages/command-panel/lib/path-view.coffee +++ b/src/packages/command-panel/lib/path-view.coffee @@ -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) => diff --git a/src/packages/command-panel/lib/preview-list.coffee b/src/packages/command-panel/lib/preview-list.coffee index 9db65e474..2620b5cec 100644 --- a/src/packages/command-panel/lib/preview-list.coffee +++ b/src/packages/command-panel/lib/preview-list.coffee @@ -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