Wrangler/Wx/Dialog/MultiRename.pm untested

filter: Statementstmt 0.0% 0 / 68 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 84 CC 4 SCAR 21.5
CC
4
Cov
0%
new
20.0
OnText
2.0
BEGIN
2.0
CRAP 8.5
1 package Wrangler::Wx::Dialog::MultiRename;
2  
3 use strict;
4 use warnings;
5  
6 use base 'Wx::Dialog';
7 use Wx qw/:id :misc :sizer :dialog/;
8 use Wx::Event 'EVT_TEXT';
9 use Encode;
10  
11 sub new {
12 my $class = shift;
13 my $parent = shift;
14 my $ref = shift;
15  
16 # Set up the dialog
17 my $self = $class->SUPER::new($parent, -1, "Rename multiple files", wxDefaultPosition, [-1,130], wxDEFAULT_DIALOG_STYLE);
18  
19 ## prepend/append gui elements
20 $self->{pre} = Wx::TextCtrl->new($self, -1, '', wxDefaultPosition, wxDefaultSize, );
21 $self->{fix} = Wx::StaticText->new($self, -1, '<multiple filenames>', wxDefaultPosition, [-1,40]);
22 $self->{ins} = Wx::TextCtrl->new($self, -1, '', wxDefaultPosition, wxDefaultSize, );
23 $self->{suf} = Wx::StaticText->new($self, -1, '.suffix', wxDefaultPosition, [-1,40]);
24  
25  
26 my $prepapp_sizer = Wx::StaticBoxSizer->new( Wx::StaticBox->new($self, -1, " Prepend/ append " ), wxHORIZONTAL);
27 $prepapp_sizer->Add($self->{pre}, 0, wxALL, 2);
28 $prepapp_sizer->Add($self->{fix}, 0, wxTOP, 7);
29 $prepapp_sizer->Add($self->{ins}, 0, wxALL, 2);
30 $prepapp_sizer->Add($self->{suf}, 0, wxALL, 7);
31 $self->{pre}->SetFocus();
32  
33 ## clever-multi-file/pattern-based-rename preparation (todo)
34 my @pos;
35 foreach my $hashref (@{ $ref }){
36 my $file = $hashref->{file};
37 $file = decode_utf8($file); # decode
38 Encode::_utf8_off($file); # then remove the utf8-flag the hard way
39  
40 foreach my $i (0..length($file)){
41 if(!defined($pos[$i])){
42 $pos[$i] = substr($file,$i,1);
43 }elsif($pos[$i] eq substr($file,$i,1)){
44 $pos[$i] = substr($file,$i,1);
45 }else{
46 $pos[$i] = '*';
47 }
48 }
49 }
50  
51 ## strange: length here counts correctly but when we assemble it back into the textctrl below
52 ## it introduces spaces, as if a utf8 string was handled incorrectly or so... todo
53 $self->{length} = scalar(@pos);
54  
55 my $sizer = Wx::BoxSizer->new(wxVERTICAL);
56 $sizer->Add($prepapp_sizer, 0, wxALL|wxGROW, 5);
57  
58 if($parent->{wrangler}->{debug}){
59 $self->SetSize([-1,250]);
60  
61 ## clever-multi-file/pattern-based-rename gui elements (todo)
62 $self->{pattern} = Wx::TextCtrl->new($self, -1, "@pos", wxDefaultPosition, wxDefaultSize, );
63 my $pattern_sizer = Wx::StaticBoxSizer->new( Wx::StaticBox->new($self, -1, " Patterns " ), wxVERTICAL);
64 $pattern_sizer->Add($self->{pattern}, 0, wxALL|wxGROW, 5);
65  
66 $sizer->Add($pattern_sizer, 0, wxALL|wxGROW, 5);
67 }
68  
69 my $btn_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
70 $btn_sizer->Add(Wx::Button->new($self, wxID_OK, 'OK'), 0, wxALL, 2);
71 $btn_sizer->Add(Wx::Button->new($self, wxID_CANCEL, 'Cancel'), 0, wxALL, 2);
72  
73 $sizer->Add($btn_sizer, 0, wxALL|wxALIGN_RIGHT, 5);
74  
75 $self->SetSizer($sizer);
76 $self->Layout();
77 $self->Centre();
78 $self->{pre}->SetFocus(); # so this modal dialog starts catching the keyboard
79  
80 # EVT_TEXT($self, $self->{textctrl}, \&OnText);
81  
82 return $self;
83 }
84  
85 sub OnText {
86 my $self = shift;
87  
88 $self->{textctrl}->SetInsertionPoint(3);
89 }
90  
91 1;