| 1 | package App::Codit::BaseClasses::TextModPlugin; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | App::Codit::BaseClasses::TextModPlugin - baseclass for plugins that respond to text modifications | ||
| 6 | |||
| 7 | =cut | ||
| 8 | |||
| 9 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 1 | ▶ | use vars qw( $VERSION ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | $VERSION = '0.19'; | ||
| 13 | 0 | ▶ | use Tk; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 14 | |||
| 15 | use base qw( Tk::AppWindow::BaseClasses::Plugin ); | ||
| 16 | require Tk::HList; | ||
| 17 | |||
| 18 | =head1 DESCRIPTION | ||
| 19 | |||
| 20 | =cut | ||
| 21 | |||
| 22 | sub new { | ||
| 23 | my $class = shift; | ||
| 24 | my $self = $class->SUPER::new(@_); | ||
| 25 | return undef unless defined $self; | ||
| 26 | |||
| 27 | $self->{ACTIVEDELAY} = 600; | ||
| 28 | $self->cmdHookBefore('quit', 'selectBlock', $self); | ||
| 29 | $self->cmdHookBefore('deferred_open', 'selectBlock', $self); | ||
| 30 | $self->cmdHookAfter('modified', 'activate', $self); | ||
| 31 | $self->cmdHookAfter('doc_select', 'docSelect', $self); | ||
| 32 | |||
| 33 | # $self->after(1000, sub { | ||
| 34 | # my $sel = $self->extGet('CoditMDI')->docSelected; | ||
| 35 | # $self->docSelect($sel) if defined $sel; | ||
| 36 | # }); | ||
| 37 | |||
| 38 | return $self; | ||
| 39 | } | ||
| 40 | |||
| 41 | sub activate { | ||
| 42 | my $self = shift; | ||
| 43 | my $id = $self->{'active_id'}; | ||
| 44 | $self->afterCancel($id) if defined $id; | ||
| 45 | $self->{'active_id'} = $self->after($self->activeDelay, ['Refresh', $self]); | ||
| 46 | } | ||
| 47 | |||
| 48 | sub activeDelay { | ||
| 49 | my $self = shift; | ||
| 50 | $self->{ACTIVEDELAY} = shift if @_; | ||
| 51 | return $self->{ACTIVEDELAY} | ||
| 52 | } | ||
| 53 | |||
| 54 | sub Clear { | ||
| 55 | } | ||
| 56 | |||
| 57 | sub docSelect { | ||
| 58 | my $self = shift; | ||
| 59 | |||
| 60 | if (exists $self->{'select_block'}) { | ||
| 61 | $self->after(100, sub { delete $self->{'select_block'} }); | ||
| 62 | } | ||
| 63 | |||
| 64 | my $mdi = $self->extGet('CoditMDI'); | ||
| 65 | return if $mdi->selectDisabled; | ||
| 66 | $self->after(10, sub { | ||
| 67 | $self->Refresh(0); | ||
| 68 | }); | ||
| 69 | } | ||
| 70 | |||
| 71 | sub Refresh { | ||
| 72 | my $self = shift; | ||
| 73 | delete $self->{'active_id'}; | ||
| 74 | } | ||
| 75 | |||
| 76 | sub selectBlock { | ||
| 77 | my $self = shift; | ||
| 78 | $self->{'select_block'} = 1; | ||
| 79 | } | ||
| 80 | |||
| 81 | sub Unload { | ||
| 82 | my $self = shift; | ||
| 83 | my $id = $self->{'active_id'}; | ||
| 84 | $self->afterCancel($id) if defined $id; | ||
| 85 | $self->cmdUnhookBefore('quit', 'selectBlock', $self); | ||
| 86 | $self->cmdUnhookBefore('deferred_open', 'selectBlock', $self); | ||
| 87 | $self->cmdUnhookAfter('modified', 'activate', $self); | ||
| 88 | $self->cmdUnhookAfter('doc_select', 'docSelect', $self); | ||
| 89 | # $self->cmdUnhookAfter('doc_close', 'docAfterClose', $self); | ||
| 90 | return $self->SUPER::Unload | ||
| 91 | } | ||
| 92 | |||
| 93 | =head1 LICENSE | ||
| 94 | |||
| 95 | Same as Perl. | ||
| 96 | |||
| 97 | =head1 AUTHOR | ||
| 98 | |||
| 99 | Hans Jeuken (hanje at cpan dot org) | ||
| 100 | |||
| 101 | =head1 TODO | ||
| 102 | |||
| 103 | =over 4 | ||
| 104 | |||
| 105 | =back | ||
| 106 | |||
| 107 | =head1 BUGS AND CAVEATS | ||
| 108 | |||
| 109 | If you find any bugs, please report them here L<https://github.com/haje61/App-Codit/issues>. | ||
| 110 | |||
| 111 | =head1 SEE ALSO | ||
| 112 | |||
| 113 | =over 4 | ||
| 114 | |||
| 115 | =back | ||
| 116 | |||
| 117 | =cut | ||
| 118 | |||
| 119 | |||
| 120 | 1; | ||