calmar <[EMAIL PROTECTED]> writes:

> Hi,
> I'm wondering if there is any interest in a little patch at the
> fvwm-menu-directory.
>
So I added `icon support'.
those new options would be
,----
| --exec-gen=program1:ext1/ext2/ext3+program2:ext1:ext2 ...
`----

then to those programs it's possible to assign a icon
,----
| --icon-gen=program1:icon.xpm+program2:icon2.xmp
`----

so here's the new patch (the hold had anyway a fault, because I
forgot to comment out a debug print .. line. Even so it worked
anyway.

Anyway,
Best Greetings
marco candrian

--- /usr/local/bin/fvwm-menu-directory2	2004-02-15 19:45:48.000000000 +0100
+++ fvwm-menu-directory	2004-02-27 17:38:32.000000000 +0100
@@ -20,12 +20,18 @@
 my $iconD = "";
 my $iconF = "";
 my $iconA = "";
+### calmar hacked here ###
+my $iconGen = "xv:mini.xv.xpm+mplayer:mini.tetris.xpm"; # prog1:pixmap+prog2:pixmap2
+#######################
 my $home  = $ENV{'HOME'} || '/tmp';
 my $dir   = $home;
 my $xterm = "xterm -e";              # the X terminal program to invoke
 my $execT = $ENV{'SHELL'} || '/bin/sh';
 my $execF = $ENV{'EDITOR'} || "vi";  # the command to execute on plain files
 my $execA = undef;
+### calmar hacked here ###
+my $extGen = "xv:jpg/jpeg+mplayer:mov/mpg/mpeg+xmms:mp3/wav"; # prog1:ext1/ext2/ext3+prog2:ext1/...
+#######################
 my $commT = undef;
 my $commF = undef;
 my $commA = undef;
@@ -53,6 +59,9 @@
 	"icon-dir=s"   => \$iconD,
 	"icon-file=s"  => \$iconF,
 	"icon-app=s"   => \$iconA,
+### calmar hacked here ###
+        "icon-gen=s"       => \$iconGen,
+#######################
 	"dir=s"        => \$dir,
 	"order=i"      => \$order,
 	"all!"         => \$all,
@@ -61,6 +70,9 @@
 	"exec-title=s" => \$execT,
 	"exec-file=s"  => \$execF,
 	"exec-app:s"   => \$execA,
+### calmar hacked here ###
+        "exec-gen=s"       => \$extGen,
+#######################
 	"command-title=s" => \$commT,
 	"command-file=s"  => \$commF,
 	"command-app=s"   => \$commA,
@@ -140,7 +152,6 @@
 $commT = defined $execT? qq(Exec cd "%d"; $execT): "Nop" if !defined $commT;
 $commF = defined $execF? qq(Exec $execF "%f"):     "Nop" if !defined $commF;
 $commA = defined $execA? qq(Exec $execA "%f"):    $commF if !defined $commA;
-
 # manage special directories if needed
 my ($specialDirLines, $specialDirPos, @specialDirs) = ("");
 $specialDirVal = "1,2" if defined $specialDirVal && $specialDirVal eq "";
@@ -195,6 +206,7 @@
 print qq(+ MissingSubmenuFunction FuncFvwmMenuDirectory\n) unless $reuse;
 
 # add a new title (item and separator, or real Title if no action)
+
 my $titleAct = $commT; $titleAct =~ s/%d/$dir/g;
 if ($title ne "") {
 	if ($titleAct eq "") {
@@ -207,6 +219,39 @@
 # add special dirs at the top if needed
 print qq($specialDirLines+ "" Nop\n) if $specialDirPos > 0;
 
+### calmar hacked here ###
+# puts strings like this: xv:jpg/jpeg+mplayer:mov/mpg/mpeg+xmms:mp3 
+# into an hash: --> may uncomment foreach loops below to see output
+	   
+	     my %extHash;
+	     my $prog;
+	     my $ext;
+	     my $rest;
+
+	     foreach (split (/\+/,$extGen)) {
+		 ($prog, $rest) = split ( /:/, $_ , 2);
+		 foreach $ext ( split (m|\/|, $rest)) { 
+		     $extHash{$ext} =  $prog ;
+		 }
+	     }
+
+# do about the same with the $iconGen string variable.
+
+	     my %iconHash;
+	     foreach (split (/\+/,$iconGen)) {
+		 ($prog, $rest) = split ( /:/, $_ , 2);
+		  $iconHash{$prog} =  $rest ;
+	     }
+
+
+#	     foreach $ext ( keys %extHash ) {
+#		 print "ext  $ext:  $extHash{$ext}\n";
+#	     }
+#	     foreach $ext ( keys %iconHash ) {
+#		 print "prog $ext:  $iconHash{$ext}\n";
+#	     }	 	     
+######################
+
 # add directory contents
 foreach (@files) {
 	next if $_ eq '.' or $_ eq '..';
@@ -222,6 +267,18 @@
 		my $isApp = -x && -f;
 		my $iconStr = $isApp && $iconAStr? $iconAStr: $iconFStr;
 		my $fileAct = $isApp? $commA: $commF;
+### calmar hacked here ### 
+# overwrite $fileAct when the file ending and the program are in @extHash
+	        my $fileEnd = lc(); #lowercase $_ 
+                $fileEnd =~ s|.*\.||; # get ending
+		if  ($extHash{$fileEnd}) {
+		    $fileAct = qq(Exec $extHash{$fileEnd} "%f");
+		}
+# when there is a file ending assigned to a program, check for icon for program
+	        if ($iconHash{$extHash{$fileEnd}}) {
+		    $iconStr = qq(%$iconHash{$extHash{$fileEnd}}%);
+		}
+#######################
 		$fileAct =~ s/%f/&escapeFileName($filePath)/ge;
 		print qq(+ "$iconStr$itemStr" $fileAct\n);
 	}


-- 
  calmar 
           (o_         GNU/Linux is GREAT      
           //\                 
           V_/_        http://www.calmar.ws 
                                          

Reply via email to