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

Diff from to

lib/Kephra/App/Part/Editor.pm

-use strict;
+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);
 
-use Kephra::API;
-use Kephra::App::Bar::Document;
+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'},
+});
 
-#my $_ref; # whole panel widget, parent of all this
-my %doc_bar;
-#my $active;
 
-sub active_docbar{ $doc_bar{'leftup'} }
+sub docbar         { $active_bar }
+sub passive_docbars{ @passive_bar}
+sub all_docbars    { $active_bar, @passive_bar }
 
 sub new {
 	my( $class, $parent) = @_;
-	$doc_bar{'leftup'} = Kephra::App::Bar::Document->new( $parent );
-	# Wx::SplitterWindow->new( $splitter{'left'}, -1 );
-	return $doc_bar{'leftup'};
+	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 create_document {
-	my $file = shift;
-	my $doc = Kephra::API::document();
-	my $win = Kephra::API::main_window();
-	my $main_doc_bar = active_docbar();
-
-	if ($doc and $doc->editor->is_empty and $file) { # overwrite empty doc
-		$doc->assign_file_path($file);
-		$main_doc_bar->set_page_title( $doc->file_name );
-	} else {                                         # make new editor
-		$doc = Kephra::Document->new();
-		$doc->assign_file_path( $file );
-		$doc->panel( Kephra::App::Panel->new( $main_doc_bar ) );
-		$doc->editor( Kephra::App::Editor->new( $doc->panel ) );
-		$doc->panel->append( \$doc->editor );
-		Kephra::API::Doc::add_and_activate( $doc );
-		$main_doc_bar->add_page($doc->panel, $doc->file_name, -1, 1);
-		Kephra::API::focus( $doc->editor );
+sub select_docbar_del {
+	my $docbar_count = scalar @passive_bar + 1;
+	return if $docbar_count < 2;
+	if    ($docbar_count == 4){
+		
 	}
-	$win->refresh_title();
-
-	return $doc;
+	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->GetSelection);
+	#Kephra::API::focus( Kephra::API::document()->panel->{$active_bar} );
+	#Kephra::API::focus( $splitter{'main'} );
+}
+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 remove_document {
-	my $doc = shift;
-	return unless ref $doc and $doc->isa('Kephra::Document');
-	my $main_doc_bar = active_docbar();
-	if ($main_doc_bar->GetPageCount > 1) {
-		$main_doc_bar->remove_page( $main_doc_bar->GetPageIndex( $doc->panel ) );
-		Kephra::API::Doc::del($doc);
-	} else {
-		$doc->editor->ClearAll;
-		$doc->assign_file_path('');
-		$main_doc_bar->set_page_title('');
-	}
-	Kephra::API::main_window()->refresh_title();
+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 raise_document {
-	my $doc = Kephra::API::Doc::doc_by_anything(shift);
-	active_docbar()->raise_page( $doc->{panel} ) if $doc;
-}
 
-sub active_title {
-	my $nb = active_docbar();
-	$nb->GetPageText( $nb->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;
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.