Source

Kephra / lib / Kephra / App / Focus.pm

Diff from to

File lib/Kephra/App/Focus.pm

 use strict;
 use warnings;
 use Wx;
-use Kephra::API;
-use Kephra::App::Util;
 
 package Kephra::App::Focus;
 my @focus_stack = ();
 my $max_stack_size = 50;
 
-#Kephra::CommandList::register_cmd({'app-focus-set-back'  =>{sub=>'set_back',label=>'',keys=>''},});
+use Kephra::API;
+use Kephra::App::Util qw(is_widget);
+
+Kephra::API::Command::register({
+ 'app-focus-set-back'  =>{ sub=>'set_back', label=>'',  keys=>'' },
+ 'app-focus-stay'      =>{ sub=>'stay',     label=>'',  keys=>'' },
+});
 
 
 sub get  {                              # give widget in focus or one that was before
 
 sub set  {                              # set focus to another widget
 	my ($widget) = @_;
+	return unless defined $widget;
 	Kephra::Log::note("focus is on :". get()." and will be: $widget");
 	return Kephra::Log::warning( "got no proper widget but $widget", 1 )
-		unless Kephra::App::Util::is_widget($widget);
+		unless is_widget($widget);
 	return if $widget eq get();
 	unshift @focus_stack, $widget;
 	pop @focus_stack while stack_size() > $max_stack_size;
 
 sub stay {                              # reset focus to current (last set) entry
 	my ($widget) = get();
-	Kephra::App::Util::is_widget($widget)
+	is_widget($widget)
 		? Wx::Window::SetFocus( $widget )
 		: Kephra::Log::warning( "no widget to stay focussed on", 1 );
 }