Ticket #7051: Deskbar Persist Expanded State 8.diff

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

Implemented the speed-up I commented on above. When expanding items go through the fExpandedItems list bottom up matching the fExpando list so that the items are in the same order. Also when a sig is found expand the item and then delete the signature from the list so that it is not considered in later loop iterations. This patch includes the same improvements of the last patch, it is just adds a small performance improvement.

  • src/apps/deskbar/BarApp.cpp

    diff --git src/apps/deskbar/BarApp.cpp src/apps/deskbar/BarApp.cpp
    index 58664f7..9f42ca3 100644
    TBarApp::TBarApp()  
    9595    InitSettings();
    9696    InitIconPreloader();
    9797
     98    fBarWindow = new TBarWindow();
     99
    98100    be_roster->StartWatching(this);
    99101
    100102    gLocalizedNamePreferred
    TBarApp::TBarApp()  
    119121
    120122    fSwitcherMessenger = BMessenger(new TSwitchManager(fSettings.switcherLoc));
    121123
    122     fBarWindow = new TBarWindow();
    123124    fBarWindow->Show();
    124125
     126    // Call UpdatePlacement() after the window is shown because expanded apps
     127    // need to resize the window.
     128    if (fBarWindow->Lock()) {
     129        BarView()->UpdatePlacement();
     130        fBarWindow->Unlock();
     131    }
     132
    125133    // this messenger now targets the barview instead of the
    126134    // statusview so that all additions to the tray
    127135    // follow the same path
    TBarApp::AddTeam(team_id team, uint32 flags, const char* sig, entry_ref* ref)  
    645653
    646654    sBarTeamInfoList.AddItem(barInfo);
    647655
     656    if (fSettings.expandNewTeams)
     657        BarView()->AddExpandedItem(sig);
     658
    648659    int32 subsCount = sSubscribers.CountItems();
    649660    if (subsCount > 0) {
    650661        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..e6d9f39 100644
    const int32 kDefaultRecentAppCount = 10;  
    6868
    6969const int32 kMenuTrackMargin = 20;
    7070
     71
    7172TBarView::TBarView(BRect frame, bool vertical, bool left, bool top,
    7273        bool showInterval, uint32 state, float, bool showTime)
    7374    : BView(frame, "BarView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW),
    TBarView::~TBarView()  
    99100{
    100101    delete fDragMessage;
    101102    delete fCachedTypesList;
     103
     104    RemoveExpandedItems();
    102105}
    103106
    104107
    TBarView::GetPreferredWindowSize(BRect screenFrame, float* width, float* height)  
    405408            windowHeight = screenFrame.bottom;
    406409            windowWidth = fBarMenuBar->Frame().Width();
    407410        } else if (fState == kExpandoState) {
    408             if (fVertical)
     411            if (fVertical) {
    409412                // top left or right
    410413                windowHeight = fExpando->Frame().bottom;
    411             else {
     414            } else {
    412415                // top or bottom, full
    413416                fExpando->CheckItemSizes(0);
    414417                windowHeight = kHModeHeight;
    TBarView::ChangeState(int32 state, bool vertical, bool left, bool top)  
    528531    PlaceBeMenu();
    529532    PlaceTray(vertSwap, leftSwap, screenFrame);
    530533
    531     // 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     }
     534    // Keep track of which apps are expanded
     535    SaveExpandedItems();
    549536
    550537    PlaceApplicationBar(screenFrame);
    551538    SizeWindow(screenFrame);
    552539    PositionWindow(screenFrame);
    553540    Window()->UpdateIfNeeded();
    554541
    555     // 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);
     542    // Re-expand apps
     543    ExpandItems();
     544    Invalidate();
     545}
     546
     547
     548void
     549TBarView::SaveExpandedItems()
     550{
     551    if (fExpando == NULL || fExpando->CountItems() <= 0)
     552        return;
     553
     554    // Get a list of the signatures of expanded apps. Can't use
     555    // team_id because there can be more than one team per application
     556    for (int32 i = 0; i < fExpando->CountItems(); i++) {
     557        TTeamMenuItem* teamItem
     558            = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(i));
     559
     560        if (teamItem != NULL && teamItem->IsExpanded())
     561            AddExpandedItem(teamItem->Signature());
     562    }
     563}
     564
     565
     566void
     567TBarView::RemoveExpandedItems()
     568{
     569    while (!fExpandedItems.IsEmpty())
     570        delete static_cast<BString*>(fExpandedItems.RemoveItem((int32)0));
     571    fExpandedItems.MakeEmpty();
     572}
     573
     574
     575void
     576TBarView::ExpandItems()
     577{
     578    if (fExpando == NULL || !fVertical || !Expando()
     579        || !static_cast<TBarApp*>(be_app)->Settings()->superExpando
     580        || fExpandedItems.CountItems() <= 0)
     581        return;
     582
     583    // Start at the 'bottom' of the list working up.
     584    // Prevents being thrown off by expanding items.
     585    for (int32 i = fExpando->CountItems() - 1; i >= 0; i--) {
     586        TTeamMenuItem* teamItem
     587            = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(i));
     588
     589        if (teamItem != NULL) {
     590            // Start at the 'bottom' of the fExpandedItems list working up
     591            // matching the order of the fExpando list in the outer loop.
     592            for (int32 j = fExpandedItems.CountItems() - 1; j >= 0; j--) {
     593                BString* itemSig =
     594                    static_cast<BString*>(fExpandedItems.ItemAt(j));
     595
     596                if (itemSig->Compare(teamItem->Signature()) == 0) {
     597                    // Found it, expand the item and delete signature from
     598                    // the list so that we don't consider it for later items.
     599                    teamItem->ToggleExpandState(false);
     600                    fExpandedItems.RemoveItem(j);
     601                    delete itemSig;
    569602                    break;
    570603                }
    571604            }
    572605        }
     606    }
    573607
    574         // Clean up expanded signature list.
    575         while (!expandedItems.IsEmpty()) {
    576             delete static_cast<BString*>(expandedItems.RemoveItem((int32)0));
    577         }
     608    // Clean up the expanded items list
     609    RemoveExpandedItems();
    578610
    579         fExpando->SizeWindow();
     611    fExpando->SizeWindow();
     612}
     613
     614
     615void
     616TBarView::AddExpandedItem(const char* signature)
     617{
     618    bool shouldAdd = true;
     619
     620    for (int32 i = 0; i < fExpandedItems.CountItems(); i++) {
     621        BString *itemSig = static_cast<BString*>(fExpandedItems.ItemAt(i));
     622        if (itemSig->Compare(signature) == 0) {
     623            // already in the list, don't add the signature
     624            shouldAdd = false;
     625            break;
     626        }
    580627    }
    581628
    582     Invalidate();
     629    if (shouldAdd)
     630        fExpandedItems.AddItem(static_cast<void*>(new BString(signature)));
    583631}
    584632
    585633
  • src/apps/deskbar/BarView.h

    diff --git src/apps/deskbar/BarView.h src/apps/deskbar/BarView.h
    index 9e165cb..5939a65 100644
    class TBarView : public BView {  
    141141        TExpandoMenuBar* ExpandoMenuBar() const;
    142142        TBarMenuBar* BarMenuBar() const;
    143143        TDragRegion* DragRegion() const { return fDragRegion; }
    144            
     144        void AddExpandedItem(const char* signature);
     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 RemoveExpandedItems();
     157        void ExpandItems();
    154158
    155159        TBarMenuBar* fBarMenuBar;
    156160        TExpandoMenuBar* fExpando;
    class TBarView : public BView {  
    177181        uint32 fMaxRecentApps;
    178182
    179183        TTeamMenuItem* fLastDragItem;
     184        BList fExpandedItems;
    180185};
    181186
    182187