60 lines
2.4 KiB
JavaScript
60 lines
2.4 KiB
JavaScript
const {remote} = require('electron');
|
|
const {dialog,Menu,MenuItem} = remote;
|
|
const CatAnimation = require('../classes/CatAnimation');
|
|
|
|
module.exports = function(Cat) {
|
|
return {
|
|
init: function(dom) {
|
|
let animationsTree = document.querySelector('#animations-tree');
|
|
animationsTree.addEventListener('click-row', evt => {
|
|
// TODO: select animation to edit/view ???
|
|
// TEMP: this is just for testing.
|
|
let timeline = document.querySelector('cat-timeline');
|
|
timeline.clearKeyframes();
|
|
let keyframes = evt.detail.animationKeyframe.getKeyframes();
|
|
for (let keyframe in keyframes) {
|
|
timeline.addKeyframe(parseInt(keyframe) / 100 * timeline.totalFrames);
|
|
}
|
|
});
|
|
// Add a right-click handler to the parent node which *should* be a vbox
|
|
animationsTree.parentNode.addEventListener('contextmenu', evt => {
|
|
var target = evt.target;
|
|
if (target.tagName === 'CAT-TREE-CELL') {
|
|
target = target.parentNode;
|
|
}
|
|
const treeMenu = new Menu();
|
|
treeMenu.append(new MenuItem({type: 'separator'}));
|
|
treeMenu.append(new MenuItem({label: 'Delete', enabled: (target ? true : false), click() {
|
|
target.animationKeyframe.remove();
|
|
animationsTree.removeRow(target);
|
|
}}));
|
|
treeMenu.popup({async: true});
|
|
});
|
|
// Add a remove-row handler for obvious reasons.
|
|
animationsTree.addEventListener('remove-row', evt => {
|
|
});
|
|
},
|
|
on: {
|
|
'project-closed': project => {
|
|
let animationsTree = document.querySelector('#animations-tree');
|
|
animationsTree.clear(false);
|
|
},
|
|
// Add hook for when a project is focused, we rebuild the animations tree to correspond to the target DOM. In the future we could cache this DOM tree.
|
|
'project-focused': project => {
|
|
let animationsTree = document.querySelector('#animations-tree');
|
|
let animations = project.getAnimations();
|
|
console.log('animations - project-focused');
|
|
|
|
animationsTree.setHeadCells([""]);
|
|
for (let anim in animations) {
|
|
let row = animationsTree.addRow([anim]);
|
|
row.animationKeyframe = animations[anim];
|
|
}
|
|
},
|
|
'project-loaded': project => {
|
|
let animationsTree = document.querySelector('#animations-tree');
|
|
}
|
|
}
|
|
}
|
|
};
|