Ticket #7051: Deskbar Persist Expanded State 4.diff

File Deskbar Persist Expanded State 4.diff, 6.8 KB (added by jscipione, 13 years ago)

If the expandNewTeams flag is set add new teams to the expanded list so that they will get expanded when you go to vertical expando mode. If you unexpanded the item already it will remember that and not re-expand it.

  • src/apps/deskbar/BarApp.cpp

    diff --git src/apps/deskbar/BarApp.cpp src/apps/deskbar/BarApp.cpp
    index 58664f7..f8d631e 100644
    TBarApp::AddTeam(team_id team, uint32 flags, const char* sig, entry_ref* ref)  
    645645
    646646    sBarTeamInfoList.AddItem(barInfo);
    647647
     648    // If expandNewTeams is set, add the item to the list of
     649    // expanded items.
     650    if (fSettings.expandNewTeams) {
     651        // Expanded, if signature is not in the list add it
     652        bool shouldAdd = true;
     653
     654        for (int32 sigIndex = BarView()->sExpandedItems.CountItems();
     655            sigIndex-- > 0;) {
     656            BString *signature =
     657                (BString *)BarView()->sExpandedItems.ItemAt(sigIndex);
     658            if (signature->ICompare(sig) == 0) {
     659                // already in the list, don't add the signature
     660                shouldAdd = false;
     661                break;
     662            }
     663        }
     664
     665        if (shouldAdd) {
     666            // Add the signature to the list
     667            BString* signature = new BString(sig);
     668            BarView()->sExpandedItems.AddItem((void*)signature);
     669        }
     670    }
     671
    648672    int32 subsCount = sSubscribers.CountItems();
    649673    if (subsCount > 0) {
    650674        for (int32 i = 0; i < subsCount; i++) {
  • src/apps/deskbar/BarView.cpp

    diff --git src/apps/deskbar/BarView.cpp src/apps/deskbar/BarView.cpp
    index 6e71956..1c57cac 100644
    const int32 kDefaultRecentAppCount = 10;  
    6868
    6969const int32 kMenuTrackMargin = 20;
    7070
     71BList TBarView::sExpandedItems;
     72
     73
    7174TBarView::TBarView(BRect frame, bool vertical, bool left, bool top,
    7275        bool showInterval, uint32 state, float, bool showTime)
    7376    : BView(frame, "BarView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW),
    TBarView::TBarView(BRect frame, bool vertical, bool left, bool top,  
    9295    fDragRegion->AddChild(fReplicantTray);
    9396    if (fTrayLocation != 0)
    9497        AddChild(fDragRegion);
     98
     99    sExpandedItems.MakeEmpty();
    95100}
    96101
    97102
    TBarView::~TBarView()  
    99104{
    100105    delete fDragMessage;
    101106    delete fCachedTypesList;
     107
     108    // Clean up the expanded items list
     109    while (!sExpandedItems.IsEmpty())
     110        delete static_cast<BString*>(sExpandedItems.RemoveItem((int32)0));
     111    sExpandedItems.MakeEmpty();
    102112}
    103113
    104114
    TBarView::ChangeState(int32 state, bool vertical, bool left, bool top)  
    529539    PlaceTray(vertSwap, leftSwap, screenFrame);
    530540
    531541    // We need to keep track of what apps are expanded.
    532     BList expandedItems;
    533     BString* signature = NULL;
    534     if (fVertical && Expando()
    535         && static_cast<TBarApp*>(be_app)->Settings()->superExpando) {
    536         // Get a list of the signatures of expanded apps. Can't use
    537         // team_id because there can be more than one team per application
    538         if (fVertical && Expando() && vertical && fExpando) {
    539             for (int index = 0; index < fExpando->CountItems(); index++) {
    540                 TTeamMenuItem* item
    541                     = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(index));
    542                 if (item != NULL && item->IsExpanded()) {
    543                     signature = new BString(item->Signature());
    544                     expandedItems.AddItem((void*)signature);
    545                 }
    546             }
    547         }
    548     }
     542    SaveExpandedItems();
    549543
    550544    PlaceApplicationBar(screenFrame);
    551545    SizeWindow(screenFrame);
    TBarView::ChangeState(int32 state, bool vertical, bool left, bool top)  
    553547    Window()->UpdateIfNeeded();
    554548
    555549    // Re-expand those apps.
    556     if (expandedItems.CountItems() > 0) {
    557         for (int sigIndex = expandedItems.CountItems(); sigIndex-- > 0;) {
    558             signature = static_cast<BString*>(expandedItems.ItemAt(sigIndex));
    559             if (signature == NULL)
    560                 continue;
    561 
    562             // Start at the 'bottom' of the list working up.
    563             // Prevents being thrown off by expanding items.
    564             for (int teamIndex = fExpando->CountItems(); teamIndex-- > 0;) {
    565                 TTeamMenuItem* item
    566                     = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex));
    567                 if (item != NULL && !signature->Compare(item->Signature())) {
    568                     item->ToggleExpandState(false);
     550    ExpandItems();
     551    Invalidate();
     552}
     553
     554
     555void
     556TBarView::SaveExpandedItems()
     557{
     558    if (!fExpando)
     559        return;
     560
     561    // Get a list of the signatures of expanded apps. Can't use
     562    // team_id because there can be more than one team per application
     563    for (int32 teamIndex = fExpando->CountItems(); teamIndex-- > 0;) {
     564        TTeamMenuItem* teamItem
     565            = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex));
     566        if (teamItem == NULL || teamItem->Signature() == NULL ||
     567            *teamItem->Signature() == '\0')
     568            continue;
     569
     570        if (teamItem->IsExpanded()) {
     571            // Expanded, if signature is not in the list add it
     572            bool shouldAdd = true;
     573
     574            for (int32 sigIndex = sExpandedItems.CountItems();
     575                sigIndex-- > 0;) {
     576                BString *signature = (BString *)sExpandedItems.ItemAt(sigIndex);
     577                if (signature->ICompare(teamItem->Signature()) == 0) {
     578                    // already in the list, don't add the signature
     579                    shouldAdd = false;
    569580                    break;
    570581                }
    571582            }
    572         }
    573583
    574         // Clean up expanded signature list.
    575         while (!expandedItems.IsEmpty()) {
    576             delete static_cast<BString*>(expandedItems.RemoveItem((int32)0));
     584            if (shouldAdd) {
     585                // Add the signature to the list
     586                BString* signature = new BString(teamItem->Signature());
     587                sExpandedItems.AddItem((void*)signature);
     588            }
    577589        }
     590    }
     591}
     592
     593
     594void
     595TBarView::ExpandItems()
     596{
     597    if (!fExpando || !fVertical || !Expando()
     598        || !static_cast<TBarApp*>(be_app)->Settings()->superExpando
     599        || sExpandedItems.CountItems() <= 0)
     600        return;
    578601
    579         fExpando->SizeWindow();
     602    // Start at the 'bottom' of the list working up.
     603    // Prevents being thrown off by expanding items.
     604    for (int32 teamIndex = fExpando->CountItems(); teamIndex-- > 0;) {
     605        TTeamMenuItem* teamItem
     606            = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex));
     607        if (teamItem == NULL || teamItem->Signature() == NULL
     608            || *teamItem->Signature() == '\0')
     609            continue;
     610
     611        for (int32 sigIndex = sExpandedItems.CountItems(); sigIndex-- > 0;) {
     612            BString* signature = (BString *)sExpandedItems.ItemAt(sigIndex);
     613
     614            if (signature->ICompare(teamItem->Signature()) == 0) {
     615                teamItem->ToggleExpandState(false);
     616                sExpandedItems.RemoveItem(sigIndex);
     617                break;
     618            }
     619        }
    580620    }
    581621
    582     Invalidate();
     622    // Clean up the expanded items list
     623    while (!sExpandedItems.IsEmpty())
     624        delete static_cast<BString*>(sExpandedItems.RemoveItem((int32)0));
     625    sExpandedItems.MakeEmpty();
     626
     627    fExpando->SizeWindow();
    583628}
    584629
    585630
  • src/apps/deskbar/BarView.h

    diff --git src/apps/deskbar/BarView.h src/apps/deskbar/BarView.h
    index 9e165cb..158b28d 100644
    class TBarView : public BView {  
    141141        TExpandoMenuBar* ExpandoMenuBar() const;
    142142        TBarMenuBar* BarMenuBar() const;
    143143        TDragRegion* DragRegion() const { return fDragRegion; }
    144            
     144        static BList sExpandedItems;
     145
    145146    private:
    146147        friend class TBeMenu;
    147148        friend class PreferencesWindow;
    class TBarView : public BView {  
    151152        void PlaceBeMenu();
    152153        void PlaceTray(bool vertSwap, bool leftSwap, BRect screenFrame);
    153154        void PlaceApplicationBar(BRect screenFrame);
     155        void SaveExpandedItems();
     156        void ExpandItems();
    154157
    155158        TBarMenuBar* fBarMenuBar;
    156159        TExpandoMenuBar* fExpando;