| 1 |
## -*- cperl -*- |
| 2 |
## |
| 3 |
## This file is part of Athena, copyright (c) 2001-2006 Bruce Ravel |
| 4 |
## |
| 5 |
## This section of the code contains subroutines associated with |
| 6 |
## Athena's plugin registry |
| 7 |
|
| 8 |
sub registry { |
| 9 |
|
| 10 |
my %reg_params = (); |
| 11 |
|
| 12 |
$fat_showing = 'registry'; |
| 13 |
$hash_pointer = \%reg_params; |
| 14 |
map {$_ -> configure(-state=>'disabled')} |
| 15 |
($data_menu, $merge_menu, $anal_menu, $settings_menu); |
| 16 |
$fat -> packForget; |
| 17 |
my $reg = $container->Frame(@fatgeom, -relief=>'sunken', -borderwidth=>3) |
| 18 |
-> pack(-fill=>'both', -expand=>1); |
| 19 |
$which_showing = $reg; |
| 20 |
|
| 21 |
$reg -> Label(-text=>"Plugin Registry", |
| 22 |
-font=>$config{fonts}{large}, |
| 23 |
-foreground=>$config{colors}{activehighlightcolor}) |
| 24 |
-> pack(-side=>'top', -fill=>'x', -anchor=>'w'); |
| 25 |
|
| 26 |
## table of available plugins |
| 27 |
my $plugin_list; |
| 28 |
$plugin_list = $reg -> Scrolled('HList', |
| 29 |
-scrollbars => 'osoe', |
| 30 |
-header => 1, |
| 31 |
-columns => 3, |
| 32 |
-borderwidth => 0, |
| 33 |
-relief => 'flat', |
| 34 |
-cursor => $mouse_over_cursor, |
| 35 |
-selectbackground => $config{colors}{background}, |
| 36 |
-highlightcolor => $config{colors}{background}, |
| 37 |
-browsecmd => |
| 38 |
sub { # Echo a bit of info on a click |
| 39 |
my $pick = $plugin_list -> selectionGet; |
| 40 |
($pick = $pick->[0]) if (ref($pick) =~ /ARRAY/); # Tk 800 returns a scalar |
| 41 |
# Tk 804 returns an array ref |
| 42 |
my $id = "Ifeffit/Plugins/Filetype/Athena/".$plugins[$pick].".pm"; |
| 43 |
my $message = ($INC{$id}) |
| 44 |
? "System plugin: $INC{$id}" |
| 45 |
: "Private plugin: " . File::Spec->catfile($groups{"Default Parameters"} -> find('athena', 'userfiletypedir'), $plugins[$pick].".pm"); |
| 46 |
Echo($message); |
| 47 |
}, |
| 48 |
-command => |
| 49 |
sub { # display pod on double-click |
| 50 |
my $pick = $plugin_list -> selectionGet; |
| 51 |
($pick = $pick->[0]) if (ref($pick) =~ /ARRAY/); # Tk 800 returns a scalar |
| 52 |
# Tk 804 returns an array ref |
| 53 |
my $id = "Ifeffit/Plugins/Filetype/Athena/".$plugins[$pick].".pm"; |
| 54 |
my $file = $INC{$id} || File::Spec->catfile($groups{"Default Parameters"} -> find('athena', 'userfiletypedir'), $plugins[$pick].".pm"); |
| 55 |
pod_display($file); |
| 56 |
}) |
| 57 |
-> pack(-side=>'top', -fill =>'both', -expand=>1, -padx=>4, -pady=>4); |
| 58 |
$plugin_list -> Subwidget("xscrollbar") |
| 59 |
-> configure(-background=>$config{colors}{background}, |
| 60 |
($is_windows) ? () : (-width=>8)); |
| 61 |
$plugin_list -> Subwidget("yscrollbar") |
| 62 |
-> configure(-background=>$config{colors}{background}, |
| 63 |
($is_windows) ? () : (-width=>8)); |
| 64 |
$plugin_list -> Subwidget("hlist") |
| 65 |
-> bind('<ButtonPress-2>', sub{anchor_registry($plugin_list)}); |
| 66 |
$plugin_list -> Subwidget("hlist") |
| 67 |
-> bind('<ButtonPress-3>', sub{anchor_registry($plugin_list)}); |
| 68 |
|
| 69 |
my $style = $plugin_list -> ItemStyle('text', |
| 70 |
-font=>$config{fonts}{small}, |
| 71 |
-anchor=>'w', |
| 72 |
-foreground=>$config{colors}{activehighlightcolor}); |
| 73 |
$plugin_list -> headerCreate(0, |
| 74 |
-text=>q{}, # Enable button |
| 75 |
-style=>$style, |
| 76 |
-headerbackground=>$config{colors}{background},); |
| 77 |
$plugin_list -> headerCreate(1, |
| 78 |
-text=>"Plugin", |
| 79 |
-style=>$style, |
| 80 |
-headerbackground=>$config{colors}{background},); |
| 81 |
$plugin_list -> headerCreate(2, |
| 82 |
-text=>"Description", |
| 83 |
-style=>$style, |
| 84 |
-headerbackground=>$config{colors}{background},); |
| 85 |
|
| 86 |
$style = $plugin_list -> ItemStyle('text', |
| 87 |
-font=>$config{fonts}{small}, |
| 88 |
-anchor=>'w', |
| 89 |
-foreground=>$config{colors}{foreground}); |
| 90 |
|
| 91 |
my @button = (); |
| 92 |
foreach my $i (0 .. $#plugins) { |
| 93 |
$plugin_list -> add($i); |
| 94 |
$button[$i] = $plugin_list -> Checkbutton(-variable => \$plugin_params{$plugins[$i]}{_enabled}, |
| 95 |
-selectcolor => $config{colors}{single}, |
| 96 |
-command => sub{ # Enable plugin |
| 97 |
my $file = $groups{"Default Parameters"} -> find('athena', 'plugins'); |
| 98 |
tied( %plugin_params )->WriteConfig($file); |
| 99 |
if ($plugin_params{$plugins[$i]}{_enabled}) { |
| 100 |
Echo("Registered plugin $plugins[$i] for use."); |
| 101 |
} else { |
| 102 |
Echo("Un-registered plugin $plugins[$i]."); |
| 103 |
}; |
| 104 |
}, |
| 105 |
); |
| 106 |
$plugin_list -> itemCreate($i, 0, -itemtype=>'window', -widget=>$button[$i]); |
| 107 |
$plugin_list -> itemCreate($i, 1, -itemtype=>'text', -text=>$plugins[$i], -style=>$style); |
| 108 |
my $description = eval "\$Ifeffit::Plugins::Filetype::Athena::$plugins[$i]::description"; |
| 109 |
$plugin_list -> itemCreate($i, 2, -itemtype=>'text', -text=>$description, -style=>$style); |
| 110 |
}; |
| 111 |
|
| 112 |
## utilities at bottom of page |
| 113 |
$reg -> Button(-text => 'Return to the main window', |
| 114 |
@button_list, |
| 115 |
-background => $config{colors}{background2}, |
| 116 |
-activebackground => $config{colors}{activebackground2}, |
| 117 |
-command => sub{ &reset_window($reg, "plugin registry", 0) }) |
| 118 |
-> pack(-side=>'bottom', -fill=>'x'); |
| 119 |
$reg -> Button(-text=>'Document section: plugins', @button_list, |
| 120 |
-command=>sub{pod_display("import::plugin.pod")}) |
| 121 |
-> pack(-side=>'bottom', -fill=>'x'); |
| 122 |
my $fr = $reg -> Frame() |
| 123 |
-> pack(-side=>'bottom', -fill=>'x'); |
| 124 |
$fr -> Button(-text => 'Register all', |
| 125 |
-width => 12, |
| 126 |
-command => sub{ |
| 127 |
foreach my $i (0..$#plugins) { $button[$i] -> select; }; |
| 128 |
my $file = $groups{"Default Parameters"} -> find('athena', 'plugins'); |
| 129 |
tied( %plugin_params )->WriteConfig($file); |
| 130 |
Echo("Registered all plugins for use."); |
| 131 |
}) |
| 132 |
-> pack(-side=>'left', -fill=>'x', -expand=>1); |
| 133 |
$fr -> Button(-text => 'Un-register all', |
| 134 |
-width => 12, |
| 135 |
-command => sub{ |
| 136 |
foreach my $i (0..$#plugins) { $button[$i] -> deselect; }; |
| 137 |
my $file = $groups{"Default Parameters"} -> find('athena', 'plugins'); |
| 138 |
tied( %plugin_params )->WriteConfig($file); |
| 139 |
Echo("Un-registered all plugins."); |
| 140 |
}) |
| 141 |
-> pack(-side=>'left', -fill=>'x', -expand=>1) |
| 142 |
|
| 143 |
}; |
| 144 |
|
| 145 |
sub anchor_registry { |
| 146 |
## this first bit swiped from HList.pm |
| 147 |
my $w = shift; |
| 148 |
my $Ev = $w->XEvent; |
| 149 |
delete $w->{'shiftanchor'}; |
| 150 |
#my $entry = $w->GetNearest($Ev->y, 1); |
| 151 |
my $entry = $w->nearest($Ev->y); |
| 152 |
return unless (defined($entry) and ($entry >= 0)); |
| 153 |
print $entry, $/; |
| 154 |
$w->anchorSet($entry); |
| 155 |
$w->selectionSet($entry); |
| 156 |
my $pick = $w -> selectionGet; |
| 157 |
($pick = $pick->[0]) if (ref($pick) =~ /ARRAY/); # Tk 800 returns a scalar |
| 158 |
# Tk 804 returns an array ref |
| 159 |
my $id = "Ifeffit/Plugins/Filetype/Athena/".$plugins[$pick].".pm"; |
| 160 |
my $file = $INC{$id} || File::Spec->catfile($groups{"Default Parameters"} -> find('athena', 'userfiletypedir'), $plugins[$pick].".pm"); |
| 161 |
pod_display($file); |
| 162 |
}; |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
## END OF PLUGIN REGISTRY SUBSECTION |
| 167 |
########################################################################################## |