Tab Enabling/Disabling commands

Bob Sneidar bobs at twft.com
Mon Apr 30 17:02:39 EDT 2012


Hi all. A while ago someone started a thread about how to enable or disable individual tabs in a Tab Panel. I wrote these two admittedly simple functions to accommodate this. They both take two parameters, the name of the tab panel, and the tab item, which can be a number or the name of the tab. If you pass "All" for the tab item, it will enable or disable all the tabs. There is some basic error chacking. They will ignore a number that is out of bounds of the number of tab items, or a tab name that does not exist, or a tab panel that does not exist as a button. They will ignore enabling or disabling of tabs that are already enable/disabled respectively. (Already shot myself in the foot with that one!) 

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
            put lineoffset(theTab, theTabOptions) into theTabLine
            IF theTabLine = 0 THEN exit disableTab
            IF char 1 of line theTabLine of theTabOptions is not "(" THEN
               put "(" before line theTabLine of theTabOptions
            END IF
            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
            put lineoffset(theTab, theTabOptions) into theTabLine
            IF theTabLine = 0 THEN exit enableTab
            IF char 1 of line theTabLine of theTabOptions is "(" THEN
               put empty into char 1 of line theTabLine of theTabOptions
            END IF
            break
      END SWITCH
   END IF
   set the text of button theTabPanel to theTabOptions
END enableTab



More information about the use-livecode mailing list