Commits

Herbert Breunung committed cd3dce8

starting open heart surgery aka sp branch

Comments (0)

Files changed (10)

lib/Kephra/App.pm

 	Kephra::CommandList::init();
 
 	my $win = Kephra::App::Window->new(__PACKAGE__);
+
 	Kephra::File::new();
 
 	$win->Center();

lib/Kephra/App/Bar/Document.pm

+use v5.10;
 use strict;
 use warnings;
 use Wx;
 		$event->Veto;
 		Kephra::File::close_active();
 	});
+	#Wx::Event::EVT_AUINOTEBOOK_PAGE_CHANGED(
+	#);
 	# keep focus on editor even when klicking on tab bar
 	#Wx::Event::EVT_LEFT_DOWN($self, sub { Kephra::API::active_editor()->focus; print "--"; });
 	#$self->Connect( -1, -1, &Wx::wxEVT_SET_FOCUS, sub {  print "--"; } )
 }
 
 sub add_page {
-	my ($self, $label, $position, $set_active, $panel_candidate ) = @_;
-	return unless $panel_candidate 
-		and ($is_panel->($panel_candidate) or $is_widget->($panel_candidate) or
-		     $panel_candidate->isa('Kephra::Document')
-	);
-	my $new_panel = $panel_candidate->isa('Kephra::Document')
-		? $panel_candidate->editor
-		: $panel_candidate;
+	my ($self, $new_page, $label, $position) = @_;
+	return unless $new_page and ($is_panel->($new_page) or $is_widget->($new_page));
 	my $active_pos = $self->GetSelection;
 
 	$label    = ''                           unless defined $label;
 	$position = $active_pos + 1              if $position eq 'right';
 	$position = $active_pos                  if $position eq 'left';
 	$position = $self->leftmost_page_pos     if $position eq 'leftmost';
-	$set_active = 1                          unless defined $set_active;
+	#$set_active = 1                          unless defined $set_active;
 
-	unless ($new_panel->isa('Wx::Panel')) { # put panel under a none-panel
-		$new_panel = Kephra::App::Panel->new( $self, $new_panel);# if ($position == 0 or $label);
-		#$new_panel->Reparent( $self )
+	# put panel under a none-panel
+	unless ($new_page->isa('Wx::Panel')) {
+		my $widget = $new_page;
+		$new_page = Kephra::App::Panel->new( $self, $widget);# if ($position == 0 or $label);
+		# document property: panel the editor sits on has to be set before EVT_AUINOTEBOOK_PAGE_CHANGED
+		Kephra::DocumentStash::doc_by_ed( $widget )->panel( $new_page ) if $widget->isa('Kephra::Editor'); # and ($position == 0 or $label);
 	}
-	else { $new_panel->Reparent( $self ) }
+	else { $new_page->Reparent( $self ) }
 
-
-	# document property: panel the editor sits on has to be set before EVT_AUINOTEBOOK_PAGE_CHANGED 
-	$panel_candidate->panel( $new_panel ) if $panel_candidate->isa('Kephra::Document');# and ($position == 0 or $label);
-
-	$self->InsertPage( $position, $new_panel, '', $set_active );# if $position == 0 or $label;
-	$self->set_page_title( $label, $new_panel);
-	Wx::Window::SetFocus( $new_panel ) if $set_active;
+print Kephra::API::document(), " $new_page ttttt\n";
+print print Kephra::DocumentStash::active_doc(), " ttttt\n";
+	$self->InsertPage( $position, $new_page, '');# if $position == 0 or $label; # last parameter sets new pace as active
+print Kephra::API::document(), " ttttt\n";
+	$self->set_page_title( $label, $new_page );
 
 	# inserting new index to position translators
 	for   (@{$self->{'visual_page_order'}}){ $_++ if $_ >= $position }
 	splice @{$self->{'visual_page_order'}},  $position, 0, $position;
 	$self->refresh_internal_page_order();
 
-	return $position;
+	return $new_page;
 }
 
 sub remove_page {
 
 sub select_page_left  { 
 	my ($self) = @_;
-	$self->SetSelection( $self->next_page_pos_rot_left( $self->GetSelection ) );
+	$self->raise_page( $self->next_page_pos_rot_left( $self->GetSelection ) );
 }
 sub select_page_right { 
 	my ($self) = @_;
-	$self->SetSelection( $self->next_page_pos_rot_right( $self->GetSelection ) );
+	$self->raise_page( $self->next_page_pos_rot_right( $self->GetSelection ) );
 }
-sub select_page_leftmost  { $_[0]->SetSelection( $_[0]->leftmost_page_pos ) }
-sub select_page_rightmost { $_[0]->SetSelection( $_[0]->rightmost_page_pos ) }
+sub select_page_leftmost  { $_[0]->raise_page( $_[0]->leftmost_page_pos ) }
+sub select_page_rightmost { $_[0]->raise_page( $_[0]->rightmost_page_pos ) }
 
 sub leftmost_page_pos { 0 }
 sub rightmost_page_pos { $_[0]->GetPageCount-1 }
 }
 
 sub raise_page {
-	my ($self, $page) = @_;
-	$self->SetSelection( $self->GetPageIndex($page) );
+	my ($self, $iop) = @_; # can be Index Or Page (panel reference)
+	my $index = int $iop eq $iop ? $iop : $self->GetPageIndex($iop);
+	return if $index < 0 or $index > $self->rightmost_page_pos;
+	$self->SetSelection( $index );
+	my $page = $self->GetPage($index);
+	print $page->GetChildren,"||\n";
+	#if ($page)
+	#Kephra::DocumentStash::doc_by_panel( $page );
+	#Kephra::App::Focus::set($page);
 }
 
 sub set_page_title {
 
 sub refresh_page_title {
 	my $self = shift;
-	my $doc = shift || Kephra::API::document();
+print "$_[1]--------\n";
+	my $doc = shift // Kephra::API::document();
+print Kephra::API::document(), "$doc--------\n";
 	my $unsaved_mark = '*';
 	my $position = $self->GetSelection;
 	my $label = $self->GetPageText( $position);
 }
 
 1;
+

lib/Kephra/App/Editor.pm

 	});
 	#Wx::Event::EVT_RIGHT_DOWN
 	#Wx::Event::EVT_STC_UPDATEUI
-	Wx::Event::EVT_STC_SAVEPOINTREACHED($self, -1, sub {
-		Kephra::API::docbar()->refresh_page_title();
-	});
-	Wx::Event::EVT_STC_SAVEPOINTLEFT($self, -1, sub {
-		Kephra::API::docbar()->refresh_page_title();
-	});
+	Wx::Event::EVT_STC_SAVEPOINTREACHED
+		($self, -1, sub { Kephra::API::docbar()->refresh_page_title() });
+	Wx::Event::EVT_STC_SAVEPOINTLEFT
+		($self, -1, sub { Kephra::API::docbar()->refresh_page_title() });
 	#Wx::Event::EVT_DROP_FILES       ($ep, sub{});
 	#Wx::Event::EVT_STC_START_DRAG   ($ep, -1, sub {
 	#Wx::Event::EVT_STC_DRAG_OVER    ($ep, -1, sub { $droppos = $_[1]->GetPosition });

lib/Kephra/App/Editor/TextDropTarget.pm

 use warnings;
 
 use Wx;
+use Wx::DND;
 
 package Kephra::App::Editor::TextDropTarget;
 use base 'Wx::TextDropTarget';

lib/Kephra/App/Focus.pm

 
 sub set {
 	my ($widget) = @_;
-	#print scalar @focus_stack, " $widget --\n";
+	print scalar @focus_stack, " $widget --\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();
 	unshift @focus_stack, $widget;
 	stay();
 }

lib/Kephra/App/Part/Editor.pm

 	my $main_doc_bar = active_docbar();
 
 	if ($doc and $doc->editor->is_empty and $file) { # overwrite empty doc
-		$doc->assign_file_name($file);
+		$doc->assign_file_path($file);
 		$main_doc_bar->set_page_title( $doc->file_name );
 	} else {                                         # make new editor
 		$doc = Kephra::Document->new();
-		$doc->assign_file_name( $file );
+		$doc->assign_file_path( $file );
 		$doc->editor( Kephra::App::Editor->new( $win ) );
 		Kephra::DocumentStash::add_and_activate( $doc );
-		$main_doc_bar->add_page( $doc->file_name, -1, 1, $doc);
+print Kephra::API::document(), " || $doc\n";
+		$main_doc_bar->add_page($doc->editor, $doc->file_name, -1, 1);
+print Kephra::API::document(), " || $doc\n";
+		Kephra::API::focus( $doc->editor );
+print Kephra::API::document(), " || $doc\n";
+
 	}
-	$doc->editor->focus();
 	$win->refresh_title();
 
 	return $doc;

lib/Kephra/App/Util.pm

 
 package Kephra::App::Util;
 
+# export a helper function into a coderef
 sub get {
 	my ($ref, @method_ref);
 	die unless @_;
 	for my $subname (@_){
 		eval { $ref = \&{__PACKAGE__ . "::$subname"} };
-		if ($@) { die "__PACKAGE__::get : no $subname sub in this Module." }
+		if ($@) { Kephra::Log::error( "no $subname sub in this Module.") }
 		else    { push @method_ref, $ref }
 	}
 	if (wantarray){ return @method_ref }
 
 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::Window') }
-sub is_panel  { return 1 if is_object( $_[0] )
-			and ($_[0]->isa('Wx::Panel') or $_[0]->isa('Kephra::App::Panel') )
-}
+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 }
 

lib/Kephra/Document.pm

 has folded_lines => ( is  => 'rw', );
 has marked_lines => ( is  => 'rw', );
 
-sub assign_file_name {
+sub assign_file_path {
 	my ($self, $file_path) = @_;
 	return unless defined $file_path and -e $file_path;
 	if ($file_path){

lib/Kephra/DocumentStash.pm

 use warnings;
 
 use Kephra::CommandList;
+use Kephra::Document;
 
 package Kephra::DocumentStash;
 
 my $active;
 my $previous;
 
-my %side_buffer;
-
 sub previous_doc  { $previous }
 sub active_doc    { $active }
 sub active_editor { $active->editor }
 	my $panel = shift;
 	Kephra::Log::warning("needs a Wx::Panel, not $panel!") unless $panel->isa('Wx::Panel');
 	for my $ed (keys %document) {
-		return $document{$ed} if $document{$ed}->panel eq $panel;
+		return $document{$ed} if $document{$ed}->panel and $document{$ed}->panel eq $panel;
 	}
 }
 sub doc_by_path {
 }
 sub all_doc { values %document }
 
-
 sub dump_all_ed { print "$_ + \n" for keys %document }
 
 sub file_loaded {

lib/Kephra/File.pm

 	my $file = normalize_name( Kephra::App::Dialog::get_file_save() );
 	return unless $file;
 	_store_under_filename($doc, $file);
-	$doc->assign_file_name($file);
+	$doc->assign_file_path($file);
 	Kephra::API::docbar()->set_page_title( $doc->file_name);
 	Kephra::API::main_window()->refresh_title();
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.