Serialize command panel history

Retains up to 100 commands between reloads
This commit is contained in:
Kevin Sawicki
2012-09-20 13:34:03 -07:00
parent c42c824f0a
commit ea77b60b15
2 changed files with 44 additions and 4 deletions

View File

@@ -24,9 +24,10 @@ class CommandPanel extends View
text: @instance.miniEditor.getText()
visible: @instance.hasParent()
miniEditorFocused: @instance.miniEditor.isFocused
history: @instance.history[-@instance.maxSerializedHistorySize..]
@deserialize: (state, rootView) ->
commandPanel = new CommandPanel(rootView)
commandPanel = new CommandPanel(rootView, state.history)
commandPanel.attach(state.text, focus: false) if state.visible
commandPanel.miniEditor.focus() if state.miniEditorFocused
commandPanel
@@ -41,10 +42,13 @@ class CommandPanel extends View
commandInterpreter: null
history: null
historyIndex: 0
maxSerializedHistorySize: 100
initialize: (@rootView)->
initialize: (@rootView, @history) ->
@commandInterpreter = new CommandInterpreter(@rootView.project)
@history = []
@history ?= []
@historyIndex = @history.length
@on 'command-panel:unfocus', => @rootView.focus()
@on 'command-panel:close', => @detach()