Tab Enabling/Disabling commands

Bob Sneidar bobs at twft.com
Tue May 1 13:25:30 EDT 2012


This is getting embarrassing. Seems that setting wholeMatches to true prevented finding a tab item that was preceded by a "(" which is the disabling character for a menu item. If I can't find it, I can't re-enable it! This should resolve that problem: 

ON disableTab theTabPanel, theTab
   IF theTabPanel is empty THEN exit disableTab
   IF not there is a button theTabPanel THEN exit disableTab
   put the text of button theTabPanel into theTabOptions
   
   IF theTab is "All" THEN
      REPEAT WITH i = 1 to the number of lines of theTabOptions
         IF char 1 of line i of theTabOptions is not "(" THEN
            put "(" before line i of theTabOptions
         END IF
      END REPEAT
   ELSE
      SWITCH 
         CASE theTab is a number
            IF theTab > the number of lines of theTabOptions OR theTab = 0 THEN exit disableTab
            IF char 1 of line theTab of theTabOptions is not "(" THEN
               put "(" before line theTab of theTabOptions
            END IF
            break
         CASE theTab is not a number
            set wholematches to true
            put lineoffset(theTab, theTabOptions) into theTabLine
            IF theTabLine = 0 THEN exit disableTab
            put "(" before line theTabLine of theTabOptions
            break
      END SWITCH
   END IF
   
   set the text of button theTabPanel to theTabOptions
END disableTab

ON enableTab theTabPanel, theTab
   put the text of button theTabPanel into theTabOptions
   
   IF theTab is "All" THEN
      REPEAT WITH i = 1 to the number of lines of theTabOptions
         IF char 1 of line i of theTabOptions is "(" THEN
            put empty into char 1 of line i of theTabOptions
         END IF
      END REPEAT
   ELSE
      SWITCH 
         CASE theTab is a number
            IF theTab > the number of lines of theTabOptions OR theTab = 0 THEN exit enableTab
            IF char 1 of line theTab of theTabOptions is "(" THEN
               put empty into char 1 of line theTab of theTabOptions
            END IF
            break
         CASE theTab is not a number
            set wholematches to true
            put lineoffset("(" & theTab, theTabOptions) into theTabLine -- DUH!
            IF theTabLine = 0 THEN exit enableTab
            put empty into char 1 of line theTabLine of theTabOptions
            break
      END SWITCH
   END IF
   
   set the text of button theTabPanel to theTabOptions
END enableTab





More information about the use-livecode mailing list