Source

Kephra / lib / Kephra / App / Focus.pm

use v5.10;
use strict;
use warnings;
use Wx;
use Kephra::API;
use Kephra::App::Util;

package Kephra::App::Focus;
my @focus_stack = ();
my $max_size = 50;

#Kephra::CommandList::register_cmd({'app-focus-set-back'  =>{sub=>'set_back',label=>'',keys=>''},});


sub get { $focus_stack[0] }
sub set {
	my ($widget) = @_;
	#print scalar @focus_stack, get(), " $widget - gets set\n";
	return Kephra::Log::warning( "got no proper widget ($widget) from ". (caller)[0] )
		unless Kephra::App::Util::is_widget($widget);
	return if get() and $widget eq get();
	unshift @focus_stack, $widget;
	pop @focus_stack if @focus_stack > $max_size;
	stay();
}
sub set_back {
	my ($times) = shift // 1;
	for (1 .. $times) { shift @focus_stack if @focus_stack > 1 }
	stay();
}
sub stay { Wx::Window::SetFocus( get() ) }

sub set_max_size { $max_size = shift } 

1;