1. Herbert Breunung
  2. Kephra

Commits

Herbert Breunung  committed f2c5730

docbar is running

  • Participants
  • Parent commits eddfad5
  • Branches sp3

Comments (0)

Files changed (5)

File lib/Kephra/API.pm

View file
  • Ignore whitespace
 
 sub app                 { $Kephra::App::_ref }
 sub main_window         { $Kephra::App::Window::_ref }
-#sub docbar              { Kephra::App::Part::Editor::docbar() }
-#sub all_docbars         { Kephra::App::Part::Editor::all_docbars() }
+sub docbar              { $Kephra::App::Bar::Document::_ref #Kephra::App::Part::Editor::docbar() 
+}
+sub all_docbars         { $Kephra::App::Bar::Document::_ref #Kephra::App::Part::Editor::all_docbars()
+}
 #sub passive_docbars     { Kephra::App::Part::Editor::passive_docbars() }
 sub document            { Kephra::API::DocumentStash::active_doc() }
 sub all_documents       { Kephra::API::DocumentStash::all_docs() }

File lib/Kephra/API/DocumentStash.pm

View file
  • Ignore whitespace
 sub is { return 1 if blessed($_[0]) and $_[0]->isa( DOC_CLASS ); return 0 }
 
 
-sub add {
+sub add_doc {
 	my $doc = shift;
 	Kephra::Log::warning('need a ' . DOC_CLASS . " thats in stash, not $doc!", 1)
 		unless is($doc);
 	$document{'ID'}  {$lowest_free_ID} = $doc;
-	add_instance($doc, $_) for keys $doc->editor;
+	add_doc_instance($doc, $_) for keys $doc->editor;
 	if ($doc->file_path) {
 		$document{'file'}{$doc->file_path} = $doc;
 	} else {
 }
 
 
-sub remove {
+sub remove_doc {
 	my $doc = shift;
 #say "remove $doc ", scalar keys %{$document{'ID'}}, ' ',scalar keys %{$document{'file'}}; 
 	Kephra::Log::warning('need a ' . DOC_CLASS . ' thats in stash, not $doc!', 1)
 		unless is($doc);
 	delete $document{'ID'}{$doc->ID} if $doc->ID;
-	#remove_instance($doc, $_) for values $doc->panel;
+	#remove_doc_instance($doc, $_) for values $doc->panel;
 	delete $document{'file'}{$doc->file_path} if $doc->file_path;
 #say "removed $doc ", scalar keys %{$document{'ID'}}, ' ',scalar keys %{$document{'file'}}; 
 }
 
 
-sub add_instance {
+sub add_doc_instance {
 	my ($doc, $bar) = @_;
 	return Kephra::Log::warning('need as first parameter a'.DOC_CLASS.' thats in stash, not $doc!', 1)
 		unless is($doc);
 }
 
 
-sub remove_instance {
+sub remove_doc_instance {
 	my ($doc, $bar) = @_;
 	return Kephra::Log::warning('need as first parameter a'.DOC_CLASS.' thats in stash, not $doc!', 1)
 		unless is($doc);

File lib/Kephra/App.pm

View file
  • Ignore whitespace
 
 sub OnInit {
 	my $app   = $_ref = shift;
-	my $frame = Kephra::App::Window->new($Kephra::NAME.' SP3 '.$Kephra::VERSION);
+	my $win = Kephra::App::Window->new($Kephra::NAME.' SP3 '.$Kephra::VERSION);
+	Kephra::File::new();
 
-	$frame->Show(1);
-	$app->SetTopWindow($frame);
+	$win->Center();
+	$win->Refresh();   # remove visual clutter on start
+	$win->Show(1);
+	$app->SetTopWindow($win);
 	1;
 }
 

File lib/Kephra/App/Bar/Document.pm

View file
  • Ignore whitespace
 	Wx::Event::EVT_AUINOTEBOOK_PAGE_CHANGED( $self, -1, sub {
 		my ($bar, $event ) = @_;
 		my $new_page = $bar->GetPage( $event->GetSelection );
-		Kephra::API::Doc::set_active( $new_page );
+		Kephra::API::DocumentStash::set_active( $new_page );
 		Kephra::API::main_window()->refresh_title();
 		Kephra::API::focus( $new_page );
 		$event->Skip;
 }
 
 
-#sub add_page {
-	#my ($self, $new_page, $position, $title, $set_active) = @_;
-	#return Kephra::Log::warning( "got no panel", 1 ) until Kephra::App::Util::is_panel($new_page);
-	#my $active_pos = $self->GetSelection;
-#
-	#$title    = ''                           unless defined $title;
-	#$position = 'right'                      if $position eq 'default' or $position eq -1;
-	#$position = $self->rightmost_page_pos+1  if $position eq 'rightmost';
-	#$position = $active_pos + 1              if $position eq 'right';
-	#$position = $active_pos                  if $position eq 'left';
-	#$position = $self->leftmost_page_pos     if $position eq 'leftmost';
-	#$set_active = 0                          unless defined $set_active;
-#
-	#$new_page->Reparent($self);
-	#$self->InsertPage( $position, $new_page, $title, $set_active);
-	#$self->set_page_title( $title, $new_page );
-	#Kephra::API::focus($new_page) if $set_active;
-#
-	 #inserting new index to position translators
-	#for   (@{$self->{'visual_page_order'}}){ $_++ if $_ >= $position }
-	#splice @{$self->{'visual_page_order'}},  $position, 0, $position;
-	#$self->refresh_internal_page_order();
-#
-	#$self;
-#}
+sub add_page {
+	my ($self, $new_page, $position, $title, $set_active) = @_;
+	return Kephra::Log::warning( "got no panel", 1 ) until Kephra::App::Util::is_panel($new_page);
+	my $active_pos = $self->GetSelection;
 
-#sub remove_page {
-	#my ($self, $page) = @_;
-	#my $internal_position = $self->GetPageIndex( $page );
-#
-	#$self->RemovePage( $internal_position );
-	#my $visual_position = $self->{'internal_page_order'}[$internal_position];
-	#my $visual = $self->{'visual_page_order'};
-	#splice @$visual, $visual_position, 1;
-	#for (@$visual) {$_-- if $_ >= $internal_position}
-	#$self->{'visual_page_order'} = $visual;
-	#$self->refresh_internal_page_order;
-#}
-#
-#
-#sub refresh_internal_page_order {       # sync visual_page_order index with internal_page_order after each change
-	#my ($self) = @_;
-	#my $visual = $self->{'visual_page_order'};
-	#return unless ref $visual eq ref [];
-	#my $internal;
-	#$internal->[ $visual->[$_] ] = $_ for 0 .. @$visual-1;
-	#$self->{'internal_page_order'} = $internal;
-#}
-#
-#sub move_page_position_visually {          # for dnd only
-	#my ($self, $from, $to ) = @_;
-	#return unless $from >= 0 and $from < $self->GetPageCount;
-	#return unless $to >= 0 and $to < $self->GetPageCount;
-	#my $position = splice @{$self->{'visual_page_order'}}, $from, 1;
-	#splice @{$self->{'visual_page_order'}}, $to, 0, $position;
-	#$self->refresh_internal_page_order();
-#}
-#
-#sub move_page_visually  {               # for movements by keyboard
-	#my ($self, $from, $to ) = @_;
-	#my $max = $self->GetPageCount - 1;
-	#return if $from < 0 or $from > $max;
-	#return if $to < 0 or $to > $max;
-	#return if $from == $to;
-#
-	#my $pos = $self->{'visual_page_order'}[ $from ];
-	#my $page = $self->GetPage( $pos );
-	#my $label = $self->GetPageText( $pos );
-	#my $visual = $self->{'visual_page_order'};
-#
-	#$self->unmount_events();
-	#$self->RemovePage( $pos );
-	#$self->InsertPage( $to, $page, $label);
-	#my $removed = splice @$visual, $from, 1;
-	#if ($from < $to) { for (@$visual) {$_-- if $_ > $removed and $_ <= $to} }
-	#else             { for (@$visual) {$_++ if $_ < $removed and $_ >= $to} }
-	#splice @$visual, $to, 0, $to;
-	#$self->{'visual_page_order'} = $visual;
-	#$self->refresh_internal_page_order();
-	#$self->SetSelection( $self->{'visual_page_order'}[$to] );
-	#$self->mount_events();
-#}
-#
-#sub move_page_left      {
-	#my ($self) = @_;
-	#$self->move_page_visually ( 
-		#$self->active_visual_pos, $self->next_page_pos_rot_left( $self->GetSelection )
-	#);
-#}
-#sub move_page_right     {
-	#my ($self) = @_;
-	#$self->move_page_visually( 
-		#$self->active_visual_pos, $self->next_page_pos_rot_right( $self->GetSelection )
-	#);
-#}
-#sub move_page_leftmost  { 
-	#my ($self) = @_;
-	#$self->move_page_visually( $self->active_visual_pos, $self->leftmost_page_pos );
-#}
-#sub move_page_rightmost { 
-	#my ($self) = @_;
-	#$self->move_page_visually( $self->active_visual_pos, $self->rightmost_page_pos );
-#}
-#
-#sub select_page_left    { 
-	#my ($self) = @_;
-	#$self->raise_page( $self->next_page_pos_rot_left( $self->GetSelection ) );
-#}
-#sub select_page_right   { 
-	#my ($self) = @_;
-	#$self->raise_page( $self->next_page_pos_rot_right( $self->GetSelection ) );
-#}
-#sub select_page_leftmost  { $_[0]->raise_page( $_[0]->leftmost_page_pos ) }
-#sub select_page_rightmost { $_[0]->raise_page( $_[0]->rightmost_page_pos ) }
+	$title    = ''                           unless defined $title;
+	$position = 'right'                      if $position eq 'default' or $position eq -1;
+	$position = $self->rightmost_page_pos+1  if $position eq 'rightmost';
+	$position = $active_pos + 1              if $position eq 'right';
+	$position = $active_pos                  if $position eq 'left';
+	$position = $self->leftmost_page_pos     if $position eq 'leftmost';
+	$set_active = 0                          unless defined $set_active;
 
-#sub active_visual_pos     { $_[0]->{'internal_page_order'}[ $_[0]->GetSelection ] }
-#sub leftmost_page_pos     { 0 }
-#sub rightmost_page_pos    { $_[0]->GetPageCount-1 }
-#sub valid_page_pos        { 
-	#1 if $_[1] >= $_[0]->leftmost_page_pos and $_[1]<= $_[0]->rightmost_page_pos
-#}
-#sub next_page_pos_rot_left{
-	#my ($self) = @_; # take in position of internal order
-	#my $pos = $self->{'internal_page_order'}[ $_[1] ];
-	#$self->{'visual_page_order'}[$pos == 0 ? $self->rightmost_page_pos : $pos-1]
-#}
-#sub next_page_pos_rot_right{
-	#my ($self) = @_; # take in position of internal order
-	#my $pos = $self->{'internal_page_order'}[ $_[1] ];
-	#$self->{'visual_page_order'}[$pos == $self->rightmost_page_pos ? 0 : $pos+1]
-#}
+	$new_page->Reparent($self);
+	$self->InsertPage( $position, $new_page, $title, $set_active);
+	$self->set_page_title( $title, $new_page );
+	Kephra::API::focus($new_page) if $set_active;
 
+	# inserting new index to position translators
+	for   (@{$self->{'visual_page_order'}}){ $_++ if $_ >= $position }
+	splice @{$self->{'visual_page_order'}},  $position, 0, $position;
+	$self->refresh_internal_page_order();
 
-#sub raise_page    {
-	#my ($self, $pop) = @_; # can be Position Or Page (panel reference)
-	#my $position = int $pop eq $pop ? $pop : $self->GetPageIndex($pop);
-	#return unless $self->valid_page_pos( $position );
+	$self;
+}
+
+sub remove_page {
+	my ($self, $page) = @_;
+	my $internal_position = $self->GetPageIndex( $page );
+
+	$self->RemovePage( $internal_position );
+	my $visual_position = $self->{'internal_page_order'}[$internal_position];
+	my $visual = $self->{'visual_page_order'};
+	splice @$visual, $visual_position, 1;
+	for (@$visual) {$_-- if $_ >= $internal_position}
+	$self->{'visual_page_order'} = $visual;
+	$self->refresh_internal_page_order;
+}
+
+
+sub refresh_internal_page_order {       # sync visual_page_order index with internal_page_order after each change
+	my ($self) = @_;
+	my $visual = $self->{'visual_page_order'};
+	return unless ref $visual eq ref [];
+	my $internal;
+	$internal->[ $visual->[$_] ] = $_ for 0 .. @$visual-1;
+	$self->{'internal_page_order'} = $internal;
+}
+
+sub move_page_position_visually {          # for dnd only
+	my ($self, $from, $to ) = @_;
+	return unless $from >= 0 and $from < $self->GetPageCount;
+	return unless $to >= 0 and $to < $self->GetPageCount;
+	my $position = splice @{$self->{'visual_page_order'}}, $from, 1;
+	splice @{$self->{'visual_page_order'}}, $to, 0, $position;
+	$self->refresh_internal_page_order();
+}
+
+sub move_page_visually  {               # for movements by keyboard
+	my ($self, $from, $to ) = @_;
+	my $max = $self->GetPageCount - 1;
+	return if $from < 0 or $from > $max;
+	return if $to < 0 or $to > $max;
+	return if $from == $to;
+
+	my $pos = $self->{'visual_page_order'}[ $from ];
+	my $page = $self->GetPage( $pos );
+	my $label = $self->GetPageText( $pos );
+	my $visual = $self->{'visual_page_order'};
+
+	$self->unmount_events();
+	$self->RemovePage( $pos );
+	$self->InsertPage( $to, $page, $label);
+	my $removed = splice @$visual, $from, 1;
+	if ($from < $to) { for (@$visual) {$_-- if $_ > $removed and $_ <= $to} }
+	else             { for (@$visual) {$_++ if $_ < $removed and $_ >= $to} }
+	splice @$visual, $to, 0, $to;
+	$self->{'visual_page_order'} = $visual;
+	$self->refresh_internal_page_order();
+	$self->SetSelection( $self->{'visual_page_order'}[$to] );
+	$self->mount_events();
+}
+
+sub move_page_left      {
+	my ($self) = @_;
+	$self->move_page_visually ( 
+		$self->active_visual_pos, $self->next_page_pos_rot_left( $self->GetSelection )
+	);
+}
+sub move_page_right     {
+	my ($self) = @_;
+	$self->move_page_visually( 
+		$self->active_visual_pos, $self->next_page_pos_rot_right( $self->GetSelection )
+	);
+}
+sub move_page_leftmost  { 
+	my ($self) = @_;
+	$self->move_page_visually( $self->active_visual_pos, $self->leftmost_page_pos );
+}
+sub move_page_rightmost { 
+	my ($self) = @_;
+	$self->move_page_visually( $self->active_visual_pos, $self->rightmost_page_pos );
+}
+
+sub select_page_left    { 
+	my ($self) = @_;
+	$self->raise_page( $self->next_page_pos_rot_left( $self->GetSelection ) );
+}
+sub select_page_right   { 
+	my ($self) = @_;
+	$self->raise_page( $self->next_page_pos_rot_right( $self->GetSelection ) );
+}
+sub select_page_leftmost  { $_[0]->raise_page( $_[0]->leftmost_page_pos ) }
+sub select_page_rightmost { $_[0]->raise_page( $_[0]->rightmost_page_pos ) }
+
+sub active_visual_pos     { $_[0]->{'internal_page_order'}[ $_[0]->GetSelection ] }
+sub leftmost_page_pos     { 0 }
+sub rightmost_page_pos    { $_[0]->GetPageCount-1 }
+sub valid_page_pos        { 
+	1 if $_[1] >= $_[0]->leftmost_page_pos and $_[1]<= $_[0]->rightmost_page_pos
+}
+sub next_page_pos_rot_left{
+	my ($self) = @_; # take in position of internal order
+	my $pos = $self->{'internal_page_order'}[ $_[1] ];
+	$self->{'visual_page_order'}[$pos == 0 ? $self->rightmost_page_pos : $pos-1]
+}
+sub next_page_pos_rot_right{
+	my ($self) = @_; # take in position of internal order
+	my $pos = $self->{'internal_page_order'}[ $_[1] ];
+	$self->{'visual_page_order'}[$pos == $self->rightmost_page_pos ? 0 : $pos+1]
+}
+
+
+sub raise_page    {
+	my ($self, $pop) = @_; # can be Position Or Page (panel reference)
+	my $position = int $pop eq $pop ? $pop : $self->GetPageIndex($pop);
+	return unless $self->valid_page_pos( $position );
 	# if just selecting the currrent, only tab drives focus nuts
-	#$self->SetSelection( $position ) unless $position == $self->GetSelection;
-	#my $page = $self->GetPage($position);
-	#my $doc = Kephra::API::Doc::find($page);
-	#Kephra::API::Doc::set_active( $doc );
-	#Kephra::API::focus ( defined $doc ? $doc->editor->{$self} : $page );
-	#Kephra::API::main_window()->refresh_title();
-#
-#}
+	$self->SetSelection( $position ) unless $position == $self->GetSelection;
+	my $page = $self->GetPage($position);
+	my $doc = Kephra::API::DocumentStash::find($page);
+	Kephra::API::DocumentStash::set_active( $doc );
+	Kephra::API::focus ( defined $doc ? $doc->editor->{$self} : $page );
+	Kephra::API::main_window()->refresh_title();
 
+}
 
-#sub active_title { $_[0]->GetPageText( $_[0]->GetSelection ) }
 
-#sub set_page_title {
-	#my ($self, $label, $page) = @_;
-	#$page = $self->GetSelection unless defined $page;
-	#return Kephra::Log::warning("need a Kephra::App::Panel or valid position number") 
-		#unless (looks_like_number($page) and $self->valid_page_pos($page))
-		#or (blessed($page) and $page->isa('Kephra::App::Panel'));
-	#my $found = $self->GetPageIndex($page);
-	#my $position = $found eq &Wx::wxNOT_FOUND ? $page : $found;
-	#$self->SetPageText( $position, $label );
-#}
+sub active_title { $_[0]->GetPageText( $_[0]->GetSelection ) }
+
+sub set_page_title {
+	my ($self, $label, $page) = @_;
+	$page = $self->GetSelection unless defined $page;
+	return Kephra::Log::warning("need a Kephra::App::Panel or valid position number") 
+		unless (looks_like_number($page) and $self->valid_page_pos($page))
+		or (blessed($page) and $page->isa('Kephra::App::Panel'));
+	my $found = $self->GetPageIndex($page);
+	my $position = $found eq &Wx::wxNOT_FOUND ? $page : $found;
+	$self->SetPageText( $position, $label );
+}
 
 
 1;

File lib/Kephra/Document.pm

View file
  • Ignore whitespace
-use v5.10;
+use v5.12;
 use File::Spec;
-use Kephra::API;
 use Kephra::File;
 
 package Kephra::Document;
 		my $self = shift;
 		return if $self->prev_file_path and $self->file_path
 				and $self->prev_file_path eq $self->file_path;
-		Kephra::API::Doc::rename_file($self) if $self->ID;
+		Kephra::API::DocumentStash::rename_file($self) if $self->ID;
 
 		if ($self->file_path) {
 			my @path_parts = File::Spec->splitpath( $self->file_path );
 sub BUILD    {
 	my $self = shift;
 	$self->add_instance($_) for Kephra::API::all_docbars();
-	$self->_set_ID( Kephra::API::Doc::add($self) );
+	$self->_set_ID( Kephra::API::DocumentStash::add_doc($self) );
 	$self->_set_title('<untitled '.$self->anon_NR.'>') unless $self->file_path;
 }
-sub DEMOLISH { Kephra::API::Doc::remove($_[0]) }
+sub DEMOLISH { Kephra::API::DocumentStash::remove_doc($_[0]) }
 
 
 sub add_instance {
 	my $ed = $self->editor->{$bar} = Kephra::App::Editor->new( $panel );
 	$panel->append( \$ed );
 	$ed->SetDocPointer( $editor[0]->GetDocPointer() ) if @editor;
-	Kephra::API::Doc::add_instance($self, $bar);
+	Kephra::API::DocumentStash::add_doc_instance($self, $bar);
 }
 
 sub del_instance {
 	return Kephra::Log::warning("need an existing Kephra::App::Bar::Document instance")
 		unless blessed($bar) eq 'Kephra::App::Bar::Document'
 		and exists $self->panel->{$bar};
-	Kephra::API::Doc::remove_instance($self, $bar);
+	Kephra::API::DocumentStash::remove_doc_instance($self, $bar);
 	$bar->remove_page( $self->panel->{$bar} );
 	delete $self->panel->{$bar};
 	delete $self->editor->{$bar};