2424# Name: obmenu-generator
2525# License: GPLv3
2626# Created: 25 March 2011
27- # Latest edit: 23 June 2020
27+ # Latest edit: 29 November 2020
2828# https://github.com/trizen/obmenu-generator
2929
3030use 5.014;
@@ -469,18 +469,21 @@ if ($with_icons) {
469469 my %fast_cache ;
470470
471471 sub check_icon {
472- $fast_cache {$_ [0] // return ' ' } //= ($cache_db {$_ [0]} //= get_icon_path($_ [0]));
472+ $fast_cache {$_ [0] // return undef } //= ($cache_db {$_ [0]} //= get_icon_path($_ [0]));
473473 }
474474}
475475
476476sub begin_category {
477- $with_icons
478- ? <<"MENU_WITH_ICON"
479- <menu id="${\r and()}" icon="${ \ch eck_icon( $_ [1])} " label="$_ [0]">
477+ if ( $with_icons and defined ( my $icon_path = check_icon( $_ [1]))) {
478+ <<"MENU_WITH_ICON" ;
479+ <menu id="${\r and()}" icon="$icon_path " label="$_ [0]">
480480MENU_WITH_ICON
481- : <<"MENU" ;
481+ }
482+ else {
483+ <<"MENU" ;
482484 <menu id="${\r and()}" label="$_ [0]">
483485MENU
486+ }
484487}
485488
486489my %categories ;
@@ -575,13 +578,16 @@ ITEM
575578 }
576579 elsif (exists $schema -> {item }) {
577580 my ($command , $label , $icon ) = @{$schema -> {item }};
578- $generated_menu .= $with_icons
579- ? <<"ITEM_WITH_ICON"
580- <item label="$label " icon="${ \ch eck_icon( $icon )} "><action name="Execute"><command><![CDATA[$command ]]></command></action></item>
581+ if ( $with_icons and defined ( my $icon_path = check_icon( $icon ))) {
582+ $generated_menu .= <<"ITEM_WITH_ICON" ;
583+ <item label="$label " icon="$icon_path "><action name="Execute"><command><![CDATA[$command ]]></command></action></item>
581584ITEM_WITH_ICON
582- : <<"ITEM" ;
585+ }
586+ else {
587+ $generated_menu .= <<"ITEM" ;
583588 <item label="$label "><action name="Execute"><command><![CDATA[$command ]]></command></action></item>
584589ITEM
590+ }
585591 }
586592 elsif (exists $schema -> {sep }) {
587593 $generated_menu .=
@@ -603,13 +609,16 @@ ITEM
603609 }
604610 elsif (exists $schema -> {exit }) {
605611 my ($label , $icon ) = @{$schema -> {exit }};
606- $generated_menu .= $with_icons
607- ? <<"EXIT_WITH_ICON"
608- <item label="$label " icon="${ \ch eck_icon( $icon )} "><action name="Exit"/></item>
612+ if ( $with_icons and defined ( my $icon_path = check_icon( $icon ))) {
613+ $generated_menu .= <<"EXIT_WITH_ICON" ;
614+ <item label="$label " icon="$icon_path "><action name="Exit"/></item>
609615EXIT_WITH_ICON
610- : <<"EXIT" ;
616+ }
617+ else {
618+ $generated_menu .= <<"EXIT" ;
611619 <item label="$label "><action name="Exit"/></item>
612620EXIT
621+ }
613622 }
614623 elsif (exists $schema -> {raw }) {
615624 $generated_menu .= qq[ $schema ->{raw}\n ] ;
@@ -620,21 +629,29 @@ EXIT
620629 }
621630 elsif (exists $schema -> {pipe }) {
622631 my ($command , $label , $icon ) = @{$schema -> {pipe }};
623- $generated_menu .= $with_icons
624- ? <<"PIPE_WITH_ICON"
625- <menu id="${\r and()}" label="$label " execute="$command " icon="${ \ch eck_icon( $icon )} "/>
632+ if ( $with_icons and defined ( my $icon_path = check_icon( $icon ))) {
633+ $generated_menu .= <<"PIPE_WITH_ICON" ;
634+ <menu id="${\r and()}" label="$label " execute="$command " icon="$icon_path "/>
626635PIPE_WITH_ICON
627- : <<"PIPE" ;
636+ }
637+ else {
638+ $generated_menu .= <<"PIPE" ;
628639 <menu id="${\r and()}" label="$label " execute="$command "/>
629640PIPE
641+ }
630642 }
631643 elsif (exists $schema -> {obgenmenu }) {
632644 my ($name , $icon ) = ref ($schema -> {obgenmenu }) eq ' ARRAY' ? @{$schema -> {obgenmenu }} : $schema -> {obgenmenu };
633- $generated_menu .= ($with_icons ? <<"MENU_WITH_ICON" : <<"MENU" );
634- <menu id="${\r and()}" label="$name " icon="${\ch eck_icon($icon )}">
645+ if ($with_icons and defined (my $icon_path = check_icon($icon ))) {
646+ $generated_menu .= <<"MENU_WITH_ICON" ;
647+ <menu id="${\r and()}" label="$name " icon="$icon_path ">
635648MENU_WITH_ICON
649+ }
650+ else {
651+ $generated_menu .= <<"MENU" ;
636652 <menu id="${\r and()}" label="$name ">
637653MENU
654+ }
638655
639656 $generated_menu .= ($with_icons ? <<"ITEMS_WITH_ICONS" : <<"ITEMS" );
640657 <item label="Menu Schema" icon="${\ch eck_icon('text-x-generic')}"><action name="Execute"><command><![CDATA[$CONFIG {editor} $schema_file ]]></command></action></item>
0 commit comments