🎨 Extract function: Pane::isItemAllowed(item)

This commit is contained in:
Jason Rudolph
2017-06-07 15:32:30 -04:00
parent 296e407284
commit de47d3d439
2 changed files with 13 additions and 6 deletions

View File

@@ -214,9 +214,7 @@ class PaneContainer {
moveActiveItemToPane (destPane) {
const item = this.activePane.getActiveItem()
if (typeof item.getAllowedLocations === 'function' && !item.getAllowedLocations().includes(destPane.getContainer().getLocation())) {
return
}
if (!destPane.isItemAllowed(item)) { return }
this.activePane.moveItemToPane(item, destPane)
destPane.setActiveItem(item)
@@ -225,9 +223,7 @@ class PaneContainer {
copyActiveItemToPane (destPane) {
const item = this.activePane.copyActiveItem()
if (typeof item.getAllowedLocations === 'function' && !item.getAllowedLocations().includes(destPane.getContainer().getLocation())) {
return
}
if (!destPane.isItemAllowed(item)) { return }
destPane.activateItem(item)
}

View File

@@ -91,6 +91,17 @@ class Pane
@container = container
container.didAddPane({pane: this})
# Private: Determine whether the given item is allowed to exist in this pane.
#
# * `item` the Item
#
# Returns a {Boolean}.
isItemAllowed: (item) ->
if (typeof item.getAllowedLocations isnt 'function')
true
else
item.getAllowedLocations().includes(@getContainer().getLocation())
setFlexScale: (@flexScale) ->
@emitter.emit 'did-change-flex-scale', @flexScale
@flexScale