Source

Kephra / lib / Kephra / App / Part / Editor.pm

use strict;
use warnings;

package Kephra::App::Part::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_path($file);
		$main_doc_bar->set_page_title( $doc->file_name );
	} else {                                         # make new editor
		$doc = Kephra::Document->new();
		$doc->assign_file_path( $file );
		$doc->editor( Kephra::App::Editor->new( $win ) );
		Kephra::DocumentStash::add_and_activate( $doc );
print Kephra::API::document(), " || $doc\n";
		$main_doc_bar->add_page($doc->editor, $doc->file_name, -1, 1);
print Kephra::API::document(), " || $doc\n";
		Kephra::API::focus( $doc->editor );
print Kephra::API::document(), " || $doc\n";

	}
	$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_name('');
		$main_doc_bar->set_page_title('');
	}
	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;