Commits

Herbert Breunung  committed 1f9de1c

extend app::focus, get returns any position, last searches of last of a type and better comments

  • Participants
  • Parent commits 8a6037f

Comments (0)

Files changed (2)

File lib/Kephra/App/Bar/Document.pm

 use strict;
 use warnings;
 use Wx;
-use Wx::DND;
 use Kephra::API;
-use Kephra::App::Editor;
 use Kephra::App::Panel;
 use Kephra::App::Util;
 use Kephra::CommandList;

File lib/Kephra/App/Focus.pm

 #Kephra::CommandList::register_cmd({'app-focus-set-back'  =>{sub=>'set_back',label=>'',keys=>''},});
 
 
-sub get { $focus_stack[0] }
-sub set {
+sub get  {                             # give widget in focus or one before
+	my ($nr) = shift // 0;
+	$focus_stack[$nr] unless $nr < @focus_stack or $nr < 0 and $nr > @focus_stack;
+}
+
+sub last {                             # give me last widget of a class in focus
+	my $class = shift;
+	return Kephra::Log::warning( "need a class name", 1 ) unless $class;
+	for (@focus_stack) { return $_ if ref $_ eq $class }
+}
+
+sub set  {                              # set focus to another widget
 	my ($widget) = @_;
-	#print scalar @focus_stack, get(), " $widget - gets set\n";
-	return Kephra::Log::warning( "got no proper widget ($widget) from ". (caller)[0] )
+	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);
 	return if get() and $widget eq get();
 	unshift @focus_stack, $widget;
 	pop @focus_stack if @focus_stack > $max_size;
 	stay();
 }
-sub set_back {
+
+sub set_back {                          # go with focus n (default 1) steps 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 } 
+sub stay {Wx::Window::SetFocus(get())}  # reset focus to last entry
+
+sub set_max_size { $max_size = shift }  # set maximum number of memorized widgets in focus
 
 1;