Commits

Herbert Breunung  committed 66b13e3

straigtened new test to work with keymap

  • Participants
  • Parent commits 0a50ed6

Comments (0)

Files changed (9)

File lib/Kephra/API.pm

 use Kephra::App::Window;
 use Kephra::CommandList;
 use Kephra::DocumentStash;
+use Kephra::Keymap;
+use Kephra::Log;
 
 Kephra::CommandList::register_switch_var({
 	'$app'    => 'app',

File lib/Kephra/App/Editor.pm

 use Wx::Scintilla;
 
 use Kephra::App::Editor::TextDropTarget;
-use Kephra::App::Keymap;
 use Kephra::App::Util;
 use Kephra::Edit;
+use Kephra::Keymap;
 use Kephra::Log;
 
 package Kephra::App::Editor;
 	} );
 	Wx::Event::EVT_KEY_DOWN ($self, sub {
 		my ($ed, $event) = @_;
-		my $key = Kephra::App::Keymap::code_from_event($event);
-		Kephra::API::log("pressed key $key");
+		my $key = Kephra::Keymap::code_from_event($event);
+		Kephra::API::log("pressed key $key inside the editor");
 		if    ($key ==  &Wx::WXK_LEFT     + 4000){$self->dedent_level() }
 		elsif ($key ==  &Wx::WXK_LEFT     + 5000){$self->move_sel_or_word_left() }
 		elsif ($key ==  &Wx::WXK_RIGHT    + 4000){$self->indent_level() }

File lib/Kephra/App/Keymap.pm

-use strict;
-use warnings;
-use Wx;
-use Kephra::CommandList;
-use Kephra::Log;
-
-package Kephra::App::Keymap;
-
-my %data;
-my %compiled;
-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,
-	del => &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,
-);
-
-sub apply {}
-sub build {}
-sub copy {}
-
-sub overlay {}
-
-sub definition_to_code {
-	my $def = shift;
-	$def =~ tr/ 	//d;
-	ord uc
-}
-
-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/App/Panel/FileBrowser.pm

 use Cwd;
 use File::Find;
 use File::Spec;
+
 use Kephra::API;
 use Kephra::File;
 
 	} );
 	Wx::Event::EVT_KEY_DOWN ($self, sub {
 		my ($fb, $event) = @_;
-		my $key = $event->GetKeyCode + 1000 * 
-			( $event->ShiftDown
-			+ $event->ControlDown * 2 
-			+ $event->AltDown     * 4);
+		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() }
 		elsif ($key ==  &Wx::WXK_F11)    {Kephra::API::main_window()->toggle_fullscreen() } 

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

 use warnings;
 use Wx::AUI;
 use Wx::Perl::ProcessStream;
-use Kephra::App::Util;
+use Kephra::Keymap;
 use Kephra::Log;
 
 package Kephra::App::Panel::IOUnit;
 
 	Wx::Event::EVT_KEY_DOWN ($input, sub {
 		my ($input, $event) = @_;
-		my $key = Kephra::App::Util::keycode_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'} };
 
 		if    ($key ==  0)                     {  }

File lib/Kephra/CommandList.pm

 use strict;
 use warnings;
+use Kephra::Keymap;
 use Kephra::Config::Default;
 use Kephra::Log;
 
 package Kephra::CommandList;
 
-my %list;
+my %list;     # by ID
+my %keyproxy; # by keycode
 my %namespace;
 my %switch   = ( 'name' => {}, 'package' => {} );
 
 			? '(\''.$data->{'parameter'}.'\')'
 			: '()';
 		$data->{'coderef'} = eval "sub { $call }";
+		if (defined $data->{'keys'} and $data->{'keys'}) {
+			$data->{'keycode'} = Kephra::Keymap::code_from_definition( $data->{'keys'} );
+			# register
+		}
 	}
 }
 sub compile_cmd {}
 	for (@$cmd) { $return = $list{$_}{'coderef'}->() if exists $list{$_} }
 	$return;
 }
+sub run_cmd_by_keycode {
+	my ($code, $map) = @_;
+}
 
 sub cmd_exists          { 1 if defined $_[0]     and exists $list{ $_[0] }          }
 sub cmd_property_exists { 1 if cmd_exists($_[0]) and exists $list{ $_[0] }{ $_[1] } }

File lib/Kephra/Config/Default/Localisation.pm

 
 package Kephra::Config::Default::Localisation;
 
-sub english { {
-	commandlist => {
+sub english { return {
+	command => {
 		label => {
-			
+			file => {
+				open => 'Open',
+				close => 'Close',
+			},
+			help => {
+				about => 'About...',
+			},
 		},
 		help => {
 			
-		}
+		},
 	}
 } }
 

File lib/Kephra/Keymap.pm

+use strict;
+use warnings;
+use Wx;
+use Kephra::CommandList;
+use Kephra::Log;
+
+package Kephra::Keymap;
+
+my %data;
+my %compiled;
+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,
+	del => &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,
+);
+
+sub apply {}
+sub build {}
+sub copy {}
+sub overlay {}
+
+sub cmd_from_code {}
+
+sub code_from_definition {
+	my $def = shift;
+	$def =~ tr/ 	//d;
+	Kephra::Log::warning ("got no key definition") unless $def;
+
+	my @key = split /[+-]/, $def;
+	my $code = length($key[-1]) == 1 ? ord uc $key[-1] : $key_value{ $key[-1] };
+	$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/610-commandlist.t

 eval { Kephra::CommandList::register_cmd({
 		'test-one' => {sub => 'probe::one', label => 'one'},
 		    '-true'=> {sub => 'true', label => 'true'},
-		    '-blue'=> {sub => '$_->IsOk', label => 'blue',keys => 'keys', help => 'help'},
+		    '-blue'=> {sub => '$_->IsOk', label => 'blue', help => 'help'},
 		    '-gc'=>   {sub => '$color->IsOk', label => 'gc'},
 		    '-chan'=> {sub => 'channel', label => 'channel', parameter => 4},
 })};