File: FolderTree.pm

package info (click to toggle)
pronto 2.4.0-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,112 kB
  • ctags: 487
  • sloc: perl: 22,159; makefile: 127; sh: 34; sql: 7
file content (93 lines) | stat: -rw-r--r-- 1,921 bytes parent folder | download | duplicates (2)
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
package HTMLWidget::FolderTree;

use strict;

sub new {
  my $class = shift;
  my $template = shift;
  my $self = {indent => 0,
	      indent_step => 4,
	      template => $template};
  
  return bless $self, $class;
}

sub insert_node {
  my ($self, $parent, $sibling, $text, $spacing, 
      $pixmap_closed, $mask_closed, $pixmap_open, $mask_open,
      $is_leaf, $expanded) = @_;
  
  my $tn = HTMLWidget::TreeNode->new($text, $parent, $sibling);

  unshift @{$self->{nodes}}, $tn;

  return $tn;
}

sub draw {
  my $self = shift;

  my @nodes = @_;

  @nodes = grep { !$_->{parent} } @{$self->{nodes}} unless @nodes;

  foreach my $node (@nodes) {
    $self->{template}->process("folders_body.html", {indent  => " " x $self->{indent},
						     folder  => $node->{text}->[0],
						     box     => $main::ft_id{$node},
						     msg     => $self->{texts}->[1]->{$node},
						     new     => $self->{texts}->[2]->{$node},
						     style   => $self->{style}->{$node},
						     session => &main::param('session')})
	|| die $self->{template}->error();
    print "\n";
    my @children = grep { $_->{parent} && $node == $_->{parent}} @{$self->{nodes}};
    $self->{indent} += $self->{indent_step};
    $self->draw(@children) if @children;
    $self->{indent} -= $self->{indent_step};
  }

}

sub node_set_text {
  my ($self, $node, $column, $text) = @_;

  $self->{texts}->[$column]->{$node} = $text;
}

sub node_get_text {
  my ($self, $node, $column) = @_;

  return $self->{texts}->[$column]->{$node};
}

sub node_set_row_style {
  my ($self, $node, $style) = @_;

  $self->{style}->{$node} = $style;
}

sub selection {
  my $self = shift;

  return @{$self->{selection}};
}

sub AUTOLOAD {
}

1;

package HTMLWidget::TreeNode;

sub new {
  my ($class, $text, $parent, $sibling) = @_;

  my $self = {text => $text,
	      parent => $parent,
	      sibling => $sibling};

  return bless $self, $class;
}

1;