line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Kwiki::Theme::Selectable; |
2
|
1
|
|
|
1
|
|
34195
|
use Kwiki::Theme -Base; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# XXX: |
6
|
|
|
|
|
|
|
# - Install all themes on -update |
7
|
|
|
|
|
|
|
# - default to basic if theme not available |
8
|
|
|
|
|
|
|
const theme_id => 'selectable'; |
9
|
|
|
|
|
|
|
const class_title => 'Selectable Theme'; |
10
|
|
|
|
|
|
|
const config_file => 'theme_selectable.yaml'; |
11
|
|
|
|
|
|
|
const default_selection => 'Kwiki::Theme::Basic'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub register { |
14
|
|
|
|
|
|
|
super; |
15
|
|
|
|
|
|
|
my $registry = shift; |
16
|
|
|
|
|
|
|
$registry->add(preference => $self->theme_selection); |
17
|
|
|
|
|
|
|
$self->hook_install; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub init { |
21
|
|
|
|
|
|
|
super; |
22
|
|
|
|
|
|
|
$self->reset_theme_class($self->selected_class); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub selected_class { |
26
|
|
|
|
|
|
|
my @all_themes = $self->all_themes; |
27
|
|
|
|
|
|
|
my %classes = map {($_, $_)} @all_themes; |
28
|
|
|
|
|
|
|
my $class = $self->preferences->theme_selection->value; |
29
|
|
|
|
|
|
|
return $classes{$class} || $all_themes[0] || die; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub reset_theme_class { |
33
|
|
|
|
|
|
|
my $class = shift; |
34
|
|
|
|
|
|
|
field theme_class => |
35
|
|
|
|
|
|
|
-package => ref($self->config); |
36
|
|
|
|
|
|
|
$self->hub->config->theme_class($class); |
37
|
|
|
|
|
|
|
$self->hub->theme(undef); |
38
|
|
|
|
|
|
|
$self->hub->theme; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub theme_selection { |
42
|
|
|
|
|
|
|
my $p = $self->new_preference('theme_selection'); |
43
|
|
|
|
|
|
|
$p->query('Select A Theme.'); |
44
|
|
|
|
|
|
|
$p->type('pulldown'); |
45
|
|
|
|
|
|
|
my $choices = [ |
46
|
|
|
|
|
|
|
map {($_, $_)} $self->all_themes |
47
|
|
|
|
|
|
|
]; |
48
|
|
|
|
|
|
|
$p->default($choices->[0]); |
49
|
|
|
|
|
|
|
$p->choices($choices); |
50
|
|
|
|
|
|
|
$p->edit('set_new_theme'); |
51
|
|
|
|
|
|
|
return $p; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub Kwiki::Theme::set_new_theme { |
55
|
|
|
|
|
|
|
my $self = shift; |
56
|
|
|
|
|
|
|
$self = __PACKAGE__->new; |
57
|
|
|
|
|
|
|
my $preference = shift; |
58
|
|
|
|
|
|
|
$self->reset_theme_class($preference->new_value); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub all_themes { |
62
|
|
|
|
|
|
|
$self->hub->config->can('theme_list') |
63
|
|
|
|
|
|
|
? @{$self->hub->config->theme_list} |
64
|
|
|
|
|
|
|
: $self->default_selection; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub hook_install { |
68
|
|
|
|
|
|
|
no strict 'refs'; |
69
|
|
|
|
|
|
|
no warnings; |
70
|
|
|
|
|
|
|
my $command_class = ref($self->hub->command); |
71
|
|
|
|
|
|
|
my $command_install = \ &{$command_class . "::install"}; |
72
|
|
|
|
|
|
|
*{$command_class . "::install"} = sub { |
73
|
|
|
|
|
|
|
my $self = shift; |
74
|
|
|
|
|
|
|
$self->$command_install(@_); |
75
|
|
|
|
|
|
|
my $class_id = shift; |
76
|
|
|
|
|
|
|
return unless $class_id eq 'theme'; |
77
|
|
|
|
|
|
|
my $theme = $self->hub->theme; |
78
|
|
|
|
|
|
|
return unless $theme->isa(__PACKAGE__); |
79
|
|
|
|
|
|
|
for my $class ($theme->all_themes) { |
80
|
|
|
|
|
|
|
$theme->reset_theme_class($class); |
81
|
|
|
|
|
|
|
$self->install('theme'); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__DATA__ |