Source

Kephra / lib / Kephra / Document.pm

Diff from to

lib/Kephra/Document.pm

 
 package Kephra::Document;
 use Moo; 
+my $max_title_width = 15;
+
 # export SUB_QUOTE_DEBUG=1
 
 
-has ID     => ( is  => 'rwp' );
+has ID     => ( is  => 'rwp' );                             # API::Docs ID
+has title  => ( is  => 'rwp' );                             # shown as tab label
 has editor => ( is  => 'ro' );
 has panel  => ( is  => 'ro' );
-has text   => ( is  => 'ro', );
-has notes  => ( is  => 'rw', );
+has anon_NR=> ( is  => 'rw' );
 has file_path=>( 
 	is      => 'rw',
 	coerce  =>  sub { Kephra::File::normalize_path($_[0]) },
 	trigger =>  sub {
-		return if $_[0]->old_file_path and $_[0]->old_file_path eq $_[0]->file_path;
-		my @path_parts = File::Spec->splitpath( $_[0]->file_path );
-		$_[0]->_set_file_dir( $path_parts[1] );
-		$_[0]->_set_file_name( $path_parts[2] );
-		Kephra::API::Docs::rename_file($_[0]) if $_[0]->ID;
-		$_[0]->_set_old_file_path( $_[0]->file_path );
+		my $self = shift;
+		return if $self->old_file_path and $self->old_file_path eq $self->file_path;
+		my @path_parts = File::Spec->splitpath( $self->file_path );
+		$self->_set_file_dir( $path_parts[1] );
+		$self->_set_file_name( $path_parts[2] );
+		Kephra::API::Docs::rename_file($self) if $self->ID;
+
+		if ($self->file_path) {
+			my $title = $path_parts[2];
+			$title = substr( $title, 0, $max_title_width - 2 ) . '..'
+				if length($title) > $max_title_width and $max_title_width > 7;
+			$self->_set_title($title);
+		}
+
+		$self->_set_old_file_path( $self->file_path );
 	});
 has file_dir     => ( is => 'rwp', );
 has file_name    => ( is => 'rwp', );
 has old_file_path=> ( is => 'rwp' );
 has content      => ( is => 'rw', reader=> sub{ $_[0] } );
+has notes        => ( is => 'rw', );
 
 has syntax_mode  => ( is => 'rw', default => sub { 'perl' } );
 has readonly     => ( is => 'rw', );
 	return \ %args;
 };
 
-sub BUILD    { $_[0]->_set_ID( Kephra::API::Docs::add($_[0]) ) }
+sub BUILD    {
+	my $self = shift;
+	$self->_set_ID( Kephra::API::Docs::add($self) );
+	$self->_set_title('<untitled '.$self->anon_NR.'>') unless $self->file_path;
+}
 sub DEMOLISH { Kephra::API::Docs::remove($_[0]); #say "demolish $_[0]"; 
 }