Commit e157d8c6 authored by Hubert Denkmair's avatar Hubert Denkmair
Browse files

implement shortcuts

parent 1ff71b87
......@@ -7,6 +7,7 @@ $(function() {
setupEditor();
setupPreview();
setupToolbar();
setupShortcuts();
$.ajaxSetup({
beforeSend: function(xhr, settings) {
......@@ -92,6 +93,33 @@ function setupToolbar()
}
function setupShortcuts()
{
$(window).bind('keydown', function(event) {
if (!(event.ctrlKey || event.metaKey)) {
return;
}
switch (String.fromCharCode(event.which).toLowerCase()) {
case 's':
if (event.shiftKey) {
$('#bt_save_as').click();
} else {
$('#bt_save').click();
}
event.preventDefault();
break;
case 'o':
$('#bt_load').click();
event.preventDefault();
break;
case 'r':
$('#bt_run').click();
event.preventDefault();
break;
}
});
}
function showModal(el, ok_func)
{
let dialog = $(el);
......@@ -134,6 +162,7 @@ function save(action, title)
snake_id = data.snake_id;
snake_title = data.comment;
game.vis.FollowDbId(snake_id);
addLogLine(null, 'saved code as version #' + data.version + " title \"" + data.comment + "\"");
});
}
......@@ -178,7 +207,9 @@ function addLogLine(frame, msg)
let div = document.createElement('div');
let frameDiv = document.createElement('div');
frameDiv.appendChild(document.createTextNode("Frame " + frame + ":"));
if (frame) {
frameDiv.appendChild(document.createTextNode("Frame " + frame + ":"));
}
div.appendChild(frameDiv);
let msgDiv = document.createElement('pre');
msgDiv.appendChild(document.createTextNode(msg));
......
......@@ -18,12 +18,12 @@
<div id="log"></div>
<div id="tools">
<div id="toolbar">
<button id="bt_run">run</button>
<button id="bt_run" title="Ctrl+R">run</button>
<button id="bt_restart">restart</button>
<button id="bt_stop">stop</button>
<button id="bt_save">save</button>
<button id="bt_save_as">save as</button>
<button id="bt_load">load</button>
<button id="bt_save" title="Ctrl+S">save</button>
<button id="bt_save_as" title="Ctrl+Shift+S">save as</button>
<button id="bt_load" title="Ctrl+O">load</button>
<button>preferences</button>
</div>
</div>
......
......@@ -87,7 +87,7 @@ def snake_save(request):
snake.activate()
send_kill_command(snake.user)
return JsonResponse({'success': True, 'snake_id': snake.id, 'comment': snake.comment})
return JsonResponse({'success': True, 'snake_id': snake.id, 'version': snake.version, 'comment': snake.comment})
def send_kill_command(user):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment