Source

Kephra / lib / Kephra / App / Window.pm

use v5.10;
use warnings;
use Wx;
use Kephra::API;
use Kephra::App::Bar::Menu;
use Kephra::App::Bar::MainTool;
use Kephra::App::Bar::Search;
use Kephra::App::Bar::Status;
use Kephra::App::Dialog;
use Kephra::App::Part::Editor;
use Kephra::App::Part::TextLab;
use Kephra::App::Part::IOUnit;
use Kephra::App::Part::FileBrowser;
use Kephra::App::Part::ProjectManager;
use Kephra::App::Part::TreeLib;
use Kephra::App::Part::OrgPad;
use Kephra::App::Part::ScratchSheet;
use Kephra::App::Splitter;


package Kephra::App::Window;
our @ISA = 'Wx::Frame';
our $_ref;
my $title_end = "$Kephra::NAME $Kephra::VERSION";

Kephra::API::Command::register({
 'window-fullscreen-toggle'=>{sub =>'$win->toggle_fullscreen', label=>'Fullscreen', keys=>'F11'},
 'iounit-focus'            =>{sub =>'$win->{"part"}{"iounit"}->focus_on_input', label => ' ', keys => 'esc'},
});


sub new {
	my( $class, $title ) = @_;
	my( $self ) = $_ref = $class->SUPER::new ( undef, -1, $title, [-1,-1],[1000, 800] );
	$self->SetIcon( Wx::GetWxPerlIcon() );
	Kephra::App::Focus::set($self);

	# container var for all panel, sizer and splitter
	my (%panel, %sizer, %splitter, %gui_part);

	for my $name (qw /left right above below/) {
		$splitter{$name} = Kephra::App::Splitter->new( ) unless $name eq 'above';
		$panel{ $name } = Wx::Panel->new( $self );
		$sizer{ $name } = ($name eq 'above' or $name eq 'below')
			? Wx::BoxSizer->new( &Wx::wxVERTICAL )
			: Wx::BoxSizer->new( &Wx::wxHORIZONTAL );
		$panel{ $name }->SetSizer( $sizer{ $name } );
	}

	$splitter{'left'}->set({
		left => $panel{'left'},   right => $splitter{'right'}, parent  => $self,
		dominant_child => 'right',  pos => 250,    min => 200
	});
	$splitter{'right'}->set({
		left => $splitter{'below'}, right => $panel{'right'}, parent  => $splitter{'left'},
		dominant_child => 'left',     pos => -200, min => 140
	});
	$splitter{'below'}->set({
		top => $panel{'above'},    bottom => $panel{'below'}, parent  => $splitter{'right'},
		dominant_child => 'top',      pos => -200, min => 100
	});


	$self->{'part'} = \%gui_part;
	$gui_part{'editor'}      = Kephra::App::Part::Editor   ->new( $panel{'above'} );
	$gui_part{'searchbar'}   = Kephra::App::Bar::Search    ->new( $panel{'above'} );
	$gui_part{'iounit'}      = Kephra::App::Part::IOUnit   ->new( $panel{'below'} );
	$gui_part{'filebrowser'} = Kephra::App::Part::FileBrowser->new($panel{'left'} );
	#my $projectman      = Kephra::App::Part::ProjectManarger->new( $panel{'left'} );
	$gui_part{'treelib'}     = Kephra::App::Part::TreeLib  ->new( $panel{'right'} );
	#my $orgpad          = Kephra::App::Part::OrgPad     ->new( $panel{'right'} );
	#my $scratchsheet    = Kephra::App::Part::ScratchSheet->new( $panel{'right'} );
	$gui_part{'statusbar'}   = Kephra::App::Bar::Status    ->new( $self );

	$sizer{'above'}->Add( $gui_part{'editor'},     1, &Wx::wxGROW );
	$sizer{'above'}->Add( $gui_part{'searchbar'},  0, &Wx::wxGROW );
	$sizer{'below'}->Add( $gui_part{'iounit'},     1, &Wx::wxGROW );
	$sizer{'right'}->Add( $gui_part{'treelib'},    1, &Wx::wxGROW );
	$sizer{'left'} ->Add( $gui_part{'filebrowser'},1, &Wx::wxGROW );

	$sizer{'main'} = Wx::BoxSizer->new( &Wx::wxVERTICAL );
	$sizer{'main'}->Add( $splitter{'left'},       1, &Wx::wxGROW);
	$sizer{'main'}->Add( $gui_part{'statusbar'},  0, &Wx::wxGROW);
	$self->SetSizer( $sizer{'main'} );


	$self->SetMenuBar( Kephra::App::Bar::Menu::get() );
	$self->GetMenuBar->SetAcceleratorTable( Wx::AcceleratorTable->new() );

	#Wx::Event::EVT_SPLITTER_DCLICK( ,sub {});  #&Wx::wxSP_NOBORDER  );
	Wx::Event::EVT_CLOSE( $self, sub{ Kephra::App::close_save() });

	return $self;
}

sub close   { $_ref->Close() }
sub destroy { $_ref->Destroy() }

sub get_title { $_ref->GetTitle( )       }
sub set_title { $_ref->SetTitle( $_[1] ) }
sub refresh_title {
	my $self = shift;
	my $doc = Kephra::API::document();
	return $self->set_title( $title_end ) unless defined $doc and $doc;

	my $title = $doc->title;
	$title .= ' ('.$doc->file_path.')' if $doc->file_path;
	$self->set_title( $title . " - $title_end" );
}

sub toggle_fullscreen {
	my ($self) = @_;
	$self->{fullscreen} ^= 1;
	$self->ShowFullScreen ( 
		$self->{fullscreen}, 
		&Wx::wxFULLSCREEN_NOCAPTION | &Wx::wxFULLSCREEN_NOBORDER
	);
}

1;