Source

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

use v5.12;
use Cwd;
use File::Find;
use File::Spec;
use Kephra::App::Panel;
use Kephra::App::Splitter;
use Kephra::App::TabBar;

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

#Kephra::API::Command::register({
# 'tabbar-prev' =>{sub=>'select_tabbar_prev', label=>'Prev TabBar',  keys=>'alt+pageup'},
# 'tabbar-next' =>{sub=>'select_tabbar_next', label=>'Next TabBar',  keys=>'alt+pagedown'},
# 'tabbar-add'  =>{sub=>'select_tabbar_add',  label=>'Prev TabBar',  keys=>'ctrl+alt+pagedown'},
# 'tabbar-del'  =>{sub=>'select_tabbar_del',  label=>'Next TabBar',  keys=>'ctrl+alt+pageup'},
# 'tabbar-resize-left' =>{sub=>'resize_left', label=>'',  keys=>'ctrl+alt+plus'},
# 'tabbar-resize-right'=>{sub=>'resize_right',label=>'',  keys=>'ctrl+alt+minus'},
#});


sub tabbar         { $active_bar }
sub passive_tabbars{ @passive_bar}
sub all_tabbars    { $active_bar, @passive_bar }

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

	$active_bar = Kephra::App::TabBar->new($self);
	@passive_bar = Kephra::App::TabBar->new($self);

	my $splitter = $splitter{'main'} = Kephra::App::Splitter->new({ parent => $self,
		left => $active_bar, right => $passive_bar[-1], dominant_child => 'left' });
	$self->append( \$splitter );
	#$splitter->resize('equal');
	$self;
}

sub delete_selected_tabbar {
	my $tabbar_count = scalar @passive_bar + 1;
	return if $tabbar_count < 2;
	if    ($tabbar_count == 4){
		
	}
	elsif ($tabbar_count == 3){
		
	}
	elsif ($tabbar_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 and_and_select_tabbar {
	my $tabbar_count = scalar @passive_bar + 1;
	return if $tabbar_count > 3;

	if    ($tabbar_count == 3){
		
	}
	elsif ($tabbar_count == 2){
		
	}
	elsif ($tabbar_count == 1){
		
		push @passive_bar, Kephra::App::Bar::Tab->new( $splitter{'main'} );
		$splitter{'main'}->set(
			{left => $active_bar, right => $passive_bar[0], dominant_child => 'left'}
		);
		$splitter{'main'}->resize('equal');
		#$splitter{'main'}->resplit();
		#$passive_bar[0]->Show(1);
	}
	Kephra::API::focus( $active_bar->GetPage( $active_bar->GetSelection ) );
}


sub select_tabbar_next {
	push @passive_bar, $active_bar;
	$active_bar = shift @passive_bar;
	$active_bar->raise_page( $active_bar->GetSelection );
}
sub select_tabbar_prev {
	unshift @passive_bar, $active_bar;
	$active_bar = pop @passive_bar;
	$active_bar->raise_page( $active_bar->GetSelection );
}
sub select_tabbar {
	my $bar = shift;
	return Kephra::Log::warning("need a Kephra::App::Bar::Tab instance")
		unless ref $bar eq 'Kephra::App::Bar::Tab';
	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 resize      { $splitter{'main'}->resize('equal') }
sub resize_left { $splitter{'main'} }
sub resize_right{ $splitter{'main'} }


sub refresh_doc_label {
	my $doc = shift // Kephra::API::document();
	return unless Kephra::API::DocumentStash::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_tabbars();
}

1;
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.