App-Codit

 view release on metacpan or  search on metacpan

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

use vars qw( $VERSION );
$VERSION = '0.19';

use Data::Compare;
require Tk::ITree;

use base qw( App::Codit::BaseClasses::TextModPlugin );

=head1 DESCRIPTION

Manage bookmarks for all files.

=head1 DETAILS

The bookmarks menu only covers bookmarks within the selected document. The bookmarks
plugin covers the bookmarks in all open files. I creates a bookmarks list in the
navigator panel and a previous and next button in the toolbar. Previous and next refer
to the previously and next selected bookmarks.

The sessions plugin restores all bookmarks in the Bookmarks plugin if it is loaded.

=head1 COMMANDS

=over 4

=item B<bm_plug_next>

Jumps to the next selected bookmark.

=item B<bm_plug_previous>

Jumps to the previous selected bookmark.

=back

=cut

sub new {
	my $class = shift;
	my $self = $class->SUPER::new(@_);
	return undef unless defined $self;

	my $page = $self->ToolLeftPageAdd('Bookmarks', 'bookmarks', undef, 'Manage your bookmarks', 250);

	$self->cmdConfig(
		bm_plug_next => ['bmNext', $self],
		bm_plug_previous => ['bmPrevious', $self],
	);
	$self->cmdHookAfter('bookmark_add', 'RefreshSelected', $self);
	$self->cmdHookAfter('bookmark_remove', 'RefreshSelected', $self);

	$self->{CURRENT} = undef;
	$self->{NEXT} = [];
	$self->{PREVIOUS} = [];

	my $tree = $page->Scrolled('ITree',
		-height => 4,
		-browsecmd => ['Select', $self],
		-scrollbars => 'osoe',
		-separator => '@',
	)->pack(-padx => 2, -pady => 2, -expand => 1, -fill => 'both');
	$self->{TREE} = $tree;

	$self->after(100, ['Initialize', $self]);
	return $self;
}

sub _visible {
	my $self = shift;
	return $self->tree->ismapped;
}

sub bmAdd {
	my $self = shift;
	my $name = shift;
	my $t = $self->tree;
	
	#add parent unless already exists
	unless ($t->infoExists($name)) {

		#calculate position
		my @ch = $t->infoChildren('');
		my @op;
		for (@ch) {
			if ($_ gt $name) {
				push @op, -before => $_;
				last;
			}
		}

		#add parent
		$t->add($name, -text => $self->abbreviate($name, 30), @op);
	}

	#add bookmarks
	while (@_) {
		my $mark = shift;
		unless ($self->bmExists($name, $mark)) {
			#calculate position
			my @ch = $t->infoChildren($name);
			my $newmark = $name . '@' . $mark;
			my $line = $self->bmLineNumber($newmark);
			my @op;
			for (@ch) {
				my $peer = $self->bmLineNumber($_);
				if ($peer > $line) {
					push @op, -before => $_;
					last;
				}
			}
	
			#add bookmark
			$t->add($newmark, -text => $mark, @op);
		}
		$t->autosetmode(1);
	}
}

sub bmCompare {
	my ($self, $mark1, $mark2) = @_;
	if ($mark1 =~ /^(\d+)/) {



( run in 0.702 second using v1.01-cache-2.11-cpan-5b529ec07f3 )