Commits

Herbert Breunung  committed 6c95f3a

editors are now mounted in docstash

  • Participants
  • Parent commits 540c1bd
  • Branches sp2

Comments (0)

Files changed (5)

File lib/ded/Kephra/App/DocBar.pm

 }
 
 sub add_page {
-	my ($self, $new_page, $title, $position, $set_active) = @_;
-	# put a proper panel under an editor widget
-	#$new_page = Kephra::App::Panel->new($self, \$new_page) if is_editor($new_page);
-	return warning( "got no panel or editor", 1 ) until is_panel($new_page) or is_editor($new_page);
+	my ($self, $new_page, $title, $position, $raise_focus) = @_;
+	return warning( "DocBar pages need to be Kephra::App::Panel", 1 ) until is_panel($new_page);
 	my $active_pos = $self->GetSelection;
 
 	$title    = ''                           unless defined $title;
 	$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 = 0                          unless defined $set_active;
+	$raise_focus = 0                         unless defined $raise_focus;
 
 	$new_page->Reparent($self);
-	$self->InsertPage( $position, $new_page, $title, $set_active);
-	#$self->set_page_title( $title, $new_page );
+	$self->InsertPage( $position, $new_page, $title, $raise_focus);
+	$self->set_page_title( $title, $new_page );
 	Kephra::API::app_window()->refresh_title();
-	focus($new_page) if $set_active;
+	focus($new_page) if $raise_focus;
 
 	# inserting new index to position translators
 	for   (@{$self->{'visual_page_order'}}){ $_++ if $_ >= $position }
 	return unless $self->valid_page_pos( $position );
 	# if just selecting the currrent, only tab drives focus nuts
 	$self->SetSelection( $position ) unless $position == $self->GetSelection;
-	my $ed = $self->GetPage($position);
-	Kephra::DocumentStash::set_active_ed( $ed );
-	focus ( $ed );
+	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();
 }
 
 	Wx::Event::EVT_AUINOTEBOOK_PAGE_CHANGED( $self, -1, sub {
 		my ($bar, $event ) = @_;
 		my $new_page = $bar->GetPage( $event->GetSelection );
-		Kephra::DocumentStash::set_active_ed( $new_page );
+		my $doc = Kephra::DocumentStash::set_active_doc_by_panel( $new_page );
+		focus ( $doc->{'active_editor'} );
 		Kephra::API::app_window()->refresh_title();
-		focus( $new_page );
 		$event->Skip;
 	});
 	Wx::Event::EVT_AUINOTEBOOK_PAGE_CLOSE( $self, -1, sub {

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

 	my ($self) = @_;
 	$self->{'doc_bar'}[$self->{'active'}];
 }
+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;
 	error('call me only from Main WIndow') if ( caller(0) )[0] ne 'Kephra::App::Window';
 	$parent = Kephra::API::app_window() unless defined $parent;
 	my $self = $class->SUPER::new( $parent );
+	$self->{'active'} = 0;
 	$bar_nr = 4 if (looks_like_number($bar_nr) and $bar_nr > 4);
 	$bar_nr = 1 if (looks_like_number($bar_nr) and $bar_nr < 1);
-	$self->{'number'} = 2;
-	$self->{'active'} = 0;
+	$self->{'number'} = $bar_nr;
 	$self->{'doc_bar'}[$_] = Kephra::App::DocBar->new( $self ) for 0..$self->{'number'}-1;
 
-	$self->{'splitter'}[0] = Kephra::App::Splitter->new({
-		parent => $self, 'left' => $self->{'doc_bar'}[0] , 'right' => $self->{'doc_bar'}[1] 
-	});
-
 	if      ($bar_nr == 1){
+		$self->{'splitter'}[0] = Kephra::App::Splitter->new({
+			parent => $self, 
+			'left' => $self->{'doc_bar'}[0],
+		});
 	} elsif ($bar_nr == 2){
+		$self->{'splitter'}[0] = Kephra::App::Splitter->new({
+			parent => $self, 
+			'left' => $self->{'doc_bar'}[0],
+			'right'=> $self->{'doc_bar'}[1] 
+		});
 	} elsif ($bar_nr == 3){
+		$self->{'splitter'}[1] = Kephra::App::Splitter->new({
+			parent => $self, 
+			'up' => $self->{'doc_bar'}[1],
+			'down'=> $self->{'doc_bar'}[2] 
+		});
+		$self->{'splitter'}[0] = Kephra::App::Splitter->new({
+			parent => $self, 
+			'left' => $self->{'doc_bar'}[0],
+			'down'=> $self->{'splitter'}[1] 
+		});
 	} elsif ($bar_nr == 4){
+		$self->{'splitter'}[1] = Kephra::App::Splitter->new({
+			parent => $self, 
+			'up' => $self->{'doc_bar'}[0],
+			'down'=> $self->{'doc_bar'}[1] 
+		});
+		$self->{'splitter'}[2] = Kephra::App::Splitter->new({
+			parent => $self, 
+			'up' => $self->{'doc_bar'}[2],
+			'down'=> $self->{'doc_bar'}[3] 
+		});
+		$self->{'splitter'}[0] = Kephra::App::Splitter->new({
+			parent => $self, 
+			'down'=> $self->{'splitter'}[1],
+			'down'=> $self->{'splitter'}[2]
+		});
 	}
 	$self->append(\$self->{'splitter'}[0]);
 

File lib/ded/Kephra/Document.pm

 
 my $max_title_width = 22;
 
-sub new {
+sub new {                                                 # blank doc object
 	my ($class, $file) = @_;
 	error('call me only from DocumentStash') if ( caller(0) )[0] ne 'Kephra::DocumentStash';
 	my $self = bless ({ }, $class);
-	$self->{'editor'} = Kephra::App::Editor->new();
-	if (defined $file){ $self->load_file($file) }
-	else              { $self->{'title'} = Kephra::DocumentStash::get_anon_title() }
-
 	return $self;
 }
 
 	my $self = shift;
 }
 
-sub saved { not shift->{'editor'}->GetModify()}
+sub saved { not shift->{'active_editor'}->GetModify()}
+
+sub DESTROY {
+	my $self = shift;
+}
 
 1;
 

File 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);
+use Kephra::API qw(:log is_document doc_panel doc_bar);
 use Kephra::Document;
 
 my %document;   # backref: doc attr => doc
 my @queue;      # order of alst usage
-my $lowest_free_anon_NR = 1; # for untiteled docs
-
+my $lowest_free_anon_NR = 1; # for untitled docs
+my $max_title_width = 22;
 
 sub active_doc    { $queue[0] }
-sub active_editor { $queue[0]->{'editor'} }
+sub active_editor { $queue[0]->{'active_editor'} }
+sub active_panel  { $queue[0]->{'panel'}{ doc_bar()} }
 sub previous_doc  { $queue[1] }
 sub all_docs      { @queue }
 sub doc_count     { scalar @queue }
-sub set_active {
+sub set_active_doc {
 	my $doc = shift;
 	return unless is_document($doc);
 	for (0 .. $#queue){ splice (@queue, $_, 1) if exists $queue[$_] and $queue[$_] eq $doc }
 	unshift @queue, $doc;
 }
-sub set_active_by_panel {
+sub set_active_doc_by_panel {
 	my $panel = shift;
+	my $doc = find_doc_by('panel', $panel);
+	return unless $doc;
+	my $bar = $panel->GetParent;
+	doc_panel->set_active_bar($bar) unless $bar eq doc_bar();
+	$doc->{'active_editor'} = $doc->{'editor'}{ $bar };
+	set_active_doc($doc);
+	return $doc;
 }
 
-sub set_active_ed { set_active( find_doc_by('editor', shift) ) }
 sub find_doc_by   {
 	my ($criterion, $selector) = @_;
 	return $document{$criterion}{$selector};
 
 #
 sub create_doc {
-	my $doc = Kephra::Document->new(@_);
-	#$doc->{'pos'} = 0;
-	set_active($doc);
-	$document{'editor'}{$doc->{'editor'}} = $doc;
+	my $file_path = shift;
+	my $doc = Kephra::Document->new();
 
-	doc_panel()->add_doc( $doc );
+	if (defined $file_path and -r $file_path){
+		$doc->{'file_path'} = $file_path;
+		my @path_parts = File::Spec->splitpath( $file_path );
+		$doc->{'file_dir'} = $path_parts[1];
+		$doc->{'file_name'} = $path_parts[2];
+		my $title = $doc->{'file_name'};
+		$title = substr( $title, 0, $max_title_width - 2 ) . '..'
+			if length($title) > $max_title_width and $max_title_width > 7;
+		$doc->{'title'} = $title;
+	} else {
+		$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}->SetDocPointer( $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() };
+
+	if (defined $file_path and -r $file_path){
+		my ($content, $encoding) = Kephra::IO::LocalFile::read( $file_path );
+		$doc->{'active_editor'}->reset( $content );
+		$doc->{'encoding'} = $encoding;
+	}
+
+	set_active_doc($doc);
 	return $doc;
 }
 
 	delete $document{$_}{$doc->{$_}} for qw(editor file_path);
 	delete $document{'panel'}{$_} for values %{$doc->{'panel'}};
 	doc_panel()->remove_doc( $doc );
+	$doc->DESTROY;
 }
 
 sub get_anon_title { 'untitled ' . $lowest_free_anon_NR++ }

File lib/ded/Kephra/File.pm

 
 sub save {
 	my $doc = Kephra::API::document();
-	Kephra::IO::LocalFile::write( $doc->{'file_path'}, $doc->{'encoding'}, $doc->{'editor'}->GetText() );
-	$doc->{'editor'}->SetSavePoint;
+	#Kephra::IO::LocalFile::write( $doc->{'file_path'}, $doc->{'encoding'}, $doc->{'active_editor'}->GetText() );
+say $doc->{'file_path'};
+	$doc->{'active_editor'}->SetSavePoint;
 }
 
 sub close {