Source

Kephra / lib / sed.pl

#!usr/bin/perl
use v5.12;
use warnings;

package SingleEdit;
use Wx;
use base qw(Wx::App);
use Kephra::App::Dialog;
use Kephra::App::Editor;
use Kephra::IO::LocalFile;

our $file = __FILE__;
our ($encoding, $content);

sub OnInit {
	my $app   = shift;
   	my $frame = Wx::Frame->new( undef, -1, __PACKAGE__ . 'Kephra xp testbed step 2', [-1,-1], [1000,800]);
  	my $ed = Kephra::App::Editor->new($frame, -1);
  	Wx::Window::SetFocus( $ed );

	Wx::Event::EVT_KEY_DOWN($ed , sub {
		my ($ed, $event) = @_;
		my $code = $event->GetUnicodeKey;
		if ($code == 79 and $event->ControlDown){
			my $selected = Kephra::App::Dialog::get_file_open(undef,undef,undef,undef,$frame);
			return unless $selected and -r $selected;
			($content, $encoding) = Kephra::IO::LocalFile::read( $file = $selected );
			$ed->SetText( $content );
		}
		elsif ($code == 81 and $event->ControlDown){ 
			$frame->Close
		}
		elsif ($code == 83 and $event->ControlDown){
			Kephra::IO::LocalFile::write( $file, $encoding, $ed->GetText() );
		} 
		else { $event->Skip }
        });
    ($content, $encoding) = Kephra::IO::LocalFile::read( $file );
	$ed->SetText( $content );

	$frame->Center();
	$frame->Show(1);
	$app->SetTopWindow($frame);
	1;
}

package main;
SingleEdit->new->MainLoop;

# autosave
# save status
# logging