| 1 | package App::Codit::Plugins::Icons; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | App::Codit::Plugins::Icons - plugin for App::Codit | ||
| 6 | |||
| 7 | =cut | ||
| 8 | |||
| 9 | use strict; | ||
| 10 | use warnings; | ||
| 11 | use vars qw( $VERSION ); | ||
| 12 | $VERSION = '0.21'; | ||
| 13 | |||
| 14 | require Tk::ListBrowser; | ||
| 15 | use base qw( Tk::AppWindow::BaseClasses::PluginJobs ); | ||
| 16 | |||
| 17 | =head1 DESCRIPTION | ||
| 18 | |||
| 19 | Easily select and insert icons. | ||
| 20 | |||
| 21 | =head1 DETAILS | ||
| 22 | |||
| 23 | The Icons plugin lets you choose an icon from the iconlibrary and insert it's name | ||
| 24 | into your document. | ||
| 25 | |||
| 26 | If a selection exists and it's content matches the name of an icon, the icon will | ||
| 27 | be selected. | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | sub new { | ||
| 32 | my $class = shift; | ||
| 33 | my $self = $class->SUPER::new(@_); | ||
| 34 | return undef unless defined $self; | ||
| 35 | |||
| 36 | my $page = $self->ToolRightPageAdd('Icons', 'preferences-desktop-icons', undef, 'Select and insert icons', 350); | ||
| 37 | |||
| 38 | my @padding = (-padx => 3, -pady => 3); | ||
| 39 | |||
| 40 | my $list; | ||
| 41 | #setting up the buttons | ||
| 42 | my $eframe = $page->Frame( | ||
| 43 | -relief => 'groove', | ||
| 44 | -borderwidth => 2, | ||
| 45 | )->pack(-fill => 'x'); | ||
| 46 | $eframe->Button( | ||
| 47 | -text => 'Insert', | ||
| 48 | -command => sub { | ||
| 49 | my ($sel) = $list->selectionGet; | ||
| 50 | $self->cmdExecute('edit_insert', 'insert', $sel) if defined $sel; | ||
| 51 | }, | ||
| 52 | )->pack(@padding, -side => 'left', -expand => 1, -fill => 'x'); | ||
| 53 | $eframe->Button( | ||
| 54 | -text => 'Copy', | ||
| 55 | -command => sub { | ||
| 56 | my ($sel) = $list->selectionGet; | ||
| 57 | if (defined $sel) { | ||
| 58 | $self->clipboardClear; | ||
| 59 | $self->clipboardAppend($sel); | ||
| 60 | } | ||
| 61 | }, | ||
| 62 | )->pack(@padding, -side => 'left', -expand => 1, -fill => 'x'); | ||
| 63 | |||
| 64 | my $current = ''; | ||
| 65 | my $l = $page->Label( | ||
| 66 | -textvariable => \$current, | ||
| 67 | )->pack(-fill => 'x', -pady => 2); | ||
| 68 | $self->{INDICATOR} = \$current, | ||
| 69 | |||
| 70 | $list = $page->ListBrowser( | ||
| 71 | -arrange => 'row', | ||
| 72 | -itemtype => 'imagetext', | ||
| 73 | -filterforce => 1, | ||
| 74 | -wraplength => 70, | ||
| 75 | -textside => 'bottom', | ||
| 76 | )->pack(-expand => 1, -fill => 'both'); | ||
| 77 | my $art = $self->extGet('Art'); | ||
| 78 | my @icons = $art->AvailableIcons($self->cget('-icontheme')); | ||
| 79 | for (@icons) { | ||
| 80 | my $img = $art->getIcon($_, 48); | ||
| 81 | next if $img->height > 48; | ||
| 82 | my $text = $self->abbreviate($_, 30); | ||
| 83 | $list->add($_, | ||
| 84 | -image => $img, | ||
| 85 | -text => $text, | ||
| 86 | ) | ||
| 87 | } | ||
| 88 | $list->refresh; | ||
| 89 | $self->{LIST} = $list; | ||
| 90 | $self->jobStart('selection_check', 'SelectionCheck', $self); | ||
| 91 | $self->jobStart('list_check', 'ListCheck', $self); | ||
| 92 | return $self; | ||
| 93 | } | ||
| 94 | |||
| 95 | sub ListCheck { | ||
| 96 | my $self = shift; | ||
| 97 | my $l = $self->{LIST}; | ||
| 98 | my $i = $self->{INDICATOR}; | ||
| 99 | my ($sel) = $l->selectionGet; | ||
| 100 | if (defined $sel) { | ||
| 101 | $$i = $sel | ||
| 102 | } else { | ||
| 103 | $$i = '' | ||
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 107 | sub SelectionCheck { | ||
| 108 | my $self = shift; | ||
| 109 | my @sel = $self->cmdExecute('doc_get_sel'); | ||
| 110 | if (@sel) { | ||
| 111 | my $text = $self->cmdExecute('doc_get_text', @sel); | ||
| 112 | chomp($text); | ||
| 113 | my $l = $self->{LIST}; | ||
| 114 | if ($l->infoExists($text)) { | ||
| 115 | $l->selectionSet($text); | ||
| 116 | $l->anchorSet($text); | ||
| 117 | $l->see($text); | ||
| 118 | } | ||
| 119 | } | ||
| 120 | } | ||
| 121 | |||
| 122 | sub Unload { | ||
| 123 | my $self = shift; | ||
| 124 | $self->ToolRightPageRemove('Icons'); | ||
| 125 | return $self->SUPER::Unload | ||
| 126 | } | ||
| 127 | |||
| 128 | =head1 LICENSE | ||
| 129 | |||
| 130 | Same as Perl. | ||
| 131 | |||
| 132 | =head1 AUTHOR | ||
| 133 | |||
| 134 | Hans Jeuken (hanje at cpan dot org) | ||
| 135 | |||
| 136 | =head1 TODO | ||
| 137 | |||
| 138 | =over 4 | ||
| 139 | |||
| 140 | =back | ||
| 141 | |||
| 142 | =head1 BUGS AND CAVEATS | ||
| 143 | |||
| 144 | If you find any bugs, please report them here L<https://github.com/haje61/App-Codit/issues>. | ||
| 145 | |||
| 146 | =head1 SEE ALSO | ||
| 147 | |||
| 148 | =over 4 | ||
| 149 | |||
| 150 | =back | ||
| 151 | |||
| 152 | =cut | ||
| 153 | |||
| 154 | |||
| 155 | 1; | ||
| 156 | |||
| 157 | |||
| 158 | |||
| 159 |