Commits

Herbert Breunung committed 64dd03d

central function how to react with event on any keymap

  • Participants
  • Parent commits 676c3f0

Comments (0)

Files changed (5)

File lib/Kephra/App/Dialog.pm

 package Kephra::App::Dialog;
 
 Kephra::CommandList::register_cmd({
-	'config-global-dialog' => {
+ 'config-global-dialog' => {
 		sub => 'config',    label => 'Global Dialog',keys  => 'ctrl+alt+c'},
-	'config-keymap-dialog' => {
+ 'config-keymap-dialog' => {
 		sub => 'keymap',    label => 'Keymapping',keys  => 'ctrl+alt+k'},
-	'help-documentation' => {
+ 'help-documentation' => {
 		sub => 'documentation', label => 'Documentation',keys  => 'F1'},
-	'help-about' => {
+ 'help-about' => {
 		sub => 'about', label => 'About...', keys  => ''},
-	'help-homepage' => {
+ 'help-homepage' => {
 		sub => 'Kephra::App::Util::lounch_browser',
 		parameter => 'http://kephra.sourceforge.net/site/en/home_news.shtml',
 		label => 'Homepage', keys  => '', help => ''},
-	'help-bugreport' => {
+ 'help-bugreport' => {
 		sub => 'Kephra::App::Util::lounch_browser',
 		parameter => 'http://sourceforge.net/tracker/?func=add&group_id=169747&atid=851593',
 		label => 'Send a Wish', keys  => '', help => ''},
 sub _parent {
 	my $parent = shift;
 	return Kephra::API::main_window() unless defined $parent;
-	die "Kephra::App::Dialog need a window as parent not $parent"
+	Kephra::Log::error("need a window as parent not $parent")
 		unless $parent and ref $parent and $parent->isa('Wx::Window');
 	return $parent;
 }

File lib/Kephra/App/Editor/TextDropTarget.pm

 
 sub new {
 	my ($class, $ed) = @_;
-	warn __PACKAGE__ ."needs a Kephra::App::Editor, not $ed!" unless $ed->isa('Kephra::App::Editor');
+	Kephra::Log::warning("needs a Kephra::App::Editor, not $ed!")
+		unless $ed->isa('Kephra::App::Editor');
 	my $self = $class->SUPER::new();
 	$self->{'ed'} = $ed;
 	return $self;

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

 
 Kephra::CommandList::register_cmd_namespace('filebrowser');
 Kephra::CommandList::register_cmd({
- '-focus'=>{ sub=>'focus', label => ' ', keys => 'F2' },
+ 'filebrowser-focus'=>{ sub=>'focus', label => ' ', keys => 'F2' },
 });
 
 

File lib/Kephra/File.pm

 
 Kephra::CommandList::register_cmd_namespace('file');
 Kephra::CommandList::register_cmd({
-	'-new' => { sub => 'new', label => 'New',keys  => 'ctrl+n', 
-				help => ''},
-	'-open'=> { sub => 'open', label => 'Open',keys  => 'ctrl+o',
-				help => ''},
-	'-save'=> { sub => 'save_active', label => 'Save', keys  => 'ctrl+s',
-				help => ''},
-	'-close'=>{ sub => 'close_active',label => 'Close',keys  => 'ctrl+q',
-				help => ''},
+ '-new' => { sub => 'new',         label => 'New',   keys => 'ctrl+n'},
+ '-open'=> { sub => 'open',        label => 'Open',  keys => 'ctrl+o'},
+ '-save'=> { sub => 'save_active', label => 'Save',  keys => 'ctrl+s'},
+ '-close'=>{ sub => 'close_active',label => 'Close', keys => 'ctrl+q'},
 });
 
 sub normalize_name {

File lib/Kephra/KeyMap.pm

 
 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');
+	Kephra::Log::warning ("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;
 	return $code;
 }
 
+sub react_on_event {
+	my ($event, $map) = @_;
+	Kephra::Log::warning ("got no event, but $event") unless $event and $event->isa('Wx::Event');
+	$map = $main_map unless defined $map;
+	my $key = code_from_event($event);
+	Kephra::API::log("pressed key $key inside the ".(caller)[0]);
+	if (code_registered($key)){
+			my $cmd = cmd_from_code($key);
+			Kephra::API::log("run command: $cmd");
+			Kephra::CommandList::run_cmd( $cmd );
+	}
+	else {$event->Skip}
+}
 
 1;
-
-__END__ 
-# WXK_NUMPAD_SPACE WXK_NUMPAD_TAB WXK_NUMPAD_ENTER WXK_NUMPAD_F1