Wrangler/Wx/Dialog/MultiRename.pm untested

filter: Statementstmt 0.0% 0 / 66 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 / 82 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  
38 foreach my $i (0..length($file)){
39 if(!defined($pos[$i])){
40 $pos[$i] = substr($file,$i,1);
41 }elsif($pos[$i] eq substr($file,$i,1)){
42 $pos[$i] = substr($file,$i,1);
43 }else{
44 $pos[$i] = '*';
45 }
46 }
47 }
48  
49 ## strange: length here counts correctly but when we assemble it back into the textctrl below
50 ## it introduces spaces, as if a utf8 string was handled incorrectly or so... todo
51 $self->{length} = scalar(@pos);
52  
53 my $sizer = Wx::BoxSizer->new(wxVERTICAL);
54 $sizer->Add($prepapp_sizer, 0, wxALL|wxGROW, 5);
55  
56 if($parent->{wrangler}->{debug}){
57 $self->SetSize([-1,250]);
58  
59 ## clever-multi-file/pattern-based-rename gui elements (todo)
60 $self->{pattern} = Wx::TextCtrl->new($self, -1, "@pos", wxDefaultPosition, wxDefaultSize, );
61 my $pattern_sizer = Wx::StaticBoxSizer->new( Wx::StaticBox->new($self, -1, " Patterns " ), wxVERTICAL);
62 $pattern_sizer->Add($self->{pattern}, 0, wxALL|wxGROW, 5);
63  
64 $sizer->Add($pattern_sizer, 0, wxALL|wxGROW, 5);
65 }
66  
67 my $btn_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
68 $btn_sizer->Add(Wx::Button->new($self, wxID_OK, 'OK'), 0, wxALL, 2);
69 $btn_sizer->Add(Wx::Button->new($self, wxID_CANCEL, 'Cancel'), 0, wxALL, 2);
70  
71 $sizer->Add($btn_sizer, 0, wxALL|wxALIGN_RIGHT, 5);
72  
73 $self->SetSizer($sizer);
74 $self->Layout();
75 $self->Centre();
76 $self->{pre}->SetFocus(); # so this modal dialog starts catching the keyboard
77  
78 # EVT_TEXT($self, $self->{textctrl}, \&OnText);
79  
80 return $self;
81 }
82  
83 sub OnText {
84 my $self = shift;
85  
86 $self->{textctrl}->SetInsertionPoint(3);
87 }
88  
89 1;