Commits

Herbert Breunung committed e525b0c

simple edit so far completed more comfort in ced

  • Participants
  • Parent commits 41b358f
  • Branches sp2

Comments (0)

Files changed (2)

+#!usr/bin/perl
+use v5.12;
+use warnings;
+BEGIN { unshift @INC, '.' }
+use Wx;
+
+SingleEdit->new->MainLoop;
+
+package SingleEdit;
+use base qw(Wx::App);
+
+sub OnInit {
+	my $app   = shift;
+	my $frame = Kephra::App::Window->new();
+	$frame->Center();
+	$frame->Show(1);
+	$app->SetTopWindow($frame);
+	1;
+}
+
+package Kephra::App::Window;
+use base qw(Wx::Frame);
+use Kephra::API qw(warning);
+use Kephra::App::Dialog;
+use Kephra::App::Editor;
+use Kephra::IO::LocalFile;
+
+our ($file, $encoding, $content, $ed);
+
+sub new {
+	my($class, $parent) = @_;
+	my $self = $class->SUPER::new( undef, -1, '', [-1,-1], [1000,800] );
+	$self->CreateStatusBar(3);
+	$self->SetStatusWidths(100, 50, -1);
+	$ed = Kephra::App::Editor->new($self, -1);
+	Wx::Window::SetFocus( $ed );
+
+	Wx::Event::EVT_KEY_DOWN($ed , sub {
+		my ($ed, $event) = @_;
+		given (Kephra::API::KeyMap::definition_from_event($event)){
+			when('ctrl+o'){ open_file( Kephra::App::Dialog::get_file_open() ) }
+			when('ctrl+q'){ $self->Close }
+			when('ctrl+s'){
+				Kephra::IO::LocalFile::write( $file, $encoding, $ed->GetText() );
+				$ed->SetSavePoint;
+			} 
+			default       { $event->Skip }
+		}
+	});
+	Wx::Event::EVT_STC_UPDATEUI($ed, -1, sub {
+		$self->SetStatusText( $ed->GetCurrentPos, 0);	
+	});
+	
+	open_file(__FILE__);
+	return $self;
+}
+
+sub open_file {
+	my $candidate = shift;
+	return unless $candidate and -r $candidate;
+	($content, $encoding) = Kephra::IO::LocalFile::read( $file = $candidate );
+	$ed->SetText( $content );
+	$ed->EmptyUndoBuffer;
+	$ed->SetSavePoint;
+	$ed->GetParent->SetStatusText( $encoding, 1);
+}
+
+sub set_title {
+	my ($self, $status) = @_;
+	my $title = 'Single Edit - Kephra xp testbed step 2 - ' . $file;
+	$title .= ' *' if $status;
+	$self->SetTitle($title);
+}
 sub new {
 	my($class, $parent) = @_;
 	my $self = $class->SUPER::new( undef, -1, '', [-1,-1], [1000,800] );
+	$self->CreateStatusBar(3);
+	$self->SetStatusWidths(100, 50, -1);
 	$ed = Kephra::App::Editor->new($self, -1);
 	Wx::Window::SetFocus( $ed );
 
 			default       { $event->Skip }
 		}
 	});
+	Wx::Event::EVT_STC_UPDATEUI($ed, -1, sub {
+		$self->SetStatusText( $ed->GetCurrentPos, 0);	
+	});
+	
 	open_file(__FILE__);
 	return $self;
 }
 	$ed->SetText( $content );
 	$ed->EmptyUndoBuffer;
 	$ed->SetSavePoint;
+	$ed->GetParent->SetStatusText( $encoding, 1);
 }
 
 sub set_title {
 	$title .= ' *' if $status;
 	$self->SetTitle($title);
 }
-# autosave
-# status line
-# ted: # how insert edit functions