File Coverage

blib/lib/Tk/PodSingle.pm
Criterion Covered Total %
statement 3 3 100.0
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 4 4 100.0


line stmt bran cond sub pod time code
1             package Tk::PodSingle;
2             our $VERSION = '1.01';
3              
4             =head1 NAME
5              
6             Tk::PodSingle - Pod browser toplevel widget for single pod files
7              
8             =head1 DESCRIPTION
9              
10             This module inherits Tk::Pod and slightly changes its' features by removing menu entries
11             (and bindings) that pertain to opening a different pod file.
12              
13             It is suitable for when you want to only display a single pod file
14             or a group of self-contained pod files. It hides access to the system's pod archive
15             and removes the options that allow opening a new pod file.
16              
17             What it does not do is prevent going to a different pod file through a link
18             in the loaded pod file. This is why I kept the History menu intact.
19              
20             The widget is created like this:
21              
22             use Tk::PodSingle;
23             $Pod = $Parent->PodSingle(-file => $name);
24              
25             Other than the removed menu entries and bindings, it behaves exactly as Tk::Pod does.
26              
27             =head1 AUTHOR
28              
29             Ken Prows (perl@xev.net)
30              
31             =head1 LICENSE
32              
33             This library is free software; you can redistribute it and/or modify
34             it under the same terms as Perl itself, either Perl version 5.8.6 or,
35             at your option, any later version of Perl 5 you may have available.
36              
37             =cut
38              
39 1     1   29769 use base qw(Tk::Derived Tk::Pod);
  1         2  
  1         792  
40             use strict;
41              
42             Construct Tk::Widget 'PodSingle';
43              
44             sub Populate
45             {
46             my ($w,$args) = @_;
47              
48             $args->{-tree} = 0;
49              
50             if ($w->Pod_Text_Module)
51             {
52             eval q{ require } . $w->Pod_Text_Module;
53             die $@ if $@;
54             }
55             #if ($w->Pod_Tree_Module)
56             # {
57             # eval q{ require } . $w->Pod_Tree_Module;
58             # die $@ if $@;
59             # }
60            
61             # SUPER wont work here because it will use the Populate from Tk::Pod, which is wrong
62             #$w->SUPER::Populate($args);
63             $w->Tk::Toplevel::Populate($args);
64              
65             #my $tree = $w->Scrolled($w->Pod_Tree_Widget,
66             # -scrollbars => 'oso'.($Tk::platform eq 'MSWin32'?'e':'w')
67             # );
68             #$w->Advertise('tree' => $tree);
69              
70             my $searchcase = 0;
71             my $p = $w->Component($w->Pod_Text_Widget => 'pod', -searchcase => $searchcase)->pack(-expand => 1, -fill => 'both');
72             $p->bind('', sub { }); # disable double-click file loading
73             $p->menu(undef); # disable right-click menu
74              
75             my $exitbutton = delete $args->{-exitbutton} || 0;
76              
77             # Experimental menu compound images:
78             # XXX Maybe there should be a way to turn this off, as the extra
79             # icons might be memory consuming...
80             my $compound = sub { () };
81             if ($Tk::VERSION >= 804 && eval { require Tk::ToolBar; 1 }) {
82             $w->ToolBar->destroy;
83             if (!$Tk::Pod::empty_image_16) { # XXX multiple MainWindows?
84             $Tk::Pod::empty_image_16 = $w->MainWindow->Photo(-data => <
85             R0lGODlhEAAQAIAAAP///////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgABACwA
86             AAAAEAAQAAACDoyPqcvtD6OctNqLsz4FADs=
87             EOF
88             }
89             $compound = sub {
90             if (@_) {
91             (-image => $_[0] . "16", -compound => "left");
92             } else {
93             (-image => $Tk::Pod::empty_image_16, -compound => "left");
94             }
95             };
96             }
97              
98             my $menuitems =
99             [
100              
101             [Cascade => '~File', -menuitems =>
102             [
103             #[Button => '~Open File...', '-accelerator' => 'F3',
104             # '-command' => ['openfile',$w],
105             # $compound->("fileopen"),
106             #],
107             #[Button => 'Open ~by Name...', '-accelerator' => 'Ctrl+O',
108             # '-command' => ['openpod',$w,$p],
109             # $compound->(),
110             #],
111             #[Button => '~New Window...', '-accelerator' => 'Ctrl+N',
112             # '-command' => ['newwindow',$w,$p],
113             # $compound->(),
114             #],
115             #[Button => '~Reload', '-accelerator' => 'Ctrl+R',
116             # '-command' => ['reload',$p],
117             # $compound->("actreload"),
118             #],
119             #[Button => '~Edit', '-command' => ['edit',$p],
120             # $compound->("edit"),
121             #],
122             #[Button => 'Edit with p~tked', '-command' => ['edit',$p,'ptked'],
123             # $compound->(),
124             #],
125             [Button => '~Print'. ($p->PrintHasDialog ? '...' : ''),
126             '-accelerator' => 'Ctrl+P', '-command' => ['Print',$p],
127             $compound->("fileprint"),
128             ],
129             [Separator => ""],
130             [Button => '~Close', '-accelerator' => 'Ctrl+W',
131             '-command' => ['quit',$w],
132             $compound->("fileclose"),
133             ],
134             ($exitbutton
135             ? [Button => 'E~xit', '-accelerator' => 'Ctrl+Q',
136             '-command' => sub { $p->MainWindow->destroy },
137             $compound->("actexit"),
138             ]
139             : ()
140             ),
141             ]
142             ],
143              
144             #[Cascade => '~View', -menuitems =>
145             # [
146             # [Checkbutton => '~Pod Tree', -variable => \$w->{Tree_on},
147             # '-command' => sub { $w->tree($w->{Tree_on}) },
148             # $compound->(),
149             # ],
150             # '-',
151             # [Button => "Zoom ~in", '-accelerator' => 'Ctrl++',
152             # -command => ['zoom_in', $p],
153             # $compound->("viewmag+"),
154             # ],
155             # [Button => "~Normal", -command => ['zoom_normal', $p],
156             # $compound->(),
157             # ],
158             # [Button => "Zoom ~out", '-accelerator' => 'Ctrl+-',
159             # -command => ['zoom_out', $p],
160             # $compound->("viewmag-"),
161             # ],
162             # ]
163             #],
164              
165             [Cascade => '~Search', -menuitems =>
166             [
167             [Button => '~Search',
168             '-accelerator' => '/', '-command' => ['Search', $p, 'Next'],
169             $compound->("viewmag"),
170             ],
171             [Button => 'Search ~backwards',
172             '-accelerator' => '?', '-command' => ['Search', $p, 'Prev'],
173             $compound->(),
174             ],
175             [Button => '~Repeat search',
176             '-accelerator' => 'n', '-command' => ['ShowMatch', $p, 'Next'],
177             $compound->(),
178             ],
179             [Button => 'R~epeat backwards',
180             '-accelerator' => 'N', '-command' => ['ShowMatch', $p, 'Prev'],
181             $compound->(),
182             ],
183             [Checkbutton => '~Case sensitive', -variable => \$searchcase,
184             '-command' => sub { $p->configure(-searchcase => $searchcase) },
185             $compound->(),
186             ],
187             #[Separator => ""],
188             #[Button => 'Search ~full text', '-command' => ['SearchFullText', $p],
189             # $compound->("filefind"),
190             #],
191             #[Button => 'Search FA~Q', '-command' => ['SearchFAQ', $w, $p],
192             # $compound->(),
193             #],
194             ]
195             ],
196              
197             [Cascade => 'H~istory', -menuitems =>
198             [
199             [Button => '~Back', '-accelerator' => 'Alt-Left',
200             '-command' => ['history_move', $p, -1],
201             $compound->("navback"),
202             ],
203             [Button => '~Forward', '-accelerator' => 'Alt-Right',
204             '-command' => ['history_move', $p, +1],
205             $compound->("navforward"),
206             ],
207             [Button => '~View', '-command' => ['history_view', $p],
208             $compound->(),
209             ],
210             '-',
211             [Button => 'Clear cache', '-command' => ['clear_cache', $p],
212             $compound->(),
213             ],
214             ]
215             ],
216              
217             # [Cascade => '~Help', -menuitems =>
218             # [
219             # # XXX restructure to not reference to tkpod
220             # [Button => '~Usage...', -command => ['help', $w]],
221             # [Button => '~Programming...', -command => sub { $w->parent->Pod(-file=>'Tk/Pod.pm', -exitbutton => $w->cget(-exitbutton)) }],
222             # [Button => '~About...', -command => ['about', $w]],
223             # ($ENV{'TKPODDEBUG'}
224             # ? ('-',
225             # [Button => 'WidgetDump', -command => sub { $w->WidgetDump }],
226             # (defined &Tk::App::Reloader::reload_new_modules
227             # ? [Button => 'Reloader', -command => sub { Tk::App::Reloader::reload_new_modules() }]
228             # : ()
229             # ),
230             # )
231             # : ()
232             # ),
233             # ]
234             # ]
235             ];
236              
237             my $mbar = $w->Menu(-menuitems => $menuitems);
238             $w->configure(-menu => $mbar);
239             $w->Advertise(menubar => $mbar);
240              
241             $w->Delegates('Menubar' => $mbar);
242             $w->ConfigSpecs(
243             -tree => ['METHOD', 'tree', 'Tree', 0],
244             -exitbutton => ['PASSIVE', 'exitButton', 'ExitButton', $exitbutton],
245             -background => ['PASSIVE'], # XXX see comment in Tk::More
246             -cursor => ['CHILDREN'],
247             'DEFAULT' => [$p],
248             );
249              
250             {
251             my $path = $w->toplevel->PathName;
252             foreach my $mod (qw(Alt Meta))
253             {
254             $w->bind($path, "<$mod-Left>" => [$p, 'history_move', -1]);
255             $w->bind($path, "<$mod-Right>" => [$p, 'history_move', +1]);
256             }
257              
258             #$w->bind($path, "" => [$p, 'zoom_out']);
259             #$w->bind($path, "" => [$p, 'zoom_in']);
260             #$w->bind($path, "" => [$w,'openfile']);
261             #$w->bind($path, "" => [$w,'openpod',$p]);
262             #$w->bind($path, "" => [$w,'newwindow',$p]);
263             $w->bind($path, "" => [$p, 'reload']);
264             $w->bind($path, "" => [$p, 'Print']);
265             $w->bind($path, "" => [$w, 'quit']);
266             $w->bind($path, "" => sub { $p->MainWindow->destroy })
267             if $exitbutton;
268             }
269              
270             $w->protocol('WM_DELETE_WINDOW',['quit',$w]);
271             }
272              
273             1;