home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Editores / Perl5 / perl / lib / site / auto / Tk / Menu / FindName.al < prev    next >
Encoding:
Text File  |  1997-08-10  |  981 b   |  35 lines

  1. # NOTE: Derived from ..\blib\lib\Tk\Menu.pm.  Changes made here will be lost.
  2. package Tk::Menu;
  3.  
  4. # FindName --
  5. # Given a menu and a text string, return the index of the menu entry
  6. # that displays the string as its label. If there is no such entry,
  7. # return an empty string. This procedure is tricky because some names
  8. # like "active" have a special meaning in menu commands, so we can't
  9. # always use the "index" widget command.
  10. #
  11. # Arguments:
  12. # menu - Name of the menu widget.
  13. # s - String to look for.
  14. sub FindName
  15. {
  16.  my $menu = shift;
  17.  my $s = shift;
  18.  my $i = undef;
  19.  if ($s !~ /^active$|^last$|^none$|^[0-9]|^@/)
  20.   {
  21.    $i = eval {local $SIG{__DIE__};  $menu->index($s) };
  22.    return $i;
  23.   }
  24.  my $last = $menu->index("last");
  25.  return if ($last eq 'none');
  26.  for ($i = 0;$i <= $last;$i += 1)
  27.   {
  28.    my $label = eval {local $SIG{__DIE__};  $menu->entrycget($i,"-label") };
  29.    return $i if (defined $label && $label eq $s);
  30.   }
  31.  return undef;
  32. }
  33.  
  34. 1;
  35.