Skip to content

Commit

Permalink
Merge pull request #115 from 2xAA/2.0-layer-menu
Browse files Browse the repository at this point in the history
Adds context menu to Layers
  • Loading branch information
2xAA authored Nov 13, 2017
2 parents 929c6df + eef4906 commit ecc424e
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 39 deletions.
44 changes: 33 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

138 changes: 123 additions & 15 deletions src/components/Layer/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
collapsed: collapsed
}"
@click="focusLayer"
v-context-menu="menuOptions"
>
<div class="columns is-gapless is-multiline">
<div class="column is-12">
Expand Down Expand Up @@ -61,13 +62,36 @@
import { mapActions, mapGetters, mapMutations } from 'vuex';
import ActiveModule from '@/components/ActiveModule';
import draggable from 'vuedraggable';
import { Menu, MenuItem } from 'nwjs-menu-browser';
if (!window.nw) {
window.nw = {
Menu,
MenuItem,
};
}
const nw = window.nw;
export default {
name: 'layer',
props: [
'Layer',
'LayerIndex',
],
data() {
return {
menuOptions: {
match: ['layerItem'],
menuItems: [],
createMenus: this.createMenus,
},
clearingChecked: false,
inheritChecked: false,
pipelineChecked: false,
drawToOutputChecked: false,
};
},
computed: {
modules: {
get() {
Expand All @@ -93,6 +117,26 @@
]),
},
methods: {
...mapActions('layers', [
'addLayer',
'toggleLocked',
'toggleCollapsed',
'addModuleToLayer',
'updateModuleOrder',
'moveModuleInstance',
]),
...mapActions('modVModules', [
'createActiveModule',
]),
...mapMutations('layers', [
'setLayerName',
'setLayerFocus',
'setClearing',
'setInherit',
'setInheritFrom',
'setPipeline',
'setDrawToOutput',
]),
drop(e) {
e.preventDefault();
const moduleName = e.item.dataset.moduleName;
Expand Down Expand Up @@ -122,21 +166,6 @@
e.item.classList.remove('deletable');
}
},
...mapActions('layers', [
'addLayer',
'toggleLocked',
'toggleCollapsed',
'addModuleToLayer',
'updateModuleOrder',
'moveModuleInstance',
]),
...mapActions('modVModules', [
'createActiveModule',
]),
...mapMutations('layers', [
'setLayerName',
'setLayerFocus',
]),
startNameEdit() {
const node = this.$el.querySelector('.layer-title');
if (node.classList.contains('editable')) return;
Expand Down Expand Up @@ -187,6 +216,85 @@
clickToggleCollapse() {
this.toggleCollapsed({ layerIndex: this.LayerIndex });
},
updateChecked() {
const Layer = this.Layer;
this.clearingChecked = Layer.clearing;
this.inheritChecked = Layer.inherit;
this.inheritanceIndex = Layer.inheritFrom;
this.pipelineChecked = Layer.pipeline;
this.drawToOutputChecked = Layer.drawToOutput;
},
createMenus() {
const that = this;
this.menuOptions.menuItems.splice(0, this.menuOptions.menuItems.length);
this.menuOptions.menuItems.push(
new nw.MenuItem({
label: this.name,
enabled: false,
}),
new nw.MenuItem({
type: 'separator',
}),
new nw.MenuItem({
type: 'checkbox',
label: 'Clearing',
checked: this.clearingChecked,
click: function click() {
that.setClearing({
layerIndex: that.LayerIndex,
clearing: this.checked,
});
},
}),
new nw.MenuItem({
type: 'checkbox',
label: 'Inherit',
checked: this.inheritChecked,
click: function click() {
that.setInherit({
layerIndex: that.LayerIndex,
inherit: this.checked,
});
},
}),
new nw.MenuItem({
type: 'checkbox',
label: 'Pipeline',
checked: this.pipelineChecked,
click: function click() {
that.setPipeline({
layerIndex: that.LayerIndex,
pipeline: this.checked,
});
},
}),
new nw.MenuItem({
type: 'checkbox',
label: 'Draw To Output',
checked: this.drawToOutputChecked,
click: function click() {
that.setDrawToOutput({
layerIndex: that.LayerIndex,
drawToOutput: this.checked,
});
},
}),
);
},
},
beforeMount() {
this.updateChecked();
},
watch: {
Layer: {
handler() {
this.updateChecked();
},
deep: true,
},
},
components: {
ActiveModule,
Expand Down
22 changes: 12 additions & 10 deletions src/components/LayerControls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@
'setPipeline',
'setDrawToOutput',
]),
},
watch: {
name() {
if (!this.Layer) return;
updateChecked() {
const Layer = this.Layer;
this.clearingChecked = Layer.clearing;
Expand All @@ -95,6 +92,15 @@
this.pipelineChecked = Layer.pipeline;
this.drawToOutputChecked = Layer.drawToOutput;
},
},
watch: {
Layer: {
handler() {
if (!this.Layer) return;
this.updateChecked();
},
deep: true,
},
clearingChecked() {
this.setClearing({
layerIndex: this.layerIndex,
Expand All @@ -116,12 +122,8 @@
},
mounted() {
if (!this.Layer) return;
const Layer = this.Layer;
this.clearingChecked = Layer.clearing;
this.inheritChecked = Layer.inherit;
this.inheritanceIndex = Layer.inheritFrom;
this.pipelineChecked = Layer.pipeline;
this.drawToOutputChecked = Layer.drawToOutput;
this.updateChecked();
},
};
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/extra/context-menu/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<component
is="contextMenuItem"
v-for="item, idx in items"
:key="item"
:key="idx"
:options="item"
:parentOptions="options"
:parentOffsetWidth="offsetWidth"
Expand Down
4 changes: 2 additions & 2 deletions src/extra/context-menu/MenuHandler.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<template>
<div>
<context-menu
v-for="menu in activeMenus"
v-for="menu, idx in activeMenus"
:options="menu"
:key="menu"
:key="idx"
></context-menu>
</div>
</template>
Expand Down
6 changes: 6 additions & 0 deletions src/extra/context-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ function buildMenu(e, id, options, vnode, store) {
menu.$id = id;
menu.isSubmenu = false;

if ('createMenus' in options) {
if (typeof options.createMenus === 'function') {
options.createMenus();
}
}

options.menuItems.forEach((item, idx) => menu.insert(item, idx));

const moduleName = vnode.context.moduleName;
Expand Down
Loading

0 comments on commit ecc424e

Please sign in to comment.