1. Herbert Breunung
  2. Kephra

Commits

Herbert Breunung  committed 0168652

sed uses io localfile now

  • Participants
  • Parent commits 745b494
  • Branches sp2

Comments (0)

Files changed (1)

File lib/sed.pl

View file
  • Ignore whitespace
 
 sub OnInit {
 	my $app   = shift;
-   	my $frame = Wx::Frame->new( undef, -1, __PACKAGE__ . 'Kephra xp testbed', [-1,-1], [1000,800]);
+   	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 );
 
 		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 );
+			($content, $encoding) = Kephra::IO::LocalFile::read( $file = $selected );
 			$ed->SetText( $content );
 		}
 		elsif ($code == 81 and $event->ControlDown){ 
 		} 
 		else { $event->Skip }
         });
-	$ed->SetText( read_file($file) );
+    ($content, $encoding) = Kephra::IO::LocalFile::read( $file );
+	$ed->SetText( $content );
 
 	$frame->Center();
 	$frame->Show(1);
 	1;
 }
 
-
-sub read_file {
-	my $file = shift;
-	return unless $file and -r $file;
-	CORE::open my $FH, '<', $file;
-	binmode($FH);
-	my $content = do { local $/; <$FH> };
-	if ($content) {
-		my $guess = Encode::Guess::guess_encoding( $content, qw/utf-8 iso8859-1 latin1/ );
-		if ( ref($guess) and ref($guess) =~ m/^Encode::/ ) {
-			$encoding = $guess->name;
-		} elsif ( $guess =~ m/utf8/ ) {
-			$encoding = 'utf-8';
-		} elsif ( $guess =~ m/or/ ) {
-			my @suggest_encodings = split /\sor\s/, $guess;
-			$encoding = $suggest_encodings[0];
-		} else { $encoding = 'utf-8' }
-		return Encode::decode( $encoding,  $content );
-	}
-}
-
-sub write_file {
-	my ($file, $content) = @_;
-	return unless $file and -w $file;
-	CORE::open my $FH, '> :raw :encoding('.$encoding.')', $file;
-	print $FH $content;
-}
-
 package main;
 SingleEdit->new->MainLoop;