Skip to content

Commit

Permalink
set correct cwd on drag for external chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
mmckegg committed Sep 14, 2017
1 parent 8e4f3e8 commit 09b1a85
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lib/widgets/orderable.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ function dragOver (ev) {

function dragStart (ev) {
var data = ev.data()
var setup = ev.data.context.setup
var type = data.node.split('/')[0]
if (type === 'externalChunk') {
type = 'chunk'
}
ev.ordering = true
ev.node = ev.data
ev.dataTransfer.setData('loop-drop/' + type, JSON.stringify(data))
ev.dataTransfer.setData('cwd', resolve(ev.data.context.cwd))
ev.dataTransfer.setData('cwd', resolve(setup.context.cwd))
window.currentDrag = ev
}

Expand Down
10 changes: 6 additions & 4 deletions nodes/loop-grid/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ function leaveButton (ev) {
function startDrag (ev) {
var chunk = ev.data.chunk
var controller = ev.data.controller
var setup = chunk.context.setup

var data = resolve(chunk)
var type = data.node.split('/')[0]
Expand All @@ -185,7 +186,7 @@ function startDrag (ev) {
coords: controller.chunkPositions.get(chunk.id())
}
ev.dataTransfer.setData('loop-drop/' + type, JSON.stringify(data))
ev.dataTransfer.setData('cwd', resolve(chunk.context.cwd))
ev.dataTransfer.setData('cwd', resolve(setup.context.cwd))
window.currentDrag = ev
}

Expand Down Expand Up @@ -224,13 +225,14 @@ function getId (chunk) {
function dragOver (ev) {
var controller = ev.data
var currentDrag = window.currentDrag
var sourceSetup = currentDrag.node.context.setup

if (!currentDrag) return
var originalDirectory = resolve(currentDrag.node.context.cwd)
var sourceDirectory = resolve(sourceSetup.context.cwd)

if (ev.altKey || originalDirectory !== resolve(controller.context.cwd)) {
if (ev.altKey || sourceDirectory !== resolve(controller.context.cwd)) {
ev.dataTransfer.dropEffect = 'copy'
} else if (currentDrag && originalDirectory === resolve(controller.context.cwd)) {
} else if (currentDrag && sourceDirectory === resolve(controller.context.cwd)) {
var chunkId = getId(currentDrag.node)
if (chunkId) {
var shape = controller.playback.shape()
Expand Down
9 changes: 5 additions & 4 deletions nodes/setup/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var updateParamReferences = require('lib/update-param-references')
var lookup = require('mutant/lookup')
var merge = require('mutant/merge')

var join = require('path').join
var Path = require('path')
var extend = require('xtend')

var Property = require('lib/property')
Expand Down Expand Up @@ -185,12 +185,13 @@ function Setup (parentContext) {
}

if (descriptor.node === 'externalChunk') {
var originalPath = join(originalDirectory, descriptor.src)
var targetPath = join(resolve(context.cwd), id + '.json')
var originalPath = Path.join(originalDirectory, descriptor.src)
var externalRoot = Path.dirname(originalPath)
var targetPath = Path.join(resolve(context.cwd), id + '.json')
context.fs.readFile(originalPath, 'utf8', function (err, data) {
if (err) return cb && cb(err)
var externalDescriptor = JSON.parse(data)
importAssociatedFiles(externalDescriptor, originalDirectory, resolve(context.cwd), function (err) {
importAssociatedFiles(externalDescriptor, externalRoot, resolve(context.cwd), function (err) {
if (err) return cb && cb(err)
context.fs.writeFile(targetPath, JSON.stringify(externalDescriptor), function (err) {
if (err) return cb && cb(err)
Expand Down

0 comments on commit 09b1a85

Please sign in to comment.