mirror of
https://github.com/JannisX11/blockbench.git
synced 2025-03-19 17:01:55 +08:00
Allow mouse wheel as keybinding
Remove reload from file menu Confirm dialog for resetting keybindings
This commit is contained in:
parent
ffa476145b
commit
1b0f67f11c
@ -400,6 +400,7 @@ class NumSlider extends Widget {
|
||||
}
|
||||
if (this.keybind) {
|
||||
this.keybind.shift = null;
|
||||
this.keybind.label = this.keybind.getText();
|
||||
}
|
||||
var scope = this;
|
||||
var css_color = 'xyz'.includes(this.color) ? `var(--color-axis-${this.color})` : this.color;
|
||||
@ -585,15 +586,17 @@ class NumSlider extends Widget {
|
||||
}
|
||||
}
|
||||
trigger(event) {
|
||||
if (!Condition(this.condition)) return false;
|
||||
if (typeof this.onBefore === 'function') {
|
||||
this.onBefore()
|
||||
}
|
||||
var difference = this.getInterval(false) * event.shiftKey ? -1 : 1;
|
||||
var difference = this.getInterval(false) * (event.shiftKey != event.deltaY > 0) ? -1 : 1;
|
||||
this.change(n => n + difference)
|
||||
this.update()
|
||||
if (typeof this.onAfter === 'function') {
|
||||
this.onAfter(difference)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
setValue(value, trim) {
|
||||
if (typeof value === 'string') {
|
||||
@ -860,8 +863,9 @@ class BarText extends Widget {
|
||||
return this;
|
||||
}
|
||||
trigger(event) {
|
||||
if (!Condition(this.condition)) return false;
|
||||
Blockbench.showQuickMessage(this.text)
|
||||
return this;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
class ColorPicker extends Widget {
|
||||
@ -1898,6 +1902,8 @@ const Keybinds = {
|
||||
localStorage.setItem('keybindings', JSON.stringify(Keybinds.stored))
|
||||
},
|
||||
reset() {
|
||||
let answer = confirm(tl('message.reset_keybindings'));
|
||||
if (!answer) return;
|
||||
for (var category in Keybinds.structure) {
|
||||
var entries = Keybinds.structure[category].actions
|
||||
if (entries && entries.length) {
|
||||
|
@ -86,6 +86,7 @@ class Keybind {
|
||||
return this;
|
||||
}
|
||||
getText() {
|
||||
if (this.key < 0) return '';
|
||||
var modifiers = []
|
||||
|
||||
if (this.ctrl) modifiers.push(tl('keys.ctrl'))
|
||||
@ -147,6 +148,7 @@ class Keybind {
|
||||
case 36: return 'pos1'; break;
|
||||
case 44: return 'printscreen'; break;
|
||||
case 19: return 'pause'; break;
|
||||
case 1001: return 'mousewheel'; break;
|
||||
default : return String.fromCharCode(key).toLowerCase(); break;
|
||||
}
|
||||
}
|
||||
@ -168,7 +170,7 @@ class Keybind {
|
||||
}
|
||||
isTriggered(event) {
|
||||
return (
|
||||
this.key === event.which &&
|
||||
(this.key === event.which || (this.key == 1001 && event instanceof MouseEvent)) &&
|
||||
(this.ctrl === event.ctrlKey || this.ctrl == null ) &&
|
||||
(this.shift === event.shiftKey || this.shift == null ) &&
|
||||
(this.alt === event.altKey || this.alt == null ) &&
|
||||
@ -184,10 +186,15 @@ class Keybind {
|
||||
overlay.find('> div').css('margin-top', top+'px')
|
||||
|
||||
function onActivate(event) {
|
||||
event = event.originalEvent;
|
||||
|
||||
if (event.target && event.target.tagName === 'BUTTON') return;
|
||||
|
||||
scope.key = event.which
|
||||
if (event instanceof WheelEvent) {
|
||||
scope.key = 1001
|
||||
} else {
|
||||
scope.key = event.which
|
||||
}
|
||||
if (scope.ctrl !== null) scope.ctrl = event.ctrlKey
|
||||
if (scope.shift !== null) scope.shift = event.shiftKey
|
||||
if (scope.alt !== null) scope.alt = event.altKey
|
||||
@ -206,8 +213,9 @@ class Keybind {
|
||||
}
|
||||
})
|
||||
overlay.on('mousedown', onActivate)
|
||||
overlay.on('mousewheel', onActivate)
|
||||
|
||||
overlay.on('keydown keypress keyup click click dblclick mouseup', function(event) {
|
||||
overlay.on('keydown keypress keyup click click dblclick mouseup mousewheel', function(event) {
|
||||
event.preventDefault()
|
||||
})
|
||||
return this;
|
||||
@ -215,7 +223,7 @@ class Keybind {
|
||||
stopRecording() {
|
||||
var scope = this;
|
||||
Keybinds.recording = false
|
||||
$('#overlay_message_box').hide().off('mousedown')
|
||||
$('#overlay_message_box').hide().off('mousedown mousewheel')
|
||||
$('#keybind_input_box').off('keyup keydown')
|
||||
return this;
|
||||
}
|
||||
@ -369,6 +377,10 @@ window.addEventListener('focus', event => {
|
||||
setTimeout(remove_func, 100);
|
||||
})
|
||||
|
||||
function getInputFocusElement() {
|
||||
return $('input[type="text"]:focus, input[type="number"]:focus, *[contenteditable="true"]:focus, textarea:focus').get(0)
|
||||
}
|
||||
|
||||
$(document).on('keydown mousedown', function(e) {
|
||||
if (Keybinds.recording || e.which < 4) return;
|
||||
//Shift
|
||||
@ -380,7 +392,7 @@ $(document).on('keydown mousedown', function(e) {
|
||||
}
|
||||
|
||||
var used = false;
|
||||
var input_focus = $('input[type="text"]:focus, input[type="number"]:focus, *[contenteditable="true"]:focus, textarea:focus').get(0)
|
||||
var input_focus = getInputFocusElement()
|
||||
|
||||
if (input_focus) {
|
||||
//User Editing Anything
|
||||
@ -493,6 +505,26 @@ $(document).on('keydown mousedown', function(e) {
|
||||
e.preventDefault()
|
||||
}
|
||||
})
|
||||
document.addEventListener('wheel', (e) => {
|
||||
if (getInputFocusElement()) return;
|
||||
let used = false;
|
||||
Keybinds.actions.forEach(function(action) {
|
||||
if (
|
||||
action.keybind &&
|
||||
(!open_dialog || action.work_in_dialog) &&
|
||||
typeof action.trigger === 'function' &&
|
||||
action.keybind.isTriggered(e)
|
||||
) {
|
||||
if (action.trigger(e)) {
|
||||
used = true
|
||||
}
|
||||
}
|
||||
})
|
||||
if (used) {
|
||||
e.stopPropagation()
|
||||
}
|
||||
|
||||
}, true)
|
||||
|
||||
$(document).keyup(function(e) {
|
||||
if (Pressing.alt && ActionControl.open) {
|
||||
|
@ -488,8 +488,7 @@ const MenuBar = {
|
||||
'_',
|
||||
'settings_window',
|
||||
'plugins_window',
|
||||
'edit_session',
|
||||
'reload'
|
||||
'edit_session'
|
||||
])
|
||||
new BarMenu('edit', [
|
||||
'undo',
|
||||
|
@ -108,6 +108,7 @@
|
||||
"keys.pos1": "Pos 1",
|
||||
"keys.printscreen": "Print Screen",
|
||||
"keys.pause": "Pause",
|
||||
"keys.mousewheel": "Mousewheel",
|
||||
|
||||
"status_bar.saved":"Model is saved",
|
||||
"status_bar.recording":"Recording Timelapse",
|
||||
@ -209,6 +210,7 @@
|
||||
"message.removed_faces": "Removed %0 faces",
|
||||
"message.add_to_palette": "Added to palette",
|
||||
"message.size_modifiers": "Hold down Ctrl or Shift to transform in smaller increments.",
|
||||
"message.reset_keybindings": "Are you sure you want to reset all keybindings?",
|
||||
|
||||
"message.wireframe.enabled": "Wireframe view enabled",
|
||||
"message.wireframe.disabled": "Wireframe view disabled",
|
||||
|
Loading…
x
Reference in New Issue
Block a user