Wrangler/Wx/Dialog/Properties.pm untested

filter: Statementstmt 0.0% 0 / 142 Branchbran 0.0% 0 / 62 Conditioncond 0.0% 0 / 21 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 238 CC 32 SCAR 66.9
CC
32
Cov
0%
new
1056.0
new
2.0
BEGIN
2.0
CRAP 805.0
1 package Wrangler::Wx::Dialog::Properties;
2  
3 use strict;
4 use warnings;
5  
6 use Wx qw(wxDefaultPosition wxDefaultSize wxDEFAULT_DIALOG_STYLE wxRESIZE_BORDER wxCAPTION wxEXPAND wxCLOSE_BOX wxTOP wxBOTH wxLEFT wxALIGN_CENTER wxVERTICAL wxBOTTOM wxHORIZONTAL wxALL wxGROW wxCLIP_CHILDREN wxID_OK);
7 use Wx::Event qw(EVT_BUTTON);
8 use base 'Wx::Dialog';
9  
10 sub new {
11 my $class = shift;
12 my $parent = shift;
13 my $selections = shift;
14  
15 my $self = $class->SUPER::new($parent, -1, "Properties", wxDefaultPosition, [460,440], wxDEFAULT_DIALOG_STYLE | wxCAPTION | wxRESIZE_BORDER | wxCLOSE_BOX);
16  
17 # main sizer
18 my $sizer = Wx::FlexGridSizer->new(2, 1, 0, 0); # rows,cols,vgap,hgap
19 $sizer->AddGrowableCol(0);
20 $sizer->AddGrowableRow(0);
21  
22 # do a notebook
23 my $nb = Wx::Notebook->new( $self, -1, wxDefaultPosition, wxDefaultSize, wxCLIP_CHILDREN );
24 $nb->{wrangler} = $parent->{wrangler}; # hook-up notebook with $wrangler
25 my $tab2 = Wrangler::Wx::Dialog::Properties::General->new($nb,$selections);
26 $nb->AddPage( $tab2, "General", 0);
27  
28 # a close button in the lower section
29 my $button_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
30 $button_sizer->Add(Wx::Button->new($self, wxID_OK, "Close", wxDefaultPosition, wxDefaultSize ), 0, wxALL, 2);
31  
32 # compose elements
33 $sizer->Add($nb, 1, wxGROW|wxALL, 5);
34 $sizer->Add($button_sizer, 1, wxGROW|wxTOP|wxEXPAND, 5);
35  
36 $self->SetSizer($sizer);
37  
38 $self->Centre();
39  
40 return $self;
41 }
42  
43  
44 package Wrangler::Wx::Dialog::Properties::General;
45  
46 use strict;
47 use warnings;
48  
49 use Wx qw(wxDefaultPosition wxDefaultSize wxDEFAULT_DIALOG_STYLE wxEXPAND wxGROW wxLEFT wxALL wxALIGN_CENTER wxVERTICAL wxBOTTOM);
50 # use Wx::Event qw();
51 use base 'Wx::Panel';
52  
53 sub new {
54 my $class = shift;
55 my $parent = shift;
56 my $selections = shift;
57  
58 my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxEXPAND);
59  
60 ## gather initial dir data
61 my $directory_text = '';
62 my @dirs_todo;
63 for(@$selections){
64 if($_->{'Filesystem::Type'} && $_->{'Filesystem::Type'} eq 'Directory'){
65 push(@dirs_todo, $_->{'Filesystem::Path'});
66 $directory_text++;
67 }
68 }
69 $directory_text = " ($directory_text directories)" if $directory_text;
70  
71 ## recurse dirs
72 for(@dirs_todo){
73 # Wrangler::debug(" Properties: entering $_ $parent->{wrangler}");
74 my $richlist = $parent->{wrangler}->{fs}->richlist($_);
75  
76 for(@$richlist){
77 next if $_->{'Filesystem::Filename'} =~ /^\.$|^\.\.$/;
78 if($_->{'Filesystem::Type'} && $_->{'Filesystem::Type'} eq 'Directory'){
79 push(@dirs_todo, $_->{'Filesystem::Path'});
80 }
81 push(@$selections, $_);
82 }
83 }
84  
85 my $prop_sizer;
86 my $totalBytes;
87 for(@$selections){
88 $totalBytes += $_->{'Filesystem::Size'};
89 }
90 my $isLink;
91 for(@$selections){
92 next unless $_->{'Filesystem::Link'};
93 $isLink ||= $_->{'Filesystem::Link'};
94 if($isLink ne $_->{'Filesystem::Link'} ){
95 $isLink = 'some';
96 last;
97 }
98 }
99 my $nodeType;
100 for(@$selections){
101 next unless $_->{'Filesystem::Type'};
102 $nodeType ||= $_->{'Filesystem::Type'};
103 if( $nodeType ne $_->{'Filesystem::Type'} ){
104 $nodeType = '-';
105 last;
106 }
107 }
108 my $mimeType;
109 for(@$selections){
110 next unless $_->{'MIME::Type'};
111 $mimeType ||= $_->{'MIME::Type'};
112 if( $mimeType ne $_->{'MIME::Type'} ){
113 $mimeType = '-';
114 last;
115 }
116 }
117 my $Modified;
118 for(@$selections){
119 next unless $_->{'Filesystem::Modified'};
120 if(!defined($Modified)){
121 $Modified = $_->{'Filesystem::Modified'};
122 }elsif( $Modified ne $_->{'Filesystem::Modified'} ){
123 $Modified = undef;
124 last;
125 }
126 }
127 my $Accessed;
128 for(@$selections){
129 next unless $_->{'Filesystem::Accessed'};
130 if(!defined($Accessed)){
131 $Accessed = $_->{'Filesystem::Accessed'};
132 }elsif( $Accessed ne $_->{'Filesystem::Accessed'} ){
133 $Accessed = undef;
134 last;
135 }
136 }
137 my $Changed;
138 for(@$selections){
139 next unless $_->{'Filesystem::Changed'};
140 if(!defined($Changed)){
141 $Changed = $_->{'Filesystem::Changed'};
142 }elsif( $Changed ne $_->{'Filesystem::Changed'} ){
143 $Changed = undef;
144 last;
145 }
146 }
147 my $Created;
148 for(@$selections){
149 next unless $_->{'Filesystem::Created'};
150 if(!defined($Created)){
151 $Created = $_->{'Filesystem::Created'};
152 }elsif( $Created ne $_->{'Filesystem::Created'} ){
153 $Created = undef;
154 last;
155 }
156 }
157 $prop_sizer = Wx::FlexGridSizer->new(2,2,15,10); # rows,cols,vgap,hgap
158 $prop_sizer->Add(Wx::StaticText->new($self, -1, 'Size:', wxDefaultPosition, wxDefaultSize), 1);
159 $prop_sizer->Add(Wx::StaticText->new($self, -1, int($totalBytes/1024) .' KB', wxDefaultPosition, wxDefaultSize), 1);
160 $prop_sizer->Add(Wx::StaticText->new($self, -1, 'Node-Type:', wxDefaultPosition, wxDefaultSize), 1, );
161 $prop_sizer->Add(Wx::StaticText->new($self, -1, ($nodeType || '-'), wxDefaultPosition, wxDefaultSize), 1);
162 $prop_sizer->Add(Wx::StaticText->new($self, -1, 'is Link:', wxDefaultPosition, wxDefaultSize), 1, );
163 $prop_sizer->Add(Wx::StaticText->new($self, -1, ($isLink || 'no'), wxDefaultPosition, wxDefaultSize), 1);
164 $prop_sizer->Add(Wx::StaticText->new($self, -1, 'MIME-Type:', wxDefaultPosition, wxDefaultSize), 1, );
165 $prop_sizer->Add(Wx::StaticText->new($self, -1, ($mimeType || '-'), wxDefaultPosition, wxDefaultSize), 1);
166 $prop_sizer->Add(Wx::StaticText->new($self, -1, 'Modified (mtime):', wxDefaultPosition, wxDefaultSize), 1);
167 $prop_sizer->Add(Wx::StaticText->new($self, -1, ($Modified ? localtime($Modified) : '-') . ($Modified ? ' ('. $Modified .')' : ''), wxDefaultPosition, wxDefaultSize), 1);
168 $prop_sizer->Add(Wx::StaticText->new($self, -1, 'Accessed (atime):', wxDefaultPosition, wxDefaultSize), 1);
169 $prop_sizer->Add(Wx::StaticText->new($self, -1, ($Accessed ? localtime($Accessed) : '-') . ($Accessed ? ' ('. $Accessed .')' : ''), wxDefaultPosition, wxDefaultSize), 1);
170 $prop_sizer->Add(Wx::StaticText->new($self, -1, 'Changed (chtime):', wxDefaultPosition, wxDefaultSize), 1);
171 $prop_sizer->Add(Wx::StaticText->new($self, -1, ($Changed ? localtime($Changed) : '-') . ($Changed ? ' ('. $Changed .')' : ''), wxDefaultPosition, wxDefaultSize), 1);
172 $prop_sizer->Add(Wx::StaticText->new($self, -1, 'Created (ctime):', wxDefaultPosition, wxDefaultSize), 1);
173 $prop_sizer->Add(Wx::StaticText->new($self, -1, ($Created ? localtime($Created) : '-') . ($Created ? ' ('. $Created .')' : ''), wxDefaultPosition, wxDefaultSize), 1);
174  
175 my $text = scalar(@$selections) > 1 ? scalar(@$selections) ." items selected". $directory_text .":" : scalar(@$selections) ." item selected$directory_text:";
176  
177 # tab
178 my $sizer = Wx::FlexGridSizer->new(2, 1, 20, 0); # rows,cols,vgap,hgap
179 $sizer->AddGrowableCol(1);
180 $sizer->AddGrowableRow(1);
181 $sizer->Add(Wx::StaticText->new($self, -1, $text, wxDefaultPosition, wxDefaultSize), 1, wxGROW|wxALL, 10);
182 $sizer->Add($prop_sizer, 1, wxGROW|wxALL, 10);
183  
184 $self->SetSizer($sizer);
185  
186 return $self;
187 }
188  
189 1;