Commits

Herbert Breunung committed d4f2ecd

limit size of focus stack

Comments (0)

Files changed (2)

lib/Kephra/App/Focus.pm

 use warnings;
 use Wx;
 use Kephra::API;
+use Kephra::App::Util;
 
 package Kephra::App::Focus;
+my @focus_stack = ();
+my $max_size = 50;
 
-my @focus_stack = ();
+#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, " $widget --\n";
+	#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 Kephra::Log::warning( "$widget is already in focus") if get() and $widget eq get();
+	return if get() and $widget eq get();
 	unshift @focus_stack, $widget;
+	pop @focus_stack if @focus_stack > $max_size;
 	stay();
 }
 sub set_back {
 	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;
 	binmode($FH);
 	return do { local $/; <$FH> };
 }
-sub _write_under_filename {
+sub _write_file {
 	my $doc = shift;
 	my $file = shift || $doc->file_path;
 	CORE::open my $FH, '>', $file;
 		next unless ref $doc eq 'Kephra::Document';
 		next unless $doc->editor->GetModify;
 		if ($doc->file_path){
-			_write_under_filename($doc);
+			_write_file($doc);
 		} else {
 			$doc->raise;
 			save_as($doc);
 	my $doc = shift || Kephra::API::document();
 	my $file = normalize_name( Kephra::App::Dialog::get_file_save() );
 	return unless $file;
-	_write_under_filename($doc, $file);
+	_write_file($doc, $file);
 	$doc->assign_file_path($file);
 	Kephra::API::docbar()->set_page_title( $doc->file_name);
 	Kephra::API::main_window()->refresh_title();