Source

Kephra / lib / Kephra / App / Part / Editor.pm

Full commit
use v5.10;
use warnings;
use Cwd;
use File::Find;
use File::Spec;
use Kephra::App::Panel;
use Kephra::App::Bar::Document;
use Kephra::App::Splitter;

package Kephra::App::Part::Editor;
our @ISA = 'Kephra::App::Panel';
my ($active_bar, @passive_bar, $panel, %splitter);
use Scalar::Util qw(blessed);

Kephra::API::Command::register({
 'docbar-prev' =>{sub=>'select_docbar_prev', label=>'Prev Docbar',  keys=>'alt+pageup'},
 'docbar-next' =>{sub=>'select_docbar_next', label=>'Next Docbar',  keys=>'alt+pagedown'},
 'docbar-del'  =>{sub=>'select_docbar_del', label=>'Next Docbar',  keys=>'ctrl+alt+pageup'},
 'docbar-add'  =>{sub=>'select_docbar_add', label=>'Prev Docbar',  keys=>'ctrl+alt+pagedown'},
});


sub docbar         { $active_bar }
sub passive_docbars{ @passive_bar}
sub all_docbars    { $active_bar, @passive_bar }

sub new {
	my( $class, $parent) = @_;
	my $self = $panel = $class->SUPER::new($parent);

	my $db  = Kephra::App::Bar::Document->new($self);
	my $db2 = Kephra::App::Bar::Document->new($self);

	my $splitter = $splitter{'main'} = Kephra::App::Splitter->new
		({parent => $self, left => $db, right => $db2, dominant_child => 'left'});
	$self->append( \$splitter );
	$splitter->resize('equal');

	$active_bar = $db;
	@passive_bar = ($db2);

	$self;
}

sub select_docbar_del {
	my $docbar_count = scalar @passive_bar + 1;
	return if $docbar_count < 2;
	if    ($docbar_count == 4){
		
	}
	elsif ($docbar_count == 3){
		
	}
	elsif ($docbar_count == 2){
		$splitter{'main'}->set({dominant_child => $active_bar});
		$splitter{'main'}->unsplit();
	}
	$passive_bar[-1]->Destroy();
	delete $passive_bar[-1];
	Kephra::API::focus( $active_bar->GetPage( $active_bar->GetSelection ) );
}

sub select_docbar_add {
	my $docbar_count = scalar @passive_bar + 1;
	return if $docbar_count > 3;
	if    ($docbar_count == 3){
		
	}
	elsif ($docbar_count == 2){
		
	}
	elsif ($docbar_count == 1){
		$passive_bar[0]->Show(1);
		$splitter{'main'}->resplit();
	}
}

sub select_docbar_next {
	push @passive_bar, $active_bar;
	$active_bar = shift @passive_bar;
	$active_bar->raise_page( $active_bar->GetSelection );
}
sub select_docbar_prev {
	unshift @passive_bar, $active_bar;
	$active_bar = pop @passive_bar;
	$active_bar->raise_page( $active_bar->GetSelection );
}
sub select_docbar {
	my $bar = shift;
	return Kephra::Log::warning("need a Kephra::App::Bar::Document instance")
		unless ref $bar eq 'Kephra::App::Bar::Document';
	return if $active_bar eq $bar;
	my $i;
	for (0 ..  $#passive_bar){ $i = $_ if $bar eq $passive_bar[$_] }
	return Kephra::Log::warning("$bar is unknown") unless defined $i;

	@passive_bar = (splice(@passive_bar, $i+1), $active_bar, splice(@passive_bar, 0, $i));
	$active_bar = $bar;
	$active_bar->raise_page( $active_bar->GetSelection );
}


sub refresh_doc_label {
	my $doc = shift // Kephra::API::document();
	return unless Kephra::API::Doc::is($doc);
	my $unsaved_mark = '*';

	my $title = $doc->title;
	$title .= $unsaved_mark if $doc->editor->{$active_bar}->GetModify;
	$_->SetPageText($_->GetPageIndex( $doc->panel->{$_} ), $title) for all_docbars();
}

1;