Wrangler/Wx/Menu.pm untested

filter: Statementstmt 0.0% 0 / 105 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 116 CC 2 SCAR 10.6
CC
2
Cov
0%
new
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.9
1 package Wrangler::Wx::Menu;
2  
3 use strict;
4 use warnings;
5  
6 use base qw( Wx::MenuBar );
7 use Wx qw(wxID_CLOSE);
8 use Wx::Event qw(EVT_MENU);
9 # use Wrangler::Wx::Menu::Help;
10  
11 sub new {
12 my $class = shift;
13 my $parent = shift;
14 my $self = $class->SUPER::new( $parent);
15  
16 bless $self, $class;
17  
18 # menu File
19 my $menu_file = Wx::Menu->new();
20 $menu_file->Append( my $settings = Wx::NewId, "&Settings", 'Configure Wrangler' );
21 $menu_file->AppendSeparator();
22 $menu_file->Append( my $exit = Wx::NewId, "E&xit", "Quit Wrangler");
23  
24 EVT_MENU( $parent, $settings, sub { Wrangler::PubSub::publish('show.settings', 0); } );
25 EVT_MENU( $parent, $exit, sub { $parent->Close(); });
26  
27 # menu Tools
28 my $menu_tools = Wx::Menu->new();
29 $menu_tools->Append( my $keywording = Wx::NewId, "&Keywording Tool", 'Keywording Tool' );
30  
31 EVT_MENU( $parent, $keywording, sub { require Wrangler::Wx::Dialog::KeywordingTool; Wrangler::Wx::Dialog::KeywordingTool->new($parent) } );
32  
33 # menu Help
34 my $menu_help = Wx::Menu->new();
35 $menu_help->Append( my $about = Wx::NewId, "&About Wrangler", 'About Wrangler' );
36 $menu_help->Append( my $purchase = Wx::NewId, "Purchasing Information", 'Purchasing Information' );
37 $menu_help->Append( my $licence = Wx::NewId, "Licence and User Agreement", 'Licence and User Agreement' );
38 $menu_help->Append( my $changes = Wx::NewId, "Changelog", 'Changelog' );
39  
40 EVT_MENU( $parent, $about, sub { Wrangler::PubSub::publish('show.about', 0); } );
41 EVT_MENU( $parent, $purchase, sub { Wrangler::PubSub::publish('show.about', 1); } );
42 EVT_MENU( $parent, $licence, sub { Wrangler::PubSub::publish('show.about', 2); } );
43 EVT_MENU( $parent, $changes, sub { Wrangler::PubSub::publish('show.about', 3); } );
44  
45  
46 # this is essentially a part of the Wx::Menu found in FileBrowser, hardcoded
47 # we'd like to have this more modular, loaded like a Plugin or similar; todo
48  
49 #+ NOTE that we don't have the tab-separated accelerator hint here, which is auto-watched by
50 #+ Wx, and this would overide our OnChar routines in FormEditor, FileBrowser, etc. as this
51 #+ here is on the main frame
52  
53 my $menu = Wx::Menu->new();
54 ## hardcoded folder context menu entries
55 EVT_MENU( $parent, $menu->Append(-1, "New folder", 'Create a folder' ), sub { $parent->{filebrowser}->Mkdir(); } );
56 EVT_MENU( $parent, $menu->Append(-1, "New file", 'Create a file/node' ), sub { $parent->{filebrowser}->Mknod(); } );
57 $menu->AppendSeparator();
58 my $itemPaste = Wx::MenuItem->new($menu, -1, "Paste (CTRL+V)", 'Paste');
59 my $itemPasteSymlinks = Wx::MenuItem->new($menu, -1, "Paste ...as symlink(s)", 'Paste files on the clipboard as symlinks');
60 my $itemPasteBitmap = Wx::MenuItem->new($menu, -1, "Paste ...as image", 'Paste clipboard contents as image file');
61 $menu->Append($itemPaste);
62 $menu->Append($itemPasteSymlinks);
63 $menu->Append($itemPasteBitmap);
64 if(1){ # as it seems, it's safe to assume there's always something in the clipboard
65 $menu->Enable($itemPaste->GetId(),1);
66 EVT_MENU( $parent, $itemPaste, sub { $parent->{filebrowser}->Paste(); } );
67 $menu->Enable($itemPasteSymlinks->GetId(),1);
68 EVT_MENU( $parent, $itemPasteSymlinks, sub { $parent->{filebrowser}->PasteSymlinks(); } );
69 $menu->Enable($itemPasteBitmap->GetId(),1);
70 EVT_MENU( $parent, $itemPasteBitmap, sub { $parent->{filebrowser}->PasteBitmap(); } );
71 }else{
72 $menu->Enable($itemPaste->GetId(),0);
73 }
74 $menu->AppendSeparator();
75 EVT_MENU( $parent, $menu->Append(-1, "Select all (CTRL+A)", 'Select all'), sub { $parent->{filebrowser}->SelectAll(); } );
76 EVT_MENU( $parent, $menu->Append(-1, "Deselect all (ESC)", 'Select none'), sub { $parent->{filebrowser}->DeselectAll(); } );
77 EVT_MENU( $parent, $menu->Append(-1, "Invert selections (SHIFT+CTRL+I)", 'Invert selections'), sub { $parent->{filebrowser}->InvertSelections(); } );
78 $menu->AppendSeparator();
79 EVT_MENU( $parent, $menu->Append(-1, "Zoom in (CTRL++)", 'Zoom in'), sub { Wrangler::PubSub::publish('zoom.in'); } );
80 EVT_MENU( $parent, $menu->Append(-1, "Zoom standard (CTRL+0)", 'Zoom standard'), sub { Wrangler::PubSub::publish('zoom.standard'); } );
81 EVT_MENU( $parent, $menu->Append(-1, "Zoom out (CTRL+-)", 'Zoom out'), sub { Wrangler::PubSub::publish('zoom.out'); } );
82 $menu->AppendSeparator();
83 EVT_MENU( $parent, $menu->Append(-1, "Export listing as text", ''), sub {
84 require Wrangler::Wx::Dialog::ListingToText;
85 Wrangler::Wx::Dialog::ListingToText->new($parent);
86 });
87 $menu->AppendSeparator();
88 EVT_MENU( $parent, $menu->Append(-1, "Settings", 'Settings'), sub { Wrangler::PubSub::publish('show.settings', 1, 0); } );
89  
90  
91 $self->Append( $menu_file, '&File' );
92 $self->Append( $menu, '&FileBrowser' );
93 $self->Append( $menu_tools, '&Tools' );
94 $self->Append( $menu_help, '&Help' ); # Wrangler::Wx::Menu::Help->new($parent)
95  
96 return $self;
97 }
98  
99 1;