Kephra / lib / Kephra / Document.pm

Diff from to

lib/Kephra/Document.pm

 
 package Kephra::Document;
 use Moo; 
+use Scalar::Util qw(blessed);
+
 my $max_title_width = 15;
 
 # export SUB_QUOTE_DEBUG=1
 
 
-has ID     => ( is  => 'rwp' );                             # API::Docs ID
+has ID     => ( is  => 'rwp' );                             # API::Doc ID
 has title  => ( is  => 'rwp' );                             # shown as tab label
 has editor => ( is  => 'ro' );
 has panel  => ( is  => 'ro' );
 		my $self = shift;
 		return if $self->old_file_path and $self->file_path
 				and $self->old_file_path eq $self->file_path;
-		Kephra::API::Docs::rename_file($self) if $self->ID;
+		Kephra::API::Doc::rename_file($self) if $self->ID;
 
 		if ($self->file_path) {
 			my @path_parts = File::Spec->splitpath( $self->file_path );
 
 sub BUILD    {
 	my $self = shift;
-	$self->_set_ID( Kephra::API::Docs::add($self) );
+	$self->_set_ID( Kephra::API::Doc::add($self) );
 	$self->_set_title('<untitled '.$self->anon_NR.'>') unless $self->file_path;
 }
-sub DEMOLISH { Kephra::API::Docs::remove($_[0]); #say "demolish $_[0]"; 
+sub DEMOLISH { Kephra::API::Doc::remove($_[0]); #say "demolish $_[0]"; 
 }
 
+sub add_instance {
+	my ($self, $bar) = @_;
+	return Kephra::Log::warning("need an existing Kephra::App::Bar::Document instance")
+		unless blessed($bar) eq 'Kephra::App::Bar::Document';
+
+	my @editor = values $self->editor;
+	my $panel = $self->panel->{$bar} = Kephra::App::Panel->new( $bar );
+	my $ed = $self->editor->{$bar} = Kephra::App::Editor->new( $panel );
+	$panel->append( \$ed );
+	$ed->SetDocPointer( $editor[0]->GetDocPointer() ) if @editor;
+	Kephra::API::Doc::add_instance($self, $bar);
+}
+
+sub del_instance {
+	my ($self, $bar) = @_;
+	return Kephra::Log::warning("need an existing Kephra::App::Bar::Document instance")
+		unless blessed($bar) eq 'Kephra::App::Bar::Document'
+		and exists $self->panel->{$bar};
+	Kephra::API::Doc::remove_instance($self, $bar);
+	$bar->remove_page( $self->panel->{$bar} );
+	delete $self->panel->{$bar};
+	delete $self->editor->{$bar};
+}
 sub raise { Kephra::API::focus( shift->panel ) }
 sub insert_before_caret {}
 sub insert_after_caret {}
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.