App-Codit

 view release on metacpan or  search on metacpan

lib/App/Codit/Ext/CoditMDI.pm  view on Meta::CPAN

package App::Codit::Ext::CoditMDI;

=head1 NAME

App::Codit::Ext::CoditMDI - Multiple Document Interface for App::Codit

=cut

use strict;
use warnings;
use Carp;
use vars qw($VERSION);
$VERSION = '0.19';

use base qw( Tk::AppWindow::Ext::MDI );

#require Tk::AppWindow::PluginsForm;
require App::Codit::CoditTagsEditor;
require App::Codit::Macro;
require Tk::YADialog;

my @navcontextmenu = (
	[ 'menu_normal',    undef,  '~Close',  'doc_close',	 'document-close', '*CTRL+SHIFT+O'],
	[ 'menu_normal',    undef,  '~Delete',  'doc_delete_dialog',	 'edit-delete'],
	[ 'menu_separator', undef,  'c1'],
	[ 'menu_normal',    undef,  '~Collapse all',  'nav_collapse'],
	[ 'menu_normal',    undef,  '~Expand all',  'nav_expand'],
);

=head1 SYNOPSIS

my $app = new App::Codit(@options,
	-extensions => ['CoditMDI'],
);
$app->MainLoop;

=head1 DESCRIPTION

Inherits L<Tk::AppWindow::Ext::MDI>.

This is a specially crafted multiple document interface for l<App::Codit>.

=head1 CONFIG VARIABLES

=over 4

=item B<-doc_autobrackets> I<hookable>

Sets and returns the autobrackets option of the currently selected document.

=item B<-doc_autocomplete> I<hookable>

Sets and returns the autocomplete option of the currently selected document.

=item B<-doc_autoindent> I<hookable>

Sets and returns the autoindent option of the currently selected document.

=item B<-doc_wrap> I<hookable>

Sets and returns the wrap option of the currently selected document.

=item B<-doc_view_folds> I<hookable>

Sets and returns the showfolds option of the currently selected document.

=item B<-doc_view_numbers> I<hookable>

Sets and returns the shownumbers option of the currently selected document.

=item B<-doc_view_status> I<hookable>

Sets and returns the showstatus option of the currently selected document.

=item B<-doc_wrap>

Sets and returns the wrap option of the currently selected document.

=back

lib/App/Codit/Ext/CoditMDI.pm  view on Meta::CPAN

sub docWidget {
	my $self = shift;
	my $name = $self->docSelected;
	return undef unless defined $name;
	my $doc = $self->docGet($name);
	return undef unless defined $doc;
	return $doc->CWidg;
}

sub docWrap {
	my $self = shift;
	return $self->docOption('-contentwrap', @_);
}

=item B<editDelete>I<($begin, $end)>

Deletes text in the currently selected document. It takes two indices as parameters.

=cut

sub editDelete {
	my $self = shift;
	my $doc = $self->docSelected;
	return unless defined $doc;
	$self->docGet($doc)->delete(@_);
}


=item B<editInsert>I<($index, $text)>

Inserts text in the currently selected document. It takes an index and the text as parameters.

=cut

sub editInsert {
	my $self = shift;
	my $doc = $self->docSelected;
	return unless defined $doc;
	$self->docGet($doc)->insert(@_);
}

=item B<editReplace>I<($begin, $end, $text)>

Inserts text in the currently selected document. It takes indices $begin and $end and the text as parameters.

=cut

sub editReplace {
	my $self = shift;
	my $doc = $self->docSelected;
	return unless defined $doc;
	$self->docGet($doc)->replace(@_);
}

sub keyReleased {
#	my ($self, $name, $key) = @_;
}

=back

Macros are callbacks executed in the background. For each line in the document the macro is linked to,
the callback is executed with a reference to the text widget and the line number as parameter.
the macro ends after the last line has been processed. Codit uses macro callback to do tasks like show
leading and trailing tabs and spaces and reparing indentation.

=over 4

=item B<macroGet>I<($doc, $name)>

Returns a reference to the macro object $name belonging to $doc.

=cut

sub macroGet {
	my ($self, $doc, $name) = @_;
	my $mcr = $self->_mcr;
	return unless exists $mcr->{$doc};
	my $l = $mcr->{$doc};
	for (@$l) {
		my $n = $_->name;
		return $_ if $_->name eq $name
	}
	return undef
}

=item B<macroInit>I<($doc, $name, $call)>

Creates a new macro object $name for $doc with $call as callback.

=cut

sub macroInit {
	my ($self, $doc, $name, $call) = @_;
	unless (defined $self->macroGet($doc, $name)) {
		my $macro = App::Codit::Macro->new($self, $name, $doc, $call);
		my $mcr = $self->_mcr;
		$mcr->{$doc} = [] unless exists $mcr->{$doc};
		my $l = $mcr->{$doc};
		push @$l, $macro;
		return $macro;
	}
	warn "macro $name for $doc already exists";
	return undef
}

=item B<macroList>I<($doc)>

Returns a list with the objects of loaded macros for $doc.

=cut

sub macroList {
	my ($self, $doc) = @_;
	my $mcr = $self->_mcr;
	return unless exists $mcr->{$doc};
	my $l = $mcr->{$doc};
	return @$l;
}

=item B<macroRemove>I<($doc, $name)>

Removes macro $name for $doc from the stack.

=cut

sub macroRemove {
	my ($self, $doc, $name) = @_;
	if (defined $self->macroGet($doc, $name)) {
		my $mcr = $self->_mcr;
		my $l = $mcr->{$doc};
		my @list = @$l;
		my $count = 0;
		for (@list) {
			if ($_->name eq $name) {
				$_->stop;
				last;
			} else {
				$count ++;
			}
		}
		splice @list, $count, 1;
		if (@list) {
			$mcr->{$doc} = \@list;
		} else {
			delete $mcr->{$doc}
		}
		return
	}
	warn "macro $name for $doc does not exist"
}

=item B<macroRemoveAll>I<($doc)>

Removes all macros for $doc from the stack.

lib/App/Codit/Ext/CoditMDI.pm  view on Meta::CPAN

	my ($first) = $self->docList;
	my $doc = $self->docGet($first);
	return () unless defined $doc;
	my $themefile = $doc->cget('-highlight_themefile');
	my $historyfile = $self->extGet('ConfigFolder')->ConfigFolder . '/color_history';
	my @opt = (
		-applycall => sub {
			my $themefile = shift;
			my @list = $self->docList;
			for (@list) {
				my $d = $self->docGet($_);
				$d->configure(-highlight_themefile => $themefile);
				$d->configureTags;
			}
		},
		-defaultbackground => $doc->cget('-contentbackground'),
		-defaultforeground => $doc->cget('-contentforeground'),
		-defaultfont => $doc->CWidg->Subwidget('XText')->cget('-font'),
		-historyfile => $historyfile,
		-extension => $self,
		-themefile => $themefile,
	);
	return (
		'Highlighting' => ['CoditTagsEditor', @opt]
	)
}

sub ToolItems {
	my $self = shift;
	my @items = $self->SUPER::ToolItems;
	return (@items,
	#	type					label			cmd					icon					help
	[	'tool_separator' ],
	[	'tool_button',		'Copy',		'<Control-c>',		'edit-copy',		'Copy selected text to clipboard'],
	[	'tool_button',		'Cut',		'<Control-x>',		'edit-cut',			'Move selected text to clipboard'],
	[	'tool_button',		'Paste',		'<Control-v>',		'edit-paste',		'Paste clipboard content into document'],
	[	'tool_separator' ],
	[	'tool_button',		'Undo',		'<Control-z>',		'edit-undo',		'Undo last action'],
	[	'tool_button',		'Redo',		'<Control-Z>',		'edit-redo',		'Cancel undo'],
	);
}

=back

=head1 LICENSE

Same as Perl.

=head1 AUTHOR

Hans Jeuken (hanje at cpan dot org)

=head1 BUGS

Unknown. If you find any, please report them here L<https://github.com/haje61/App-Codit/issues>.

=head1 SEE ALSO

=over 4

=item L<App::Codit::Macro>

=item L<Tk::AppWindow::Ext::MDI>

=back

=cut

1;



( run in 0.553 second using v1.01-cache-2.11-cpan-df04353d9ac )