App-Codit

 view release on metacpan or  search on metacpan

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

use base qw( Tk::AppWindow::BaseClasses::Plugin );

require Tk::Adjuster;
require Tk::YANoteBook;
require App::Codit::CodeTextManager;

=head1 DESCRIPTION

Create a secondary document interface for simultaneous reviewing.

=head1 DETAILS

This plugin creates a secondary document interface that holds all the
documents in the primary one in a readonly state. You can create
a horizontal or a vertical split through the View menu. Whenever
a document is opened or closed in the primary interface it is also
opened or closed in the secondary interface.

=head1 COMMANDS

=over 4

=item B<split_cancel>

Removes an existing split from view.

=item B<split_horizontal>

Creates a horizontal split.

=item B<split_vertical>

Creates a vertical split.

=back

=cut

sub new {
	my $class = shift;
	my $self = $class->SUPER::new(@_);
	return undef unless defined $self;
	
	$self->{ADJUSTER} = undef;
	$self->{DOCS} = {};
	$self->{SPLIT} = undef;
	$self->{STATE} = 'none';
	my $w = $self->WorkSpace;
	
	$self->cmdHookAfter('doc_close', 'splitClose', $self);
	$self->cmdHookAfter('doc_open', 'splitOpen', $self);

	$self->cmdConfig(
		split_cancel => ['splitCancel', $self],
		split_horizontal => ['splitHorizontal', $self],
		split_vertical => ['splitVertical', $self],
	);
	return $self;
}

sub MenuItems {
	my $self = shift;
	my $path = 'View::Show navigator panel';
	return (
#This table is best viewed with tabsize 3.
#			 type					 menupath			label	              cmd                icon
		[	'menu_normal', 	 $path,     'Split ~horizontal',		'split_horizontal',   'view-split-left-right'],
		[	'menu_normal', 	 $path,     'Split ~vertical',		  'split_vertical',     'view-split-top-bottom'],
		[	'menu_normal', 	 $path,     'Split ~cancel',		    'split_cancel', ],
		[	'menu_separator',$path,     's1'],
	)
}

sub split { return $_[0]->{SPLIT} }

sub splitCancel {
	my $self = shift;
	my $state = $self->{STATE};
	return if $self->{STATE} eq 'none';
	$self->splitRemove;
	$self->{STATE} = 'none';
}

sub splitClose {
	my ($self, $name) = @_;
	my $split = $self->{SPLIT};
	return unless defined $split;
	return if $name eq '';
	my $plit = $self->split;
	$split->deletePage($name);
}

sub splitGet {
	my $self = shift;
	my $split = $self->{SPLIT};
	unless (defined $split) {
		$split = 	$self->{INTERFACE} = $self->WorkSpace->YANoteBook(
			-image => $self->getArt('document-multiple', 16),
			-selecttabcall => ['splitSelect', $self ],
		);
		my $mdi = $self->mdi;
		my $interface = $self->mdi->Interface;
		my $disp = $interface->{DISPLAYED};
		my $undisp = $interface->{UNDISPLAYED};
		for (@$disp, @$undisp) {
			my ($t) = $mdi->docTitle($_);
			$split->addPage($_,
				-title => $t,
			);
		}
		$self->{SPLIT} = $split;
		my $sel = $mdi->docSelected;
		$split->selectPage($sel);
	}
	return $split
}

sub splitHorizontal {
	my $self = shift;
	$self->splitRemove;
	my $w = $self->WorkSpace;



( run in 0.994 second using v1.01-cache-2.11-cpan-d7f47b0818f )