Merge pull request #228 from DOCGroup/jwillemsen-patch-1
[MPC.git] / modules / HTMLProjectCreator.pm
blob00e49087393473ea8e473999c8c1726bf71cf852
1 package HTMLProjectCreator;
3 # ************************************************************
4 # Description : An HTML project creator to display all settings
5 # Author : Justin Michel & Chad Elliott
6 # Create Date : 8/25/2003
7 # ************************************************************
9 # ************************************************************
10 # Pragmas
11 # ************************************************************
13 use strict;
15 use ProjectCreator;
16 use XMLProjectBase;
18 use vars qw(@ISA);
19 @ISA = qw(XMLProjectBase ProjectCreator);
21 # ************************************************************
22 # Data Section
23 # ************************************************************
25 my $style_indent = .5;
27 # ************************************************************
28 # Subroutine Section
29 # ************************************************************
31 sub file_sorter {
32 #my $self = shift;
33 #my $left = shift;
34 #my $right = shift;
35 return lc($_[1]) cmp lc($_[2]);
39 sub label_nodes {
40 my($self, $hash, $nodes, $level) = @_;
42 foreach my $key (sort keys %$hash) {
43 push(@$nodes, [$level, $key]);
44 $self->label_nodes($$hash{$key}, $nodes, $level + 1);
49 sub count_levels {
50 my($self, $hash, $current, $count) = @_;
52 foreach my $key (keys %$hash) {
53 $self->count_levels($$hash{$key}, $current + 1, $count);
55 $$count = $current if ($current > $$count);
59 sub fill_value {
60 my($self, $name) = @_;
61 my $value;
63 if ($name eq 'inheritance_nodes') {
64 ## Get the nodes with numeric labels for the level
65 my @nodes;
66 $self->label_nodes($self->get_inheritance_tree(), \@nodes, 0);
68 ## Push each node onto the value array
69 $value = [];
70 for(my $i = 0; $i <= $#nodes; ++$i) {
71 my $file = $nodes[$i]->[1];
72 my $dir = $self->mpc_dirname($file);
73 my $base = $self->mpc_basename($file);
75 ## Relative paths do not work at all in a web browser
76 $file = $base if ($dir eq '.');
78 my $path = ($base eq $file ? $self->getcwd() . '/' : '');
79 my $name;
81 if ($i == 0) {
82 ## If this is the first node, then replace the base filename
83 ## with the actual project name.
84 $name = $self->project_name();
86 else {
87 ## This is a base project, so we use the basename and
88 ## remove the file extension.
89 $name = $base;
90 $name =~ s/\.[^\.]+$//;
93 ## Create the div and a tags.
94 push(@$value, '<a href="file://' . $path . $file .
95 '" onClick="return popup(this, \'Project File\')" ' .
96 'target=_blank>' .
97 '<div class="tree' . $nodes[$i]->[0] . '">' .
98 $name . '</div></a>');
101 elsif ($name eq 'tree_styles') {
102 ## Count the number of levels deep the inheritance goes
103 my $count = 0;
104 $self->count_levels($self->get_inheritance_tree(), 0, \$count);
106 my $margin = 0;
107 my $start = 100;
108 my $max = 255;
109 my $inc = ($count ne 0 ? int(($max - $start) / $count) : $max);
111 ## Push each tree style onto the value array
112 $value = [];
113 for(my $i = 0; $i < $count; ++$i) {
114 push(@$value, ".tree$i { background-color: #" .
115 sprintf("%02x%02x%02x", 0, $start, $start) . ';' .
116 ($margin != 0 ? " margin-left: $margin" . 'in;' : '') .
117 ' }');
118 $start += $inc;
119 $margin += $style_indent;
123 return $value;
127 sub project_file_extension {
128 #my $self = shift;
129 return '.html';