1. Herbert Breunung
  2. Kephra

Commits

Herbert Breunung  committed af514a9

rename to Keymap KeyMap

  • Participants
  • Parent commits da82cb1
  • Branches default

Comments (0)

Files changed (10)

File lib/Kephra.pm

View file
  • Ignore whitespace
 our @starttime_loaded_modules = qw/
 	App App::Util API Config Config::Default Config::File
 	Document DocumentStash CommandList Edit EventTable 
-	File PluginRegistrar SanddrumInterpreter Works/;
+	File KeyMap PluginRegistrar SanddrumInterpreter Works/;
 our @runtime_loaded_namespaces =
 	qw/App::Dialog Config::Default/;
 
 	App::Panel::OrgPad App::Panel::ProjectManager App::Panel::SratchSheet
 	App::Panel::TextLab App::Panel::TreeLib
 	CommandList Config 
-	Edit File EventTable PluginRegistrar SanddrumInterpreter/;
+	Edit File EventTable KeyMap PluginRegistrar SanddrumInterpreter/;
 our @oop_interfaces = 
 	qw/App::Editor App::Panel App::Splitter App::SidePanelController 
 	   App::Bar::Document Document/;
 
 sub load_libs {
 	my $pkg = __PACKAGE__;
-	my $require_string = 'require ';
-	eval $require_string . $_ for @external_dependencies, @used_wx_modules;
-	$require_string .= $pkg . '::';
-	eval $require_string . $_ for @needed_at_first;
+	eval 'require ' . $_ for @external_dependencies, @used_wx_modules;
+	require Kephra::App;
+	#$require_string .= $pkg . '::'; eval $require_string . $_ for @needed_at_first;
 }
 
 

File lib/Kephra/API.pm

View file
  • Ignore whitespace
 
 use Carp;
 use Kephra::App::Window;
+use Kephra::Config::Global;
 use Kephra::CommandList;
 use Kephra::DocumentStash;
-use Kephra::Keymap;
+use Kephra::KeyMap;
 use Kephra::Log;
 
 Kephra::CommandList::register_switch_var({

File lib/Kephra/App.pm

View file
  • Ignore whitespace
 
 use Wx;
 use Kephra::API;
-use Kephra::Config::Global;
 
 package Kephra::App;
 our @ISA = 'Wx::App';

File lib/Kephra/App/Editor.pm

View file
  • Ignore whitespace
 	} );
 	Wx::Event::EVT_KEY_DOWN ($self, sub {
 		my ($ed, $event) = @_;
-		my $key = Kephra::Keymap::code_from_event($event);
+		my $key = Kephra::KeyMap::code_from_event($event);
 		Kephra::API::log("pressed key $key inside the editor");
-		if (Kephra::Keymap::code_registered($key)){
-			Kephra::CommandList::run_cmd( Kephra::Keymap::cmd_from_code($key) )
+		if (Kephra::KeyMap::code_registered($key)){
+			my $cmd = Kephra::KeyMap::cmd_from_code($key);
+			Kephra::API::log("run command: $cmd");
+			Kephra::CommandList::run_cmd( $cmd );
 		}
 		else {$event->Skip}
 	});

File lib/Kephra/App/Panel/FileBrowser.pm

View file
  • Ignore whitespace
 	} );
 	Wx::Event::EVT_KEY_DOWN ($self, sub {
 		my ($fb, $event) = @_;
-		my $key = Kephra::Keymap::code_from_event($event);
+		my $key = Kephra::KeyMap::code_from_event($event);
 		Kephra::API::log("pressed key $key inside the filebrowser");
 		if    ($key ==  &Wx::WXK_ESCAPE) {Kephra::API::editor()->focus() }
 		elsif ($key ==  &Wx::WXK_F2)     {Kephra::API::editor()->focus() }

File lib/Kephra/App/Panel/IOUnit.pm

View file
  • Ignore whitespace
 use warnings;
 use Wx::AUI;
 use Wx::Perl::ProcessStream;
-use Kephra::Keymap;
-use Kephra::Log;
+use Kephra::API;
 
 package Kephra::App::Panel::IOUnit;
 our @ISA = 'Wx::Panel';
 
 	Wx::Event::EVT_KEY_DOWN ($input, sub {
 		my ($input, $event) = @_;
-		my $key = Kephra::Keymap::code_from_event($event);
+		my $key = Kephra::KeyMap::code_from_event($event);
 		Kephra::API::log("pressed key $key inside the IOUnit");
 
 		my $slot = $self->{'output_slots'}{ $self->{'active_slot_name'} };

File lib/Kephra/CommandList.pm

View file
  • Ignore whitespace
 use strict;
 use warnings;
-use Kephra::Keymap;
+use Kephra::KeyMap;
 use Kephra::Config::Default;
 use Kephra::Log;
 
 			? '(\''.$data->{'parameter'}.'\')'
 			: '()';
 		$data->{'coderef'} = eval "sub { $call }";
-		Kephra::Keymap::register_keys( { $cmd => $data->{'keys'} } )
+		Kephra::KeyMap::register_keys( { $cmd => $data->{'keys'} } )
 			if defined $data->{'keys'} and $data->{'keys'};
 	}
 }

File lib/Kephra/KeyMap.pm

View file
  • Ignore whitespace
+use strict;
+use warnings;
+use Wx;
+use Kephra::CommandList;
+use Kephra::Log;
+
+package Kephra::KeyMap;
+
+my %definition;
+my %code;
+my %mod_key_value = ( shift => 1000, ctrl => 2000, alt  => 4000);
+my %key_value = (
+	left  => &Wx::WXK_LEFT,      right => &Wx::WXK_RIGHT,
+	up    => &Wx::WXK_UP,         down => &Wx::WXK_DOWN,
+	pageup=> &Wx::WXK_PAGEUP, pagedown => &Wx::WXK_PAGEDOWN,
+	home  => &Wx::WXK_HOME,        end => &Wx::WXK_END,
+	back  => &Wx::WXK_BACK,        tab => &Wx::WXK_TAB,
+	esc   => &Wx::WXK_ESCAPE,    
+	enter => &Wx::WXK_RETURN,    space => &Wx::WXK_SPACE,
+	delete => &Wx::WXK_DELETE,  insert => &Wx::WXK_INSERT,
+	F1 => &Wx::WXK_F1, F2 => &Wx::WXK_F2,  F3 => &Wx::WXK_F3,  F4 => &Wx::WXK_F4,
+	F5 => &Wx::WXK_F5, F6 => &Wx::WXK_F6,  F7 => &Wx::WXK_F7,  F8 => &Wx::WXK_F8,
+	F9 => &Wx::WXK_F9,F10 => &Wx::WXK_F10,F11 => &Wx::WXK_F11,F12 => &Wx::WXK_F12,
+	pound => 35, tilde => 92,
+	num_left  => &Wx::WXK_NUMPAD_LEFT,  num_right=> &Wx::WXK_NUMPAD_RIGHT,
+	num_up    => &Wx::WXK_NUMPAD_UP,    num_down => &Wx::WXK_NUMPAD_DOWN,
+	num_space => &Wx::WXK_NUMPAD_SPACE, num_tab  => &Wx::WXK_NUMPAD_TAB,
+	num_enter => &Wx::WXK_NUMPAD_ENTER, num_F1   => &Wx::WXK_NUMPAD_F1,
+);
+my $main_map = 'editor';
+
+sub apply {}
+sub build {}
+sub copy {}
+sub overlay {}
+
+sub register_keys {
+	my ($keys, $map) = @_;
+	return Kephra::Log::warning ("register_code: got no hashref") unless ref $keys eq ref {};
+	$map = $main_map unless defined $map;
+	for my $cmd (keys %$keys) {
+		$definition{$map}{ $cmd } = $keys->{$cmd};
+		$code{$map}{ code_from_definition( $keys->{$cmd} ) } = $cmd;
+	}
+}
+
+sub code_registered {
+	my ($code, $map) = @_;
+	Kephra::Log::warning ("code_registered: got no key code") unless $code;
+	$map = $main_map unless defined $map;
+	return 1 if defined $code{$map}{$code} and $code{$map}{$code}
+}
+
+sub cmd_from_code {
+	my ($code, $map) = @_;
+	Kephra::Log::warning ("cmd_from_code: got no key code") unless $code;
+	$map = $main_map unless defined $map;
+	$code{$map}{$code};
+}
+
+sub code_from_definition {
+	my $def = shift;
+	$def =~ tr/ 	//d;
+	Kephra::Log::warning ("code_from_definition: got no key definition") unless $def;
+
+	my @key = split '\+', $def;           # only + can combine key in definition
+	my $code = length($key[-1]) == 1 ? ord uc $key[-1] : $key_value{ $key[-1] };
+	Kephra::Log::warning ("code_from_definition: don't know this key ".$key[-1]) unless $code;
+
+	$code += $mod_key_value{ shift(@key) } while @key > 1;
+	Kephra::Log::warning ("got unknown key definition $def") unless $code;
+	return $code;
+}
+
+sub code_from_event {
+	my $event = shift;
+	Kephra::Log::warning ('keycode_from_event got no event, but: '.$event)
+		unless $event and $event->isa('Wx::Event');
+	my $code = $event->GetKeyCode;
+	$code += $mod_key_value{'shift'} if $event->ShiftDown;
+	$code += $mod_key_value{'ctrl'} if $event->ControlDown;
+	$code += $mod_key_value{'alt'} if $event->AltDown;
+	return $code;
+}
+
+
+1;
+
+__END__ 
+# WXK_NUMPAD_SPACE WXK_NUMPAD_TAB WXK_NUMPAD_ENTER WXK_NUMPAD_F1

File lib/Kephra/Keymap.pm

  • Ignore whitespace
-use strict;
-use warnings;
-use Wx;
-use Kephra::CommandList;
-use Kephra::Log;
-
-package Kephra::Keymap;
-
-my %definition;
-my %code;
-my %mod_key_value = ( shift => 1000, ctrl => 2000, alt  => 4000);
-my %key_value = (
-	left  => &Wx::WXK_LEFT,      right => &Wx::WXK_RIGHT,
-	up    => &Wx::WXK_UP,         down => &Wx::WXK_DOWN,
-	pageup=> &Wx::WXK_PAGEUP, pagedown => &Wx::WXK_PAGEDOWN,
-	home  => &Wx::WXK_HOME,        end => &Wx::WXK_END,
-	back  => &Wx::WXK_BACK,        tab => &Wx::WXK_TAB,
-	esc   => &Wx::WXK_ESCAPE,    
-	enter => &Wx::WXK_RETURN,    space => &Wx::WXK_SPACE,
-	delete => &Wx::WXK_DELETE,  insert => &Wx::WXK_INSERT,
-	F1 => &Wx::WXK_F1, F2 => &Wx::WXK_F2,  F3 => &Wx::WXK_F3,  F4 => &Wx::WXK_F4,
-	F5 => &Wx::WXK_F5, F6 => &Wx::WXK_F6,  F7 => &Wx::WXK_F7,  F8 => &Wx::WXK_F8,
-	F9 => &Wx::WXK_F9,F10 => &Wx::WXK_F10,F11 => &Wx::WXK_F11,F12 => &Wx::WXK_F12,
-	pound => 35, tilde => 92,
-	num_left  => &Wx::WXK_NUMPAD_LEFT,  num_right=> &Wx::WXK_NUMPAD_RIGHT,
-	num_up    => &Wx::WXK_NUMPAD_UP,    num_down => &Wx::WXK_NUMPAD_DOWN,
-	num_space => &Wx::WXK_NUMPAD_SPACE, num_tab  => &Wx::WXK_NUMPAD_TAB,
-	num_enter => &Wx::WXK_NUMPAD_ENTER, num_F1   => &Wx::WXK_NUMPAD_F1,
-);
-my $main_map = 'editor';
-
-sub apply {}
-sub build {}
-sub copy {}
-sub overlay {}
-
-sub register_keys {
-	my ($keys, $map) = @_;
-	return Kephra::Log::warning ("register_code: got no hashref") unless ref $keys eq ref {};
-	$map = $main_map unless defined $map;
-	for my $cmd (keys %$keys) {
-		$definition{$map}{ $cmd } = $keys->{$cmd};
-		$code{$map}{ code_from_definition( $keys->{$cmd} ) } = $cmd;
-	}
-}
-
-sub code_registered {
-	my ($code, $map) = @_;
-	Kephra::Log::warning ("code_registered: got no key code") unless $code;
-	$map = $main_map unless defined $map;
-	return 1 if defined $code{$map}{$code} and $code{$map}{$code}
-}
-
-sub cmd_from_code {
-	my ($code, $map) = @_;
-	Kephra::Log::warning ("cmd_from_code: got no key code") unless $code;
-	$map = $main_map unless defined $map;
-	$code{$map}{$code};
-}
-
-sub code_from_definition {
-	my $def = shift;
-	$def =~ tr/ 	//d;
-	Kephra::Log::warning ("code_from_definition: got no key definition") unless $def;
-
-	my @key = split '\+', $def;           # only + can combine key in definition
-	my $code = length($key[-1]) == 1 ? ord uc $key[-1] : $key_value{ $key[-1] };
-	Kephra::Log::warning ("code_from_definition: don't know this key ".$key[-1]) unless $code;
-
-	$code += $mod_key_value{ shift(@key) } while @key > 1;
-	Kephra::Log::warning ("got unknown key definition $def") unless $code;
-	return $code;
-}
-
-sub code_from_event {
-	my $event = shift;
-	Kephra::Log::warning ('keycode_from_event got no event, but: '.$event)
-		unless $event and $event->isa('Wx::Event');
-	my $code = $event->GetKeyCode;
-	$code += $mod_key_value{'shift'} if $event->ShiftDown;
-	$code += $mod_key_value{'ctrl'} if $event->ControlDown;
-	$code += $mod_key_value{'alt'} if $event->AltDown;
-	return $code;
-}
-
-
-1;
-
-__END__ 
-# WXK_NUMPAD_SPACE WXK_NUMPAD_TAB WXK_NUMPAD_ENTER WXK_NUMPAD_F1

File t/620-keymap.t

View file
  • Ignore whitespace
+#!usr/bin/perl
+
+# making local lib favoured
+BEGIN { unshift @INC, -d 't' ? 'lib' : '../lib' }
+
+package probe;
+use Test::More tests => 1;
+use Test::NoWarnings;
+
+use Wx;
+use Kephra::App::Util;
+use Kephra::KeyMap;
+
+#sub one     { 1 }
+#sub true    { 'true' }
+#sub color   { Kephra::App::Util::create_color("blue") }
+#sub channel { $_[0] }
+#
+#
+#eval { Kephra::CommandList::register_cmd_namespace('test') };
+#is($@, '', 'registered cmd namespace');
+#
+#eval { Kephra::CommandList::register_switch_var('color') };
+#is($@, '', 'registered package switch var');
+#
+#eval { Kephra::CommandList::register_switch_var({ '$color' => 'color'}) };
+#is($@, '', 'registered named switch var');
+#
+#eval { Kephra::CommandList::register_cmd({
+		#'test-one' => {sub => 'probe::one', label => 'one'},
+		    #'-true'=> {sub => 'true', label => 'true'},
+		    #'-blue'=> {sub => '$_->IsOk', label => 'blue', help => 'help'},
+		    #'-gc'=>   {sub => '$color->IsOk', label => 'gc'},
+		    #'-chan'=> {sub => 'channel', label => 'channel', parameter => 4},
+#})};
+#is($@, '', 'registered command');
+#
+#eval { Kephra::CommandList::init() };
+#is($@, '', 'initialized command list');
+#
+#
+#my $data = Kephra::CommandList::cmd_all_properties('test-one');
+#is(ref $data, 'HASH', 'command entry created');
+#is($data->{'label'}, 'one', 'command data stored');
+#is( Kephra::CommandList::run_cmd('test-one'), 1, 'run command');
+#
+#my $data = Kephra::CommandList::cmd_all_properties('test-true');
+#is(ref $data, 'HASH', 'command ID prefix completion');
+#is( Kephra::CommandList::run_cmd('test-true'), 'true', 'sub prefix completion (module name)');
+#is( Kephra::CommandList::run_cmd('test-blue'), 1, 'package switch var substitution');
+#is( Kephra::CommandList::run_cmd('test-gc'), 1, 'named switch var substitution');
+#is( Kephra::CommandList::run_cmd('test-chan'), 4, 'parameter insertion');
+
+
+exit(0);