Source

Kephra / lib / Kephra / App / Panel / Editor.pm

Full commit
use strict;
use warnings;

package Kephra::App::Panel::Editor;
use Kephra::API;
use Kephra::App::Bar::Document;
use Kephra::Document;
use Kephra::DocumentStash;
#my $_ref; # whole panel widget, parent of all this
my %doc_bar;
#my $active;

sub active_docbar{ $doc_bar{'leftup'} }

sub new {
	my( $class, $parent) = @_;
	$doc_bar{'leftup'} = Kephra::App::Bar::Document->new( $parent );
	# Wx::SplitterWindow->new( $splitter{'left'}, -1 );
	return $doc_bar{'leftup'};
}

sub create_document {
	my $file = shift;
	my $doc = Kephra::API::document();
	my $win = Kephra::API::main_window();
	my $main_doc_bar = active_docbar();

	if ($doc and $doc->editor->is_empty and $file) { # overwrite empty doc
		$doc->assign_file($file);
		$main_doc_bar->SetPageText( $main_doc_bar->GetSelection , $doc->file_name );
	} else {                                         # make new editor
		$doc = Kephra::Document->new();
		$doc->assign_file( $file );
		$doc->editor( Kephra::App::Editor->new( $win ) );
		Kephra::DocumentStash::add_and_activate( $doc );
		$main_doc_bar->add_page( $doc->file_name, -1, 1, $doc);
	}
	$doc->editor->focus();
	$win->refresh_title();
	return $doc;
}

sub remove_document {
	my $doc = shift;
	return unless ref $doc and $doc->isa('Kephra::Document');
	my $main_doc_bar = active_docbar();
	if ($main_doc_bar->GetPageCount > 1) {
		$main_doc_bar->remove_page( $main_doc_bar->GetPageIndex( $doc->panel ) );
		Kephra::DocumentStash::del($doc);
	} else {
		$doc->editor->ClearAll;
		$doc->assign_file('');
		$main_doc_bar->set_page_title(0, '');
	}
	Kephra::API::main_window()->refresh_title();
}

sub raise_document {
	my $doc = Kephra::DocumentStash::doc_by_anything(shift);
	active_docbar()->raise_page( $doc->{panel} ) if $doc;
}

sub active_title {
	my $nb = active_docbar();
	$nb->GetPageText( $nb->GetSelection );
}

1;