check
This commit is contained in:
parent
0459fe94fd
commit
36d85b096d
5 changed files with 149 additions and 114 deletions
|
|
@ -141,31 +141,6 @@ var Editor = class Editor {
|
|||
|
||||
})
|
||||
|
||||
keyboardJS.bind('mod + s', (e)=>{
|
||||
e.preventDefault()
|
||||
sessionManager.save()
|
||||
})
|
||||
|
||||
keyboardJS.bind('mod + shift + s', (e)=>{
|
||||
e.preventDefault()
|
||||
sessionManager.saveAs()
|
||||
})
|
||||
|
||||
keyboardJS.bind('mod + o', (e)=>{
|
||||
e.preventDefault()
|
||||
sessionManager.browse()
|
||||
})
|
||||
|
||||
keyboardJS.bind('mod + e', (e)=>{
|
||||
e.preventDefault()
|
||||
if (this.enabled) {
|
||||
this.disable()
|
||||
} else {
|
||||
if (sessionManager.session.type) this.enable()
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
this.selectarea = new UiSelectArea('[data-widget]:not(.not-editable)', (elements)=>{
|
||||
|
||||
elements = elements.map(e => widgetManager.getWidgetByElement(e, ':not(.not-editable)')).filter(e => e)
|
||||
|
|
@ -324,16 +299,6 @@ var Editor = class Editor {
|
|||
|
||||
break
|
||||
|
||||
// case 'f2':
|
||||
// var input = DOM.get(this.form, 'textarea[name="label"]')[0]
|
||||
// if (input) {
|
||||
// var folded = input.closest('.category.folded')
|
||||
// if (folded) DOM.dispatchEvent(DOM.get(folded, '.separator'), 'fast-click')
|
||||
// input.focus()
|
||||
// input.setSelectionRange(0, input.value.length)
|
||||
// }
|
||||
// break
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,106 +1,132 @@
|
|||
var html = require('nanohtml'),
|
||||
raw = require('nanohtml/raw'),
|
||||
keyboardJS = require('keyboardjs'),
|
||||
UiWidget = require('./ui-widget'),
|
||||
mod = (navigator.platform || '').match('Mac') ? 'cmd' : 'ctrl',
|
||||
MENU_CONTAINER
|
||||
|
||||
|
||||
class ContextMenu extends UiWidget {
|
||||
|
||||
constructor(options){
|
||||
constructor(options={}){
|
||||
|
||||
super(options)
|
||||
|
||||
if (!MENU_CONTAINER) MENU_CONTAINER = DOM.get('osc-workspace')[0]
|
||||
|
||||
|
||||
this.container = null
|
||||
this.container = html`<div class="context-menu"></div>`
|
||||
this.clickHandler = (e)=>{
|
||||
if (this.container && !this.container.contains(e.target)) this.close()
|
||||
if (this.container && !this.container.contains(e.target)) {
|
||||
this.close()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.position = options.position
|
||||
if (this.position) {
|
||||
this.container.style.top = this.position[0] + 'rem'
|
||||
this.container.style.left = this.position[1] + 'rem'
|
||||
}
|
||||
|
||||
this.container.addEventListener('click', (e)=>{
|
||||
e.preventDefault()
|
||||
if (e.target._action){
|
||||
e.target._action()
|
||||
this.close()
|
||||
}
|
||||
})
|
||||
|
||||
this.hoverNode = null
|
||||
this.container.addEventListener('mousemove', (e)=>{
|
||||
if (this.hoverNode === e.target) return
|
||||
this.hoverNode = e.target
|
||||
if (!e.target.classList.contains('focus')) {
|
||||
DOM.each(e.target.parentNode, '.focus', (el)=>{
|
||||
el.classList.remove('focus')
|
||||
})
|
||||
e.target.classList.add('focus')
|
||||
}
|
||||
})
|
||||
|
||||
this.container.addEventListener('touchstart', (e)=>{
|
||||
if (!e.target.classList.contains('focus')) {
|
||||
DOM.each(e.target.parentNode, '.focus', (el)=>{
|
||||
el.classList.remove('focus')
|
||||
})
|
||||
e.target.classList.add('focus')
|
||||
} else {
|
||||
e.target.classList.remove('focus')
|
||||
DOM.each(e.target, '.focus', (el)=>{
|
||||
el.classList.remove('focus')
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
open(e, actions, parent) {
|
||||
|
||||
var menu = html`<div class="context-menu"></div>`
|
||||
parse(actions, node) {
|
||||
|
||||
for (let action of actions) {
|
||||
|
||||
if (action.separator) {
|
||||
|
||||
menu.appendChild(html`<div class="separator"></div>`)
|
||||
node.appendChild(html`<div class="separator"></div>`)
|
||||
|
||||
} else if (Array.isArray(action.action)) {
|
||||
|
||||
let label = typeof action.label === 'function' ? action.label() : action.label,
|
||||
let submenu = html`<div class="context-menu"></div>`,
|
||||
label = typeof action.label === 'function' ? action.label() : action.label,
|
||||
iclass = typeof action.class === 'function' ? action .class() : action.class,
|
||||
item = html`<div class="item has-sub ${iclass}" tabIndex="1">${raw(label)}</div>`
|
||||
item = html`<div class="item has-sub ${iclass || ''}" tabIndex="1">${raw(label)}</div>`
|
||||
|
||||
menu.appendChild(item)
|
||||
item.appendChild(submenu)
|
||||
node.appendChild(item)
|
||||
|
||||
this.open(e, action.action, item)
|
||||
this.parse(action.action, submenu)
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
let label = typeof action.label === 'function' ? action.label() : action.label,
|
||||
iclass = typeof action.class === 'function' ? action.class() : action.class,
|
||||
item = html`<div class="item ${iclass}">${raw(label)}</div>`
|
||||
item = html`<div class="item ${iclass || ''}">${raw(label)}</div>`
|
||||
|
||||
menu.appendChild(item)
|
||||
item._action = action.action
|
||||
node.appendChild(item)
|
||||
|
||||
// if (action.click) {
|
||||
if (action.shortcut) {
|
||||
|
||||
item.addEventListener('click', (e)=>{
|
||||
e.preventDefault()
|
||||
action.action()
|
||||
this.close()
|
||||
})
|
||||
item.appendChild(html`<div class="shortcut">${action.shortcut.replace('mod', mod)}</div>`)
|
||||
|
||||
// } else {
|
||||
//
|
||||
// item.addEventListener('fast-click', (e)=>{
|
||||
// e.detail.preventOriginalEvent = true
|
||||
// action.action()
|
||||
// this.close()
|
||||
// })
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (parent) parent.appendChild(menu)
|
||||
}
|
||||
|
||||
if (!parent) {
|
||||
open(e, actions, parent) {
|
||||
|
||||
this.container = menu
|
||||
this.container.innerHTML = ''
|
||||
this.parse(actions, this.container)
|
||||
|
||||
MENU_CONTAINER.appendChild(menu)
|
||||
|
||||
DOM.each(menu, '.item', (item)=>{
|
||||
item.addEventListener('mouseenter', ()=>{
|
||||
DOM.each(item.parentNode, '.focus', (focused)=>{
|
||||
focused.classList.remove('focus')
|
||||
})
|
||||
item.classList.add('focus')
|
||||
})
|
||||
item.addEventListener('mouseleave', ()=>{
|
||||
if (!item.classList.contains('has-sub')) item.classList.remove('focus')
|
||||
})
|
||||
})
|
||||
|
||||
menu.style.top = e.pageY / PXSCALE + 'rem'
|
||||
menu.style.left = e.pageX / PXSCALE + 'rem'
|
||||
|
||||
this.correctPosition(menu)
|
||||
|
||||
DOM.each(menu, '.context-menu', (m)=>{
|
||||
this.correctPosition(m, m.parentNode)
|
||||
})
|
||||
MENU_CONTAINER.appendChild(this.container)
|
||||
|
||||
if (!this.position) {
|
||||
this.container.style.top = e.pageY / PXSCALE + 'rem'
|
||||
this.container.style.left = e.pageX / PXSCALE + 'rem'
|
||||
}
|
||||
|
||||
|
||||
this.correctPosition(this.container)
|
||||
|
||||
DOM.each(this.container, '.context-menu', (m)=>{
|
||||
this.correctPosition(m, m.parentNode)
|
||||
})
|
||||
|
||||
document.addEventListener('fast-click', this.clickHandler, true)
|
||||
document.addEventListener('fast-right-click', this.clickHandler, true)
|
||||
|
||||
|
|
@ -113,13 +139,14 @@ class ContextMenu extends UiWidget {
|
|||
if (this.container) {
|
||||
|
||||
this.container.parentNode.removeChild(this.container)
|
||||
this.container = null
|
||||
|
||||
}
|
||||
|
||||
document.removeEventListener('fast-click', this.clickHandler, true)
|
||||
document.removeEventListener('fast-right-click', this.clickHandler, true)
|
||||
|
||||
this.hoverNode = null
|
||||
|
||||
this.trigger('close')
|
||||
|
||||
}
|
||||
|
|
@ -136,7 +163,7 @@ class ContextMenu extends UiWidget {
|
|||
if (position.left - width > 0) {
|
||||
menu.style.right = parent ? '100%' : '0'
|
||||
menu.style.left = 'auto'
|
||||
menu.style.marginRight = '1rem'
|
||||
menu.style.marginRight = '-0.5rem'
|
||||
} else {
|
||||
menu.style.left = (parent.offsetWidth + (totalWidth - width - position.left)) / PXSCALE + 'rem'
|
||||
}
|
||||
|
|
@ -149,6 +176,27 @@ class ContextMenu extends UiWidget {
|
|||
|
||||
}
|
||||
|
||||
bindShortcuts(actions) {
|
||||
|
||||
for (let action of actions) {
|
||||
|
||||
if (Array.isArray(action.action)) {
|
||||
|
||||
this.bindShortcuts(action.action)
|
||||
|
||||
} else if (action.shortcut && action.action) {
|
||||
|
||||
keyboardJS.bind(action.shortcut, (e)=>{
|
||||
e.preventDefault()
|
||||
action.action()
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = ContextMenu
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ class UiSidePanel extends UiWidget {
|
|||
disable() {
|
||||
|
||||
this.container.classList.add('disabled')
|
||||
this.disabled = false
|
||||
this.disabled = true
|
||||
|
||||
this.close()
|
||||
|
||||
|
|
@ -70,7 +70,8 @@ class UiSidePanel extends UiWidget {
|
|||
if (this.minimized) return
|
||||
|
||||
this.minimized = true
|
||||
this.close()
|
||||
|
||||
if (!this.disabled) this.close()
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -80,7 +81,8 @@ class UiSidePanel extends UiWidget {
|
|||
if (!this.minimized) return
|
||||
|
||||
this.minimized = false
|
||||
this.open()
|
||||
|
||||
if (!this.disabled) this.open()
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ var UiWidget = require('./ui-widget'),
|
|||
stateManager = require('../managers/state'),
|
||||
uiSidePanel = require('./ui-sidepanel')
|
||||
|
||||
|
||||
var recentSessions = []
|
||||
var menuEntries = [
|
||||
|
||||
|
|
@ -28,7 +29,8 @@ var menuEntries = [
|
|||
},
|
||||
{
|
||||
label: locales('file_open'),
|
||||
action: sessionManager.browse.bind(sessionManager)
|
||||
action: sessionManager.browse.bind(sessionManager),
|
||||
shortcut: 'mod + o'
|
||||
},
|
||||
{
|
||||
label: locales('file_open_recent'),
|
||||
|
|
@ -39,11 +41,13 @@ var menuEntries = [
|
|||
},
|
||||
{
|
||||
label: locales('file_save'),
|
||||
action: sessionManager.save.bind(sessionManager)
|
||||
action: sessionManager.save.bind(sessionManager),
|
||||
shortcut: 'mod + s'
|
||||
},
|
||||
{
|
||||
label: locales('file_save_as'),
|
||||
action: sessionManager.saveAs.bind(sessionManager)
|
||||
action: sessionManager.saveAs.bind(sessionManager),
|
||||
shortcut: 'mod + shift + s'
|
||||
},
|
||||
{
|
||||
separator: true
|
||||
|
|
@ -120,7 +124,8 @@ var menuEntries = [
|
|||
action: ()=>{
|
||||
if (editor.enabled) editor.disable()
|
||||
else editor.enable()
|
||||
}
|
||||
},
|
||||
shortcut: 'mod + e'
|
||||
},
|
||||
{
|
||||
separator: true
|
||||
|
|
@ -128,13 +133,15 @@ var menuEntries = [
|
|||
{
|
||||
label: locales('editor_grid'),
|
||||
class: ()=>{return 'toggle ' + (editor.grid ? 'on' : 'off')},
|
||||
action: editor.toggleGrid.bind(editor)
|
||||
action: editor.toggleGrid.bind(editor),
|
||||
// shortcut: 'mod + g'
|
||||
|
||||
},
|
||||
{
|
||||
label: locales('editor_tree'),
|
||||
class: ()=>{return 'toggle ' + (uiSidePanel.left.minimized ? 'off' : 'on')},
|
||||
action: ()=>{return uiSidePanel.left.minimized ? uiSidePanel.left.restore() : uiSidePanel.left.minimize()},
|
||||
// shortcut: 'mod + t'
|
||||
|
||||
|
||||
},
|
||||
|
|
@ -142,6 +149,7 @@ var menuEntries = [
|
|||
label: locales('editor_inspector'),
|
||||
class: ()=>{return 'toggle ' + (uiSidePanel.right.minimized ? 'off' : 'on')},
|
||||
action: ()=>{return uiSidePanel.right.minimized ? uiSidePanel.right.restore() : uiSidePanel.right.minimize()},
|
||||
// shortcut: 'mod + i'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
@ -153,7 +161,8 @@ var menuEntries = [
|
|||
class: ()=>{return 'toggle ' + (fullscreen.isFullscreen ? 'on' : 'off')},
|
||||
action: ()=>{
|
||||
if (fullscreen.isEnabled) fullscreen.toggle()
|
||||
}
|
||||
},
|
||||
shortcut: 'f11'
|
||||
},
|
||||
|
||||
]
|
||||
|
|
@ -180,16 +189,17 @@ if (navigator.userAgent.match(/Android|iPhone|iPad|iPod/i)) {
|
|||
|
||||
|
||||
|
||||
|
||||
class UiToolbar extends UiWidget {
|
||||
|
||||
constructor(options) {
|
||||
|
||||
super(options)
|
||||
|
||||
this.menu = new ContextMenu()
|
||||
this.menu = new ContextMenu({
|
||||
position: [39, 1]
|
||||
})
|
||||
this.opened = false
|
||||
|
||||
this.menu.bindShortcuts(menuEntries)
|
||||
|
||||
ipc.on('sessionList', (data)=>{
|
||||
if (recentSessions.length) {
|
||||
|
|
@ -221,11 +231,7 @@ class UiToolbar extends UiWidget {
|
|||
|
||||
if (this.opened) return
|
||||
|
||||
this.menu.open({
|
||||
target: e.detail.target,
|
||||
pageX: e.detail.pageX - e.detail.offsetX + PXSCALE,
|
||||
pageY: e.detail.pageY - e.detail.offsetY + e.detail.target.offsetHeight + 5 * PXSCALE
|
||||
}, menuEntries)
|
||||
this.menu.open(e, menuEntries)
|
||||
|
||||
this.opened = true
|
||||
this.toggleState()
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ $line-height: 30rem;
|
|||
position:fixed;
|
||||
z-index: 999999999;
|
||||
background: var(--color-context-menu);
|
||||
box-shadow: 0 0 0 1rem rgba(0, 0, 0, 0.1) inset;
|
||||
box-shadow: 0 0 0 0.5rem rgba(0, 0, 0, 0.15) inset;
|
||||
text-transform: none;
|
||||
color: var(--color-context-menu-text);
|
||||
line-height: $line-height;
|
||||
|
|
@ -19,7 +19,7 @@ $line-height: 30rem;
|
|||
top:0;
|
||||
opacity:0;
|
||||
pointer-events: none;
|
||||
margin-left: 1rem;
|
||||
margin-left: -0.5rem;
|
||||
&:before {
|
||||
content:"";
|
||||
position: absolute;
|
||||
|
|
@ -34,6 +34,8 @@ $line-height: 30rem;
|
|||
padding-right: 30rem;
|
||||
position:relative;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
i {
|
||||
position: absolute;
|
||||
left: 10rem;
|
||||
|
|
@ -42,7 +44,7 @@ $line-height: 30rem;
|
|||
line-height: $line-height - 2;
|
||||
font-size: 90%;
|
||||
}
|
||||
&.focus, &:focus {
|
||||
&.focus {
|
||||
> .context-menu {
|
||||
pointer-events: auto;
|
||||
opacity: 1;
|
||||
|
|
@ -54,11 +56,12 @@ $line-height: 30rem;
|
|||
content:"\f105";
|
||||
display: block;
|
||||
font-family: FontAwesome;
|
||||
float:right;
|
||||
margin-right:-25rem;
|
||||
width: 15rem;
|
||||
text-align: center;
|
||||
text-align: right;
|
||||
margin-right: -20rem;
|
||||
position: relative;
|
||||
flex: 1;
|
||||
order: 1;
|
||||
margin-left: 10rem;
|
||||
}
|
||||
&.disabled {
|
||||
pointer-events: none;
|
||||
|
|
@ -82,6 +85,17 @@ $line-height: 30rem;
|
|||
&.toggle.on:before {
|
||||
content:"\f00c";
|
||||
}
|
||||
.shortcut {
|
||||
display: inline-block;
|
||||
margin-left: 20rem;
|
||||
margin-right: -20rem;
|
||||
position: relative;
|
||||
text-align: right;
|
||||
position: relative;
|
||||
flex: 1;
|
||||
text-transform: capitalize;
|
||||
opacity: 0.5;
|
||||
}
|
||||
}
|
||||
.separator{
|
||||
margin: 2rem 1rem;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue