1. Herbert Breunung
  2. Kephra

Commits

Herbert Breunung  committed f05812e

focussing over central API to enable switchback, because you cant really ask where focus is so you have to store the info

  • Participants
  • Parent commits 8637852
  • Branches default

Comments (0)

Files changed (10)

File lib/Kephra/API.pm

View file
 	document_bar => sub { Kephra::App::Panel::Editor::_active_docbar() },
 );
 
-sub app { $Kephra::App::_ref }
-# gui parts of main window
-sub widget { # widget names are same as in the config
-	my $name = shift;
+sub app    { $Kephra::App::_ref }
+sub widget {                           # gui parts of main window
+	my $name = shift;                  # widget names are same as in the config
 	croak "requested widget withou name from Kephra::API::widget " unless $name;
 	my $coderef = $widget_caller{ $name };
 	croak caller, "wanted a widget noneexisting in the API: ", $name
 		unless ref $coderef eq ref sub {};
 	return &$coderef();
 }
+sub focus      {$Kephra::App::Window::_ref->set_focus(@_)}
+sub focus_back {$Kephra::App::Window::_ref->set_focus_back()}
+
+# IO-unit
+sub input             { $Kephra::App::Panel::IOUnit::_ref->get_line() }
+sub output            { $Kephra::App::Panel::IOUnit::_ref->output(@_) }
+sub log               { $Kephra::App::Panel::IOUnit::_ref->output('log', @_) }
+sub raise_output_slot { $Kephra::App::Panel::IOUnit::_ref->raise_slot(@_) }
 
 sub configs  { }
 

File lib/Kephra/App/Editor.pm

View file
 	Wx::Event::EVT_KEY_DOWN ($self, sub {
 		my ($ed, $event) = @_;
 		my $key = Kephra::App::Util::keycode_from_event($event);
-		Kephra::App::Panel::IOUnit::output('log',"pressed key $key");
+		Kephra::API::log("pressed key $key");
 		if    ($key ==  &Wx::WXK_LEFT   + 4000){$self->dedent_level() }
 		elsif ($key ==  &Wx::WXK_LEFT   + 5000){$self->move_sel_or_word_left() }
 		elsif ($key ==  &Wx::WXK_RIGHT  + 4000){$self->indent_level() }
 	$self->StyleSetFont( &Wx::wxSTC_STYLE_DEFAULT, $wx_font ) if $wx_font->Ok > 0;
 }
 
-sub focus {  Wx::Window::SetFocus( $_[0] ) }
+sub focus {  Kephra::API::focus( $_[0] ) }
 
 sub set_perlhighlight {
 	my ($self) = @_;

File lib/Kephra/App/Panel.pm

View file
 		border => 0,
 	);
 	if (ref $item_def eq ref {}) {
-		die __PACKAGE__."::_insert got no proper item definition"
+		die __PACKAGE__."::_insert got no proper widget, but ", $item_def->{'widget'}
 			unless $is_widget->( $item_def->{'widget'} );
 
 		for (qw/proportion widget border/)
 			{ $item{$_} = $item_def->{$_} if exists $item_def->{$_} }
 	} elsif (ref $item_def eq ref \$item_def ) {
-		die __PACKAGE__."::_insert got no proper item definition"
+		die __PACKAGE__."::_insert got no proper widget, but ", $$item_def
 			unless $is_widget->($$item_def);
 
 		$item {'widget'} = $$item_def;
 		$item {'proportion'} = 1;
 	} else {
-		die __PACKAGE__."::_insert got no proper item definition"
+		die __PACKAGE__."::_insert got no proper widget, but ", $item_def
 			unless $is_widget->($item_def);
 
 		$item {'widget'} = $item_def;

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

View file
 	return $self;
 }
 
-sub focus{ Wx::Window::SetFocus( $panel ) }
+sub focus{ Kephra::API::focus( $panel ) }
 
 sub get_modules_and_paths {
 	my $dir = shift;

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

View file
 
 package Kephra::App::Panel::IOUnit;
 our @ISA = 'Wx::Panel';
-my $_ref;
+our $_ref;
 
 sub new {
 	my( $class, $parent) = @_;
 	my $self = $_ref = $class->SUPER::new($parent, -1);
 	$self->{'input'} = my $input = Wx::TextCtrl->new
 		($self, -1, '', [-1,-1], [-1, -1], &Wx::wxTE_PROCESS_ENTER );
-	$self->{'output_book'} = my $output_book = Wx::AuiNotebook->new (
-		$self, -1, [-1,-1], [-1, -1],
-		&Wx::wxAUI_NB_TOP | &Wx::wxAUI_NB_TAB_MOVE
+	$self->{'output_book'} = my $output_book = Wx::Notebook->new (
+		$self, -1, [-1,-1], [-1, -1], &Wx::wxNB_TOP
 	);
 	$self->{'output_slots'} = {};
 	$self->{'master_slot_name'} = 'all';
 	$self->{'active_slot_name'} = 'drum';
 	$self->{'process'} = '';
 
+	Wx::Event::EVT_SET_FOCUS($output_book, \&focus);
 	$self->create_slot($_)
 		for ($self->{'master_slot_name'}, qw/drum perl shell output log/);
-	my $active_slot = $self->{'output_slots'}{ $self->{'active_slot_name'} };
-	$output_book->SetSelection( $output_book->GetPageIndex( $active_slot ) );
+	$self->raise_slot( $self->{'active_slot_name'} );
 
-	Wx::Event::EVT_AUINOTEBOOK_BEGIN_DRAG  ( $output_book, -1, sub { });
-	Wx::Event::EVT_AUINOTEBOOK_END_DRAG    ( $output_book, -1, sub { });
-	Wx::Event::EVT_AUINOTEBOOK_PAGE_CHANGED( $output_book, -1, sub {
+	Wx::Event::EVT_NOTEBOOK_PAGE_CHANGED( $output_book, -1, sub {
 		my ($nb, $event ) = @_;
 		$self->{'active_slot_name'} = $nb->GetPageText( $event->GetSelection );
 	});
 				   or $active_name eq 'perl'
 				   or $active_name eq 'shell'
 				   or $active_name eq 'output';
-		output_line('log',"$active_name command $cmd");
+		$self->output_line('log',"$active_name command $cmd");
 		my $outxt = $self->{'output_slots'}{ $active_name };
 		if    ($active_name eq 'drum')  { 
 		}
-		elsif ($active_name eq 'perl')  { output_line ('perl',  "\"$cmd\" => \"".eval($cmd) . '"' ) }
+		elsif ($active_name eq 'perl')  { 
+			$self->output_line ('perl',  "\"$cmd\" => \"".eval($cmd) . '"' ) 
+		}
 		elsif ($active_name eq 'shell') { 
 			$self->{'process'} = Wx::Perl::ProcessStream->OpenProcess
 				(qq~bash "$cmd"~ , __PACKAGE__, $self->{'output_slots'}{'shell'});
 		$self->{'output_slots'}{'shell'}, sub {
 			my ($txt, $event) = @_;
 			$event->Skip(1);
-			output_line('shell', $event->GetLine );
+			$self->output_line('shell', $event->GetLine );
 	} );
 
 	Wx::Event::EVT_KEY_DOWN ($input, sub {
 	my $pos = $self->{'output_book'}->GetPageCount;
 	$pos-- if $pos;
 	$self->{'output_book'}->InsertPage ( $pos, $slot, $slot_name, 0 );
-	Wx::Event::EVT_SET_FOCUS($slot, \&focus);
+	Wx::Event::EVT_SET_FOCUS($slot, sub{ Kephra::API::focus( $self->{'input'} ) });
 }
 
 sub output {
-	my ($slot_name, $msg) = @_;
-	my $self = $_ref;
+	my ($self, $slot_name, $msg, $raise) = @_;
 	return unless defined $self->{'output_slots'}{ $slot_name };
 	my $slot = $self->{'output_slots'}{ $slot_name };
 	my $stamped_msg = timestamp() . ' ' . $msg;
 		$slot->AppendText("\n") if $slot->GetValue;
 		$slot->AppendText($stamped_msg);
 	}
-	else                     {$slot->AppendText($msg)}
+	else                     { $slot->AppendText($msg) }
 	$slot->ShowPosition( $slot->GetCaretPosition );
 	unless ($slot_name eq $self->{'master_slot_name'}) {
 		my $masterslot =  $self->{'output_slots'}{ $self->{'master_slot_name'} };
 		$masterslot->AppendText("<$slot_name> $stamped_msg");
 		$masterslot->ShowPosition( $masterslot->GetCaretPosition);
 	}
+	$self->raise_slot($slot_name) if $raise;
 }
-sub output_string { output(@_) }
+sub output_string { $_[0]->output(@_) }
 sub output_line {
-	my ($slot_name, $msg) = @_;
-	my $self = $_ref;
+	my ($self, $slot_name, $msg) = @_;
 	return unless defined $self->{'output_slots'}{ $slot_name };
 	my $slot = $self->{'output_slots'}{ $slot_name };
 	my ($x, $y) = $slot->GetLastPosition;
 	$slot->AppendText("\n")
 		if ($slot_name ne 'log' and $slot_name ne $self->{'master_slot_name'})
 		and $slot->GetValue     and $x > 0;
-	output(@_);
+	$self->output(@_);
 }
-sub output_on_clear_and_activate {
-	my ($slot_name, $msg) = @_;
-	my $self = $_ref;
+sub output_on_clear_and_raised {
+	my ($self, $slot_name, $msg) = @_;
 	return unless defined $self->{'output_slots'}{ $slot_name };
-	my $slot = $self->{'output_slots'}{ $slot_name };
-	$self->{'output_book'}->SetSelection( $self->{'output_book'}->GetPageIndex($slot) );
-	$slot->Clear;
-	output(@_);
+	$self->raise_slot($slot_name);
+	$self->{'output_slots'}{ $slot_name }->Clear;
+	$self->output(@_);
 }
 
+sub raise_slot {
+	my ($self, $slot_name) = @_;
+	return unless defined $self->{'output_slots'}{ $slot_name };
+	my $nb = $self->{'output_book'};
+	my $page = $self->{'output_slots'}{ $slot_name };
+	for (0 .. $nb->GetPageCount-1) {
+		$nb->ChangeSelection( $_ ),last if $nb->GetPage($_) eq $page;
+	}
+	Kephra::API::focus_back();
+}
+sub focus { Kephra::API::focus( $_ref->{'input'} ) }
+
+sub get_line  {}
+sub get_click {}
 
 sub timestamp { sprintf("[%02u:%02u:%02u]", (localtime)[2,1,0]) }
-sub focus { Wx::Window::SetFocus( $_ref->{'input'} ) }
 
 1;

File lib/Kephra/App/Util.pm

View file
 	else          { return $method_ref[0] }
 }
 
-sub is_object { ( ref $_[0] and index(ref $_[0], '=') == -1) ? 1 : 0 }
-sub is_widget { ( is_object( $_[0] ) and $_[0]->isa('Wx::Control') ) ? 1 : 0 }
-sub is_panel  {
-	($_[0] and ref $_[0] and 
-	 ($_[0]->isa('Wx::Panel') or $_[0]->isa('Kephra::App::Panel') )) ? 1 : 0
+sub is_object { return 1 if ref $_[0] and index($_[0], '=') > -1 }
+sub is_widget { return 1 if is_object( $_[0] ) and $_[0]->isa('Wx::Control') }
+sub is_panel  { return 1 if is_object( $_[0] )
+			and ($_[0]->isa('Wx::Panel') or $_[0]->isa('Kephra::App::Panel') )
 }
 sub is_sizer  { ( is_object( $_[0] ) and $_[0]->isa('Wx::Sizer') ) ? 1 : 0 }
 sub is_color  { ( is_object( $_[0] ) and $_[0]->isa('Wx::Colour') and $_[0]->IsOk ) ? 1 : 0 }

File lib/Kephra/App/Window.pm

View file
 	);
 }
 
+sub get_focus { $_[0]->{'focus'} }
+sub set_focus {
+	my ($self, $widget) = @_;
+	die __PACKAGE__."::set_focus got no proper widget ($widget) from ", (caller)[0]
+		unless Kephra::App::Util::is_widget($widget);
+	$self->{'old_focus'} = $self->{'focus'};
+	$self->{'focus'} = $widget;
+	Wx::Window::SetFocus( $self->{'focus'} );
+}
+sub set_focus_back {
+	my ($self) = @_;
+	($self->{'old_focus'}, $self->{'focus'}) = ($self->{'focus'} , $self->{'old_focus'});
+	Wx::Window::SetFocus( $self->{'focus'} ) if $self->{'focus'};
+}
+
 1;
 
 __END__

File lib/Kephra/Document.pm

View file
 sub assign_file {
 	my ($self, $file_path) = @_;
 	return unless defined $file_path;
-	$file_path = Kephra::File::normalize_name($file_path);
-	$self->file_path($file_path);
-	my @path_parts = File::Spec->splitpath( $_[0]->file_path );
-	$self->file_dir( $path_parts[1] );
-	$self->file_name( $path_parts[2] );
+	if ($file_path){
+		$file_path = Kephra::File::normalize_name($file_path);
+		$self->file_path($file_path);
+		my @path_parts = File::Spec->splitpath( $_[0]->file_path );
+		$self->file_dir( $path_parts[1] );
+		$self->file_name( $path_parts[2] );
+	} else {
+		$self->file_path('');
+		$self->file_dir('');
+		$self->file_name('');
+	}
 	$self;
 }
 sub insert_before_caret {}

File lib/Kephra/DocumentStash.pm

View file
 }
 sub add {            # silently
 	my $doc = shift;
-	warn "Kephra::DocumentStash::add: add to me only docs, not $doc!"
+	warn __PACKAGE__."::add: add to me only docs, not $doc!"
 		unless $doc->isa('Kephra::Document');
 	$document{$doc->editor} = $doc;
 }
 sub del {
 	my $doc = shift;
-	warn "Kephra::DocumentStash::del: add to me only docs, not $doc!" 
+	warn __PACKAGE__."::del: add to me only docs, not $doc!" 
 		unless $doc->isa('Kephra::Document');
 	warn "DocStash:del: $doc was not in the stash!" unless $document{$doc->editor};
 	delete $document{$doc->editor};
 
 sub doc_by_anything {
 	my $any = shift;
-	warn "Kephra::DocumentStash::get_by_anything: need a parameter!" unless $any;
+	warn __PACKAGE__."::get_by_anything: need a parameter!" unless $any;
 	return ref($any) eq ''                      ? doc_by_path ($any)
 			 : $any->isa('Wx::Panel')           ? doc_by_panel($any)
 			 : $any->isa('Kephra::App::Editor') ? doc_by_ed   ($any)
 }
 sub doc_by_ed {
 	my $ed = shift;
-	warn "Kephra::DocumentStash::get_by_ed needs a Kephra::App::Editor, not $ed!"
+	warn __PACKAGE__."::get_by_ed needs a Kephra::App::Editor, not $ed!"
 		unless $ed->isa('Kephra::App::Editor');
 	return $document{$ed};
 }

File lib/Kephra/Edit.pm

View file
 package Kephra::App::Editor;
 
 
-sub move_sel_or_word_left {
-}
-sub move_sel_or_word_right {
+sub move_sel_or_word_left  { $_[0]->move_sel_or_word(-1) }
+sub move_sel_or_word_right { $_[0]->move_sel_or_word(+1) }
+sub move_sel_or_word {
+	my ($self, $movement) = @_;
+	my ($start, $end) = $self->GetSelection;
+	Kephra::API::log("$start, $end", 1);
 }
 sub move_sel_or_line_up      { $_[0]->move_sel_or_line(-1) }
 sub move_sel_or_line_down    { $_[0]->move_sel_or_line(+1) }
 	my $line_sel = [ $self->LineFromPosition($start), $self->LineFromPosition($end) ];
 	my $last_line = $self->LineFromPosition( $self->GetLength );
 	return if $line_sel->[0] == 0 and $movement < 0;
-#print "before move:$movement ",,"  mode: \n"; 
 	# move inside document borders
 	$movement = $line_sel->[0]              
 		if $movement < 0 and $line_sel->[0]+$movement < 0;