| 1 | package Tk::AppWindow::Ext::Selector; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | Tk::AppWindow::Ext::Selector - Navigate opened documents and files | ||
| 6 | |||
| 7 | =cut | ||
| 8 | |||
| 9 | use strict; | ||
| 10 | use warnings; | ||
| 11 | use vars qw($VERSION); | ||
| 12 | $VERSION = "0.24"; | ||
| 13 | |||
| 14 | use base qw( Tk::AppWindow::BaseClasses::Extension ); | ||
| 15 | |||
| 16 | require Tk::DocumentTree; | ||
| 17 | |||
| 18 | =head1 SYNOPSIS | ||
| 19 | |||
| 20 | my $app = new Tk::AppWindow(@options, | ||
| 21 | -extensions => ['MDI', 'Selector'], | ||
| 22 | ); | ||
| 23 | $app->MainLoop; | ||
| 24 | |||
| 25 | =head1 DESCRIPTION | ||
| 26 | |||
| 27 | Adds a document list to your application. | ||
| 28 | Creates a tool panel called navigator panel unless it already exists. | ||
| 29 | |||
| 30 | =head1 CONFIG VARIABLES | ||
| 31 | |||
| 32 | =over 4 | ||
| 33 | |||
| 34 | =item B<-documentinterface> | ||
| 35 | |||
| 36 | Default value 'MDI'. Sets the extension name for the | ||
| 37 | multiple docoment interface that B<Selector> communicates with. | ||
| 38 | |||
| 39 | =item B<-treeiconsize> | ||
| 40 | |||
| 41 | By default undefined. Sets and returns the size of icons | ||
| 42 | in the document tree. | ||
| 43 | |||
| 44 | =back | ||
| 45 | |||
| 46 | =cut | ||
| 47 | |||
| 48 | sub new { | ||
| 49 | my $class = shift; | ||
| 50 | my $self = $class->SUPER::new(@_); | ||
| 51 | |||
| 52 | $self->Require('SideBars'); | ||
| 53 | |||
| 54 | my $args = $self->GetArgsRef; | ||
| 55 | my $panel = delete $args->{'-selectorpanel'}; | ||
| 56 | $panel = 'LEFT' unless defined $panel; | ||
| 57 | |||
| 58 | $self->addPreConfig( | ||
| 59 | -documentinterface => ['PASSIVE', undef, undef, 'MDI'], | ||
| 60 | -treeiconsize => ['PASSIVE'], | ||
| 61 | ); | ||
| 62 | |||
| 63 | my $sb = $self->extGet('SideBars'); | ||
| 64 | $sb->nbAdd('navigator panel', $panel, 'left') unless $sb->nbExists('navigator panel'); | ||
| 65 | if ($sb->canRotateText) { | ||
| 66 | $sb->nbTextSide('navigator panel', 'bottom'); | ||
| 67 | $sb->nbTextRotate('navigator panel', 90); | ||
| 68 | } | ||
| 69 | |||
| 70 | $self->addPostConfig('CreateSideBar', $self, $panel); | ||
| 71 | return $self; | ||
| 72 | } | ||
| 73 | |||
| 74 | =head1 METHODS | ||
| 75 | |||
| 76 | =over 4 | ||
| 77 | |||
| 78 | =item B<Add>I<($name)> | ||
| 79 | |||
| 80 | Adds $name to the document list. | ||
| 81 | |||
| 82 | =cut | ||
| 83 | |||
| 84 | sub Add { | ||
| 85 | my ($self, $name) = @_; | ||
| 86 | my $t = $self->Subwidget('NAVTREE'); | ||
| 87 | $t->entryAdd($name); | ||
| 88 | } | ||
| 89 | |||
| 90 | sub CreateSideBar { | ||
| 91 | my ($self, $panel) = @_; | ||
| 92 | my $sb = $self->extGet('SideBars'); | ||
| 93 | my $page = $sb->pageAdd('navigator panel', 'Documents', 'document-open', undef, 'Document list', 20); | ||
| 94 | my $dt = $page->DocumentTree( | ||
| 95 | -entryselect => ['SelectDocument', $self], | ||
| 96 | -diriconcall => ['GetDirIcon', $self], | ||
| 97 | -fileiconcall => ['GetFileIcon', $self], | ||
| 98 | -saveiconcall => ['GetSaveIcon', $self], | ||
| 99 | )->pack(-expand => 1, -fill => 'both'); | ||
| 100 | |||
| 101 | $self->Advertise('NAVTREE', $dt); | ||
| 102 | } | ||
| 103 | |||
| 104 | =item B<Delete>I<($name)> | ||
| 105 | |||
| 106 | Deletes $name from the document list | ||
| 107 | |||
| 108 | =cut | ||
| 109 | |||
| 110 | sub Delete { | ||
| 111 | my ($self, $name) = @_; | ||
| 112 | $self->Subwidget('NAVTREE')->entryDelete($name); | ||
| 113 | } | ||
| 114 | |||
| 115 | =item B<EntryModified>I<($name)> | ||
| 116 | |||
| 117 | Changes the icon of $name to the save icon, indicating | ||
| 118 | the document is modified. | ||
| 119 | |||
| 120 | =cut | ||
| 121 | |||
| 122 | sub EntryModified { | ||
| 123 | my ($self, $name) = @_; | ||
| 124 | $self->Subwidget('NAVTREE')->entryModified($name); | ||
| 125 | } | ||
| 126 | |||
| 127 | =item B<EntrySaved>I<($name)> | ||
| 128 | |||
| 129 | Changes the icon of $name to the normal file icon. | ||
| 130 | |||
| 131 | =cut | ||
| 132 | |||
| 133 | sub EntrySaved { | ||
| 134 | my ($self, $name) = @_; | ||
| 135 | $self->Subwidget('NAVTREE')->entrySaved($name); | ||
| 136 | } | ||
| 137 | |||
| 138 | =item B<GetDirIcon> | ||
| 139 | |||
| 140 | Callback for the document tree. Returns the folder icon. | ||
| 141 | |||
| 142 | =cut | ||
| 143 | |||
| 144 | sub GetDirIcon { | ||
| 145 | my ($self, $name) = @_; | ||
| 146 | my $icon = $self->getArt('folder', $self->configGet('-treeiconsize')); | ||
| 147 | return $icon if defined $icon; | ||
| 148 | return $self->Subwidget('NAVTREE')->DefaultDirIcon; | ||
| 149 | } | ||
| 150 | |||
| 151 | =item B<GetFileIcon>I<($name)> | ||
| 152 | |||
| 153 | Callback for the document tree. Returns the file icon. | ||
| 154 | |||
| 155 | =cut | ||
| 156 | |||
| 157 | sub GetFileIcon { | ||
| 158 | my ($self, $name) = @_; | ||
| 159 | my $art = $self->extGet('Art'); | ||
| 160 | if (defined $art) { | ||
| 161 | my $icon = $art->getFileIcon($name, $self->configGet('-treeiconsize')); | ||
| 162 | return $icon if defined $icon; | ||
| 163 | } | ||
| 164 | return $self->Subwidget('NAVTREE')->DefaultFileIcon; | ||
| 165 | } | ||
| 166 | |||
| 167 | =item B<GetSaveIcon>I<($name)> | ||
| 168 | |||
| 169 | Callback for the document tree. Returns the save icon. | ||
| 170 | |||
| 171 | =cut | ||
| 172 | |||
| 173 | sub GetSaveIcon { | ||
| 174 | my ($self, $name) = @_; | ||
| 175 | my $icon = $self->getArt('document-save'); | ||
| 176 | return $icon if defined $icon; | ||
| 177 | return $self->Subwidget('NAVTREE')->DefaultSaveIcon; | ||
| 178 | } | ||
| 179 | |||
| 180 | =item B<SelectDocument>I<($name)> | ||
| 181 | |||
| 182 | Selects document $name in the multiple document interface. | ||
| 183 | |||
| 184 | =cut | ||
| 185 | |||
| 186 | sub SelectDocument { | ||
| 187 | my ($self, $name) = @_; | ||
| 188 | $self->cmdExecute('doc_select', $name); | ||
| 189 | } | ||
| 190 | |||
| 191 | =item B<SelectEntry>I<($name)> | ||
| 192 | |||
| 193 | Selects $name in the document tree. | ||
| 194 | |||
| 195 | =cut | ||
| 196 | |||
| 197 | sub SelectEntry { | ||
| 198 | my ($self, $name) = @_; | ||
| 199 | $self->Subwidget('NAVTREE')->entrySelect($name); | ||
| 200 | } | ||
| 201 | |||
| 202 | =back | ||
| 203 | |||
| 204 | =head1 AUTHOR | ||
| 205 | |||
| 206 | Hans Jeuken (hanje at cpan dot org) | ||
| 207 | |||
| 208 | =head1 BUGS | ||
| 209 | |||
| 210 | Unknown. If you find any, please contact the author. | ||
| 211 | |||
| 212 | =head1 SEE ALSO | ||
| 213 | |||
| 214 | =over 4 | ||
| 215 | |||
| 216 | =item L<Tk::AppWindow> | ||
| 217 | |||
| 218 | =item L<Tk::AppWindow::BaseClasses::Extension> | ||
| 219 | |||
| 220 | =item L<Tk::AppWindow::Ext::SideBars> | ||
| 221 | |||
| 222 | =back | ||
| 223 | |||
| 224 | =cut | ||
| 225 | |||
| 226 | 1; | ||
| 227 | |||
| 228 | |||
| 229 | |||
| 230 | |||
| 231 | |||
| 232 | |||
| 233 | |||
| 234 | |||
| 235 |