Commits

Herbert Breunung committed 8df03e3

save status of only doc now visible

  • Participants
  • Parent commits b94d606
  • Branches sp2

Comments (0)

Files changed (6)

lib/Kephra/API.pm

 #use Kephra::API::DocumentStash;
 #use Kephra::API::Event;
 #use Kephra::API::GuiBuilder;
-#use Kephra::API::KeyMap;
+use Kephra::API::KeyMap;
 use Kephra::API::Log;
 #use Kephra::API::MacroRecorder;
 #use Kephra::API::Plugin;
 our $VERSION = 0.1002;
 our @ISA = qw(Exporter);
 our @EXPORT = qw(message warning error);
-our @EXPORT_OK = qw(message warning error);  # symbols to export on request
+our @EXPORT_OK = qw(message warning error output);  # symbols to export on request
 #%EXPORT_TAGS = (T => [qw()], 2 => [qw()]);
 
 our $ed;
 sub warning  { Kephra::API::Log::warning(@_) }
 sub error    { Kephra::API::Log::error(@_)   }
 
+sub output {}
+
 
 'all you need should is there for you';

lib/Kephra/API/Log.pm

 
 package Kephra::API::Log;
 
-use Kephra::API ();
+use Kephra::API qw(output);
 
 our $level;
 our @output;
-our %switch = (global => 1, cli => 1); # logging is on per default
+our %switch = (global => 1, cli => 1, gui => 0); # logging is on per default
 
 sub mode {
 	my $mode = shift;

lib/Kephra/App/Editor.pm

 	#Wx::Event::EVT_RIGHT_DOWN
 	#Wx::Event::EVT_STC_UPDATEUI
 	Wx::Event::EVT_STC_SAVEPOINTREACHED($self, -1, sub {
+		$self->GetParent->set_title(0);
 		#Kephra::App::Part::Editor::refresh_doc_label()
 	});
-	Wx::Event::EVT_STC_SAVEPOINTLEFT($self, -1, sub { 
+	Wx::Event::EVT_STC_SAVEPOINTLEFT($self, -1, sub {
+		$self->GetParent->set_title(1);
 		#Kephra::App::Part::Editor::refresh_doc_label() 
 	});
 	Wx::Event::EVT_SET_FOCUS( $self, sub {

lib/Kephra/IO/LocalFile.pm

 	my $encoding;
 	return warning("can't load nonexising file") unless $file and -e $file;
 	return warning("can't read $file") unless -r $file;
-	CORE::open my $FH, '<', $file;
+	open my $FH, '<', $file;
 	binmode($FH);
 	my $content = do { local $/; <$FH> };
 	if ($content) {
 	$file = normalize_path( $file );
 	return warning("need a file path") unless $file;
 	return warning("can't overwrite $file") if -e $file and not -w $file;
-	CORE::open my $FH, "> :raw :encoding($encoding)", $file;
+	open my $FH, "> :raw :encoding($encoding)", $file;
 	print $FH $content;
 }
 
 			print $FH $ed->GetText();
 		} 
 		else { $event->Skip }
-    });
+	});
 
 	$frame->Show(1);
 	$app->SetTopWindow($frame);
 use v5.12;
 use warnings;
 BEGIN { unshift @INC, '.' }
+use Wx;
+
+SingleEdit->new->MainLoop;
 
 package SingleEdit;
-use Wx;
 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 = __FILE__;
-our ($encoding, $content);
+our ($file, $encoding, $content, $ed);
 
-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);
+sub new {
+	my($class, $parent) = @_;
+	my $self = $class->SUPER::new( undef, -1, '', [-1,-1], [1000,800] );
+	$ed = Kephra::App::Editor->new($self, -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 );
+			open_file( Kephra::App::Dialog::get_file_open(undef,undef,undef,undef,$self) );
 		}
-		elsif ($code == 81 and $event->ControlDown){ 
-			$frame->Close
-		}
+		elsif ($code == 81 and $event->ControlDown){ $self->Close }
 		elsif ($code == 83 and $event->ControlDown){
 			Kephra::IO::LocalFile::write( $file, $encoding, $ed->GetText() );
+			$ed->SetSavePoint;
 		} 
-		else { $event->Skip }
+		else                                       { $event->Skip }
 	});
-	($content, $encoding) = Kephra::IO::LocalFile::read( $file );
-	$ed->SetText( $content );
-
-	#say $Kephra::API::VERSION;
-
-	$frame->Center();
-	$frame->Show(1);
-	$app->SetTopWindow($frame);
-	1;
+	open_file(__FILE__); #say $Kephra::API::VERSION;
+	return $self;
 }
 
-package main;
-SingleEdit->new->MainLoop;
+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;
+}
+
+sub set_title {
+	my ($self, $status) = @_;
+	my $title = 'Kephra xp testbed step 2 - ' . $file;
+	$title .= ' *' if $status;
+	$self->SetTitle($title);
+}
 
 # autosave
-# save status
-# logging
-# show file name
 # status line
-# how insert edit functions
+# how insert edit functions
+# use keymap