editor: show keyboard shortcuts in context menu; add shortcuts to change widget order; add shortcut to show widget in project tree

This commit is contained in:
bordun 2020-09-30 13:30:06 +02:00
parent 7d59d5cbd5
commit 75251613fb
6 changed files with 119 additions and 9 deletions

View file

@ -63,7 +63,8 @@ var handleClick = function(event) {
label: icon('project-diagram') + ' ' + locales('editor_show_in_tree'),
action: ()=>{
editor.widgetTree.showWidget(editor.selectedWidgets[0])
}
},
shortcut: 't'
})
actions.push({
separator: true
@ -71,14 +72,55 @@ var handleClick = function(event) {
}
if (editor.selectedWidgets[0].parent.children.length > 1) {
actions.push({
label: icon('layer-group') + ' Position',
action: [
{
label: locales('editor_back'),
action: ()=>{
editor.handleKeyboard('home')
},
shortcut: 'Home'
},
{
label: locales('editor_farther'),
action: ()=>{
editor.handleKeyboard('pageup')
},
shortcut: 'Page Up'
},
{
label: locales('editor_closer'),
action: ()=>{
editor.handleKeyboard('pagedown')
},
shortcut: 'Page Down'
},
{
label: locales('editor_front'),
action: ()=>{
editor.handleKeyboard('end')
},
shortcut: 'End'
}
]
})
actions.push({
separator: true
})
}
actions.push({
label: icon('copy') + ' ' + locales('editor_copy'),
action: editor.copyWidget.bind(editor)
action: editor.copyWidget.bind(editor),
shortcut: 'mod + c'
})
actions.push({
label: icon('cut') + ' ' + locales('editor_cut'),
action: editor.cutWidget.bind(editor)
action: editor.cutWidget.bind(editor),
shortcut: 'mod + x'
})
}
@ -101,13 +143,16 @@ var handleClick = function(event) {
label: icon('paste') + ' ' + locales('editor_paste'),
action: ()=>{
editor.pasteWidget(clickX, clickY)
}
},
shortcut: 'mod + v'
})
pasteActions.push({
label: icon('plus-square') + ' ' + locales('editor_pasteindent'),
action: ()=>{
editor.pasteWidget(clickX, clickY, true)
}
},
shortcut: 'mod + shift + v'
})
if (editor.idClipboard && widgetManager.getWidgetById(editor.idClipboard).length && editor.clipboard[0].type !== 'tab') {
@ -219,7 +264,8 @@ var handleClick = function(event) {
actions.push({
label: icon('trash') + ' ' + locales('editor_delete'),
action: editor.deleteWidget.bind(editor)
action: editor.deleteWidget.bind(editor),
shortcut: 'delete'
})
}

View file

@ -170,7 +170,11 @@ class Editor {
'mod + down',
'mod + left',
'mod + right',
'f2'
'pageup',
'pagedown',
'home',
'end',
't'
]
for (let c of combos) {
@ -196,9 +200,9 @@ class Editor {
handleKeyboard(combo, e){
if (this.inspector.helpModalOpened || e.target && (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA' || e.target.tagName === 'SELECT')) return
if (this.inspector.helpModalOpened || e && e.target && (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA' || e.target.tagName === 'SELECT')) return
e.preventDefault()
if (e) e.preventDefault()
switch (combo) {
@ -339,6 +343,37 @@ class Editor {
break
case 'pagedown':
case 'pageup':
case 'home':
case 'end':
if (!this.selectedWidgets.length || this.selectedWidgets[0].parent.children.length <= 1) return
var curWidget = this.selectedWidgets[0],
index = curWidget.parent.children.indexOf(curWidget),
maxIndex = curWidget.parent.children.length - 1,
newIndex
if (combo === 'pagedown') newIndex = Math.min(index + 1, maxIndex)
else if (combo === 'pageup') newIndex = Math.max(index - 1, 0)
else if (combo === 'end') newIndex = maxIndex
else if (combo === 'home') newIndex = 0
if (index !== newIndex) {
this.widgetTree.trigger('sorted', {
widget: curWidget.parent,
oldIndex: index,
newIndex: newIndex
})
}
break
case 't':
if (!this.selectedWidgets.length) return
this.widgetTree.showWidget(editor.selectedWidgets[0])
break
}

View file

@ -10,6 +10,10 @@ module.exports = {
// editor context-menu
editor_show_in_tree: 'Show in tree',
editor_front: 'Bring to front',
editor_closer: 'Bring closer',
editor_back: 'Send to back',
editor_farther: 'Send farther',
editor_copy: 'Copy',
editor_cut: 'Cut',
editor_paste: 'Paste',

View file

@ -10,6 +10,10 @@ module.exports = {
// editor context-menu
editor_show_in_tree: 'Voir dans l\'arborescence',
editor_front: 'Amener devant',
editor_closer: 'Amener plus près',
editor_back: 'Envoyer à l\'arrière',
editor_farther: 'Envoyer plus loin',
editor_copy: 'Copier',
editor_cut: 'Couper',
editor_paste: 'Coller',