line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
89042
|
use Renard::Incunabula::Common::Setup; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
17
|
|
2
|
|
|
|
|
|
|
package Renard::Curie::Component::MenuBar; |
3
|
|
|
|
|
|
|
# ABSTRACT: Component that provides a menu bar for the application |
4
|
|
|
|
|
|
|
$Renard::Curie::Component::MenuBar::VERSION = '0.003'; |
5
|
1
|
|
|
1
|
|
12402
|
use Moo; |
|
1
|
|
|
|
|
17994
|
|
|
1
|
|
|
|
|
10
|
|
6
|
1
|
|
|
1
|
|
4689
|
use Renard::Incunabula::Frontend::Gtk3::Helper; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use URI; |
8
|
|
|
|
|
|
|
use Glib 'TRUE', 'FALSE'; |
9
|
|
|
|
|
|
|
use Renard::Incunabula::Common::Types qw(InstanceOf); |
10
|
|
|
|
|
|
|
use Lingua::EN::Inflect qw(PL); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has _gtk_widget => ( |
13
|
|
|
|
|
|
|
is => 'lazy', |
14
|
|
|
|
|
|
|
handles => [qw(add get_child signal_connect)], |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
method _build__gtk_widget() { Gtk3::Overlay->new }; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has recent_manager => ( |
19
|
|
|
|
|
|
|
is => 'lazy', # _build_recent_manager |
20
|
|
|
|
|
|
|
isa => InstanceOf['Gtk3::RecentManager'], |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has recent_chooser => ( |
24
|
|
|
|
|
|
|
is => 'lazy', # _build_recent_chooser |
25
|
|
|
|
|
|
|
isa => InstanceOf['Gtk3::RecentChooserMenu'], |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has view_manager => ( |
29
|
|
|
|
|
|
|
is => 'ro', |
30
|
|
|
|
|
|
|
required => 1, |
31
|
|
|
|
|
|
|
isa => InstanceOf['Renard::Curie::ViewModel::ViewManager'], |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
method BUILD(@) { |
35
|
|
|
|
|
|
|
# File menu |
36
|
|
|
|
|
|
|
$self->builder->get_object('menu-item-file-open') |
37
|
|
|
|
|
|
|
->signal_connect( activate => |
38
|
|
|
|
|
|
|
\&on_menu_file_open_activate_cb, $self ); |
39
|
|
|
|
|
|
|
$self->builder->get_object('menu-item-file-quit') |
40
|
|
|
|
|
|
|
->signal_connect( activate => |
41
|
|
|
|
|
|
|
\&on_menu_file_quit_activate_cb, $self ); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$self->builder->get_object('menu-item-file-recentfiles') |
44
|
|
|
|
|
|
|
->set_submenu($self->recent_chooser); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$self->recent_chooser->signal_connect( 'item-activated' => |
47
|
|
|
|
|
|
|
\&on_menu_file_recentfiles_item_activated_cb, $self ); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# View menu |
51
|
|
|
|
|
|
|
#$self->builder->get_object('menu-item-view-pagemode-singlepage') |
52
|
|
|
|
|
|
|
#->set_active(TRUE); |
53
|
|
|
|
|
|
|
## View -> Continuous |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$self->builder->get_object('menu-item-view-continuous') |
56
|
|
|
|
|
|
|
->signal_connect( toggled => |
57
|
|
|
|
|
|
|
\&on_menu_view_continuous_cb, $self ); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$self->builder->get_object('menu-item-view-sidebar') |
60
|
|
|
|
|
|
|
->signal_connect( toggled => |
61
|
|
|
|
|
|
|
\&on_menu_view_sidebar_cb, $self ); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
## View -> Zoom menu |
64
|
|
|
|
|
|
|
my @zoom_levels = ( |
65
|
|
|
|
|
|
|
{ text => "50%", zoom_level => 0.5 }, |
66
|
|
|
|
|
|
|
{ text => "70%", zoom_level => 0.7071067811 }, |
67
|
|
|
|
|
|
|
{ text => "85%", zoom_level => 0.8408964152 }, |
68
|
|
|
|
|
|
|
{ text => "100%", zoom_level => 1.0 }, |
69
|
|
|
|
|
|
|
{ text => "125%", zoom_level => 1.1892071149 }, |
70
|
|
|
|
|
|
|
{ text => "150%", zoom_level => 1.4142135623 }, |
71
|
|
|
|
|
|
|
{ text => "175%", zoom_level => 1.6817928304 }, |
72
|
|
|
|
|
|
|
{ text => "200%", zoom_level => 2.0 }, |
73
|
|
|
|
|
|
|
{ text => "300%", zoom_level => 2.8284271247 }, |
74
|
|
|
|
|
|
|
{ text => "400%", zoom_level => 4.0 }, |
75
|
|
|
|
|
|
|
{ text => "800%", zoom_level => 8.0 }, |
76
|
|
|
|
|
|
|
{ text => "1600%", zoom_level => 16.0 }, |
77
|
|
|
|
|
|
|
{ text => "3200%", zoom_level => 32.0 }, |
78
|
|
|
|
|
|
|
{ text => "6400%", zoom_level => 64.0 } |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
my $zoom_submenu = $self->builder->get_object('menu-view-zoom'); |
81
|
|
|
|
|
|
|
for my $zoom_menu_info (@zoom_levels) { |
82
|
|
|
|
|
|
|
my $menu_item = Gtk3::MenuItem->new_with_label( $zoom_menu_info->{text} ); |
83
|
|
|
|
|
|
|
$zoom_submenu->add( $menu_item ); |
84
|
|
|
|
|
|
|
$menu_item->signal_connect( activate => |
85
|
|
|
|
|
|
|
\&on_menu_view_zoom_item_activate_cb, [ $self, $zoom_menu_info->{zoom_level} ] ); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
## View -> Columns menu |
89
|
|
|
|
|
|
|
my $columns_submenu = $self->builder->get_object('menu-view-columns'); |
90
|
|
|
|
|
|
|
my @column_menu_info = map { |
91
|
|
|
|
|
|
|
my $n_columns = $_; |
92
|
|
|
|
|
|
|
+{ |
93
|
|
|
|
|
|
|
text => "$n_columns @{[ PL('column', $n_columns) ]}", |
94
|
|
|
|
|
|
|
columns => $n_columns, |
95
|
|
|
|
|
|
|
}; |
96
|
|
|
|
|
|
|
} 1..6; |
97
|
|
|
|
|
|
|
for my $column_menu_info (@column_menu_info) { |
98
|
|
|
|
|
|
|
my $menu_item = Gtk3::MenuItem->new_with_label( $column_menu_info->{text} ); |
99
|
|
|
|
|
|
|
$columns_submenu->add( $menu_item ); |
100
|
|
|
|
|
|
|
$menu_item->signal_connect( activate => |
101
|
|
|
|
|
|
|
\&on_menu_view_column_item_activate_cb, [ $self, $column_menu_info->{columns} ] ); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# Help menu |
105
|
|
|
|
|
|
|
$self->builder->get_object('menu-item-help-logwin') |
106
|
|
|
|
|
|
|
->signal_connect( activate => |
107
|
|
|
|
|
|
|
\&on_menu_help_logwin_activate_cb, $self ); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# delay this because it is circular |
110
|
|
|
|
|
|
|
Glib::Timeout->add(0, sub { |
111
|
|
|
|
|
|
|
$self->_wireup; |
112
|
|
|
|
|
|
|
return FALSE; # run only once |
113
|
|
|
|
|
|
|
}); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# add as child for this Gtk3::Bin |
116
|
|
|
|
|
|
|
$self->add( |
117
|
|
|
|
|
|
|
$self->builder->get_object('menubar') |
118
|
|
|
|
|
|
|
); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
method _wireup() { |
122
|
|
|
|
|
|
|
# Accelerator group |
123
|
|
|
|
|
|
|
$self->main_window->window->add_accel_group( |
124
|
|
|
|
|
|
|
$self->builder->get_object('menu-accel-group') |
125
|
|
|
|
|
|
|
); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
$self->builder->get_object('menu-item-view-sidebar') |
128
|
|
|
|
|
|
|
->set_active($self->main_window->outline->get_reveal_child); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
method _build_recent_manager() :ReturnType(InstanceOf['Gtk3::RecentManager']) { |
132
|
|
|
|
|
|
|
Gtk3::RecentManager::get_default; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
method _build_recent_chooser() :ReturnType(InstanceOf['Gtk3::RecentChooserMenu']) { |
136
|
|
|
|
|
|
|
my $recent_chooser = Gtk3::RecentChooserMenu->new_for_manager( $self->recent_manager ); |
137
|
|
|
|
|
|
|
$recent_chooser->set_sort_type('mru'); |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
$recent_chooser; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# Callbacks {{{ |
144
|
|
|
|
|
|
|
callback on_menu_file_open_activate_cb($event, $self) { |
145
|
|
|
|
|
|
|
Renard::Incunabula::Frontend::Gtk3::Helper->callback( $self->main_window, on_open_file_dialog_cb => $event ); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
callback on_menu_file_quit_activate_cb($event, $self) { |
149
|
|
|
|
|
|
|
Renard::Incunabula::Frontend::Gtk3::Helper->callback( $self->main_window, on_application_quit_cb => $event ); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
callback on_menu_file_recentfiles_item_activated_cb( (InstanceOf['Gtk3::RecentChooserMenu']) $recent_chooser, $self ) { |
153
|
|
|
|
|
|
|
my $selected_item = $recent_chooser->get_current_item; |
154
|
|
|
|
|
|
|
my $uri = $selected_item->get_uri; |
155
|
|
|
|
|
|
|
$self->view_manager->open_document_as_file_uri( URI->new( $uri, 'file' ) ); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
callback on_menu_help_logwin_activate_cb($event, $self) { |
159
|
|
|
|
|
|
|
$self->main_window->log_window->show_log_window; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
callback on_menu_view_continuous_cb( $event_menu_item, $self ) { |
163
|
|
|
|
|
|
|
if( $event_menu_item->get_active ) { |
164
|
|
|
|
|
|
|
$self->view_manager->set_view_to_continuous_page; |
165
|
|
|
|
|
|
|
} else { |
166
|
|
|
|
|
|
|
$self->view_manager->set_view_to_single_page; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
callback on_menu_view_sidebar_cb($event_menu_item, $self) { |
171
|
|
|
|
|
|
|
$self->main_window->outline->reveal( $event_menu_item->get_active ); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
callback on_menu_view_zoom_item_activate_cb($event, $data) { |
175
|
|
|
|
|
|
|
my ($self, $zoom_level) = @$data; |
176
|
|
|
|
|
|
|
$self->view_manager->set_zoom_level( $zoom_level ); |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
callback on_menu_view_column_item_activate_cb($event, $data) { |
180
|
|
|
|
|
|
|
my ($self, $columns) = @$data; |
181
|
|
|
|
|
|
|
$self->view_manager->number_of_columns( $columns ); |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# }}} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
with qw( |
188
|
|
|
|
|
|
|
Renard::Incunabula::Frontend::Gtk3::Component::Role::FromBuilder |
189
|
|
|
|
|
|
|
Renard::Incunabula::Frontend::Gtk3::Component::Role::UIFileFromPackageName |
190
|
|
|
|
|
|
|
Renard::Curie::Component::Role::HasParentMainWindow |
191
|
|
|
|
|
|
|
); |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
1; |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
__END__ |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=pod |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=encoding UTF-8 |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 NAME |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Renard::Curie::Component::MenuBar - Component that provides a menu bar for the application |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head1 VERSION |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
version 0.003 |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head1 EXTENDS |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=over 4 |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=item * L<Moo::Object> |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=back |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head1 CONSUMES |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=over 4 |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=item * L<Renard::Curie::Component::Role::HasParentMainWindow> |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item * L<Renard::Incunabula::Frontend::Gtk3::Component::Role::FromBuilder> |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=item * L<Renard::Incunabula::Frontend::Gtk3::Component::Role::UIFileFromPackageName> |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=back |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head2 recent_manager |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
A lazy attribute that holds the default instance of L<Gtk3::RecentManager>. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head2 recent_chooser |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
Instance of L<Gtk3::RecentChooserMenu> which is placed under the C<<File -> |
238
|
|
|
|
|
|
|
Recent files>> sub-menu. |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head2 view_manager |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
The view manager model for this application. |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head1 METHODS |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head2 BUILD |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
method BUILD |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
Initialises the menu bar signals. |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=head1 CALLBACKS |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head2 on_menu_file_open_activate_cb |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
callback on_menu_file_open_activate_cb($event, $self) |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
Callback for the C<< File -> Open >> menu item. |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=head2 on_menu_file_quit_activate_cb |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
callback on_menu_file_quit_activate_cb($event, $self) |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
Callback for the C<< File -> Quit >> menu item. |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=head2 on_menu_file_recentfiles_item_activated_cb |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
callback on_menu_file_recentfiles_item_activated_cb( (InstanceOf['Gtk3::RecentChooserMenu']) $recent_chooser, $self ) |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
Callback for items under the C<< File -> Recent files >> sub-menu. |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=head2 on_menu_help_logwin_activate_cb |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
callback on_menu_help_logwin_activate_cb($event, $self) |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
Callback for C<< Help -> Message log >> menu item. |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
Displays the Message log window. |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=head2 on_menu_view_continuous_cb |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
Callback for C<< View -> Continuous >> menu item. |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
Toggles the view between a continuous page view and single page view. |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=head2 on_menu_view_sidebar_cb |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
Callback for the C<< View -> Sidebar >> menu item. |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
This toggles whether or not the outline sidebar is visible. |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=head2 on_menu_view_zoom_item_activate_cb |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
Callback for zoom level menu items under the C<< View -> Zoom >> submenu. |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
callback on_menu_view_zoom_item_activate_cb($event, $data) |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
where C<$data> is an C<ArrayRef> that contains C<< [ $self, $zoom_level ] >>. |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=head2 on_menu_view_column_item_activate_cb |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
Callback for number of columns menu items under the C<< View -> Columns >> submenu. |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
callback on_menu_view_column_item_activate_cb($event, $data) |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
where C<$data> is an C<ArrayRef> that contains C<< [ $self, $number_of_columns ] >>. |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
=head1 AUTHOR |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
Project Renard |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Project Renard. |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
317
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
=cut |