File Coverage

lib/Kephra/App/ContextMenu.pm
Criterion Covered Total %
statement 6 40 15.0
branch 0 20 0.0
condition n/a
subroutine 2 10 20.0
pod 0 6 0.0
total 8 76 10.5


line stmt bran cond sub pod time code
1             package Kephra::App::ContextMenu;
2             our $VERSION = '0.10';
3            
4 1     1   1399 use strict;
  1         2  
  1         55  
5 1     1   6 use warnings;
  1         3  
  1         672  
6            
7 0 0   0 0   sub get{ &Kephra::Menu::ready || Wx::Menu->new() }
8             #
9             sub create_all {
10 0     0 0   my $config = Kephra::API::settings()->{app}{contextmenu};
11 0           my $default_file = Kephra::Config::filepath($config->{defaultfile});
12 0           my $default_menu_def = Kephra::Config::File::load($default_file);
13 0 0         unless ($default_menu_def) {
14 0           $default_menu_def = Kephra::Config::Default::contextmenus();
15             }
16            
17 0           for my $menu_id (keys %{$config->{id}}){
  0            
18 0 0         if (not ref $menu_id){
    0          
19 0           my $start_node = $config->{id}{$menu_id};
20             substr($start_node, 0, 1) eq '&'
21             ? Kephra::Menu::create_dynamic($menu_id, $start_node)
22 0 0         : do {
23 0           my $menu_def = Kephra::Config::Tree::get_subtree
24             ($default_menu_def, $start_node);
25 0           Kephra::Menu::create_static ($menu_id, $menu_def);
26             }
27             } elsif (ref $menu_id eq 'HASH'){
28 0           my $menu = $config->{id}{$menu_id};
29 0 0         next unless exists $menu->{file};
30 0           my $file_name = $Kephra::temp{path}{config} . $menu->{file};
31 0 0         next unless -e $file_name;
32 0           my $menu_def = Kephra::Config::File::load($file_name);
33 0           $menu_def = Kephra::Config::Tree::get_subtree($menu_def, $menu->{node});
34 0           Kephra::Menu::create_static($menu_id, $menu_def);
35             }
36             }
37             }
38            
39            
40             # connect the static and build the dynamic
41 0     0 0   sub connect_all {}
42             # to editpanel can connect 2 menus,
43             sub connect_tabbar {
44 0     0 0   my $tabbar = Kephra::App::TabBar::_ref();
45 0 0         if ( Kephra::App::TabBar::get_contextmenu_visibility() ) {
46 0           connect_widget( $tabbar, Kephra::App::TabBar::_config()->{contextmenu} )
47             } else {
48 0           disconnect_widget($tabbar)
49             }
50             }
51            
52             sub connect_widget {
53 0     0 0   my $widget = shift;
54 0           my $menu_id = shift;
55             Wx::Event::EVT_RIGHT_DOWN ($widget, sub {
56 0     0     my ($widget, $event) = @_;
57 0           my $menu = get($menu_id);
58 0 0         $widget->PopupMenu($menu, $event->GetX, $event->GetY) if Kephra::Menu::is($menu);
59 0           } );
60             }
61            
62             sub disconnect_widget{
63 0     0 0   my $widget = shift;
64 0 0   0     Wx::Event::EVT_RIGHT_DOWN($widget, sub {} ) if substr(ref $widget, 0, 4) eq 'Wx::';
  0            
65             }
66            
67             1;