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: Selection SelItype single
*FvwmForm-Desktop: Choice IconsOn IconsOn on \"Yes\"
*FvwmForm-Desktop: Choice IconsOff IconsOff off \"No\"
*FvwmForm-Desktop: Line left
*FvwmForm-Desktop: Text \"Icon size: \"
*FvwmForm-Desktop: Input Size 2 \"\"
*FvwmForm-Desktop: Text \" (in pixels. Default is 24)
*FvwmForm-Desktop: Line Left
*FvwmForm-Desktop: Text \"Use Titles in Menus? \"
*FvwmForm-Desktop: Selection SelItype single
*FvwmForm-Desktop: Choice TitlesOn TitlesOn on \"Yes\"
*FvwmForm-Desktop: Choice TitlesOff TitlesOff off \"No\"
*FvwmForm-Desktop: Line Left
*FvwmForm-Desktop: Text \"Insert Menu(s) in a Menu? \"
*FvwmForm-Desktop: Selection SelItype single
*FvwmForm-Desktop: Choice InsertOn InsertOn off \"Yes\"
*FvwmForm-Desktop: Choice InsertOff InsertOff on \"No\"
*FvwmForm-Desktop: Text \"Top title name: \"
*FvwmForm-Desktop: Input InMenu 20 \"\"
*FvwmForm-Desktop: Line left
*FvwmForm-Desktop: Text \"Used Icon theme: \"
*FvwmForm-Desktop: Input Theme 20 \"\"
*FvwmForm-Desktop: Text \" (Theme name for icon selection)\"
*FvwmForm-Desktop: Line left
*FvwmForm-Desktop: Line
*FvwmForm-Desktop: Line center
*FvwmForm-Desktop: Text \"------------------ Single Menu
------------------\"
*FvwmForm-Desktop: Line
*FvwmForm-Desktop: Line Left
*FvwmForm-Desktop: Text \"If you want a single menu only deselect all
menus above and fill out\"
*FvwmForm-Desktop: Line Left
*FvwmForm-Desktop: Text \"the fields below. But remember, if the menu
not exist, nothing happens.\"
*FvwmForm-Desktop: Line
*FvwmForm-Desktop: Line left
*FvwmForm-Desktop: Text \"Menu Top Title:\"
*FvwmForm-Desktop: Input Title 20 \"\"
*FvwmForm-Desktop: Text \" (Eg. FvwmTestMenu)
*FvwmForm-Desktop: Line left
*FvwmForm-Desktop: Text \"Install-Prefix:\"
*FvwmForm-Desktop: Input Installprefix 20 \"\"
*FvwmForm-Desktop: Text \" (Eg. /etc/xdg/menus/)
*FvwmForm-Desktop: Line left
*FvwmForm-Desktop: Text \"Desktop: \"
*FvwmForm-Desktop: Input Desktop 20 \"\"
*FvwmForm-Desktop: Text \" (Eg. gnome, kde, xfce, lxde)
*FvwmForm-Desktop: Line left
*FvwmForm-Desktop: Text \"Menutype: \"
*FvwmForm-Desktop: Input Menutype 20 \"\"
*FvwmForm-Desktop: Text \" (Eg. applications, settings)
*FvwmForm-Desktop: Line left
*FvwmForm-Desktop: Text \"Output path: \"
*FvwmForm-Desktop: Input Path 25 \"\$FVWM_USERDIR/.menu\"
*FvwmForm-Desktop: Text \" (Full path to store output)\"
*FvwmForm-Desktop: Line left
*FvwmForm-Desktop: Line
*FvwmForm-Desktop: Line center
*FvwmForm-Desktop: Text \"------------------ Actions
------------------\"
*FvwmForm-Desktop: Line left
*FvwmForm-Desktop: Line
*FvwmForm-Desktop: Line center
*FvwmForm-Desktop: Selection SelItype single
*FvwmForm-Desktop: Choice MultiOn MultiOn on \"Multiple\"
*FvwmForm-Desktop: Choice MultiOff MultiOff off \"Single\"
*FvwmForm-Desktop: Button continue \"Generate Menu(s)\"
*FvwmForm-Desktop: Command PipeRead 'fvwm-menu-desktop \\
\$(IconsOn\?--enable-mini-icons )\\
\$(Size\?-s \$(Size) )\\
\$(TitlesOn\?--with-titles )\\
\$(InsertOn\?--insert-in-menu \$(InMenu) )\\
\$(Title\?--title \$(Title) )\\
\$(Installprefix\?--install-prefix \$(Installprefix) )\\
\$(Desktop\?--desktop \$(Desktop) )\\
\$(Menutype\?--menutype \$(Menutype) )\\
\$(Theme\?--theme \$(Theme) )\\
\$(MultiOn\?--set-menus \"\\
";
foreach my $key (keys %all_menus) {
foreach my $file (keys %{$all_menus{$key}}) {
my @menu = @{$all_menus{$key}{$file}};
$fvwmform_commands .= "\$($menu[1]\?$key$menu[0].menu )\\\n";
}
}
$fvwmform_commands .= "\") \$(Path\? > \$(Path)) 2> ~/.xsession-errors && echo
\"Read \$(Path\? \$(Path))\"'
*FvwmForm-Desktop: Line expand
*FvwmForm-Desktop: Button continue \"Save Settings\"
# Before saving the data, remove any previously saved data:
*FvwmForm-Desktop: Command DestroyModuleConfig FvwmForm-Desktop: *
*FvwmForm-Desktop: Command !( /bin/echo \\
\"# This file last created by FvwmForm-Desktop on: `/bin/date`.\"; /bin/echo
\\
";
foreach my $key (keys %all_menus) {
foreach my $count (keys %{$all_menus{$key}}) {
my @menu = @{$all_menus{$key}{$count}};
$fvwmform_commands .= " '*FvwmForm-DesktopDefault: $menu[1]
\$($menu[1]\?on) ' ; /bin/echo \\
";
}
}
$fvwmform_commands .= ") > \$FVWM_USERDIR/.FvwmForm-Desktop
*FvwmForm-Desktop: Command !( /bin/echo \\
'*FvwmForm-DesktopDefault: IconsOn \$(IconsOn\?on) ' ; /bin/echo \\
'*FvwmForm-DesktopDefault: IconsOff \$(IconsOff\?on) ' ; /bin/echo \\
'*FvwmForm-DesktopDefault: Size \$(Size) ' ; /bin/echo \\
'*FvwmForm-DesktopDefault: TitlesOn \$(TitlesOn\?on) ' ; /bin/echo \\
'*FvwmForm-DesktopDefault: TitlesOff \$(TitlesOff\?on) ' ; /bin/echo \\
'*FvwmForm-DesktopDefault: InsertOn \$(InsertOn\?on) ' ; /bin/echo \\
'*FvwmForm-DesktopDefault: InsertOff \$(InsertOff\?on) ' ; /bin/echo \\
'*FvwmForm-DesktopDefault: InMenu \$(InMenu) ' ; /bin/echo \\
'*FvwmForm-DesktopDefault: Theme \$(Theme) ' \\
) >> \$FVWM_USERDIR/.FvwmForm-Desktop
*FvwmForm-Desktop: Command !( /bin/echo \\
'*FvwmForm-DesktopDefault: Title \$(Title) ' ; /bin/echo \\
'*FvwmForm-DesktopDefault: Installprefix \$(Installprefix) ' ; /bin/echo \\
'*FvwmForm-DesktopDefault: Desktop \$(Desktop) ' ; /bin/echo \\
'*FvwmForm-DesktopDefault: Menutype \$(Menutype) ' ; /bin/echo \\
'*FvwmForm-DesktopDefault: Path \$(Path) ' ; /bin/echo \\
'*FvwmForm-DesktopDefault: MultiOn \$(MultiOn\?on) ' ; /bin/echo \\
'*FvwmForm-DesktopDefault: MultiOff \$(MultiOff\?on) ' \\
) >> \$FVWM_USERDIR/.FvwmForm-Desktop
*FvwmForm-Desktop: Button restart \"Reset\"
*FvwmForm-Desktop: Command Nop
*FvwmForm-Desktop: Button continue \"Help\"
*FvwmForm-Desktop: Command Exec exec xterm -g 100x50 -n \"Help
fvwm-menu-desktop\" -T \"Help fvwm-menu-desktop\" -e \"man fvwm-menu-desktop\" &
*FvwmForm-Desktop: Button quit \"Quit\"
*FvwmForm-Desktop: Command Nop
# Tell FvwmForm-Desktop to read vars from .FvwmForm-DesktopDefault file:
*FvwmForm-Desktop: UseData .FvwmForm-Desktop *FvwmForm-DesktopDefault
";
# We are just asked to open a window, give fvwm a chance to do it
::unlock();
::command(qq[
$fvwmform_commands
FvwmForm FvwmForm-Desktop
]);
#print MSG "$fvwmform_commands\n\n";
#close(MSG);