Commits

Herbert Breunung committed dd713cf

at least remodeled to work more effective, still crashes on resplit

  • Participants
  • Parent commits 53bc6e2
  • Branches sp2

Comments (0)

Files changed (5)

lib/ded/Kephra/API.pm

     our @EXPORT_OK = qw( 
         app_window doc_panel doc_bar editor input output focus focus_back
         message warning error
-        output is_widget is_panel is_sizer is_color is_font is_editor is_document
+        is_widget is_panel is_sizer is_color is_font is_editor is_document is_doc_bar
     );
     our %EXPORT_TAGS = (log => [qw(message warning error)], 
-                        cmp => [qw(is_widget is_panel is_sizer is_color is_font is_editor is_document)],
+                        cmp => [qw(is_widget is_panel is_sizer is_color is_font is_editor is_document is_doc_bar)],
                         app => [qw(app_window doc_panel doc_bar editor input output)],
     );
     my %seen;                                                 # code for :all tag
 sub is_widget    {(blessed($_[0]) and $_[0]->isa('Wx::Window')              )  ? 1 : 0}
 sub is_editor    {(blessed($_[0]) and $_[0]->isa('Kephra::App::Editor')     )  ? 1 : 0}
 sub is_document  {(blessed($_[0]) and $_[0]->isa('Kephra::Document')        )  ? 1 : 0}
+sub is_doc_bar   {(blessed($_[0]) and $_[0]->isa('Kephra::App::DocBar')     )  ? 1 : 0}
 sub is_panel     {(blessed($_[0]) and $_[0]->isa('Wx::Panel')               )  ? 1 : 0}
 sub is_sizer     {(blessed($_[0]) and $_[0]->isa('Wx::Sizer')               )  ? 1 : 0}
 sub is_color     {(blessed($_[0]) and $_[0]->isa('Wx::Colour') and $_[0]->IsOk)? 1 : 0}

lib/ded/Kephra/App/DocBar.pm

 
 use Wx::AUI;
 use Scalar::Util qw(blessed looks_like_number);
-use Kephra::API  qw(:log :cmp focus);
+use Kephra::API  qw(:log :cmp focus app_window);
 use Kephra::App::Editor;
 
 my $max_title_width = 22;
 	$new_page->Reparent($self);
 	$self->InsertPage( $position, $new_page, $title, $raise_focus);
 	$self->set_page_title( $title, $new_page );
-	Kephra::API::app_window()->refresh_title();
+	app_window()->refresh_title();
 	focus($new_page) if $raise_focus;
 
 	# inserting new index to position translators
 	my $panel = $self->GetPage($position);
 	my $doc = Kephra::DocumentStash::set_active_doc_by_panel( $panel );
 	focus ( $doc->{'active_editor'} );
-	Kephra::API::app_window()->refresh_title();
+	app_window()->refresh_title();
 }
 
 sub move_page_position_visually {          # for dnd only
 		my $new_page = $bar->GetPage( $event->GetSelection );
 		my $doc = Kephra::DocumentStash::set_active_doc_by_panel( $new_page );
 		focus ( $doc->{'active_editor'} );
-		Kephra::API::app_window()->refresh_title();
+		app_window()->refresh_title();
 		$event->Skip;
 	});
 	Wx::Event::EVT_AUINOTEBOOK_PAGE_CLOSE( $self, -1, sub {
 	for (@$visual) {$_-- if $_ >= $internal_position}
 	$self->{'visual_page_order'} = $visual;
 	$self->refresh_internal_page_order;
+	$page->Reparent( app_window() );
 }
 
 sub remove_all_pages {

lib/ded/Kephra/App/Panel.pm

 sub detach {}
 sub show {}
 sub hide {}
-sub all_widgets {  }
-sub widget_by_nr { }
+sub all_widgets  {  }
+sub child_by_nr  { $_[0]->sizer->child_item($_[1]) }
 sub get_position { $_[0]->sizer->get_position($_[1]) }
 
 1;

lib/ded/Kephra/App/Part/Main.pm

 	my ($self) = @_;
 	$self->{'doc_bar'}[$self->{'active'}];
 }
+sub first_doc_bar { shift->{'doc_bar'}[0] }
+sub later_doc_bar {
+	my ($self) = @_;
+	@{$self->{'doc_bar'}}[1 .. $self->{'number'}-1];
+}
+sub all_doc_bar {
+	my ($self) = @_;
+	@{$self->{'doc_bar'}}[0 .. $self->{'number'}-1];
+}
+sub doc_bar_count { scalar @{shift->{'doc_bar'}} }
 sub set_active_bar {
 	my ($self, $bar) = @_;
 	for my $nr (0 .. $self->{'number'} - 1) {
 		$self->{'active'} = $nr if $bar eq $self->{'doc_bar'}[$nr];
 	}
 }
-sub doc_bar {
-	my ($self, $which) = @_;
-	return $self->{'doc_bar'}[0] unless defined $which;
-	$self->{'doc_bar'}[$which];
-}
-sub all_doc_bar { @{shift->{'doc_bar'}} }
-sub doc_bar_count { scalar @{shift->{'doc_bar'}} }
 
 
 sub new {

lib/ded/Kephra/DocumentStash.pm

 package Kephra::DocumentStash;
 
 use Scalar::Util qw(blessed looks_like_number weaken);
-use Kephra::API qw(:log is_document doc_panel doc_bar);
+use Kephra::API qw(:log doc_panel doc_bar is_doc_bar is_document);
 use Kephra::Document;
 
 my %document;   # backref: doc attr => doc
 my @queue;      # order of alst usage
 my $lowest_free_anon_NR = 1; # for untitled docs
 my $max_title_width = 22;
-my %used_doc_panels; # wih_sci_refs and without
+my %used_ed_panels = (with_sci_refs =>[], without_sci_refs =>[]);
 
 sub active_doc    { $queue[0] }
 sub active_editor { $queue[0]->{'active_editor'} }
 	set_active_doc($doc);
 	return $doc;
 }
-
-
 sub find_doc_by   {
 	my ($criterion, $selector) = @_;
 	return $document{$criterion}{$selector};
 		$doc->{'title'} = get_anon_title();
 	}
 
-	# create editor instances on all doc bars
-	my $ed_pointer; # scintilla doc reference
-	for my $doc_bar (doc_panel()->all_doc_bar()){
-		$doc->{'panel'}{$doc_bar} = Kephra::App::Panel->new($doc_bar);
-		$doc->{'editor'}{$doc_bar} = Kephra::App::Editor->new($doc->{'panel'}{$doc_bar});
-		$doc->{'panel'}{$doc_bar}->append_expanded($doc->{'editor'}{$doc_bar});
-		if (defined $ed_pointer) { $doc->{'editor'}{$doc_bar}->clone( $ed_pointer ) }
-		else      { $ed_pointer =  $doc->{'editor'}{$doc_bar}->GetDocPointer() }
-		$document{'panel'}{ $doc->{'panel'}{$doc_bar} } = $doc;
-		$document{'editor'}{ $doc->{'editor'}{$doc_bar} } = $doc;
-		$doc_bar->add_page( $doc->{'panel'}{$doc_bar}, $doc->{'title'}, -1, 0);
-	}
-	$doc->{'active_editor'} = $doc->{'editor'}{ doc_bar() };
+	add_editor_instance($doc, $_) for doc_panel()->all_doc_bar();
 
 	if (defined $file_path and -r $file_path){
 		my ($content, $encoding) = Kephra::IO::LocalFile::read( $file_path );
 	return $doc;
 }
 
+
+sub add_editor_instance {
+	my ($doc, $doc_bar) = @_;
+	return unless is_document($doc) and is_doc_bar($doc_bar);
+say "$doc, $doc_bar";
+	my ($ed, $panel);
+	if ($doc_bar eq doc_panel()->first_doc_bar()){ # first docbar has all the original sci docs
+		$panel = pop @{$used_ed_panels{'with_sci_refs'}};
+	} else {                                       # other docbars just hold the clones
+		$panel = pop @{$used_ed_panels{'without_sci_refs'}};
+	}
+	if ($panel){
+		$panel->Show(1);
+		$ed = $panel->child_by_nr(0);
+	} else {
+		$panel = Kephra::App::Panel->new($doc_bar);
+		$ed = Kephra::App::Editor->new($panel);
+		$panel->append_expanded($ed);
+	}
+	if ($doc_bar eq doc_panel()->first_doc_bar()){
+		$doc->{'active_editor'} = $ed;
+	} else {                                        
+		$ed->clone( $doc->{'active_editor'} );
+	}
+	$doc->{'panel'}{$doc_bar} = $panel;
+	$doc->{'editor'}{$doc_bar} = $ed;
+	$document{'panel'}{ $panel } = $doc;
+	$document{'editor'}{ $ed } = $doc;
+	$doc_bar->add_page( $doc->{'panel'}{$doc_bar}, $doc->{'title'}, -1, 0);
+}
+
+sub remove_editor_instance {
+	my ($doc, $doc_bar) = @_;
+	return unless is_document($doc) and is_doc_bar($doc_bar);
+
+	my $ed = $doc->{'editor'}{$doc_bar};
+	my $panel = $doc->{'panel'}{$doc_bar};
+
+	$doc_bar->remove_page( $panel );
+	$panel->Show(0);
+	delete $doc->{'editor'}{$doc_bar};
+	delete $doc->{'panel'}{$doc_bar};
+	delete $document{'editor'}{ $ed };
+	delete $document{'panel'}{ $panel };
+
+	if ($doc_bar eq doc_panel()->first_doc_bar()){ # first docbar has all the original sci docs
+		push @{$used_ed_panels{'with_sci_refs'}}, $panel;
+	} else {
+		$ed->unclone();
+		push @{$used_ed_panels{'without_sci_refs'}}, $panel;
+	}
+}
+
 sub add_doc_bar    {
 	my $doc_bar = shift;
-	for my $doc (all_docs()){
-		$doc->{'panel'}{$doc_bar} = Kephra::App::Panel->new($doc_bar);
-		$doc->{'editor'}{$doc_bar} = Kephra::App::Editor->new($doc->{'panel'}{$doc_bar});
-		$doc->{'panel'}{$doc_bar}->append_expanded($doc->{'editor'}{$doc_bar});
-say "bc ", $doc->{'active_editor'};
-say $doc->{'active_editor'}->GetDocPointer();
-		$doc->{'editor'}{$doc_bar}->clone( $doc->{'active_editor'} );
-#say "  $doc  $doc_bar ", $doc->{'panel'}{$doc_bar};
-		$document{'panel'}{ $doc->{'panel'}{$doc_bar} } = $doc;
-		$document{'editor'}{ $doc->{'editor'}{$doc_bar} } = $doc;
-		$doc_bar->add_page( $doc->{'panel'}{$doc_bar}, $doc->{'title'}, -1, 0);
-	}
+	return unless is_doc_bar($doc_bar);
+	add_editor_instance($_, $doc_bar) for all_docs();
 }
 sub remove_doc_bar {
 	my $doc_bar = shift;
-	for my $doc (all_docs()){
-		$doc_bar->remove_page( $doc->{'panel'}{$doc_bar} );
-		$doc->{'editor'}{$doc_bar}->Destroy();
-		$doc->{'panel'}{$doc_bar}->Destroy();
-		delete $document{'panel'}{ $doc->{'panel'}{$doc_bar} };
-		delete $document{'editor'}{ $doc->{'editor'}{$doc_bar} };
-		delete $doc->{'panel'}{$doc_bar};
-		delete $doc->{'editor'}{$doc_bar};
-	}
+	return unless is_doc_bar($doc_bar);
+	remove_editor_instance($_, $doc_bar) for all_docs();
 }