Commits

Herbert Breunung committed 1671727

yeah real multy view in ded

  • Participants
  • Parent commits 9cba0c4
  • Branches sp2

Comments (0)

Files changed (10)

lib/ded/Kephra/API.pm

 BEGIN {  # because API is called first at start, to even work when mutually recursive included
     require Exporter;
     our @ISA = qw(Exporter);
-    our @EXPORT_OK = qw(message warning error output is_widget is_panel is_sizer is_color is_font is_editor is_document focus focus_back);
+    our @EXPORT_OK = qw( 
+        app_window doc_panel doc_bar editor input output focus focus_back
+        message warning error
+        output is_widget is_panel is_sizer is_color is_font is_editor is_document
+    );
     our %EXPORT_TAGS = (log => [qw(message warning error)], 
                         cmp => [qw(is_widget is_panel is_sizer is_color is_font is_editor is_document)],
-                        app => [qw(app_window doc_panel docbar editor )],
+                        app => [qw(app_window doc_panel doc_bar editor input output)],
     );
     my %seen;                                                 # code for :all tag
     push @{$EXPORT_TAGS{all}}, grep {!$seen{$_}++} @{$EXPORT_TAGS{$_}} for keys %EXPORT_TAGS;
 }
 
-
 # application parts, environment
 #sub app          { }
 sub app_window   { $Kephra::App::win           }
-sub doc_panel    { app_window()->{'doc_panel'} }
-sub docbar       { doc_panel()->docbar()       }
+sub doc_panel    { app_window()->doc_panel() }
+sub doc_bar      { doc_panel()->active_docbar()}
 sub all_docbar   { doc_panel()->all_docbar()   }
 sub document     { Kephra::DocumentStash::active_doc()   }
 sub all_documents{ Kephra::DocumentStash::all_docs()     }

lib/ded/Kephra/App.pm

 
 	#my $doc = Kephra::DocumentStash::create_doc();
 	Kephra::File::open(__FILE__);
-	#Kephra::File::open('Kephra/API.pm');
-	#Kephra::File::open('Kephra/Log.pm');
+	Kephra::File::open('Kephra/API.pm');
+	Kephra::File::open('Kephra/Log.pm');
 
 	$win->Center();
 	$win->Show(1);

lib/ded/Kephra/App/DocBar.pm

 
 sub add_page {
 	my ($self, $new_page, $title, $position, $set_active) = @_;
-	return warning( "got no panel", 1 ) until is_panel($new_page) or is_editor($new_page);
+	# put a proper panel under an editor widget
+	#$new_page = Kephra::App::Panel->new($self, \$new_page) if is_editor($new_page);
+	return warning( "got no panel or editor", 1 ) until is_panel($new_page) or is_editor($new_page);
 	my $active_pos = $self->GetSelection;
 
 	$title    = ''                           unless defined $title;
 sub remove_page {
 	my ($self, $page) = @_;
 	my $internal_position = $self->GetPageIndex( $page );
+	if ($internal_position == -1 and is_editor($page) ){
+		for my $index (0 .. $self->GetPageCount){
+			$internal_position = $index
+				if is_editor($self->GetPage($index))
+				and $self->GetPage($index)->GetDocPointer() == $page->GetDocPointer();
+		}
+	}
+	return warning("could not remove requested page $page") if $internal_position == -1;
 
 	$self->RemovePage( $internal_position );
 	my $visual_position = $self->{'internal_page_order'}[$internal_position];

lib/ded/Kephra/App/Editor.pm

 
 sub new {
 	my( $class, $parent, $style) = @_;
-	$parent = Kephra::API::docbar() if not defined $parent or $parent == -1;
+	$parent = Kephra::API::doc_bar() if not defined $parent or $parent == -1;
 	my $self = $class->SUPER::new($parent, -1,[-1,-1],[-1,-1]);
 	$self->load_font();  # before setting highlighting
 	$self->set_perlhighlight();
 			when('ctrl+q'){ Kephra::File::close() }
 			when('alt+q') { Kephra::API::app_window->Close() }
 			when('ctrl+s'){ Kephra::File::save() } 
-			when('ctrl+pageup')  { Kephra::API::docbar->select_page_left() }
-			when('ctrl+pagedown'){ Kephra::API::docbar->select_page_right() } 
+			when('ctrl+pageup')  { Kephra::API::doc_bar->select_page_left() }
+			when('ctrl+pagedown'){ Kephra::API::doc_bar->select_page_right() } 
 			when('ctrl+alt+pageup')  { Kephra::API::app_window->{'doc_panel'}->unsplit() }
 			when('ctrl+alt+pagedown'){ Kephra::API::app_window->{'doc_panel'}->split() } 
 			default                  { $event->Skip }
 	Wx::Event::EVT_SET_FOCUS( $self, sub {
 		my ($ed, $event ) = @_;
 		$event->Skip;
-		#Kephra::App::Part::Editor::select_docbar( $ed->GetParent->GetParent );
+		#Kephra::App::Part::Editor::select_doc_bar( $ed->GetParent->GetParent );
 	});
 	#Wx::Event::EVT_DROP_FILES       ($ep, sub{});
 	#Wx::Event::EVT_STC_START_DRAG   ($ep, -1, sub {

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

 use Kephra::App::Panel;
 use Kephra::App::Splitter;
 
+sub active_docbar {
+	my ($self) = @_;
+	$self->{'docbar'}[$self->{'active'}];
+}
+
 sub docbar {
 	my ($self, $which) = @_;
 	return $self->{'docbar'}[0] unless defined $which;
+	$self->{'docbar'}[$which];
 }
 sub all_docbar { @{shift->{'docbar'}} }
 
 	my $self = $class->SUPER::new( $parent );
 	$bar_nr = 4 if (looks_like_number($bar_nr) and $bar_nr > 4);
 	$bar_nr = 1 if (looks_like_number($bar_nr) and $bar_nr < 1);
-	#$self->{'docbar'}[$_-1] = Kephra::App::DocBar->new( $self ) for 1 .. $bar_nr;
-	$self->{'docbar'}[$_] = Kephra::App::DocBar->new( $self ) for 0..1;
+	$self->{'number'} = 2;
+	$self->{'active'} = 0;
+	$self->{'docbar'}[$_] = Kephra::App::DocBar->new( $self ) for 0..$self->{'number'}-1;
 
 	$self->{'splitter'}[0] = Kephra::App::Splitter->new({
 		parent => $self, 'left' => $self->{'docbar'}[0] , 'right' => $self->{'docbar'}[1] 
 
 sub split {
 	my ($self) = @_;
-	$self->{'splitter'}[0]->resplit();
+	$self->{'splitter'}[0]->resplit() unless $self->{'splitter'}[0]->is_split();
 }
 
 sub unsplit {
 	my ($self) = @_;
-	$self->{'splitter'}[0]->unsplit();
+	$self->{'splitter'}[0]->unsplit() if $self->{'splitter'}[0]->is_split();
 }
 
+sub add_doc {
+	my ($self, $doc) = @_;
+	$self->{'docbar'}[0]->add_page( $doc->{'editor'}, $doc->{'title'}, -1, 1);
+	my $ed1 = Kephra::App::Editor->new($self->{'docbar'}[1]);
+	$ed1->SetDocPointer( $doc->{'editor'}->GetDocPointer() );
+	$self->{'docbar'}[1]->add_page( $ed1, $doc->{'title'}, -1, 1);
+}
+
+sub remove_doc {
+	my ($self, $doc) = @_;
+	$self->{'docbar'}[0]->remove_page( $doc->{'editor'});
+	$self->{'docbar'}[1]->remove_page( $doc->{'editor'});
+
+}
+
+sub set_page_title {
+}
 
 1;

lib/ded/Kephra/App/Splitter.pm

 	$self->IsSplit ? $self->unsplit : $self->resplit;
 }
 
+sub is_split { shift->IsSplit }
+
 1;

lib/ded/Kephra/App/Window.pm

 use Kephra::App::Sizer;
 use Kephra::App::Splitter;
 
+sub doc_panel { shift->{'doc_panel'} }
+
 sub new {
 	my($class, $parent) = @_;
 	my $self = $class->SUPER::new( undef, -1, '', [-1,-1], [1000,800] );

lib/ded/Kephra/Document.pm

 		$self->{'encoding'} = $encoding;
 
 		# rename docbar title
-		Kephra::API::docbar->set_page_title($self->{'title'}, $self->{'editor'});
-
+		#Kephra::API::doc_panel->set_page_title($self->{'title'}, $self->{'editor'});
 		return 1;
 	}
 }
 	$ed->EmptyUndoBuffer;
 	$ed->SetSavePoint;
 	Kephra::DocumentStash::get_anon_title($self);
-	Kephra::API::docbar->set_page_title($self->{'title'}, $self->{'editor'});
+	#Kephra::API::doc_bar->set_page_title($self->{'title'}, $self->{'editor'});
 	Kephra::API::app_window->SetStatusText( $self->{'encoding'}, 1);
 	Kephra::API::app_window->refresh_title();
 	Kephra::API::focus_back();

lib/ded/Kephra/DocumentStash.pm

 package Kephra::DocumentStash;
 
 use Scalar::Util qw(blessed looks_like_number);
-use Kephra::API qw(:log :cmp);
+use Kephra::API qw(:log is_document doc_panel);
 
 use Kephra::Document;
 
 sub set_active_ed { set_active( find_doc_by('editor', shift) ) }
 sub set_active {
 	my $doc = shift;
+	return unless is_document($doc);
 	for (0 .. $#queue){ splice (@queue, $_, 1) if exists $queue[$_] and $queue[$_] eq $doc }
 	unshift @queue, $doc;
 }
 	#$doc->{'pos'} = 0;
 	set_active($doc);
 	$document{'editor'}{$doc->{'editor'}} = $doc;
-	push @{$document{'bar'}{$doc}}, Kephra::API::docbar;
+	push @{$document{'bar'}{$doc}}, $_ for Kephra::API::all_docbar();
 
-	Kephra::API::docbar->add_page( $doc->{'editor'}, $doc->{'title'}, -1, 1);
-
+	doc_panel()->add_doc( $doc );
 	return $doc;
 }
 
 	return unless is_document($doc);
 	delete $document{$_}{$doc->{$_}} for qw(editor file_path);
 	delete $document{'bar'}{$doc};
-	Kephra::API::docbar->remove_page( $doc->{'editor'});
+	doc_panel()->remove_doc( $doc );
 }
 
 sub get_anon_title {

lib/ded/Kephra/File.pm

 	$file = Kephra::App::Dialog::get_file_open() unless defined $file;
 	return unless $file and -r $file;
 	my $doc = Kephra::API::document();
-	if (Kephra::API::docbar->GetPageCount == 1 and not $doc->{'file_name'}){
+	if (Kephra::API::doc_bar->GetPageCount == 1 and not $doc->{'file_name'}){
 		$doc->load_file($file);
 	} else {
 		Kephra::DocumentStash::create_doc($file);