Browse Source

Add a module to handle keyboard shortcuts and add zooming shortcuts

main
Tissevert 7 months ago
parent
commit
fe30409baf
4 changed files with 25 additions and 25 deletions
  1. +2
    -0
      js/Main.js
  2. +2
    -5
      js/Toolbar/Menu.js
  3. +3
    -6
      js/Toolbar/Page.js
  4. +18
    -14
      js/View.js

+ 2
- 0
js/Main.js View File

@ -1,3 +1,4 @@
import * as Keys from GUI.Keys;
import * as EditMode from Toolbar.EditMode;
import * as Menu from Toolbar.Menu;
import * as Page from Toolbar.Page;
@ -5,3 +6,4 @@ import * as Page from Toolbar.Page;
EditMode.sync();
Page.syncNumber();
Menu.init();
Keys.init();

+ 2
- 5
js/Toolbar/Menu.js View File

@ -1,12 +1,9 @@
import {menus, windowCatchAll} from GUI;
import * as Keys from GUI.Keys;
var selectedMenu = null;
window.addEventListener('keydown', function(e) {
switch(e.keyCode) {
case 0x1b: closeMenu(); break;
}
});
Keys.bind('Escape', closeMenu);
windowCatchAll.addEventListener('click', closeMenu);
return {


+ 3
- 6
js/Toolbar/Page.js View File

@ -1,5 +1,6 @@
import File;
import * as GUI from GUI;
import * as Keys from GUI.Keys;
import * as Async from UnitJS.Async;
import XML;
import * as ALTO from XML.ALTO;
@ -40,12 +41,8 @@ GUI.saveALTO.addEventListener('click', function() {
});
GUI.fileNumber.addEventListener('change', updateNumber);
window.addEventListener('keydown', function(e) {
switch(e.keyCode) {
case 0x25: moveFile(-1); break;
case 0x27: moveFile(+1); break;
}
});
Keys.bind('ArrowLeft', function() {moveFile(-1)});
Keys.bind('ArrowRight', function() {moveFile(+1)});
return {
syncNumber: syncNumber


+ 18
- 14
js/View.js View File

@ -1,5 +1,6 @@
import File;
import GUI;
import * as Keys from GUI.Keys;
import Scoria;
import * as Zoom from Toolbar.Zoom;
import * as Async from UnitJS.Async;
@ -11,20 +12,13 @@ GUI.wcThreshold.addEventListener('change', refresh);
GUI.loadScoria.addEventListener('click', importScoria);
GUI.saveScoria.addEventListener('click', exportScoria);
GUI.fitWidth.addEventListener('click', function() {
Zoom.setScalingMode({fitWidth: true});
refresh();
});
GUI.zoomAmount.addEventListener('change', function() {
Zoom.setScalingMode({zoom: GUI.zoomAmount.value});
refresh();
});
GUI.fitHeight.addEventListener('click', function() {
Zoom.setScalingMode({fitHeight: true});
refresh();
});
GUI.fitWidth.addEventListener('click', scale({fitWidth: true}));
GUI.zoomAmount.addEventListener('change', scale({zoom: GUI.zoomAmount.value}));
GUI.fitHeight.addEventListener('click', scale({fitHeight: true}));
Keys.bind('w', scale({fitWidth: true}));
Keys.bind('h', scale({fitHeight: true}));
Keys.bind('+', scale(function(x) {return Math.min(GUI.zoomAmount.max, x + 10);}));
Keys.bind('-', scale(function(x) {return Math.max(GUI.zoomAmount.min, x - 10);}));
return {
open: open
@ -49,6 +43,16 @@ function refresh() {
}
}
function scale(o) {
return function() {
if(typeof o == 'function') {
o.zoom = GUI.zoomAmount.value = o(1*GUI.zoomAmount.value);
}
Zoom.setScalingMode(o);
refresh();
}
}
function importScoria() {
Async.run(
Async.bind(


Loading…
Cancel
Save