App-Codit

 view release on metacpan or  search on metacpan

lib/App/Codit/Plugins/SplitView.pm  view on Meta::CPAN

sub splitHorizontal {
	my $self = shift;
	$self->splitRemove;
	my $w = $self->WorkSpace;
	$w->gridColumnconfigure(2, -weight => 1);
	my $i = $self->mdi->Interface;
	
	my $a = $w->Adjuster(
		-widget => $i,
		-side => 'left'
	)->grid(-row => 0, -column => 1, -sticky => 'ns');
	$self->{ADJUSTER} = $a;

	my $s = $self->splitGet;
	$s->grid(-row => 0, -column => 2, -sticky => 'nsew');
	my $width = $w->width;
	$i->GeometryRequest(int(($width)/2), $w->height);

	$self->{STATE} = 'horizontal';
}

sub splitOpen {
	my ($self, $name) = @_;
	my $split = $self->{SPLIT};
	return unless defined $split;
	return if $name eq '';
	my $plit = $self->split;
	my ($t) = $self->mdi->docTitle($name);
	$split->addPage($name,
		-title => $t,
	);
}

sub splitRemove {
	my $self = shift;
	my $s = $self->{STATE};
	return if $self->{STATE} eq 'none';
	my $m = $self->{SPLIT};
	$m->gridForget;
	my $a = $self->{ADJUSTER};
	$a->gridForget;
	$a->destroy;
	my $w = $self->WorkSpace;
	$w->gridColumnconfigure(2, -weight => 0);
	$w->gridRowconfigure(2, -weight => 0);
	my $i = $self->mdi->Interface;
	$w->gridColumnconfigure(0, -weight => 1);
	$w->gridRowconfigure(0, -weight => 1);
	$i->grid(-column => 0, -row => 0, -sticky => 'nsew');
}

sub splitSelect {
	my ($self, $name) = @_;
	my $split = $self->split;
	my $mdi = $self->mdi;
	my $w;
	unless (exists $self->{DOCS}->{$name}) {
		my $page = $split->getPage($name);
		my $man = $page->CodeTextManager(
			-extension => $mdi,
		)->pack(-expand => 1, -fill => 'both');
		$w = $man->CWidg;
		$w->configure('-readonly', 1);
		$self->{DOCS}->{$name} = $w;
	} else {
		$w = $self->{DOCS}->{$name}
	}
	if ($mdi->deferredExists($name)) {
		$w->load($name);
	} else {
		my $d = $mdi->docGet($name);
		my $content = $d->get('1.0', 'end - 1c');
		$w->delete('1.0', 'end');
		$w->insert('end', $content);
		$w->ResetRedo;
		$w->ResetUndo;
		$w->editModified(0);
		$w->configure('-syntax', $d->CWidg->cget('-syntax'));
	}
}

sub splitVertical {
	my $self = shift;
	$self->splitRemove;
	my $w = $self->WorkSpace;
	$w->gridRowconfigure(2, -weight => 1);
	my $i = $self->mdi->Interface;
	
	my $a = $w->Adjuster(
		-widget => $i,
		-side => 'top'
	)->grid(-row => 1, -column => 0, -sticky => 'ew');
	$self->{ADJUSTER} = $a;

	my $s = $self->splitGet;
	$s->grid(-row => 2, -column => 0, -sticky => 'nsew');
	my $height = $w->height;
	$i->GeometryRequest($w->width, int(($height)/2));

	$self->{STATE} = 'vertical';
}


sub Unload {
	my $self = shift;
	
	#destroy the split window
	my $split = $self->split;
	$split->destroy if defined $split;

	#unhook commands
	$self->cmdUnhookAfter('doc_close', 'splitClose', $self);
	$self->cmdUnhookAfter('doc_open', 'splitOpen', $self);

	#unload commands
	for (qw/
		split_horizontal
		split_vertical
		split_cancel
	/) {
		$self->cmdRemove($_);



( run in 0.485 second using v1.01-cache-2.11-cpan-5623c5533a1 )