Gitlab CSE Unil

Commit 2c2eb513 authored by Julien Furrer's avatar Julien Furrer
Browse files

Optimisé support raccourcis clavier

Les reccourcis clavier sont configurable par environement, et par contexte dans un environnement.
Il y a deux contextes globaux (pour tous les environement) 'edt' et 'rewiew'. Chaque environement peut en défénir d'autre.
parent f3486238
......@@ -24,8 +24,16 @@ module.exports = function(grunt) {
}]
},
libs: {
options: {
preserveComments: "some"
},
files: [{
src: "lib/requirejs/require.js",
dest: "../js/libs/require.min.js"
},{
src: "lib/jquery.hotkeys/jquery.hotkeys.js",
dest: "lib/jquery.hotkeys/jquery.hotkeys.min.js"
}]
}
},
......
......@@ -31,9 +31,12 @@ requirejs([
"adim/io",
"adim/view",
"env/ui-analyse"
"helper/utils",
"env/ui-analyse",
"env/env"
],
function ($, paper, Signal, config, io, view, ui) {
function ($, paper, Signal, config, io, view, utils, ui, environ) {
// ----- Ajax init ------------------------------------
$.ajaxSetup({
......@@ -341,6 +344,8 @@ function ($, paper, Signal, config, io, view, ui) {
ui.events.graphParamChanged.add(updateGraph);
utils.initShortcuts(environ.shortcuts);
// ----- DOM ready ------------------------------------
$(function(){
if (!view.init("my-canvas")) {
......@@ -350,6 +355,9 @@ function ($, paper, Signal, config, io, view, ui) {
ui.init();
io.loadData(config.api.annotables + config.annotable.id + '/');
utils.setShortcutsContext(config.mode);
});
// ----- Global Scopevar ------------------------------
......
......@@ -13,9 +13,10 @@ define([
"adim/attributes",
"adim/io",
"adim/tools",
"adim/ui"
"adim/ui",
"env/shortcuts"
],
function($, _, paper, Signal, config, view, attributes, io, tools, ui){
function($, _, paper, Signal, config, view, attributes, io, tools, ui, shortcuts){
/**
* Signal binding specific to CIMAF environment
......@@ -131,6 +132,7 @@ define([
return {
name: 'cimaf',
shortcuts: shortcuts,
initSignalRouting: _initSignalRouting,
initUI: _initUI
}
......
/**
* Copyright (C) 2014 Université de Lausanne, RISET,
* < http://www.unil.ch/riset/ >
* This file is part of AdIm.
* AdIm is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* AdIm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* This copyright notice MUST APPEAR in all copies of the file.
*
* @AUTHOR: Julien Furrer <Julien.Furrer@unil.ch>
* @CREATION-DATE: 29.06.15
*
*/
define([
"jquery",
"paper",
"signals",
// ----- app
"adim/config",
"adim/view",
"adim/tools",
"adim/ui",
// plugins
"jquery.hotkeys"
],
function ($, paper, Signal, config, view, tools, ui) {
// Two contexts corresponding to the view modes: 'edit' 'review' 'analysis'
var _keyblock = function(){ return function(){return false} };
var activeTool;
var SHORTCUTS = {
// DELETE -> [edit]:delete selected annot. [review]:prevent default
'backspace del': [{
event: "keydown",
ctxt: "edit",
fn: function(){
view.removeSelectedItems();
return false;
}
}, {
event: "keydown",
ctxt: "review",
fn: _keyblock()
}],
// SPACEBAR -> [*]:activate pan tool while pressed, in all context
'space': [{
event: "keydown",
ctxt: "edit review",
fn: function(){
if (!activeTool) {
activeTool = tools.getActiveTool();
tools.activateTool('pan');
}
return false;
}
}, {
event: "keyup",
ctxt: "edit review",
fn: function(){
if (activeTool) {
tools.activateTool(activeTool);
activeTool = null;
}
return false;
}
}],
'1 2 3': {
ctxt: 'edit',
fn : function(event) {
if (paper.project.selectedItems.length > 0)
$("#confidence-input").val([event.key]).change()
.siblings("[data-value]").trigger('mouseleave');
return false;
}
},
// A -> [edit]:activate select tool
'a': [{
event: "keydown",
ctxt: "edit",
fn: function(){
tools.activateTool('select');
return false;
}
}],
// CTRL-A -> [edit]:select all annotations in edit mode. [review]:prevent default
'ctrl+a meta+a': [{
event: "keydown",
ctxt: "edit",
fn: function(){
paper.project.activeLayer.children.map(function(c){c.selected = true;});
return false;
}
}, {
event: "keydown",
ctxt: "review",
fn: _keyblock()
}],
// C -> [edit]:activate concordant tool [analysis]:show/hide concordant striae
'c': [{
event: "keydown",
ctxt: "edit",
fn: function () {
if ($("#tool-concordantstr").is(":disabled"))
return false;
tools.activateTool('concordantstr');
return false;
}
},{
event: "keydown",
ctxt: "analysis",
fn: function(){
var c = $("#checkShowConcordance");
c.val([c.is(":checked")?'off':'on']).change();
return false;
}
}],
// D -> [edit]:activate discordant tool [analysis]:show/hide discordant striae
'd': [{
event: "keydown",
ctxt: "edit",
fn: function(){
if ($("#tool-discordantstr").is(":disabled"))
return false;
tools.activateTool('discordantstr');
return false;
}
},{
event: "keydown",
ctxt: "analysis",
fn: function(){
var c = $("#checkShowDiscordance");
c.val([c.is(":checked")?'off':'on']).change();
return false;
}
}],
// SHIFT-D, SHIFT-C -> [edit,review]:show hide striae
'shift+d shift+c': {
ctxt: "edit review",
fn: function(){
$("#annotation-display-container").find("[data-type-name='concordantstr,discordantstr']").click();
}
},
// E,B -> [edit]:activate field edges tool
'e b': [{
event: "keydown",
ctxt: "edit",
fn: function(){
if ($("#tool-fieldedges").is(":disabled"))
return false;
tools.activateTool('fieldedges');
return false;
}
}],
// SHIFT-E -> [edit,review]:show hide field edges
'shift+e': {
ctxt: "edit review",
fn: function(){
$("#annotation-display-container").find("[data-type-name='fieldedges']").click();
}
},
// F -> [edit]:activate arrow tool
'f': [{
event: "keydown",
ctxt: "edit",
fn: function(){
tools.activateTool('arrow');
return false;
}
}],
// SHIFT-I -> [edit,review]:show/hide image
'shift+i': {
ctxt: "edit review",
fn: function(){
$("#annotation-display-container").find("[data-type-name='image']").click();
}
},
// N -> [analysis]:show/hide confidence levels
'n': [{
event: "keydown",
ctxt: "analysis",
fn: function(){
var c = $("#checkShowConfidence");
c.val([c.is(":checked")?'off':'on']).change();
return false;
}
}],
// T -> [edit]:activate text tool
't': [{
event: "keydown",
ctxt: "edit",
fn: function(){
tools.activateTool('text');
return false;
}
}],
// Z -> [edit]:activate zone tool
'z': [{
event: "keydown",
ctxt: "edit",
fn: function(){
if ($("#tool-cmsarea").is(":disabled"))
return false;
tools.activateTool('cmsarea');
return false;
}
}],
// SHIFT-Z -> [edit,review]:show hide striae
'shift+z': {
ctxt: "edit review",
fn: function(){
$("#annotation-display-container").find("[data-type-name='cmsarea']").click();
}
},
// UP -> [analysis]:increase resolution window
'up': [{
event: "keydown",
ctxt: "analysis",
fn: deltaGroupSize(1)
}],
// down -> [analysis]:increase resolution window
'down': [{
event: "keydown",
ctxt: "analysis",
fn: deltaGroupSize(-1)
}]
};
function deltaGroupSize(d){
var inputGroupSize = $("#inputGroupSize");
return function(){
var groupSize = parseInt(inputGroupSize.val(),10) + d;
if (groupSize > 0) {
inputGroupSize.val(groupSize).change();
//_events.graphParamChanged.dispatch({groupSize: groupSize});
}
return false;
}
}
return SHORTCUTS;
}
);
......@@ -8,24 +8,28 @@
define([
"underscore",
"adim/config",
// below are environments modules
"env/cimaf/env"
"env/shortcuts"
// below are proxied environments modules
//, "env/cimaf/env"
],
function(_, config){
function(_, config, shortcuts){
var _envs = _.filter(
Array.prototype.slice.call(arguments, 2),
Array.prototype.slice.call(arguments, 3),
{name: config.annotable.env}
);
function _proxy(fname) {
console.log("_proxy");
return function() {
_.invoke(_envs, fname, arguments);
}
}
return {
name: 'default'
name: 'default',
shortcuts: shortcuts
// Dev only
, initSignalRouting: _proxy('initSignalRouting')
, initUI: _proxy('initUI')
}
......
/**
* Copyright (C) 2014 Université de Lausanne, RISET,
* < http://www.unil.ch/riset/ >
* This file is part of AdIm.
* AdIm is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* AdIm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* This copyright notice MUST APPEAR in all copies of the file.
*
* @AUTHOR: Julien Furrer <Julien.Furrer@unil.ch>
* @CREATION-DATE: 29.06.15
*
*/
define([
"jquery",
"paper",
"signals",
// ----- app
"adim/config",
"adim/view",
"adim/tools",
"adim/ui",
// plugins
"jquery.hotkeys"
],
function ($, paper, Signal, config, view, tools, ui) {
// Two contexts corresponding to the view modes: 'edit' and 'review'
var _keyblock = function(){ return function(){return false} };
var activeTool;
var SHORTCUTS = {
// DELETE -> [edit]:delete selected annot. [review]:prevent default
'backspace del': [{
event: "keydown",
ctxt: "edit",
fn: function(){
view.removeSelectedItems();
return false;
}
}, {
event: "keydown",
ctxt: "review",
fn: _keyblock()
}],
// SPACEBAR -> [*]:activate pan tool while pressed, in all context
'space': [{
event: "keydown",
//ctxt: "*",
fn: function(){
if (!activeTool) {
activeTool = tools.getActiveTool();
tools.activateTool('pan');
}
return false;
}
}, {
event: "keyup",
//ctxt: "*",
fn: function(){
if (activeTool) {
tools.activateTool(activeTool);
activeTool = null;
}
return false;
}
}],
// A -> [edit]:activate select tool
'a': [{
event: "keydown",
ctxt: "edit",
fn: function(){
tools.activateTool('select');
return false;
}
}],
// CTRL-A -> [edit]:select all annotations in edit mode. [review]:prevent default
'ctrl+a meta+a': [{
event: "keydown",
ctxt: "edit",
fn: function(){
paper.project.activeLayer.children.map(function(c){c.selected = true;});
return false;
}
}, {
event: "keydown",
ctxt: "review",
fn: _keyblock()
}],
// D -> [edit]:activate drawing tool
'd': [{
event: "keydown",
ctxt: "edit",
fn: function(){
tools.activateTool('drawing');
return false;
}
}],
// F -> [edit]:activate arrow tool
'f': [{
event: "keydown",
ctxt: "edit",
fn: function(){
tools.activateTool('arrow');
return false;
}
}],
// L -> [edit]:activate lines tool
'l': [{
event: "keydown",
ctxt: "edit",
fn: function(){
tools.activateTool('lines');
return false;
}
}],
// C -> [edit]:activate ellipse tool
'c': [{
event: "keydown",
ctxt: "edit",
fn: function(){
tools.activateTool('ellipse');
return false;
}
}],
// R -> [edit]:activate rectangle tool
'r': [{
event: "keydown",
ctxt: "edit",
fn: function(){
tools.activateTool('rectangle');
return false;
}
}],
// T -> [edit]:activate text tool
't': [{
event: "keydown",
ctxt: "edit",
fn: function(){
tools.activateTool('text');
return false;
}
}]
};
return SHORTCUTS;
}
);
......@@ -18,6 +18,8 @@ define(["paper"], function (paper) {
}*/
// DEAD CODE ??? -----vvvvvvvvvvvvvvvvvvvvvvvvv
/**
*
* @param item
......@@ -55,6 +57,7 @@ define(["paper"], function (paper) {
}
}
}
// --------------------------^^^^^^^^^^^^^^^^
/*var _namedLayers = {};
function getLayerByName(layerName) {
......@@ -95,15 +98,49 @@ define(["paper"], function (paper) {
}
var _shortcuts = null;
function initShortcuts(shortcuts) {
_shortcuts = shortcuts
}
/**
* Apply shortcuts for the specified context.
* The sortcuts are defined in the environment
*
* @param ctxt
*/
function setShortcutsContext(ctxt) {
if (_shortcuts)
$.each(_shortcuts, function(keys, defs){