1. Herbert Breunung
  2. Kephra

Commits

Herbert Breunung  committed dfbe38b

closing docs

  • Participants
  • Parent commits 591fbc4
  • Branches default

Comments (0)

Files changed (4)

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

View file
 		my $new_nr = $event->GetSelection;
 		Kephra::DocumentStash::set_active_doc( $nb->GetPage($new_nr) );
 		Kephra::API::widget('win')->refresh_title();
-		$event->Skip; # $event->Veto;
+		$event->Skip;
 	});
-	Wx::Event::EVT_AUINOTEBOOK_PAGE_CLOSE( $self, -1, sub { });
+	Wx::Event::EVT_AUINOTEBOOK_PAGE_CLOSE( $self, -1, sub {
+		my ($nb, $event ) = @_; 
+		$event->Veto;
+		Kephra::File::close_active();
+	});
 
 	return $self;
 }
 
 sub add_page {
 	my ($self, $label, $position, $set_active, $panel ) = @_;
-	$label = '<untitled>' unless $label;
-	$set_active = 1       unless defined $set_active;
+
+	$label       = ''     unless defined $label;
 
 	my $pages      = $self->GetPageCount;
 	my $active_pos = $self->GetSelection;
-	my $active_ed  = $self->GetPage($active_pos);
+	#my $active_ed  = $self->GetPage($active_pos);
+	$position = $pages if $position == -1;
+
+	$set_active = 1       unless defined $set_active;
 
 	my $ed = defined $panel
 		? $panel
 		: Kephra::App::Editor->new($self);
 
-	$self->InsertPage( $pages, $ed, $label, $set_active );
+	$self->InsertPage( $position, $ed, $label, $set_active );
+	$self->set_title( $position, $label);
 	$ed->focus() if $set_active;
 
 	return $ed;
 	$self->SetSelection( $self->GetPageIndex($ed) );
 }
 
+sub set_title {
+	my ($self, $nr, $label) = @_;
+	return unless $nr >= 0 and $nr < $self->GetPageCount;
+	$label = '<untitled>' unless $label;
+	$self->SetPageText( $nr, $label );
+}
+#AdvanceSelection
+
+
 1;

File lib/Kephra/App/Editor.pm

View file
 			( $event->ShiftDown
 			+ $event->ControlDown * 2 
 			+ $event->AltDown     * 4);
-		if      ($event->GetKeyCode ==  &Wx::WXK_UP and $event->ControlDown) {
+		if      ($key ==  &Wx::WXK_UP + 2000) {
 			if ($event->ShiftDown) {$self->CmdKeyExecute(&Wx::wxSTC_CMD_PARAUPEXTEND)} 
 			else                   {$self->CmdKeyExecute(&Wx::wxSTC_CMD_PARAUP)}
-		} elsif ($event->GetKeyCode ==  &Wx::WXK_DOWN and $event->ControlDown){
+		} elsif ($key ==  &Wx::WXK_DOWN + 2000){
 			if ($event->ShiftDown) {$self->CmdKeyExecute(&Wx::wxSTC_CMD_PARADOWNEXTEND)} 
 			else                   {$self->CmdKeyExecute(&Wx::wxSTC_CMD_PARADOWN)}
-		} elsif ($event->GetKeyCode ==  &Wx::WXK_ESCAPE) {
-			Kephra::App::Panel::FileBrowser::focus();
-		} else {$event->Skip}
+		}
+		elsif ($key ==  &Wx::WXK_ESCAPE){ Kephra::App::Panel::FileBrowser::focus() } 
+		elsif ($key ==  ord('Q') + 2000) { Kephra::File::close_active() }
+		else {$event->Skip}
 
 		#print " $key- \n";
 	});

File lib/Kephra/App/Panel/Editor.pm

View file
 use Kephra::DocumentStash;
 #my $_ref; # whole panel widget, parent of all this
 my %doc_bar;
-my $active;
+#my $active;
 
 sub _active_docbar{ $doc_bar{'leftup'} }
 
 	$nb->GetPageText( $nb->GetSelection );
 }
 
+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->DeletePage( $main_doc_bar->GetPageIndex( $doc->editor ) );
+	} else {
+		$doc->editor->ClearAll;
+		$doc->assign_file('');
+		$main_doc_bar->set_title(0, '');
+	}
+}
+
 1;

File lib/Kephra/File.pm

View file
 use strict;
 use warnings;
 use File::Spec;
+use Kephra::API;
 use Kephra::App::Panel::Editor;
 
 package Kephra::File;
 sub save_active {}
 sub save_all    {}
 
-sub close_active {}
+
+sub close_active {
+	my $doc = Kephra::API::active_doc();
+	return unless $doc;
+	Kephra::App::Panel::Editor::remove_document( $doc );
+}
 sub close_other  {}
 sub close_all    {}