#!/usr/bin/env perl 
#A test script that crtaes a minimalist text editor
#use GUIDeFATE (which in turn depends on Wx)

use strict;
use warnings;
use GUIDeFATE qw<$frame>;

my $window=<<END;
+--------------------------------------+
|T  Test GnuPlot                       |
+M-------------------------------------+
|+T------------------------------------+
||text editor                          |
||                                     |
||                                     |
||                                     |
||                                     |
||                                     |
||                                     |
||                                     |
|+-------------------------------------+
|                                      |
+--------------------------------------+

Menu
-File
--New
--Open
--Save
--Quit
-Image
--Save As
--Options

END

GUIDeFATE::convert($window);
GUIDeFATE->new()->MainLoop;

sub menu4{
	if($frame->showDialog("Sure?","This will wipe existing text...proceed?","OKC","!")){
	   $frame->{TextCtrl1}->SetValue("");
   }
}
sub menu5{
	if($frame->showDialog("Sure?","This will wipe existing text...proceed?","OKC","!")){
	  $frame->{TextCtrl1}->SetValue("");
	  my $file= $frame->showFileSelectorDialog("Open file",1);
	    if (open(my $fh, '<:encoding(UTF-8)', $file)) {
          while (my $row = <$fh>) {
             $frame->{TextCtrl1}->AppendText($row)
          }
       close $fh;
      }
  }
}
sub menu6{
	my $file= $frame->showFileSelectorDialog("Save file",0);
	if (open(my $fh, '>', $file)) {
       print $fh  $frame->{TextCtrl1}->GetValue();
       close $fh
       }
    }
    
sub menu7{
	$frame->quit();
}
