-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathgui_hlist.pm
140 lines (117 loc) · 2.77 KB
/
gui_hlist.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package gui_hlist;
use Tk;
use Tk::HList;
use utf8;
# Usage:
# gui_hlist->copy( $hlist_obj );
# gui_hlist->copy_all( $hlist_obj );
my $debug = 0;
sub copy{
my $class = shift;
my $self;
$self->{list} = shift;
bless $self, $class;
my @selected = $self->list->infoSelection;
my $cols = pop @{$self->list->configure(-columns)}; --$cols; # 列数調べ
my $clip;
foreach my $i (@selected){
#print "row: $i\n";
for (my $c = 0; $c <= $cols; ++$c){
if ( $self->list->itemExists($i, $c) ){
my $cell = $self->list->itemCget($i, $c, -text);
#$cell = gui_window->gui_jg($cell);
while ($cell =~ /\s$/o){
chop $cell
}
$clip .= "$cell\t";
} else {
$clip .= "\t";
}
}
chop $clip;
$clip .= "\n";
}
if (defined($clip) && length($clip)){
use kh_clipboard;
kh_clipboard->string($clip);
}
}
sub copy_all{
my $class = shift;
my $self;
$self->{list} = shift;
bless $self, $class;
my $clip = gui_hlist->get_all($self->list);
if (defined($clip) && length($clip)){
use kh_clipboard;
kh_clipboard->string($clip);
}
}
sub update4scroll{
my $class = shift;
my $self;
$self->{list} = shift;
bless $self, "$class"."::".$::config_obj->os;
if ($debug) {
print "\ngui_hlist::update4scroll: \n";
my ($package_name, $file_name, $line) = caller;
print "\t$package_name, $file_name, $line\n";
print "\t",ref $self->{list}, "\n";
my $p = $self->{list}->Parent;
print "\t",ref $p, "\n";
}
$self->{list}->update;
$self->{list}->yview(moveto => 0);
$self->{list}->yview('scroll', 1,'units');
$self->{list}->yview('scroll',-1,'units');
}
sub get_all{
my $class = shift;
my $self;
$self->{list} = shift;
bless $self, $class;
# 列数
my $cols = pop @{$self->list->configure(-columns)}; --$cols;
print "gui_hlist / cols: $cols\n" if $debug;
my $t = '';
my $n = 0;
while ($self->list->info('exists', $n)){
# 通常の行
print "n$n, " if $debug;
for (my $c = 0; $c <= $cols; ++$c){
if ( $self->list->itemExists($n, $c) ){
$t .= $self->list->itemCget($n, $c, -text)."\t";
print "c$c: ".$self->list->itemCget($n, $c, -text).", " if $debug;
} else {
$t .= "\t";
}
}
print "line-end\n" if $debug;
chop $t; $t .= "\n";
# 子供の行
my @children = $self->list->info('children', $n);
foreach my $i (@children){
print "n$i, " if $debug;
$t .= "[]";
for (my $c = 0; $c <= $cols; ++$c){
if ( $self->list->itemExists($i, $c) ){
$t .= $self->list->itemCget($i, $c, -text)."\t";
print "c$c: ".$self->list->itemCget($i, $c, -text).", " if $debug;
} else {
print "c$c: [none]," if $debug;
$t .= "\t";
}
}
print "line-end\n" if $debug;
chop $t; $t .= "\n";
++$n;
}
++$n;
}
return $t;
}
sub list{
my $self = shift;
return $self->{list};
}
1;