This patch allows for redfining the keyboard shortcuts used in rancor.
For now these are set globally (per instance)
Ctrl-S is a codemirror setting and cannot be altered
To test:
1 - Apply patches
2 - update database
3 - Load the advanced cataloging editor
4 - Click the "Keyboard shortcuts" button
5 - Ensure the list looks correct
6 - Note that 'Ctrl-S' note sit cannot be remapped
7 - Note the 'Redefine shortcuts' link at the top of the menu
8 - Confirm all the listed shortcuts work as expected
9 - Click the 'Redefine' link
10 - Ensure current mappings load correctly
11 - Read explanation and verify it makes sense
12 - Remap some functions
13 - Return to the cataloging editor
14 - Confirm your mappings work
Signed-off-by: Liz Rea <liz@catalyst.net.nz>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
--- /dev/null
+package Koha::KeyboardShortcut;
+
+# This file is part of Koha.
+#
+# Koha 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.
+#
+# Koha 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 Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use Modern::Perl;
+
+use Carp;
+
+use Koha::Database;
+
+use base qw(Koha::Object);
+
+=head1 NAME
+
+Koha::KeyboardShortcut - Koha KeyboardShortcut Object class
+
+=head1 API
+
+=head2 Class Methods
+
+=cut
+
+=head3 type
+
+=cut
+
+sub _type {
+ return 'KeyboardShortcut';
+}
+
+1;
--- /dev/null
+package Koha::KeyboardShortcuts;
+
+# This file is part of Koha.
+#
+# Koha 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.
+#
+# Koha 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 Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use Modern::Perl;
+
+use Carp;
+
+use Koha::Database;
+
+use Koha::KeyboardShortcut;
+
+use base qw(Koha::Objects);
+
+=head1 NAME
+
+Koha::KeyboardShortcuts - Koha KeyboardShortcut Object set class
+
+=head1 API
+
+=head2 Class Methods
+
+=cut
+
+=head3 type
+
+=cut
+
+sub _type {
+ return 'KeyboardShortcut';
+}
+
+sub object_class {
+ return 'Koha::KeyboardShortcut';
+}
+
+1;
use Koha::Database;
use Koha::MarcSubfieldStructures;
use Koha::BiblioFrameworks;
+use Koha::KeyboardShortcuts;
my $input = CGI->new;
my $schema = Koha::Database->new->schema;
+my @keyboard_shortcuts = Koha::KeyboardShortcuts->search();
+
+# Keyboard shortcuts
+$template->param(
+ shortcuts => \@keyboard_shortcuts,
+);
+
# Available import batches
$template->{VARS}->{editable_batches} = [ $schema->resultset('ImportBatch')->search(
{
--- /dev/null
+$DBversion = 'XXX';
+if( CheckVersion( $DBversion ) ) {
+ unless ( TableExists( 'keyboard_shortcuts' ) ) {
+ $dbh->do(q|
+ CREATE TABLE keyboard_shortcuts (
+ shortcut_name varchar(80) NOT NULL,
+ shortcut_keys varchar(80) NOT NULL,
+ shortcut_desc varchar(200) NOT NULL,
+ PRIMARY KEY (shortcut_name)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;|
+ );
+ }
+ $dbh->do(q|
+ INSERT IGNORE INTO keyboard_shortcuts (shortcut_name, shortcut_keys, shortcut_desc) VALUES
+ ("insert_copyright","Alt-C","Insert copyright symbol (©)"),
+ ("insert_copyright_sound","Alt-P","Insert copyright symbol (℗) (sound recordings)"),
+ ("insert_delimiter","Ctrl-D","Insert delimiter (‡)"),
+ ("subfield_help","Ctrl-H","Get help on current subfield"),
+ ("link_authorities","Shift-Ctrl-L","Link field to authorities"),
+ ("delete_field","Ctrl-X","Delete current field"),
+ ("delete_subfield","Shift-Ctrl-X","Delete current subfield"),
+ ("new_line","Enter","New field on next line"),
+ ("line_break","Shift-Enter","Insert line break"),
+ ("next_position","Tab","Move to next position"),
+ ("prev_position","Shift-Tab","Move to previous position")
+ ;|
+ );
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug XXXXX - Add keyboard_shortcuts table)\n";
+}
--- /dev/null
+--
+-- Default keyboard shortcuts
+-- for Koha.
+--
+-- Copyright (C) 2007 LiblimeA
+-- Copyright 2018 Koha Development Team
+--
+-- This file is part of Koha.
+--
+-- Koha 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 2 of the License, or (at your option) any later
+-- version.
+--
+-- Koha 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 Koha; if not, write to the Free Software Foundation, Inc.,
+-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+-- keyboard shortcuts
+INSERT INTO keyboard_shortcuts (shortcut_name, shortcut_keys, shortcut_desc) VALUES
+ ("insert_copyright","Alt-C","Insert copyright symbol (©)"),
+ ("insert_copyright_sound","Alt-P","Insert copyright symbol (℗) (sound recordings)"),
+ ("insert_delimiter","Ctrl-D","Insert delimiter (‡)"),
+ ("subfield_help","Ctrl-H","Get help on current subfield"),
+ ("link_authorities","Shift-Ctrl-L","Link field to authorities"),
+ ("delete_field","Ctrl-X","Delete current field"),
+ ("delete_subfield","Shift-Ctrl-X","Delete current subfield"),
+ ("new_line","Enter","New field on next line"),
+ ("line_break","Shift-Enter","Insert line break"),
+ ("next_position","Tab","Move to next position"),
+ ("prev_position","Shift-Tab","Move to previous position");
--- /dev/null
+Default keyboard shorcuts
ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+--
+-- Table structure for table `keyboardshortcuts`
+--
+
+DROP TABLE IF EXISTS `keyboard_shortcuts`;
+CREATE TABLE keyboard_shortcuts (
+shortcut_name varchar(80) NOT NULL,
+shortcut_keys varchar(80) NOT NULL,
+shortcut_desc varchar(200) NOT NULL,
+PRIMARY KEY (shortcut_name)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
return [];
}
}
+ var _editorKeys = {};
- var _editorKeys = {
- 'Alt-C': function( cm ) {
+ _editorKeys[insert_copyright] = function( cm ) {
cm.replaceRange( '©', cm.getCursor() );
- },
+ }
- 'Alt-P': function( cm ) {
+ _editorKeys[insert_copyright_sound] = function( cm ) {
cm.replaceRange( '℗', cm.getCursor() );
- },
+ }
- Enter: function( cm ) {
+ _editorKeys[new_line] = function( cm ) {
var cursor = cm.getCursor();
cm.replaceRange( '\n', { line: cursor.line }, null, 'marcAware' );
cm.setCursor( { line: cursor.line + 1, ch: 0 } );
- },
+ }
- 'Shift-Enter': function( cm ) {
+ _editorKeys[line_break] = function( cm ) {
var cur = cm.getCursor();
cm.replaceRange( "\n", cur, null );
- },
+ }
- 'Ctrl-X': function( cm ) {
+ _editorKeys[delete_field] = function( cm ) {
// Delete line (or cut)
if ( cm.somethingSelected() ) return true;
cm.execCommand('deleteLine');
- },
+ }
- 'Shift-Ctrl-L': function( cm ) {
+ _editorKeys[link_authorities] = function( cm ) {
// Launch the auth search popup
var field = cm.marceditor.getCurrentField();
}
newin=window.open("../authorities/auth_finder.pl?source=biblio&authtypecode="+authtype+"&index="+index+"&value_mainstr="+encodeURI(mainmainstring)+"&value_main="+encodeURI(mainstring), "_blank",'width=700,height=550,toolbar=false,scrollbars=yes');
- },
+ }
- 'Shift-Ctrl-X': function( cm ) {
+ _editorKeys[delete_subfield] = function( cm ) {
// Delete subfield
var field = cm.marceditor.getCurrentField();
if ( !field ) return;
var subfield = field.getSubfieldAt( cm.getCursor().ch );
if ( subfield ) subfield.delete();
- },
+ }
- Tab: function( cm ) {
+ _editorKeys[next_position] = function( cm ) {
// Move through parts of tag/fixed fields
var positions = getTabPositions( cm.marceditor );
var cur = cm.getCursor();
}
cm.setCursor( { line: cur.line + 1, ch: 0 } );
- },
+ }
- 'Shift-Tab': function( cm ) {
+ _editorKeys[prev_position] = function( cm ) {
// Move backwards through parts of tag/fixed fields
var positions = getTabPositions( cm.marceditor );
var cur = cm.getCursor();
} else {
cm.setCursor( { line: cur.line - 1, ch: 0 } );
}
- },
+ }
- 'Ctrl-D': function( cm ) {
- // Insert subfield delimiter
- var cur = cm.getCursor();
+ _editorKeys[insert_delimiter] = function(cm){
+ var cur = cm.getCursor();
- cm.replaceRange( "‡", cur, null );
- },
- };
+ cm.replaceRange( "‡", cur, null );
+ }
// The objects below are part of a field/subfield manipulation API, accessed through the base
// editor object.
[% Asset.js("lib/koha/cateditor/marc-mode.js") | $raw %]
[% Asset.js("lib/require.js") | $raw %]
<script>
+[% FOREACH shortcut IN shortcuts -%]
+ var [% shortcut.shortcut_name | html %] = "[% shortcut.shortcut_keys | html %]";
+[% END %]
var authInfo = {
[%- FOREACH authtag = authtags -%]
[% authtag.tagfield | html %]: {
</div>
<div id="shortcuts-contents" style="display: none">
+<a id="redefine_shortcuts" href="/cgi-bin/koha/tools/adveditorshortcuts.pl">Redefine shortcuts</a>
<table class="table table-condensed">
<thead>
<tr>
</tr>
</thead>
<tbody>
- <tr>
- <td>Alt-C</td>
- <td>Insert copyright symbol (©)</td>
- </tr>
- <tr>
- <td>Alt-P</td>
- <td>Insert copyright symbol (℗) (sound recordings)</td>
- </tr>
- <tr>
- <td>Ctrl-D</td>
- <td>Insert delimiter (‡)</td>
- </tr>
- <tr>
- <td>Ctrl-H</td>
- <td>Get help on current subfield</td>
- </tr>
- <tr>
- <td>Ctrl-Shift-L</td>
- <td>Link field to authorities</td>
- </tr>
+ [% FOREACH shortcut IN shortcuts %]
+ <tr>
+ <td>[% shortcut.shortcut_keys %]</td>
+ <td>[% shortcut.shortcut_desc %]</td>
+ </tr>
+ [% END %]
<tr>
<td>Ctrl-S</td>
- <td>Save record</td>
- </tr>
- <tr>
- <td>Ctrl-X</td>
- <td>Delete current field</td>
- </tr>
- <tr>
- <td>Ctrl-Shift-X</td>
- <td>Delete current subfield</td>
- </tr>
- <tr>
- <td>Enter</td>
- <td>New field on next line</td>
- </tr>
- <tr>
- <td>Shift-Enter</td>
- <td>Insert line break</td>
- </tr>
- <tr>
- <td>Tab</td>
- <td>Move to next position</td>
- </tr>
- <tr>
- <td>Shift-Tab</td>
- <td>Move to previous position</td>
+ <td>Save record (cannot be remapped)</td>
</tr>
</tbody>
</table>
--- /dev/null
+[% USE raw %]
+[% USE Asset %]
+[% SET footerjs = 1 %]
+[% INCLUDE 'doc-head-open.inc' %]
+<title>Koha › Tools › Advanced editor shortcuts</title>
+[% INCLUDE 'doc-head-close.inc' %]
+</head>
+<body id="adveditor_shortcuts" class="tools">
+ [% INCLUDE 'header.inc' %]
+ [% INCLUDE 'cat-search.inc' %]
+
+<div id="breadcrumbs">
+ <a href="/cgi-bin/koha/mainpage.pl">Home</a> ›
+ <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> ›
+ <a href="/cgi-bin/koha/tools/adveditorshortcuts.pl">Advanced editor shortcuts</a>
+</div>
+
+<div class="main container-fluid">
+ <div class="row">
+ <div class="col-sm-10 col-sm-push-2">
+ <main>
+ <h1>Advanced editor keyboard shortcuts</h1>
+ <ul>
+ <li>Separate keys using a hyphen "-"</li>
+ <li>Control key is "Ctrl"</li>
+ <li>Alt key is "Alt"</li>
+ <li>Shift is "Shift"</li>
+ <li>If combing multiple keys they must be in specified order: Shift-Cmd-Ctrl-Alt</li>
+ <li><a href="https://codemirror.net/doc/manual.html#keymaps">More documentation on defining key maps</a></li>
+ </ul>
+
+ <form id="adveditor_shortcuts" method="post" action="/cgi-bin/koha/tools/adveditorshortcuts.pl">
+ <input type=hidden name="op" value="save" />
+
+ <table id="adv_editor_keyboard_shortcuts">
+ <thead>
+ <th>Description</th>
+ <th>Shortcut keys</th>
+ </thead>
+ <tbody>
+ [% FOREACH shortcut IN shortcuts %]
+ <tr>
+ <td><label for="shortcut_keys">[% shortcut.shortcut_desc %]</label></td>
+ <td>
+ <input type="hidden" name="shortcut_name" value="[% shortcut.shortcut_name %]">
+ <input type="text" name="shortcut_keys" value="[% shortcut.shortcut_keys %]">
+ </td>
+ </tr>
+ [% END %]
+ </table>
+ <input type="submit" value="Save shortcuts">
+ </form>
+
+ </main>
+ </div> <!-- /.col-sm-10.col-sm-push-2 -->
+
+ <div class="col-sm-2 col-sm-pull-10">
+ <aside>
+ [% INCLUDE 'tools-menu.inc' %]
+ </aside>
+ </div> <!-- /.col-sm-2.col-sm-pull-10 -->
+ </div> <!-- /.row -->
+
+[% MACRO jsinclude BLOCK %]
+ [% Asset.js("js/tools-menu.js") | $raw %]
+[% END %]
+
+[% INCLUDE 'intranet-bottom.inc' %]
--- /dev/null
+#!/usr/bin/perl
+
+# Copyright 2018 Koha Development Team
+#
+# This file is part of Koha.
+#
+# Koha 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.
+#
+# Koha 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 Koha; if not, see <http://www.gnu.org/licenses>.
+
+=head1 NAME
+
+adveditorshortcuts.pl : Define keyboard shortcuts for the advanced cataloging editor (rancor)
+
+=head1 SYNOPSIS
+
+=cut
+
+=head1 DESCRIPTION
+
+This script allows the user to redefine the keyboard shortcuts for the advacned cataloging editor
+
+=head1 FUNCTIONS
+
+=cut
+
+use Modern::Perl;
+use Encode;
+
+use C4::Auth;
+use C4::Context;
+use C4::Output;
+use CGI qw ( -utf8 );
+use C4::Koha;
+use Koha::KeyboardShortcuts;
+
+my $input = new CGI;
+my $op = $input->param('op') || 'list';
+my @messages;
+
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+ { template_name => "tools/adveditorshortcuts.tt",
+ query => $input,
+ type => "intranet",
+ authnotrequired => 1,
+ flagsrequired => {},
+ debug => 1,
+ }
+);
+
+my $shortcuts = Koha::KeyboardShortcuts->search();
+
+if ( $op eq 'save' ) {
+ my @shortcut_names = $input->multi_param('shortcut_name');
+ my @shortcut_keys = $input->multi_param('shortcut_keys');
+ my %updated_shortcuts;
+ @updated_shortcuts{@shortcut_names} = @shortcut_keys;
+
+ while ( my $shortcut = $shortcuts->next() ){
+ $shortcut->shortcut_keys( $updated_shortcuts{$shortcut->shortcut_name} );
+ $shortcut->store();
+ }
+}
+
+
+$template->param(
+ shortcuts => $shortcuts,
+);
+
+output_html_with_http_headers $input, $cookie, $template->output;