Ticket #7051: Deskbar Persist Expanded State 4.diff
File Deskbar Persist Expanded State 4.diff, 6.8 KB (added by , 13 years ago) |
---|
-
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) 645 645 646 646 sBarTeamInfoList.AddItem(barInfo); 647 647 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 648 672 int32 subsCount = sSubscribers.CountItems(); 649 673 if (subsCount > 0) { 650 674 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; 68 68 69 69 const int32 kMenuTrackMargin = 20; 70 70 71 BList TBarView::sExpandedItems; 72 73 71 74 TBarView::TBarView(BRect frame, bool vertical, bool left, bool top, 72 75 bool showInterval, uint32 state, float, bool showTime) 73 76 : BView(frame, "BarView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW), … … TBarView::TBarView(BRect frame, bool vertical, bool left, bool top, 92 95 fDragRegion->AddChild(fReplicantTray); 93 96 if (fTrayLocation != 0) 94 97 AddChild(fDragRegion); 98 99 sExpandedItems.MakeEmpty(); 95 100 } 96 101 97 102 … … TBarView::~TBarView() 99 104 { 100 105 delete fDragMessage; 101 106 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(); 102 112 } 103 113 104 114 … … TBarView::ChangeState(int32 state, bool vertical, bool left, bool top) 529 539 PlaceTray(vertSwap, leftSwap, screenFrame); 530 540 531 541 // 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(); 549 543 550 544 PlaceApplicationBar(screenFrame); 551 545 SizeWindow(screenFrame); … … TBarView::ChangeState(int32 state, bool vertical, bool left, bool top) 553 547 Window()->UpdateIfNeeded(); 554 548 555 549 // 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 555 void 556 TBarView::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; 569 580 break; 570 581 } 571 582 } 572 }573 583 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 } 577 589 } 590 } 591 } 592 593 594 void 595 TBarView::ExpandItems() 596 { 597 if (!fExpando || !fVertical || !Expando() 598 || !static_cast<TBarApp*>(be_app)->Settings()->superExpando 599 || sExpandedItems.CountItems() <= 0) 600 return; 578 601 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 } 580 620 } 581 621 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(); 583 628 } 584 629 585 630 -
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 { 141 141 TExpandoMenuBar* ExpandoMenuBar() const; 142 142 TBarMenuBar* BarMenuBar() const; 143 143 TDragRegion* DragRegion() const { return fDragRegion; } 144 144 static BList sExpandedItems; 145 145 146 private: 146 147 friend class TBeMenu; 147 148 friend class PreferencesWindow; … … class TBarView : public BView { 151 152 void PlaceBeMenu(); 152 153 void PlaceTray(bool vertSwap, bool leftSwap, BRect screenFrame); 153 154 void PlaceApplicationBar(BRect screenFrame); 155 void SaveExpandedItems(); 156 void ExpandItems(); 154 157 155 158 TBarMenuBar* fBarMenuBar; 156 159 TExpandoMenuBar* fExpando;