summaryrefslogtreecommitdiff
path: root/ACE/MPC/modules/HTMLProjectCreator.pm
blob: 00e49087393473ea8e473999c8c1726bf71cf852 (plain)
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
package HTMLProjectCreator;

# ************************************************************
# Description   : An HTML project creator to display all settings
# Author        : Justin Michel & Chad Elliott
# Create Date   : 8/25/2003
# ************************************************************

# ************************************************************
# Pragmas
# ************************************************************

use strict;

use ProjectCreator;
use XMLProjectBase;

use vars qw(@ISA);
@ISA = qw(XMLProjectBase ProjectCreator);

# ************************************************************
# Data Section
# ************************************************************

my $style_indent = .5;

# ************************************************************
# Subroutine Section
# ************************************************************

sub file_sorter {
  #my $self  = shift;
  #my $left  = shift;
  #my $right = shift;
  return lc($_[1]) cmp lc($_[2]);
}


sub label_nodes {
  my($self, $hash, $nodes, $level) = @_;

  foreach my $key (sort keys %$hash) {
    push(@$nodes, [$level, $key]);
    $self->label_nodes($$hash{$key}, $nodes, $level + 1);
  }
}


sub count_levels {
  my($self, $hash, $current, $count) = @_;

  foreach my $key (keys %$hash) {
    $self->count_levels($$hash{$key}, $current + 1, $count);
  }
  $$count = $current if ($current > $$count);
}


sub fill_value {
  my($self, $name) = @_;
  my $value;

  if ($name eq 'inheritance_nodes') {
    ## Get the nodes with numeric labels for the level
    my @nodes;
    $self->label_nodes($self->get_inheritance_tree(), \@nodes, 0);

    ## Push each node onto the value array
    $value = [];
    for(my $i = 0; $i <= $#nodes; ++$i) {
      my $file = $nodes[$i]->[1];
      my $dir  = $self->mpc_dirname($file);
      my $base = $self->mpc_basename($file);

      ## Relative paths do not work at all in a web browser
      $file = $base if ($dir eq '.');

      my $path = ($base eq $file ? $self->getcwd() . '/' : '');
      my $name;

      if ($i == 0) {
        ## If this is the first node, then replace the base filename
        ## with the actual project name.
        $name = $self->project_name();
      }
      else {
        ## This is a base project, so we use the basename and
        ## remove the file extension.
        $name = $base;
        $name =~ s/\.[^\.]+$//;
      }

      ## Create the div and a tags.
      push(@$value, '<a href="file://' . $path . $file .
                    '" onClick="return popup(this, \'Project File\')" ' .
                    'target=_blank>' .
                    '<div class="tree' . $nodes[$i]->[0] . '">' .
                     $name . '</div></a>');
    }
  }
  elsif ($name eq 'tree_styles') {
    ## Count the number of levels deep the inheritance goes
    my $count = 0;
    $self->count_levels($self->get_inheritance_tree(), 0, \$count);

    my $margin = 0;
    my $start  = 100;
    my $max    = 255;
    my $inc    = ($count ne 0 ? int(($max - $start) / $count) : $max);

    ## Push each tree style onto the value array
    $value = [];
    for(my $i = 0; $i < $count; ++$i) {
      push(@$value, ".tree$i { background-color: #" .
                    sprintf("%02x%02x%02x", 0, $start, $start) . ';' .
                    ($margin != 0 ? " margin-left: $margin" . 'in;' : '') .
                    ' }');
      $start += $inc;
      $margin += $style_indent;
    }
  }

  return $value;
}


sub project_file_extension {
  #my $self = shift;
  return '.html';
}


1;