| 1 | package DBIx::dbMan::Extension::CmdKeyBindings; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use base 'DBIx::dbMan::Extension'; | ||
| 5 | |||
| 6 | our $VERSION = '0.01'; | ||
| 7 | |||
| 8 | 1; | ||
| 9 | |||
| 10 | sub IDENTIFICATION { return "000001-000088-000001"; } | ||
| 11 | |||
| 12 | sub preference { return 2000; } | ||
| 13 | |||
| 14 | sub known_actions { return [ qw/COMMAND/ ]; } | ||
| 15 | |||
| 16 | sub handle_action { | ||
| 17 | my ($obj,%action) = @_; | ||
| 18 | |||
| 19 | if ($action{action} eq 'COMMAND') { | ||
| 20 | if ($action{cmd} =~ /^show\s+keys?$/i) { | ||
| 21 | $action{action} = 'KEYS'; | ||
| 22 | $action{operation} = 'show'; | ||
| 23 | } elsif ($action{cmd} =~ /^(?:clear|erase)\s+keys?(\s+permanent(?:ly)?)?$/i) { | ||
| 24 | $action{action} = 'KEYS'; | ||
| 25 | $action{operation} = 'clear'; | ||
| 26 | $action{permanent} = $1?1:0; | ||
| 27 | } elsif ($action{cmd} =~ /^(re)?load\s+keys?$/i) { | ||
| 28 | $action{action} = 'KEYS'; | ||
| 29 | $action{operation} = 'reload'; | ||
| 30 | } elsif ($action{cmd} =~ /^def(?:ine)?\s+key(?:\s+for)?\s+(.+)$/i) { | ||
| 31 | $action{action} = 'KEYS'; | ||
| 32 | $action{operation} = 'define'; | ||
| 33 | $action{text} = $1; | ||
| 34 | } elsif ($action{cmd} =~ /^undef(?:ine)?\s+key\s*$/i) { | ||
| 35 | $action{action} = 'KEYS'; | ||
| 36 | $action{operation} = 'undefine'; | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | $action{processed} = 1; | ||
| 41 | return %action; | ||
| 42 | } | ||
| 43 | |||
| 44 | sub cmdhelp { | ||
| 45 | return [ | ||
| 46 | 'SHOW KEYS' => 'Show key bindings', | ||
| 47 | 'CLEAR KEYS [PERMAMENT]' => 'Clear key bindings - permanent or temporary', | ||
| 48 | 'RELOAD KEYS' => 'Reload key bindings from file', | ||
| 49 | 'DEFINE KEY FOR <macro>' => 'Define key for macro text', | ||
| 50 | 'UNDEFINE KEY' => 'Undefine key (pressed)' | ||
| 51 | ]; | ||
| 52 | } | ||
| 53 | |||
| 54 | sub cmdcomplete { | ||
| 55 | my ($obj,$text,$line,$start) = @_; | ||
| 56 | return qw/PERMANENT/ if $line =~ /^\s*(CLEAR|ERASE)\s+KEYS\s+\S*$/i; | ||
| 57 | return qw/FOR/ if $line =~ /^\s*DEFINE\s+KEY\s+\S*$/i; | ||
| 58 | return qw/KEYS/ if $line =~ /^\s*(SHOW|CLEAR|ERASE|RELOAD)\s+\S*$/i; | ||
| 59 | return qw/KEY/ if $line =~ /^\s*(UN)?DEFINE\s+\S*$/i; | ||
| 60 | return qw/SHOW CLEAR RELOAD DEFINE UNDEFINE/ if $line =~ /^\s*[A-Z]*$/i; | ||
| 61 | return (); | ||
| 62 | } |