Show preview list when X x operation completes

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-07-17 18:39:29 -06:00
parent f998da301c
commit faea4aedcc
7 changed files with 73 additions and 20 deletions

View File

@@ -2,6 +2,7 @@
CommandInterpreter = require 'command-panel/command-interpreter'
RegexAddress = require 'command-panel/commands/regex-address'
CompositeCommand = require 'command-panel/commands/composite-command'
PreviewItem = require 'command-panel/preview-item'
Editor = require 'editor'
{SyntaxError} = require('pegjs').parser
@@ -16,6 +17,9 @@ class CommandPanel extends View
else
@instance = new CommandPanel(rootView)
@deactivate: ->
@instance.detach()
@serialize: ->
text: @instance.miniEditor.getText()
visible: @instance.hasParent()
@@ -27,8 +31,10 @@ class CommandPanel extends View
@content: ->
@div class: 'command-panel', =>
@div ':', class: 'prompt', outlet: 'prompt'
@subview 'miniEditor', new Editor(mini: true)
@ol class: 'preview-list', outlet: 'previewList'
@div class: 'prompt-and-editor', =>
@div ':', class: 'prompt', outlet: 'prompt'
@subview 'miniEditor', new Editor(mini: true)
commandInterpreter: null
history: null
@@ -54,16 +60,25 @@ class CommandPanel extends View
attach: (text='') ->
@rootView.append(this)
@previewList.hide()
@miniEditor.focus()
@miniEditor.setText(text)
detach: ->
@rootView.focus()
if @previewedOperations
operation.destroy() for operation in @previewedOperations
super
execute: (command = @miniEditor.getText()) ->
try
@commandInterpreter.eval(command, @rootView.getActiveEditSession())
@commandInterpreter.eval(command, @rootView.getActiveEditSession()).done (operations) =>
@history.push(command)
@historyIndex = @history.length
if operations?.length
@populatePreviewList(operations)
else
@detach()
catch error
if error instanceof SyntaxError
@flashError()
@@ -71,9 +86,12 @@ class CommandPanel extends View
else
throw error
@history.push(command)
@historyIndex = @history.length
@detach()
populatePreviewList: (operations) ->
@previewedOperations = operations
@previewList.empty()
for operation in operations
@previewList.append(new PreviewItem(operation))
@previewList.show()
navigateBackwardInHistory: ->
return if @historyIndex == 0

View File

@@ -21,10 +21,10 @@ class CompositeCommand
@executeCommands(remainingCommands, project, editSession, nextRanges).done ->
deferred.resolve()
else
editSession?.clearAllSelections() unless currentCommand.preserveSelections
if currentCommand.previewOperations
deferred.resolve(operations)
else
editSession?.clearAllSelections() unless currentCommand.preserveSelections
for operation in operations
operation.execute(editSession)
operation.destroy()

View File

@@ -14,6 +14,9 @@ class Operation
@buffer.change(@getBufferRange(), @newText) if @newText
editSession.addSelectionForBufferRange(@getBufferRange()) unless @preserveSelection
preview: ->
"sad :-("
destroy: ->
@buffer.release()
@anchorRange.destroy()

View File

@@ -0,0 +1,8 @@
{View} = require 'space-pen'
module.exports =
class PreviewItem extends View
@content: (operation) ->
@li =>
@span operation.getPath()
@span operation.preview()