Keeping trackk of tabs in TabbedComponent


#1

i have a problem with keeping a list of tabs in this component.

I create a list of max 512 tabs and this is a MAX value of all possible tabs, now i want keep track and have UNIQUE ID’s of all tabs (and thus all component ID’s in those tabs).

I noticed that when i delete a tab, the index list of tabs gets reorganized for ex. in case of 7 tabs when i delete the number 5 tab the number 6 tab becomes number 5 and number 7 becomes number 6. The indexes get reorganized. This makes impossible (or at least i htink for now) to keep track of all IDs. Here is what i want to get in pseudo code

/* somehwere in the class constructor */
Panel *panelsPtr[512]; /* my own component for each tab */
TabbedComponent *tabs; /* the component for tabs */

zeroAll (panelsPtr); /* sets all values to 0 in the table */

/* button listener methods */
if (addTabButtonPressed)
{
    for (x=0; x<512; x++)
    {
       if (panelsPtr[x] == 0) /* this place is free in the index table */
       panelsPtr[x] = new Panel(x);
       tabs->addTab ("a panel", Colours::white, panelsPtr[x], false, x); /* addTab() method */
    }
}

if (deleteTabButtonPressed)
{
     x = tabs->getCurrentTabIndex();
     if (x >= 0)
     {
        tabs->removeTab(x);
        panelsPtr[x] = 0; /* indicate that a place in a table is now free */
     }
}

now this works, but when a user selects a tab and deletes more than one tab everything gets messed up cause only one element in the panelsPtr table get’s zero’ed out (because of the internal index realignment). I was wondering if there is a simple way to keep track of those indexes within the tabs component, or should i implement my own internal methods + variables to do so. Hope this is clear enough.


#2

Sounds like you’re over-complicating things a lot. If you need to get the ID of one of the tabs, you could just call getTabContentComponent() to get the component, dynamic_cast it to whatever your own class is, and get the ID from the object itself…?


#3