Thomas Adam tho...@fvwm.org wrote:
package Test;
Will need better namespacing.
changed it to package MenuConfig;
use File::Basename;
use strict;
use warnings;
added
my $selected = `fvwm-menu-desktop --get-menus selected`;
How long do these commands take to run in backticks? If long,
perhaps use
IPC::Run?
marginal:
Backticks:
all menus: 0.63 s
selected menus: 0.29 s
both menus: 0.92 s
IPC::Run:
all menus: 0.62 s
all menus: 0.28 s
both menus: 0.90 s
Furthermore IPC::Run isn't installed by default and in older distributions
not available only on CPAN.
my ($filename, $directories, $suffix) = fileparse($path,
qr/\.[^.]*/);
Why qr?
From perldoc: ... qr matched against the end of the $filename. The
matching portion is removed and becomes the $suffix.
push (@{$all_menus{$directories}{$i}}, $filename);
push (@{$all_menus{$directories}{$i}}, $name);
push (@{$all_menus{$directories}{$i}}, off);
push (@{...}, ($foo, $bar, hello));
changed
if (exists $selected__menus{$directories}) {
foreach my $hit (@{$selected__menus{$directories}}) {
Better:
foreach my $foo (...)
{
next if !defined $bar;
...
}
changed
You need to use FvwmPerl here for this.
In the next step with the module.
Btw. I altered the script from
ftp://ftp.fvwm.org/pub/fvwm/devel/sources/tests/perl/xmessage.fpl
and no, I don't reinvented the wheel as you see. Ok, it's not the
best way ... give me some time to put this in a correct module,
ok? But for now it is a usable approach. Or not?
Fixed script is attached.
@Dan:
I found a wrong typo in the manpage. Please change
Module FvwmPerl -l fvwm-menu-desktop-gui.fpl
to
Module FvwmPerl -l fvwm-menu-desktop-config.fpl
Thanks.
Thomas
# This script generates a FvwmForm similar to the FvwmForm-Desktop by
# Dan Espen but insert the found xdg menus dynamically into the Form
# before processed.
# Author: Thomas Funk t.f...@web.de
# Version: 1.1
package MenuConfig;
use File::Basename;
use strict;
use warnings;
#open(MSG ,[path]/log.txt) || die Error $!;
my $all = `fvwm-menu-desktop --get-menus all`;
my $selected = `fvwm-menu-desktop --get-menus selected`;
my @all_filelist = split(/ /,$all);
my @selected_filelist = split(/ /,$selected);
my %all_menus = ();
my %selected__menus = ();
my $max_length = 0;
foreach my $path (@selected_filelist) {
my ($filename, $directories, $suffix) = fileparse($path, qr/\.[^.]*/);
push (@{$selected__menus{$directories}}, $filename);
}
my $i = 1;
foreach my $path (@all_filelist) {
my $name = MEN . $i;
# qr matched against the end of the $filename.
# The matching portion is removed and becomes the $suffix.
my ($filename, $directories, $suffix) = fileparse($path, qr/\.[^.]*/);
push (@{$all_menus{$directories}{$i}}, ($filename, $name, off));
next if !defined $selected__menus{$directories};
foreach my $hit (@{$selected__menus{$directories}}) {
if ($filename eq $hit) {
pop (@{$all_menus{$directories}{$i}});
push (@{$all_menus{$directories}{$i}}, on);
}
}
$max_length = length($filename) if ($max_length length($filename));
$i++;
}
my $fvwmform_commands =
DestroyModuleConfig FvwmForm-Desktop: *
*FvwmForm-Desktop: WarpPointer
*FvwmForm-Desktop: Title\fvwm-menu-desktop options\
*FvwmForm-Desktop: Line center
*FvwmForm-Desktop: Text \-- Multiple Menu
--\
*FvwmForm-Desktop: Line
;
foreach my $key (sort( keys %all_menus)) {
$fvwmform_commands .=
*FvwmForm-Desktop: Line left
*FvwmForm-Desktop: Text \Menus in $key\
*FvwmForm-Desktop: Line left
*FvwmForm-Desktop: Selection meth multiple
;
my $m_count = 0;
foreach my $count (sort(keys %{$all_menus{$key}})) {
my @menu = @{$all_menus{$key}{$count}};
my $newstring = $menu[0] . ' ' x eval($max_length-length($menu[0]));
$fvwmform_commands .= *FvwmForm-Desktop: Choice $menu[1] $menu[1]
$menu[2] \$newstring\
;
$m_count++;
if ($m_count == 3) {
$fvwmform_commands .=
*FvwmForm-Desktop: Line left
*FvwmForm-Desktop: Selection meth multiple
;
$m_count = 0;
}
}
$fvwmform_commands .=
*FvwmForm-Desktop: Line left
*FvwmForm-Desktop: Text \ \
;
}
$fvwmform_commands .=
*FvwmForm-Desktop: Line center
*FvwmForm-Desktop: Text \-- General Options
--\
*FvwmForm-Desktop: Line
*FvwmForm-Desktop: Line Left
*FvwmForm-Desktop: Text \Use Icons in Menus? \
*FvwmForm-Desktop: SelectionSelItype single
*FvwmForm-Desktop: Choice IconsOn IconsOnon \Yes\
*FvwmForm-Desktop: Choice IconsOff IconsOff off \No\
*FvwmForm-Desktop: Line left
*FvwmForm-Desktop: Text \Icon size:\
*FvwmForm-Desktop: InputSize 2 \\