mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Add serialize and deserialize functionality to the itemStack.
This commit is contained in:
@@ -20,7 +20,7 @@ class Pane extends Model
|
||||
focused: false
|
||||
|
||||
@deserialize: (state, {deserializers, applicationDelegate, config, notifications}) ->
|
||||
{items, activeItemURI, activeItemUri} = state
|
||||
{items, itemStack, activeItemURI, activeItemUri} = state
|
||||
activeItemURI ?= activeItemUri
|
||||
state.items = compact(items.map (itemState) -> deserializers.deserialize(itemState))
|
||||
state.activeItem = find state.items, (item) ->
|
||||
@@ -48,15 +48,20 @@ class Pane extends Model
|
||||
|
||||
@addItems(compact(params?.items ? []))
|
||||
@setActiveItem(@items[0]) unless @getActiveItem()?
|
||||
@addItemsToStack(params?.itemStack ? [])
|
||||
@setFlexScale(params?.flexScale ? 1)
|
||||
|
||||
serialize: ->
|
||||
if typeof @activeItem?.getURI is 'function'
|
||||
activeItemURI = @activeItem.getURI()
|
||||
itemStack = []
|
||||
for item in @items
|
||||
itemStack.push(@itemStack.indexOf(item)) if typeof item.serialize is 'function'
|
||||
|
||||
deserializer: 'Pane'
|
||||
id: @id
|
||||
items: compact(@items.map((item) -> item.serialize?()))
|
||||
itemStack: itemStack
|
||||
activeItemURI: activeItemURI
|
||||
focused: @focused
|
||||
flexScale: @flexScale
|
||||
@@ -291,6 +296,14 @@ class Pane extends Model
|
||||
@emitter.emit 'did-change-active-item', @activeItem
|
||||
@activeItem
|
||||
|
||||
# Build the itemStack after deserializing
|
||||
addItemsToStack: (itemStack) ->
|
||||
if itemStack.length is 0 or itemStack.length isnt @items.length or itemStack.indexOf(-1) >= 0
|
||||
itemStack = @items.map((item) => @items.indexOf(item))
|
||||
for item, i in itemStack
|
||||
index = itemStack.indexOf(i)
|
||||
@addItemToStack(@items[index]) unless index is -1
|
||||
|
||||
# Add item (or move item) to the end of the itemStack
|
||||
addItemToStack: (newItem) ->
|
||||
index = @itemStack.indexOf(newItem)
|
||||
@@ -311,7 +324,6 @@ class Pane extends Model
|
||||
|
||||
# Makes the most recently used item active.
|
||||
activateMostRecentlyUsedItem: ->
|
||||
console.log(@items[0].serialize)
|
||||
if @items.length > 1
|
||||
index = @itemStack.length - 2
|
||||
mostRecentlyUsedItem = @itemStack[index]
|
||||
|
||||
Reference in New Issue
Block a user