Commits

Herbert Breunung  committed 62fb22e

prepared med.pl for dev

  • Participants
  • Parent commits 49886f4
  • Branches sp2

Comments (0)

Files changed (3)

File README.txt

Empty file added.

File lib/docbar.pl

-use v5.12;
-use warnings;
-
-package Kephra;
-BEGIN {
-        our $NAME = __PACKAGE__;
-        our $VERSION = 'sp1';
-}
-
-package Kephra::App;
-use Wx;
-use Kephra::API;
-use Kephra::App::Bar::Document;
-use Kephra::App::Dialog;
-use Kephra::App::Editor;
-use Kephra::App::Frame;
-use Kephra::Log;
-use Kephra::File;
-use base qw(Wx::App);
-our $_ref;
-
-sub OnInit {
-        my $app  = $_ref = shift;
-        Kephra::Log::off(); 
-        my $win = Kephra::App::Frame->new( 'DBD - docbar demo' );
-        my $db = Kephra::App::Bar::Document->new($win);
-
-        Kephra::File::new();
-        Kephra::API::focus( Kephra::API::document()->panel );
-        my $doc = Kephra::API::document();
-
-        $win->Center();
-        $win->Show(1);
-        $app->SetTopWindow($win);
-        1;
-}
-
-
-package main;
-Kephra::App->new->MainLoop;
 #!usr/bin/perl
 use v5.12;
 use warnings;
+BEGIN { unshift @INC, '.' }
+
+MultiEdit->new->MainLoop;
 
 package MultiEdit;
-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 3', [-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);
+	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;
 
-package main;
-MultiEdit->new->MainLoop;
+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 = 'Multi Edit - Kephra xp testbed step 3 - ' . $file;
+	$title .= ' *' if $status;
+	$self->SetTitle($title);
+}