Source

Kephra / lib / Kephra / App / Window.pm

Full commit
use strict;
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;


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

Kephra::CommandList::register_cmd({
 '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);
	$splitter{'left'}  = Wx::SplitterWindow->new( $self,             -1 );
	$splitter{'right'} = Wx::SplitterWindow->new( $splitter{'left'}, -1 );
	$splitter{'below'} = Wx::SplitterWindow->new( $splitter{'right'},-1 );
	$panel   {'above'} = Wx::Panel         ->new( $splitter{'below'});
	$splitter{'edit'}  = Wx::SplitterWindow->new( $panel   {'above'},-1 );

	for my $name (qw /left right above below edit/) {
		$panel{ $name } = Wx::Panel->new( $splitter{ $name } ) unless $name eq 'above';
		$sizer{ $name } = Wx::BoxSizer->new( &Wx::wxHORIZONTAL );
		$sizer{ $name } = Wx::BoxSizer->new( &Wx::wxVERTICAL ) if $name eq 'above'
															   or $name eq 'below';
		$panel{ $name }->SetSizer( $sizer{ $name } );
	}
	$self->{'part'} = \%gui_part;
	$gui_part{'editor'}      = Kephra::App::Part::Editor   ->new( $panel{'edit'} );
	$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 );

	$splitter{'left'}->SplitVertically( $panel{'left'}, $splitter{'right'}, 200);
	$splitter{'left'}->SetSashGravity(0);
	$splitter{'left'}->SetSashPosition(200);
	$splitter{'left'}->SetMinimumPaneSize(140);
	$splitter{'right'}->SplitVertically( $splitter{'below'}, $panel{'right'}, -200);
	$splitter{'right'}->SetSashGravity(1);
	$splitter{'right'}->SetSashPosition(-200);
	$splitter{'right'}->SetMinimumPaneSize(140);
	$splitter{'below'}->SplitHorizontally( $panel{'above'}, $panel{'below'}, -200);
	$splitter{'below'}->SetSashGravity(1);
	$splitter{'below'}->SetSashPosition(-200);
	$splitter{'below'}->SetMinimumPaneSize(100);
	$splitter{'edit'}->Initialize( $panel{'edit'} );

	$sizer{'edit'} ->Add( $gui_part{'editor'},     1, &Wx::wxGROW );
	$sizer{'above'}->Add( $splitter{'edit'},       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::DocumentStash::active_doc();
	my $title = (ref $doc and $doc->file_name)
		? $doc->file_name.' ('.$doc->file_path.')'
		: Kephra::App::Part::Editor::active_title();
	$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;